ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4AllDstOutputManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4AllDstOutputManager.cc
2 
3 #include "Fun4AllServer.h"
4 
5 #include <phool/PHNode.h>
7 #include <phool/PHNodeIterator.h>
8 #include <phool/phool.h> // for PHWHERE, PHReadOnly, PHRunTree
9 
10 #include <TSystem.h>
11 
12 #include <cstdlib>
13 #include <iostream>
14 #include <string>
15 
16 using namespace std;
17 
18 Fun4AllDstOutputManager::Fun4AllDstOutputManager(const string &myname, const string &fname)
19  : Fun4AllOutputManager(myname, fname)
20 {
21  dstOut = new PHNodeIOManager(fname, PHWrite);
22  if (!dstOut->isFunctional())
23  {
24  delete dstOut;
25  cout << PHWHERE << " Could not open " << fname
26  << " exiting now" << endl;
27  gSystem->Exit(1);
28  exit(1); // cppcheck does not know gSystem->Exit(1)
29  }
31  return;
32 }
33 
35 {
36  delete dstOut;
37  return;
38 }
39 
40 int Fun4AllDstOutputManager::AddNode(const string &nodename)
41 {
42  savenodes.insert(nodename);
43  return 0;
44 }
45 
46 int Fun4AllDstOutputManager::AddRunNode(const string &nodename)
47 {
48  saverunnodes.insert(nodename);
49  return 0;
50 }
51 
52 int Fun4AllDstOutputManager::StripNode(const string &nodename)
53 {
54  stripnodes.insert(nodename);
55  return 0;
56 }
57 
58 int Fun4AllDstOutputManager::StripRunNode(const string &nodename)
59 {
60  striprunnodes.insert(nodename);
61  return 0;
62 }
63 
65 {
66  delete dstOut;
67  dstOut = new PHNodeIOManager(fname, PHWrite);
68  if (!dstOut->isFunctional())
69  {
70  delete dstOut;
71  dstOut = nullptr;
72  cout << PHWHERE << " Could not open " << fname << endl;
73  return -1;
74  }
75 
77  return 0;
78 }
79 
80 void Fun4AllDstOutputManager::Print(const string &what) const
81 {
82  if (what == "ALL" || what == "WRITENODES")
83  {
84  // vector<string>::const_iterator iter;
85  cout << Name() << " writes " << OutFileName() << endl;
86  if (savenodes.empty())
87  {
88  if (stripnodes.empty())
89  {
90  cout << Name() << ": All Nodes will be written out" << endl;
91  }
92  else
93  {
94  for (auto &nodename : stripnodes)
95  {
96  cout << Name() << ": Node " << nodename << " will be stripped" << endl;
97  }
98  }
99  }
100  else
101  {
102  for (auto &nodename : savenodes)
103  {
104  cout << Name() << ": Node " << nodename << " is written out" << endl;
105  }
106  }
107  }
108  // base class print method
110 
111  return;
112 }
113 
114 // All nodes are set to transient by the framework
115 // here we first change the nodes we want to write out
116 // to persistent and then call the write method
117 // of the io manager
118 // afterwards the nodes we just wrote out are changed back
119 // to transient
120 // if we want to strip nodes (only meaningful if we take the default
121 // that everything is written out), those nodes are declared transient
123 {
124  PHNodeIterator nodeiter(startNode);
125  if (savenodes.empty())
126  {
128  se->MakeNodesPersistent(startNode);
129  if (!stripnodes.empty())
130  {
131  for (auto &nodename : stripnodes)
132  {
133  PHNode *ChosenNode = nodeiter.findFirst("PHIODataNode", nodename);
134  if (ChosenNode)
135  {
136  ChosenNode->makeTransient();
137  }
138  else
139  {
140  if (Verbosity() > 0)
141  {
142  cout << PHWHERE << Name() << ": Node " << nodename
143  << " does not exist" << endl;
144  }
145  }
146  }
147  }
148  }
149  else
150  {
151  for (auto &nodename : savenodes)
152  {
153  PHNode *ChosenNode = nodeiter.findFirst("PHIODataNode", nodename);
154  if (ChosenNode)
155  {
156  ChosenNode->makePersistent();
157  }
158  else
159  {
160  if (Verbosity() > 0)
161  {
162  cout << PHWHERE << Name() << ": Node " << nodename
163  << " does not exist" << endl;
164  }
165  }
166  }
167  }
168  dstOut->write(startNode);
169  // to save some cpu cycles we only make it globally transient if
170  // all nodes have been written (savenodes set is empty)
171  // else we only make the nodes transient which we have written (all
172  // others are transient by construction)
173  if (savenodes.empty())
174  {
176  se->MakeNodesTransient(startNode);
177  }
178  else
179  {
180  for (auto &nodename : savenodes)
181  {
182  PHNode *ChosenNode = nodeiter.findFirst("PHIODataNode", nodename);
183  if (ChosenNode)
184  {
185  ChosenNode->makeTransient();
186  }
187  }
188  }
189  return 0;
190 }
191 
193 {
194  delete dstOut;
195  if (! m_SaveRunNodeFlag)
196  {
197  dstOut = nullptr;
198  return 0;
199  }
202  PHNodeIterator nodeiter(thisNode);
203  if (saverunnodes.empty())
204  {
205  se->MakeNodesPersistent(thisNode);
206  if (!striprunnodes.empty())
207  {
208  for (auto &nodename : striprunnodes)
209  {
210  PHNode *ChosenNode = nodeiter.findFirst("PHIODataNode", nodename);
211  if (ChosenNode)
212  {
213  ChosenNode->makeTransient();
214  }
215  else
216  {
217  if (Verbosity() > 0)
218  {
219  cout << PHWHERE << Name() << ": Node " << nodename
220  << " does not exist" << endl;
221  }
222  }
223  }
224  }
225  }
226  else
227  {
228  for (auto &nodename : saverunnodes)
229  {
230  PHNode *ChosenNode = nodeiter.findFirst("PHIODataNode", nodename);
231  if (ChosenNode)
232  {
233  ChosenNode->makePersistent();
234  }
235  else
236  {
237  if (Verbosity() > 0)
238  {
239  cout << PHWHERE << Name() << ": Node " << nodename
240  << " does not exist" << endl;
241  }
242  }
243  }
244  }
245  dstOut->write(thisNode);
246  se->MakeNodesTransient(thisNode);
247  delete dstOut;
248  dstOut = nullptr;
249  return 0;
250 }