Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:22:01

0001 #include "RunInfoUnpackPRDF.h"
0002 
0003 #include <ffaobjects/EventHeaderv1.h>
0004 
0005 #include <pdbcalbase/PdbParameterMap.h>
0006 
0007 #include <phparameter/PHParameters.h>
0008 
0009 #include <fun4all/Fun4AllBase.h>  // for Fun4AllBase::VERBOSITY_SOME
0010 #include <fun4all/Fun4AllReturnCodes.h>
0011 #include <fun4all/SubsysReco.h>  // for SubsysReco
0012 
0013 #include <phool/PHCompositeNode.h>
0014 #include <phool/PHIODataNode.h>    // for PHIODataNode
0015 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0016 #include <phool/PHObject.h>        // for PHObject
0017 #include <phool/getClass.h>
0018 
0019 #include <Event/Event.h>
0020 #include <Event/EventTypes.h>
0021 #include <Event/packet.h>
0022 
0023 #include <cmath>    // for NAN
0024 #include <cstddef>  // for NULL
0025 #include <iostream>
0026 #include <string>
0027 #include <utility>  // for pair, make_pair
0028 
0029 using namespace std;
0030 
0031 typedef PHIODataNode<PHObject> PHObjectNode_t;
0032 
0033 //____________________________________
0034 RunInfoUnpackPRDF::RunInfoUnpackPRDF()
0035   : SubsysReco("RunInfoUnpackPRDF")
0036   , runinfo_node_name("RUN_INFO")
0037 {
0038 }
0039 
0040 //_____________________________________
0041 int RunInfoUnpackPRDF::InitRun(PHCompositeNode *topNode)
0042 {
0043   CreateNodeTree(topNode);
0044   return Fun4AllReturnCodes::EVENT_OK;
0045 }
0046 
0047 //____________________________________
0048 int RunInfoUnpackPRDF::process_event(PHCompositeNode *topNode)
0049 {
0050   Event *event = findNode::getClass<Event>(topNode, "PRDF");
0051   if (event == NULL)
0052   {
0053     if (Verbosity() >= VERBOSITY_SOME)
0054       cout << "RunInfoUnpackPRDF::Process_Event - Event not found" << endl;
0055     return Fun4AllReturnCodes::DISCARDEVENT;
0056   }
0057 
0058   // construct event info
0059   EventHeaderv1 *eventheader =
0060       findNode::getClass<EventHeaderv1>(topNode, "EventHeader");
0061   if (eventheader)
0062   {
0063     eventheader->set_RunNumber(event->getRunNumber());
0064     eventheader->set_EvtSequence(event->getEvtSequence());
0065     eventheader->set_EvtType(event->getEvtType());
0066     eventheader->set_TimeStamp(event->getTime());
0067     if (Verbosity())
0068     {
0069       eventheader->identify();
0070     }
0071   }
0072 
0073   // search for run info
0074   if (event->getEvtType() != BEGRUNEVENT)
0075   {
0076     return Fun4AllReturnCodes::EVENT_OK;
0077   }
0078   else
0079   {
0080     if (Verbosity() >= VERBOSITY_SOME)
0081     {
0082       cout << "RunInfoUnpackPRDF::process_event - with BEGRUNEVENT events ";
0083       event->identify();
0084     }
0085 
0086     map<int, Packet *> packet_list;
0087 
0088     PHParameters Params("RunInfo");
0089 
0090     for (typ_channel_map::const_iterator it = channel_map.begin();
0091          it != channel_map.end(); ++it)
0092     {
0093       const string &name = it->first;
0094       const channel_info &info = it->second;
0095 
0096       if (packet_list.find(info.packet_id) == packet_list.end())
0097       {
0098         packet_list[info.packet_id] = event->getPacket(info.packet_id);
0099       }
0100 
0101       Packet *packet = packet_list[info.packet_id];
0102 
0103       if (!packet)
0104       {
0105         //          if (Verbosity() >= VERBOSITY_SOME)
0106         cout << "RunInfoUnpackPRDF::process_event - failed to locate packet "
0107              << info.packet_id << " from ";
0108         event->identify();
0109 
0110         Params.set_double_param(name, NAN);
0111         continue;
0112       }
0113 
0114       const int ivalue = packet->iValue(info.offset);
0115 
0116       const double dvalue = ivalue * info.calibration_const;
0117 
0118       if (Verbosity() >= VERBOSITY_SOME)
0119       {
0120         cout << "RunInfoUnpackPRDF::process_event - " << name << " = " << dvalue
0121              << ", raw = " << ivalue << " @ packet " << info.packet_id
0122              << ", offset " << info.offset << endl;
0123       }
0124 
0125       Params.set_double_param(name, dvalue);
0126     }
0127 
0128     for (map<int, Packet *>::iterator it = packet_list.begin();
0129          it != packet_list.end(); ++it)
0130     {
0131       delete it->second;
0132     }
0133 
0134     Params.SaveToNodeTree(topNode, runinfo_node_name);
0135 
0136     if (Verbosity() >= VERBOSITY_SOME)
0137     {
0138       Params.Print();
0139     }
0140   }
0141   return Fun4AllReturnCodes::EVENT_OK;
0142 }
0143 
0144 //_______________________________________
0145 void RunInfoUnpackPRDF::CreateNodeTree(PHCompositeNode *topNode)
0146 {
0147   PHNodeIterator nodeItr(topNode);
0148   // DST node
0149   PHCompositeNode *run_node = static_cast<PHCompositeNode *>(
0150       nodeItr.findFirst("PHCompositeNode", "RUN"));
0151   if (!run_node)
0152   {
0153     cout << "PHComposite node created: RUN" << endl;
0154     run_node = new PHCompositeNode("RUN");
0155     topNode->addNode(run_node);
0156   }
0157 
0158   PdbParameterMap *nodeparams =
0159       findNode::getClass<PdbParameterMap>(run_node, runinfo_node_name);
0160   if (not nodeparams)
0161   {
0162     run_node->addNode(new PHIODataNode<PdbParameterMap>(new PdbParameterMap(),
0163                                                         runinfo_node_name));
0164   }
0165 
0166   // DST node
0167   PHCompositeNode *dst_node = static_cast<PHCompositeNode *>(
0168       nodeItr.findFirst("PHCompositeNode", "DST"));
0169   if (!dst_node)
0170   {
0171     cout << "PHComposite node created: DST" << endl;
0172     dst_node = new PHCompositeNode("DST");
0173     topNode->addNode(dst_node);
0174   }
0175 
0176   EventHeaderv1 *eventheader = new EventHeaderv1();
0177   PHObjectNode_t *EventHeaderNode = new PHObjectNode_t(
0178       eventheader, "EventHeader", "PHObject");  // contain PHObject
0179   dst_node->addNode(EventHeaderNode);
0180 }
0181 
0182 void RunInfoUnpackPRDF::add_channel(
0183     const std::string &name,        //! name of the channel
0184     const int packet_id,            //! packet id
0185     const unsigned int offset,      //! offset in packet data
0186     const double calibration_const  //! conversion constant from integer to
0187                                     //! meaningful value
0188 )
0189 {
0190   channel_map.insert(
0191       make_pair(name, channel_info(packet_id, offset, calibration_const)));
0192 }