ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
Fun4AllPrdfInputManager.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file Fun4AllPrdfInputManager.cc
1
#include "
Fun4AllPrdfInputManager.h
"
2
3
#include <
fun4all/Fun4AllInputManager.h
>
// for Fun4AllInputManager
4
#include <
fun4all/Fun4AllReturnCodes.h
>
5
#include <
fun4all/Fun4AllServer.h
>
6
#include <
fun4all/Fun4AllSyncManager.h
>
7
#include <
fun4all/Fun4AllUtils.h
>
8
9
#include <
ffaobjects/SyncObject.h
>
// for SyncObject
10
#include <
ffaobjects/SyncObjectv1.h
>
11
12
#include <
frog/FROG.h
>
13
14
#include <
phool/PHCompositeNode.h
>
15
#include <
phool/PHDataNode.h
>
16
#include <
phool/PHNode.h
>
// for PHNode
17
#include <
phool/PHNodeIterator.h
>
// for PHNodeIterator
18
#include <
phool/PHObject.h
>
// for PHObject
19
#include <
phool/phool.h
>
// for PHWHERE
20
21
#include <Event/Event.h>
22
#include <Event/Eventiterator.h>
// for Eventiterator
23
#include <Event/fileEventiterator.h>
24
25
#include <cassert>
26
#include <cstdlib>
27
#include <iostream>
// for operator<<, basic_ostream, endl
28
#include <utility>
// for pair
29
30
using namespace
std;
31
32
Fun4AllPrdfInputManager::Fun4AllPrdfInputManager
(
const
string
&
name
,
const
string
&prdfnodename,
const
string
&topnodename)
33
:
Fun4AllInputManager
(name, prdfnodename, topnodename)
34
, m_Segment(-999)
35
, m_EventsTotal(0)
36
, m_EventsThisFile(0)
37
, m_Event(nullptr)
38
, m_SaveEvent(nullptr)
39
, m_EventIterator(nullptr)
40
, m_SyncObject(new
SyncObjectv1
())
41
, m_PrdfNodeName(prdfnodename)
42
{
43
Fun4AllServer
*se =
Fun4AllServer::instance
();
44
m_topNode
= se->
topNode
(
TopNodeName
());
45
PHNodeIterator
iter(
m_topNode
);
46
PHDataNode<Event>
*PrdfNode =
dynamic_cast<
PHDataNode<Event>
*
>
(iter.
findFirst
(
"PHDataNode"
,
m_PrdfNodeName
));
47
if
(!PrdfNode)
48
{
49
PHDataNode<Event>
*newNode =
new
PHDataNode<Event>
(
m_Event
,
m_PrdfNodeName
,
"Event"
);
50
m_topNode
->
addNode
(newNode);
51
}
52
return
;
53
}
54
55
Fun4AllPrdfInputManager::~Fun4AllPrdfInputManager
()
56
{
57
if
(
IsOpen
())
58
{
59
fileclose
();
60
}
61
delete
m_SyncObject
;
62
}
63
64
int
Fun4AllPrdfInputManager::fileopen
(
const
string
&filenam)
65
{
66
if
(
IsOpen
())
67
{
68
cout <<
"Closing currently open file "
69
<<
FileName
()
70
<<
" and opening "
<< filenam << endl;
71
fileclose
();
72
}
73
FileName
(filenam);
74
FROG
frog;
75
string
fname
= frog.
location
(
FileName
());
76
if
(
Verbosity
() > 0)
77
{
78
cout <<
Name
() <<
": opening file "
<<
FileName
() << endl;
79
}
80
int
status = 0;
81
m_EventIterator
=
new
fileEventiterator
(fname.c_str(), status);
82
m_EventsThisFile
= 0;
83
if
(status)
84
{
85
delete
m_EventIterator
;
86
m_EventIterator
=
nullptr
;
87
cout <<
PHWHERE
<<
Name
() <<
": could not open file "
<< fname << endl;
88
return
-1;
89
}
90
pair<int, int> runseg =
Fun4AllUtils::GetRunSegment
(fname);
91
m_Segment
= runseg.second;
92
IsOpen
(1);
93
AddToFileOpened
(fname);
// add file to the list of files which were opened
94
return
0;
95
}
96
97
int
Fun4AllPrdfInputManager::run
(
const
int
nevents)
98
{
99
readagain:
100
if
(!
IsOpen
())
101
{
102
if
(
FileListEmpty
())
103
104
{
105
if
(
Verbosity
() > 0)
106
{
107
cout <<
Name
() <<
": No Input file open"
<< endl;
108
}
109
return
-1;
110
}
111
else
112
{
113
if
(
OpenNextFile
())
114
{
115
cout <<
Name
() <<
": No Input file from filelist opened"
<< endl;
116
return
-1;
117
}
118
}
119
}
120
if
(
Verbosity
() > 3)
121
{
122
cout <<
"Getting Event from "
<<
Name
() << endl;
123
}
124
// cout << "running event " << nevents << endl;
125
PHNodeIterator
iter(
m_topNode
);
126
PHDataNode<Event>
*PrdfNode =
dynamic_cast<
PHDataNode<Event>
*
>
(iter.
findFirst
(
"PHDataNode"
,
m_PrdfNodeName
));
127
if
(
m_SaveEvent
)
// if an event was pushed back, copy saved pointer and reset m_SaveEvent pointer
128
{
129
m_Event
=
m_SaveEvent
;
130
m_SaveEvent
=
nullptr
;
131
m_EventsThisFile
--;
132
m_EventsTotal
--;
133
}
134
else
135
{
136
m_Event
=
m_EventIterator
->
getNextEvent
();
137
}
138
PrdfNode->
setData
(
m_Event
);
139
if
(!
m_Event
)
140
{
141
fileclose
();
142
goto
readagain;
143
}
144
if
(
Verbosity
() > 1)
145
{
146
cout <<
Name
() <<
" PRDF run "
<<
m_Event
->
getRunNumber
() <<
", evt no: "
<<
m_Event
->
getEvtSequence
() << endl;
147
}
148
m_EventsTotal
++;
149
m_EventsThisFile
++;
150
SetRunNumber
(
m_Event
->
getRunNumber
());
151
MySyncManager
()->
PrdfEvents
(
m_EventsThisFile
);
152
MySyncManager
()->
SegmentNumber
(
m_Segment
);
153
MySyncManager
()->
CurrentEvent
(
m_Event
->
getEvtSequence
());
154
m_SyncObject
->
EventCounter
(
m_EventsThisFile
);
155
m_SyncObject
->
SegmentNumber
(
m_Segment
);
156
m_SyncObject
->
RunNumber
(
m_Event
->
getRunNumber
());
157
m_SyncObject
->
EventNumber
(
m_Event
->
getEvtSequence
());
158
// check if the local SubsysReco discards this event
159
if
(
RejectEvent
() !=
Fun4AllReturnCodes::EVENT_OK
)
160
{
161
ResetEvent
();
162
goto
readagain;
163
}
164
return
0;
165
}
166
167
int
Fun4AllPrdfInputManager::fileclose
()
168
{
169
if
(!
IsOpen
())
170
{
171
cout <<
Name
() <<
": fileclose: No Input file open"
<< endl;
172
return
-1;
173
}
174
delete
m_EventIterator
;
175
m_EventIterator
=
nullptr
;
176
IsOpen
(0);
177
// if we have a file list, move next entry to top of the list
178
// or repeat the same entry again
179
UpdateFileList
();
180
return
0;
181
}
182
183
void
Fun4AllPrdfInputManager::Print
(
const
string
&what)
const
184
{
185
Fun4AllInputManager::Print
(what);
186
return
;
187
}
188
189
int
Fun4AllPrdfInputManager::ResetEvent
()
190
{
191
PHNodeIterator
iter(
m_topNode
);
192
PHDataNode<Event>
*PrdfNode =
dynamic_cast<
PHDataNode<Event>
*
>
(iter.
findFirst
(
"PHDataNode"
,
m_PrdfNodeName
));
193
PrdfNode->
setData
(
nullptr
);
// set pointer in Node to nullptr before deleting it
194
delete
m_Event
;
195
m_Event
=
nullptr
;
196
m_SyncObject
->
Reset
();
197
return
0;
198
}
199
200
int
Fun4AllPrdfInputManager::PushBackEvents
(
const
int
i)
201
{
202
// PushBackEvents is supposedly pushing events back on the stack which works
203
// easily with root trees (just grab a different entry) but hard in these HepMC ASCII files.
204
// A special case is when the synchronization fails and we need to only push back a single
205
// event. In this case we save the m_Event pointer as m_SaveEvent which is used in the run method
206
// instead of getting the next event.
207
if
(i > 0)
208
{
209
if
(i == 1 &&
m_Event
)
// check on m_Event pointer makes sure it is not done from the cmd line
210
{
211
m_SaveEvent
=
m_Event
;
212
return
0;
213
}
214
cout <<
PHWHERE
<<
Name
()
215
<<
" Fun4AllPrdfInputManager cannot push back "
<< i <<
" events into file"
216
<< endl;
217
return
-1;
218
}
219
if
(!
m_EventIterator
)
220
{
221
cout <<
PHWHERE
<<
Name
()
222
<<
" no file open"
<< endl;
223
return
-1;
224
}
225
// Skipping events is implemented as
226
// pushing a negative number of events on the stack, so in order to implement
227
// the skipping of events we read -i events.
228
int
nevents = -i;
// negative number of events to push back -> skip num events
229
int
errorflag = 0;
230
while
(nevents > 0 && !errorflag)
231
{
232
m_Event
=
m_EventIterator
->
getNextEvent
();
233
if
(!
m_Event
)
234
{
235
cout <<
"Error after skipping "
<< i - nevents
236
<<
" file exhausted?"
<< endl;
237
errorflag = -1;
238
fileclose
();
239
}
240
else
241
{
242
if
(
Verbosity
() > 3)
243
{
244
cout <<
"Skipping evt no: "
<<
m_Event
->
getEvtSequence
() << endl;
245
}
246
}
247
delete
m_Event
;
248
m_Event
=
nullptr
;
249
nevents--;
250
}
251
return
errorflag;
252
}
253
254
int
Fun4AllPrdfInputManager::GetSyncObject
(
SyncObject
**mastersync)
255
{
256
// here we copy the sync object from the current file to the
257
// location pointed to by mastersync. If mastersync is a 0 pointer
258
// the syncobject is cloned. If mastersync allready exists the content
259
// of syncobject is copied
260
if
(!(*mastersync))
261
{
262
if
(
m_SyncObject
)
263
{
264
*mastersync =
dynamic_cast<
SyncObject
*
>
(
m_SyncObject
->
CloneMe
());
265
assert(*mastersync);
266
}
267
}
268
else
269
{
270
*(*mastersync) = *
m_SyncObject
;
// copy syncobject content
271
}
272
return
Fun4AllReturnCodes::SYNC_OK
;
273
}
274
275
int
Fun4AllPrdfInputManager::SyncIt
(
const
SyncObject
*mastersync)
276
{
277
if
(!mastersync)
278
{
279
cout <<
PHWHERE
<<
Name
() <<
" No MasterSync object, cannot perform synchronization"
<< endl;
280
cout <<
"Most likely your first file does not contain a SyncObject and the file"
<< endl;
281
cout <<
"opened by the Fun4AllDstInputManager with Name "
<<
Name
() <<
" has one"
<< endl;
282
cout <<
"Change your macro and use the file opened by this input manager as first input"
<< endl;
283
cout <<
"and you will be okay. Fun4All will not process the current configuration"
<< endl
284
<< endl;
285
return
Fun4AllReturnCodes::SYNC_FAIL
;
286
}
287
int
iret =
m_SyncObject
->
Different
(mastersync);
288
if
(iret)
289
{
290
cout <<
"big problem"
<< endl;
291
exit
(1);
292
}
293
return
Fun4AllReturnCodes::SYNC_OK
;
294
}
coresoftware
blob
master
offline
framework
fun4allraw
Fun4AllPrdfInputManager.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:24:33
using
1.8.2 with
ECCE GitHub integration