Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventCombiner.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EventCombiner.cc
1 #include "EventCombiner.h"
2 
5 #include <fun4all/SubsysReco.h> // for SubsysReco
6 
8 #include <phool/PHDataNode.h>
9 #include <phool/PHNode.h> // for PHNode
10 #include <phool/PHNodeIterator.h> // for PHNodeIterator
11 #include <phool/getClass.h>
12 
13 #include <Event/Event.h>
14 #include <Event/oncsEvent.h>
15 
16 #include <TSystem.h>
17 
18 #include <iostream> // for operator<<, endl, basic_ost...
19 #include <utility> // for pair
20 #include <vector> // for vector
21 
22 //____________________________________________________________________________..
24  : SubsysReco(name)
25 {
26 }
27 
28 //____________________________________________________________________________..
30 {
31  PHNodeIterator iter(topNode);
32  PHDataNode<Event> *PrdfNode = dynamic_cast<PHDataNode<Event> *>(iter.findFirst("PHDataNode", m_PrdfOutputNodeName));
33  if (!PrdfNode)
34  {
36  std::cout << "Creating new prdfnode 0x" << std::hex << newNode << std::dec << std::endl;
37  topNode->addNode(newNode);
38  }
39 
40  std::cout << "EventCombiner::Init(PHCompositeNode *topNode) Initializing" << std::endl;
42 }
43 
44 //____________________________________________________________________________..
46 {
47  std::vector<Event *> subeventeventvec;
48  unsigned int total_length = 0;
49  for (auto &nam : m_PrdfInputNodeNameSet)
50  {
51  Event *evt = findNode::getClass<Event>(topNode, nam);
52  subeventeventvec.push_back(evt);
53  total_length += evt->getEvtLength();
54  }
55  // safety belts
56  int eventno = subeventeventvec[0]->getEvtSequence();
57  for (auto &e : subeventeventvec)
58  {
59  if (e->getEvtSequence() != eventno)
60  {
61  std::cout << "Event number mismatch, first subevt: " << eventno
62  << " current subevt: " << e->getEvtSequence() << std::endl;
63  }
64  }
65 
66  // lets copy them all together
67  int nwout;
68  int current = 0;
69  m_OutArray = new int[total_length];
70  // the first Copy is without "DATA", "DATA" skips the first few words which contain event number, length, etc
71  subeventeventvec[0]->Copy(m_OutArray, total_length, &nwout);
72  current = nwout;
73  for (unsigned int icnt = 1; icnt < subeventeventvec.size(); icnt++)
74  {
75  subeventeventvec[icnt]->Copy(&m_OutArray[current], total_length - current, &nwout, "DATA");
76  current += nwout;
77  m_OutArray[0] += nwout;
78  }
79 
80  PHNodeIterator iter(topNode);
81  PHDataNode<Event> *PrdfNode = dynamic_cast<PHDataNode<Event> *>(iter.findFirst("PHDataNode", m_PrdfOutputNodeName));
82 
84  PrdfNode->setData(m_Event);
86 }
87 
88 //____________________________________________________________________________..
89 // the events need to be cleaned up outside of the framework
90 // in principal this is a prdf input manager which has to clear the data it puts on the tree
92 {
93  PHNodeIterator iter(topNode);
94  PHDataNode<Event> *PrdfNode = dynamic_cast<PHDataNode<Event> *>(iter.findFirst("PHDataNode", m_PrdfOutputNodeName));
95  PrdfNode->setData(nullptr); // set pointer in Node to nullptr before deleting it
96  delete m_Event;
97  m_Event = nullptr;
98  delete[] m_OutArray;
100 }
101 
103 {
104  auto result = m_PrdfInputNodeNameSet.insert(name);
105  if (!result.second)
106  {
107  std::cout << "EventCombiner::AddPrdfInputNodeName: Prdf Input Node name "
108  << name << " already in list - that will wreak havoc and has to be fixed" << std::endl;
109  std::cout << "exiting now" << std::endl;
110  gSystem->Exit(1);
111  }
112  else
113  {
114  if (Verbosity() > 0)
115  {
116  std::cout << "Prdf node " << name << " inserted" << std::endl;
117  }
118  }
119  return;
120 }
121 
123 {
124  AddPrdfInputNodeName(in->GetString("PRDFNODENAME"));
125  return;
126 }