Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:16:06

0001 #include "EventCombiner.h"
0002 
0003 #include <fun4all/Fun4AllInputManager.h>
0004 #include <fun4all/Fun4AllReturnCodes.h>
0005 #include <fun4all/SubsysReco.h>  // for SubsysReco
0006 
0007 #include <phool/PHCompositeNode.h>
0008 #include <phool/PHDataNode.h>
0009 #include <phool/PHNode.h>          // for PHNode
0010 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0011 #include <phool/getClass.h>
0012 
0013 #include <Event/Event.h>
0014 #include <Event/oncsEvent.h>
0015 
0016 #include <TSystem.h>
0017 
0018 #include <iostream>  // for operator<<, endl, basic_ost...
0019 #include <utility>   // for pair
0020 #include <vector>    // for vector
0021 
0022 //____________________________________________________________________________..
0023 EventCombiner::EventCombiner(const std::string &name)
0024   : SubsysReco(name)
0025 {
0026 }
0027 
0028 //____________________________________________________________________________..
0029 int EventCombiner::Init(PHCompositeNode *topNode)
0030 {
0031   PHNodeIterator iter(topNode);
0032   PHDataNode<Event> *PrdfNode = dynamic_cast<PHDataNode<Event> *>(iter.findFirst("PHDataNode", m_PrdfOutputNodeName));
0033   if (!PrdfNode)
0034   {
0035     PHDataNode<Event> *newNode = new PHDataNode<Event>(m_Event, m_PrdfOutputNodeName, "Event");
0036     std::cout << "Creating new prdfnode 0x" << std::hex << newNode << std::dec << std::endl;
0037     topNode->addNode(newNode);
0038   }
0039 
0040   std::cout << "EventCombiner::Init(PHCompositeNode *topNode) Initializing" << std::endl;
0041   return Fun4AllReturnCodes::EVENT_OK;
0042 }
0043 
0044 //____________________________________________________________________________..
0045 int EventCombiner::process_event(PHCompositeNode *topNode)
0046 {
0047   std::vector<Event *> subeventeventvec;
0048   unsigned int total_length = 0;
0049   for (const auto &nam : m_PrdfInputNodeNameSet)
0050   {
0051     Event *evt = findNode::getClass<Event>(topNode, nam);
0052     subeventeventvec.push_back(evt);
0053     total_length += evt->getEvtLength();
0054   }
0055   // safety belts
0056   int eventno = subeventeventvec[0]->getEvtSequence();
0057   for (auto &e : subeventeventvec)
0058   {
0059     if (e->getEvtSequence() != eventno)
0060     {
0061       std::cout << "Event number mismatch, first subevt: " << eventno
0062                 << " current subevt: " << e->getEvtSequence() << std::endl;
0063     }
0064   }
0065 
0066   // lets copy them all together
0067   int nwout;
0068   int current = 0;
0069   m_OutArray = new int[total_length];
0070   // the first Copy is without "DATA", "DATA" skips the first few words which contain event number, length, etc
0071   subeventeventvec[0]->Copy(m_OutArray, total_length, &nwout);
0072   current = nwout;
0073   for (unsigned int icnt = 1; icnt < subeventeventvec.size(); icnt++)
0074   {
0075     subeventeventvec[icnt]->Copy(&m_OutArray[current], total_length - current, &nwout, "DATA");
0076     current += nwout;
0077     m_OutArray[0] += nwout;
0078   }
0079 
0080   PHNodeIterator iter(topNode);
0081   PHDataNode<Event> *PrdfNode = dynamic_cast<PHDataNode<Event> *>(iter.findFirst("PHDataNode", m_PrdfOutputNodeName));
0082 
0083   m_Event = new oncsEvent(m_OutArray);
0084   PrdfNode->setData(m_Event);
0085   return Fun4AllReturnCodes::EVENT_OK;
0086 }
0087 
0088 //____________________________________________________________________________..
0089 // the events need to be cleaned up outside of the framework
0090 // in principal this is a prdf input manager which has to clear the data it puts on the tree
0091 int EventCombiner::ResetEvent(PHCompositeNode *topNode)
0092 {
0093   PHNodeIterator iter(topNode);
0094   PHDataNode<Event> *PrdfNode = dynamic_cast<PHDataNode<Event> *>(iter.findFirst("PHDataNode", m_PrdfOutputNodeName));
0095   PrdfNode->setData(nullptr);  // set pointer in Node to nullptr before deleting it
0096   delete m_Event;
0097   m_Event = nullptr;
0098   delete[] m_OutArray;
0099   return Fun4AllReturnCodes::EVENT_OK;
0100 }
0101 
0102 void EventCombiner::AddPrdfInputNodeName(const std::string &name)
0103 {
0104   auto result = m_PrdfInputNodeNameSet.insert(name);
0105   if (!result.second)
0106   {
0107     std::cout << "EventCombiner::AddPrdfInputNodeName: Prdf Input Node name "
0108               << name << " already in list - that will wreak havoc and has to be fixed" << std::endl;
0109     std::cout << "exiting now" << std::endl;
0110     gSystem->Exit(1);
0111   }
0112   else
0113   {
0114     if (Verbosity() > 0)
0115     {
0116       std::cout << "Prdf node " << name << " inserted" << std::endl;
0117     }
0118   }
0119   return;
0120 }
0121 
0122 void EventCombiner::AddPrdfInputNodeFromManager(const Fun4AllInputManager *in)
0123 {
0124   AddPrdfInputNodeName(in->GetString("PRDFNODENAME"));
0125   return;
0126 }