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