Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:21:59

0001 #include "MvtxRunInfoUnpackPRDF.h"
0002 
0003 #include <Event/Event.h>
0004 #include <Event/EventTypes.h>
0005 #include <Event/packetConstants.h>
0006 #include <Event/packet.h>
0007 #include <Event/packet_hbd_fpgashort.h>
0008 #include <phool/PHCompositeNode.h>
0009 #include <phool/phool.h>
0010 #include <phool/getClass.h>
0011 #include <phool/recoConsts.h>
0012 #include <fun4all/Fun4AllReturnCodes.h>
0013 #include <pdbcalbase/PdbParameterMap.h>
0014 #include <phparameter/PHParameters.h>
0015 
0016 #include <ffaobjects/EventHeaderv1.h>
0017 
0018 #include <iostream>
0019 #include <string>
0020 #include <cassert>
0021 #include <sstream>
0022 
0023 using namespace std;
0024 
0025 typedef PHIODataNode<PHObject> PHObjectNode_t;
0026 
0027 //____________________________________
0028 MvtxRunInfoUnpackPRDF::MvtxRunInfoUnpackPRDF() :
0029     SubsysReco("MvtxRunInfoUnpackPRDF"),
0030         /*PHCompositeNode **/ dstNode(NULL),
0031         /*Event**/_event(NULL),
0032         /*Packet_hbd_fpgashort**/_packet(NULL)
0033 {
0034 
0035 }
0036 
0037 //____________________________________
0038 int
0039 MvtxRunInfoUnpackPRDF::Init(PHCompositeNode *topNode)
0040 {
0041 
0042     cout << "-----MvtxRunInfoUnpackPRDF::Init-----" << endl;
0043   return Fun4AllReturnCodes::EVENT_OK;
0044 }
0045 
0046 //_____________________________________
0047 int
0048 MvtxRunInfoUnpackPRDF::InitRun(PHCompositeNode *topNode)
0049 {
0050 
0051     CreateNodeTree(topNode);
0052 
0053     cout << "-----MvtxRunInfoUnpackPRDF::Init-----" << endl;
0054   return Fun4AllReturnCodes::EVENT_OK;
0055 }
0056 
0057 //____________________________________
0058 int
0059 MvtxRunInfoUnpackPRDF::process_event(PHCompositeNode *topNode)
0060 {
0061     /*
0062     _event = findNode::getClass<Event>(topNode, "PRDF");
0063     if (_event==0)
0064     {
0065         cout << "MvtxRunInfoUnpackPRDF::Process_Event - Event not found" << endl;
0066         return -1;
0067     }
0068     */
0069 
0070     stringstream ss_packet;
0071     string s_packet;
0072     char par_name[30], par_sval[30], par_unit[30];
0073     int par_ival; 
0074 
0075     Event *event = findNode::getClass<Event>(topNode, "PRDF");
0076     if ( event==NULL )
0077     {
0078         if ( Verbosity()>=VERBOSITY_SOME )
0079             cout << "RunInfoUnpackPRDF::Process_Event - Event not found" << endl;
0080         return Fun4AllReturnCodes::DISCARDEVENT;
0081     }
0082 
0083     EventHeaderv1 *eventheader = findNode::getClass<EventHeaderv1>(topNode, "EventHeader");
0084     if ( eventheader )
0085     {
0086         eventheader->set_RunNumber(event->getRunNumber());
0087         eventheader->set_EvtSequence(event->getEvtSequence());
0088         eventheader->set_EvtType(event->getEvtType());
0089         eventheader->set_TimeStamp(event->getTime());
0090         if ( verbosity )
0091         {   
0092             eventheader->identify();
0093         }   
0094     }
0095 
0096     if ( event->getEvtType()!=BEGRUNEVENT )
0097         return Fun4AllReturnCodes::EVENT_OK;
0098     else
0099     {
0100         if ( verbosity>=VERBOSITY_SOME )
0101         {
0102             cout << "RunInfoUnpackPRDF::process_event - with BEGRUNEVENT events ";
0103             event->identify();
0104         }
0105 
0106         PHParameters Params("RunInfo");
0107 
0108         Packet *packet = event->getPacket(910);
0109         if ( !packet )
0110         {
0111             cout << "RunInfoUnpackPRDF::process_event - failed to locate packet 910" << endl;
0112         }else{
0113             ss_packet.clear();
0114             packet->dump(ss_packet);
0115 
0116             getline(ss_packet,s_packet);
0117             sscanf(s_packet.c_str(), "%s = %i %s", par_name, &par_ival, par_unit);
0118             Params.set_int_param(par_name,par_ival);
0119 
0120             getline(ss_packet,s_packet);
0121             sscanf(s_packet.c_str(), "%s = %s", par_name, par_sval);
0122             Params.set_string_param(par_name,par_sval);
0123         }//910
0124 
0125         packet = event->getPacket(920);
0126         if ( !packet )
0127         {
0128             cout << "RunInfoUnpackPRDF::process_event - failed to locate packet 910" << endl;
0129             //Params.set_double_param(name, NAN);
0130         }else{
0131             ss_packet.clear();
0132             packet->dump(ss_packet);
0133 
0134             getline(ss_packet,s_packet);
0135             sscanf(s_packet.c_str(), "%s = %i", par_name, &par_ival);
0136             Params.set_int_param(par_name,par_ival);
0137 
0138             getline(ss_packet,s_packet);
0139             sscanf(s_packet.c_str(), "%s = %s", par_name, par_sval);
0140             Params.set_string_param(par_name,par_sval);
0141 
0142             getline(ss_packet,s_packet);
0143             sscanf(s_packet.c_str(), "%s = %i %s", par_name, &par_ival, par_unit);
0144             Params.set_int_param(par_name,par_ival);
0145 
0146             while ( getline(ss_packet,s_packet) )
0147             {
0148                 sscanf(s_packet.c_str(), "%s = %i", par_name, &par_ival);
0149                 Params.set_int_param(par_name,par_ival);
0150             }
0151         }//920
0152 
0153         packet = event->getPacket(930);
0154         if ( !packet )
0155         {
0156             cout << "RunInfoUnpackPRDF::process_event - failed to locate packet 930" << endl;
0157             //Params.set_double_param(name, NAN);
0158         }else{
0159             ss_packet.clear();
0160             packet->dump(ss_packet);
0161 
0162             while ( getline(ss_packet,s_packet) )
0163             {
0164                 sscanf(s_packet.c_str(), "%s = %i %s", par_name, &par_ival, par_unit);
0165                 Params.set_int_param(par_name,par_ival);
0166             }
0167         }//930
0168 
0169         Params.SaveToNodeTree(topNode, "RUN_INFO");
0170 
0171         if ( verbosity>=VERBOSITY_SOME )
0172         {
0173             Params.Print();
0174         }
0175             
0176     }//
0177 
0178 
0179   return Fun4AllReturnCodes::EVENT_OK;
0180 }
0181 
0182 //_______________________________________
0183 void
0184 MvtxRunInfoUnpackPRDF::CreateNodeTree(PHCompositeNode *topNode)
0185 {
0186 
0187   PHNodeIterator nodeItr(topNode);
0188 
0189   PHCompositeNode *run_node = static_cast<PHCompositeNode *>(nodeItr.findFirst("PHCompositeNode", "RUN"));
0190   if (!run_node)
0191   {
0192     cout << "PHComposite node created: RUN" << endl;
0193     run_node = new PHCompositeNode("RUN");
0194     topNode->addNode(run_node);
0195   }
0196 
0197   PdbParameterMap *nodeparams = findNode::getClass<PdbParameterMap>(run_node,"RUN_INFO");
0198     if (!nodeparams)
0199     {
0200         run_node->addNode(new PHIODataNode<PdbParameterMap>(new PdbParameterMap(),"RUN_INFO"));
0201     }
0202 
0203   //DST node
0204   PHCompositeNode *dst_node = static_cast<PHCompositeNode *>(nodeItr.findFirst("PHCompositeNode", "DST"));
0205   if (!dst_node)
0206   {
0207     cout << "PHComposite node created: DST" << endl;
0208     dst_node = new PHCompositeNode("DST");
0209     topNode->addNode(dst_node);
0210   }
0211 
0212   EventHeaderv1 *eventheader = new EventHeaderv1();
0213   PHObjectNode_t *EventHeaderNode = new PHObjectNode_t(eventheader, "EventHeader", "PHObject");  // contain PHObject
0214   dst_node->addNode(EventHeaderNode);
0215 
0216 }
0217 
0218 //___________________________________
0219 int
0220 MvtxRunInfoUnpackPRDF::End(PHCompositeNode *topNode)
0221 {
0222     cout << "-----MvtxRunInfoUnpackPRDF::End-----" << endl;
0223 
0224   return Fun4AllReturnCodes::EVENT_OK;
0225 }
0226