ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHNodeDump.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHNodeDump.cc
1 #include "PHNodeDump.h"
2 #include "DumpObject.h"
3 
5 #include "DumpBbcVertexMap.h"
6 #include "DumpCaloTriggerInfo.h"
7 #include "DumpEventHeader.h"
8 #include "DumpGlobalVertexMap.h"
9 #include "DumpJetMap.h"
13 #include "DumpPHG4CellContainer.h"
17 #include "DumpPHG4HitContainer.h"
18 #include "DumpPHG4InEvent.h"
21 #include "DumpPHHepMCGenEventMap.h"
22 #include "DumpPdbParameterMap.h"
25 #include "DumpRawTowerContainer.h"
27 #include "DumpRunHeader.h"
28 #include "DumpSvtxTrackMap.h"
29 #include "DumpSvtxVertexMap.h"
30 #include "DumpSyncObject.h"
31 #include "DumpTowerBackground.h"
35 #include "DumpTrkrHitTruthAssoc.h"
36 #include "DumpVariableArray.h"
37 
38 #include <phool/PHIODataNode.h>
39 #include <phool/PHNode.h>
40 #include <phool/getClass.h>
41 #include <phool/phool.h>
42 
43 #include <ffaobjects/RunHeader.h>
44 
45 #include <TObject.h>
46 
47 #include <iostream>
48 #include <string>
49 #include <utility>
50 
51 using namespace std;
52 
54  : runnumber(-9999)
55  , evtsequence(-9999)
56  , fp_precision(-1)
57  , outdir("./")
58 {
59 }
60 
62 {
63  ignore.clear();
64  exclusive.clear();
65  while (dumpthis.begin() != dumpthis.end())
66  {
67  delete dumpthis.begin()->second;
68  dumpthis.erase(dumpthis.begin());
69  }
70  return;
71 }
72 
73 int PHNodeDump::AddIgnore(const string &name)
74 {
75  if (ignore.find(name) != ignore.end())
76  {
77  cout << PHWHERE << " "
78  << name << "already in ignore list" << endl;
79  return -1;
80  }
81  ignore.insert(name);
82  return 0;
83 }
84 
85 int PHNodeDump::Select(const string &name)
86 {
87  if (exclusive.find(name) != exclusive.end())
88  {
89  cout << PHWHERE << " "
90  << name << "already in exclusive list" << endl;
91  return -1;
92  }
93  exclusive.insert(name);
94  return 0;
95 }
96 
98 {
99  RunHeader *runheader = findNode::getClass<RunHeader>(topNode, "RunHeader");
100  if (runheader)
101  {
102  runnumber = runheader->get_RunNumber();
103  }
104  return 0;
105 }
106 
108 {
109  map<string, DumpObject *>::iterator iter;
110  if (node->getType() == "PHIODataNode")
111  {
112  string NodeName = node->getName();
113  iter = dumpthis.find(NodeName);
114  if (iter == dumpthis.end())
115  {
116  cout << "Adding Dump Object for " << NodeName << endl;
117  AddDumpObject(NodeName, node);
118  iter = dumpthis.find(NodeName); // update iterator
119  }
120 
121  if (iter != dumpthis.end())
122  {
123  iter->second->process_event(node);
124  }
125  else
126  {
127  // for (iter = dumpthis.begin(); iter != dumpthis.end(); iter++)
128  // {
129  // cout << "registered: " << iter->second->Name() << endl;
130  // }
131  cout << "Something went wrong with adding Dump Object for " << NodeName
132  << ", it should exist !! Trying to create it again" << endl;
133  AddDumpObject(NodeName, node);
134  }
135  }
136  return;
137 }
138 
140 {
141  map<string, DumpObject *>::iterator iter;
142  for (iter = dumpthis.begin(); iter != dumpthis.end(); ++iter)
143  {
144  iter->second->CloseOutputFile();
145  }
146  return 0;
147 }
148 
149 int PHNodeDump::AddDumpObject(const string &NodeName, PHNode *node)
150 {
151  DumpObject *newdump;
152  string newnode = NodeName;
153  if (!exclusive.empty())
154  {
155  if (exclusive.find(NodeName) == exclusive.end())
156  {
157  cout << "Exclusive find: Ignoring " << NodeName << endl;
158  newdump = new DumpObject(NodeName);
159  newdump->NoOutput();
160  goto initdump;
161  }
162  }
163  if (ignore.find(NodeName) != ignore.end())
164  {
165  cout << "Ignoring " << NodeName << endl;
166  newdump = new DumpObject(NodeName);
167  }
168  else
169  {
170  if (node->getType() == "PHIODataNode")
171  {
172  // need a static cast since only from DST these guys are of type PHIODataNode<TObject*>
173  // when created they are normally PHIODataNode<PHObject*> but can be anything else as well
174  TObject *tmp = (TObject *) (static_cast<PHIODataNode<TObject> *>(node))->getData();
175  if (tmp->InheritsFrom("AssocInfoContainer"))
176  {
177  newdump = new DumpAssocInfoContainer(NodeName);
178  }
179  else if (tmp->InheritsFrom("BbcVertexMap"))
180  {
181  newdump = new DumpBbcVertexMap(NodeName);
182  }
183  else if (tmp->InheritsFrom("CaloTriggerInfo"))
184  {
185  newdump = new DumpCaloTriggerInfo(NodeName);
186  }
187  else if (tmp->InheritsFrom("EventHeader"))
188  {
189  newdump = new DumpEventHeader(NodeName);
190  }
191  else if (tmp->InheritsFrom("GlobalVertexMap"))
192  {
193  newdump = new DumpGlobalVertexMap(NodeName);
194  }
195  else if (tmp->InheritsFrom("JetMap"))
196  {
197  newdump = new DumpJetMap(NodeName);
198  }
199  else if (tmp->InheritsFrom("ParticleFlowElementContainer"))
200  {
201  newdump = new DumpParticleFlowElementContainer(NodeName);
202  }
203  else if (tmp->InheritsFrom("PdbParameterMap"))
204  {
205  newdump = new DumpPdbParameterMap(NodeName);
206  }
207  else if (tmp->InheritsFrom("PdbParameterMapContainer"))
208  {
209  newdump = new DumpPdbParameterMapContainer(NodeName);
210  }
211  else if (tmp->InheritsFrom("PHG4BlockGeomContainer"))
212  {
213  newdump = new DumpPHG4BlockGeomContainer(NodeName);
214  }
215  else if (tmp->InheritsFrom("PHG4BlockCellGeomContainer"))
216  {
217  newdump = new DumpPHG4BlockCellGeomContainer(NodeName);
218  }
219  else if (tmp->InheritsFrom("PHG4CellContainer"))
220  {
221  newdump = new DumpPHG4CellContainer(NodeName);
222  }
223  else if (tmp->InheritsFrom("PHG4CylinderCellContainer"))
224  {
225  newdump = new DumpPHG4CylinderCellContainer(NodeName);
226  }
227  else if (tmp->InheritsFrom("PHG4CylinderGeomContainer"))
228  {
229  newdump = new DumpPHG4CylinderGeomContainer(NodeName);
230  }
231  else if (tmp->InheritsFrom("PHG4CylinderCellGeomContainer"))
232  {
233  newdump = new DumpPHG4CylinderCellGeomContainer(NodeName);
234  }
235  else if (tmp->InheritsFrom("PHG4HitContainer"))
236  {
237  newdump = new DumpPHG4HitContainer(NodeName);
238  }
239  else if (tmp->InheritsFrom("PHG4InEvent"))
240  {
241  newdump = new DumpPHG4InEvent(NodeName);
242  }
243  else if (tmp->InheritsFrom("PHG4ScintillatorSlatContainer"))
244  {
245  newdump = new DumpPHG4ScintillatorSlatContainer(NodeName);
246  }
247  else if (tmp->InheritsFrom("PHG4TruthInfoContainer"))
248  {
249  newdump = new DumpPHG4TruthInfoContainer(NodeName);
250  }
251  else if (tmp->InheritsFrom("PHHepMCGenEventMap"))
252  {
253  newdump = new DumpPHHepMCGenEventMap(NodeName);
254  }
255  else if (tmp->InheritsFrom("RawClusterContainer"))
256  {
257  newdump = new DumpRawClusterContainer(NodeName);
258  }
259  else if (tmp->InheritsFrom("RawTowerContainer"))
260  {
261  newdump = new DumpRawTowerContainer(NodeName);
262  }
263  else if (tmp->InheritsFrom("RawTowerGeomContainer"))
264  {
265  newdump = new DumpRawTowerGeomContainer(NodeName);
266  }
267  else if (tmp->InheritsFrom("RunHeader"))
268  {
269  newdump = new DumpRunHeader(NodeName);
270  }
271  else if (tmp->InheritsFrom("SvtxTrackMap"))
272  {
273  newdump = new DumpSvtxTrackMap(NodeName);
274  }
275  else if (tmp->InheritsFrom("SvtxVertexMap"))
276  {
277  newdump = new DumpSvtxVertexMap(NodeName);
278  }
279  else if (tmp->InheritsFrom("SyncObject"))
280  {
281  newdump = new DumpSyncObject(NodeName);
282  }
283  else if (tmp->InheritsFrom("TowerBackground"))
284  {
285  newdump = new DumpTowerBackground(NodeName);
286  }
287  else if (tmp->InheritsFrom("TrkrClusterContainer"))
288  {
289  newdump = new DumpTrkrClusterContainer(NodeName);
290  }
291  else if (tmp->InheritsFrom("TrkrClusterHitAssoc"))
292  {
293  newdump = new DumpTrkrClusterHitAssoc(NodeName);
294  }
295  else if (tmp->InheritsFrom("TrkrHitSetContainer"))
296  {
297  newdump = new DumpTrkrHitSetContainer(NodeName);
298  }
299  else if (tmp->InheritsFrom("TrkrHitTruthAssoc"))
300  {
301  newdump = new DumpTrkrHitTruthAssoc(NodeName);
302  }
303  else if (tmp->InheritsFrom("VariableArray"))
304  {
305  newdump = new DumpVariableArray(NodeName);
306  }
307  else
308  {
309  cout << "Registering Dummy for " << NodeName
310  << ", Class: " << tmp->ClassName() << endl;
311  newdump = new DumpObject(NodeName);
312  }
313  }
314  else
315  {
316  cout << "ignoring PHDataNode: " << NodeName << endl;
317  newdump = new DumpObject(NodeName);
318  }
319  }
320 
321 initdump:
322  newdump->SetParentNodeDump(this);
323  newdump->SetOutDir(outdir);
324  newdump->SetPrecision(fp_precision);
325  newdump->Init();
326  dumpthis[newnode] = newdump;
327  return 0;
328 }
329 
330 int PHNodeDump::SetOutDir(const string &dirname)
331 {
332  outdir = dirname;
333  return 0;
334 }