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