Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:12:22

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