Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SingleGl1PoolInput.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SingleGl1PoolInput.cc
1 #include "SingleGl1PoolInput.h"
2 
4 
6 
8 #include <phool/PHIODataNode.h> // for PHIODataNode
9 #include <phool/PHNode.h> // for PHNode
10 #include <phool/PHNodeIterator.h> // for PHNodeIterator
11 #include <phool/PHObject.h> // for PHObject
12 #include <phool/getClass.h>
13 #include <phool/phool.h>
14 
15 #include <Event/Event.h>
16 #include <Event/EventTypes.h>
17 #include <Event/Eventiterator.h>
18 #include <Event/packet.h> // for Packet
19 
20 #include <cstdint> // for uint64_t
21 #include <iostream> // for operator<<, basic_ostream<...
22 #include <iterator> // for reverse_iterator
23 #include <limits> // for numeric_limits
24 #include <memory>
25 #include <set>
26 #include <utility> // for pair
27 
29  : SingleStreamingInput(name)
30 {
32 }
33 
35 {
36  CleanupUsedPackets(std::numeric_limits<uint64_t>::max());
37 }
38 
39 void SingleGl1PoolInput::FillPool(const unsigned int /*nbclks*/)
40 {
41  if (AllDone()) // no more files and all events read
42  {
43  return;
44  }
45  while (GetEventiterator() == nullptr) // at startup this is a null pointer
46  {
47  if (!OpenNextFile())
48  {
49  AllDone(1);
50  return;
51  }
52  }
53  // std::set<uint64_t> saved_beamclocks;
54  while (GetSomeMoreEvents())
55  {
56  std::unique_ptr<Event> evt(GetEventiterator()->getNextEvent());
57  while (!evt)
58  {
59  fileclose();
60  if (!OpenNextFile())
61  {
62  AllDone(1);
63  return;
64  }
65  evt.reset(GetEventiterator()->getNextEvent());
66  }
67  if (Verbosity() > 2)
68  {
69  std::cout << PHWHERE << "Fetching next Event" << evt->getEvtSequence() << std::endl;
70  }
71  RunNumber(evt->getRunNumber());
72  if (GetVerbosity() > 1)
73  {
74  evt->identify();
75  }
76  if (evt->getEvtType() != DATAEVENT)
77  {
79  continue;
80  }
81  int EventSequence = evt->getEvtSequence();
82  Packet *packet = evt->getPacket(14001);
83 
84  if (Verbosity() > 1)
85  {
86  packet->identify();
87  }
88 
89  // by default use previous bco clock for gtm bco
90  Gl1RawHit *newhit = new Gl1RawHitv1();
91  uint64_t gtm_bco = packet->lValue(0, "BCO");
92  newhit->set_bco(packet->lValue(0, "BCO"));
93 
94  m_BeamClockFEE.insert(gtm_bco);
95  m_FEEBclkMap.insert(gtm_bco);
96  if (Verbosity() > 2)
97  {
98  std::cout << PHWHERE << "evtno: " << EventSequence
99  << ", bco: 0x" << std::hex << gtm_bco << std::dec
100  << std::endl;
101  }
102  if (StreamingInputManager())
103  {
104  StreamingInputManager()->AddGl1RawHit(gtm_bco, newhit);
105  }
106  m_Gl1RawHitMap[gtm_bco].push_back(newhit);
107  m_BclkStack.insert(gtm_bco);
108 
109  delete packet;
110  }
111 }
112 
113 void SingleGl1PoolInput::Print(const std::string &what) const
114 {
115  if (what == "ALL" || what == "FEE")
116  {
117  for (const auto &bcliter : m_BeamClockFEE)
118  {
119  std::cout << PHWHERE << "Beam clock 0x" << std::hex << bcliter << std::dec << std::endl;
120  }
121  }
122  if (what == "ALL" || what == "FEEBCLK")
123  {
124  for (auto bcliter : m_FEEBclkMap)
125  {
126  std::cout << PHWHERE << " bclk: 0x"
127  << std::hex << bcliter << std::dec << std::endl;
128  }
129  }
130  if (what == "ALL" || what == "STORAGE")
131  {
132  for (const auto &bcliter : m_Gl1RawHitMap)
133  {
134  std::cout << PHWHERE << "Beam clock 0x" << std::hex << bcliter.first << std::dec << std::endl;
135  for (auto feeiter : bcliter.second)
136  {
137  std::cout << PHWHERE << "fee: " << feeiter->get_bco()
138  << " at " << std::hex << feeiter << std::dec << std::endl;
139  }
140  }
141  }
142  if (what == "ALL" || what == "STACK")
143  {
144  for (auto iter : m_BclkStack)
145  {
146  std::cout << PHWHERE << "stacked bclk: 0x" << std::hex << iter << std::dec << std::endl;
147  }
148  }
149 }
150 
151 void SingleGl1PoolInput::CleanupUsedPackets(const uint64_t bclk)
152 {
153  std::vector<uint64_t> toclearbclk;
154  for (const auto &iter : m_Gl1RawHitMap)
155  {
156  if (iter.first <= bclk)
157  {
158  for (auto pktiter : iter.second)
159  {
160  delete pktiter;
161  }
162  toclearbclk.push_back(iter.first);
163  }
164  else
165  {
166  break;
167  }
168  }
169  // for (auto iter : m_BeamClockFEE)
170  // {
171  // iter.second.clear();
172  // }
173 
174  for (auto iter : toclearbclk)
175  {
176  m_BclkStack.erase(iter);
177  m_BeamClockFEE.erase(iter);
178  m_Gl1RawHitMap.erase(iter);
179  }
180 }
181 
182 bool SingleGl1PoolInput::CheckPoolDepth(const uint64_t bclk)
183 {
184  // if (m_FEEBclkMap.size() < 10)
185  // {
186  // std::cout << PHWHERE << "not all FEEs in map: " << m_FEEBclkMap.size() << std::endl;
187  // return true;
188  // }
189  for (auto iter : m_FEEBclkMap)
190  {
191  if (Verbosity() > 2)
192  {
193  std::cout << PHWHERE << "my bclk 0x" << std::hex << iter
194  << " req: 0x" << bclk << std::dec << std::endl;
195  }
196  if (iter < bclk)
197  {
198  if (Verbosity() > 1)
199  {
200  std::cout << PHWHERE << "FEE " << iter << " beamclock 0x" << std::hex << iter
201  << " smaller than req bclk: 0x" << bclk << std::dec << std::endl;
202  }
203  return false;
204  }
205  }
206  return true;
207 }
208 
210 {
211  // called interactively, to get rid of the current event
212  uint64_t currentbclk = *m_BclkStack.begin();
213  // std::cout << PHWHERE << "clearing bclk 0x" << std::hex << currentbclk << std::dec << std::endl;
214  CleanupUsedPackets(currentbclk);
215  // m_BclkStack.erase(currentbclk);
216  // m_BeamClockFEE.erase(currentbclk);
217  return;
218 }
219 
221 {
222  if (AllDone())
223  {
224  return false;
225  }
226  if (m_Gl1RawHitMap.empty())
227  {
228  return true;
229  }
230 
231  uint64_t lowest_bclk = m_Gl1RawHitMap.begin()->first;
232  lowest_bclk += m_BcoRange;
233  uint64_t last_bclk = m_Gl1RawHitMap.rbegin()->first;
234  if (Verbosity() > 1)
235  {
236  std::cout << PHWHERE << "first bclk 0x" << std::hex << lowest_bclk
237  << " last bco: 0x" << last_bclk
238  << std::dec << std::endl;
239  }
240  if (lowest_bclk >= last_bclk)
241  {
242  return true;
243  }
244  return false;
245 }
246 
248 {
249  PHNodeIterator iter(topNode);
250  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
251  if (!dstNode)
252  {
253  dstNode = new PHCompositeNode("DST");
254  topNode->addNode(dstNode);
255  }
256  PHNodeIterator iterDst(dstNode);
257  PHCompositeNode *detNode = dynamic_cast<PHCompositeNode *>(iterDst.findFirst("PHCompositeNode", "GL1"));
258  if (!detNode)
259  {
260  detNode = new PHCompositeNode("GL1");
261  dstNode->addNode(detNode);
262  }
263  Gl1RawHit *gl1hitcont = findNode::getClass<Gl1RawHit>(detNode, "GL1RAWHIT");
264  if (!gl1hitcont)
265  {
266  gl1hitcont = new Gl1RawHitv1();
267  PHIODataNode<PHObject> *newNode = new PHIODataNode<PHObject>(gl1hitcont, "GL1RAWHIT", "PHObject");
268  detNode->addNode(newNode);
269  }
270 }
271 
272 // void SingleGl1PoolInput::ConfigureStreamingInputManager()
273 // {
274 // if (StreamingInputManager())
275 // {
276 // StreamingInputManager()->SetGl1BcoRange(m_BcoRange);
277 // }
278 // return;
279 // }