/
Forester.h
327 lines (262 loc) · 7.82 KB
/
Forester.h
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/**
\file
Declaration of class erhic::Forester.
\author Thomas Burton
\date 2011-06-23
\copyright 2011 Brookhaven National Lab
*/
#ifndef INCLUDE_EICSMEAR_ERHIC_FORESTER_H_
#define INCLUDE_EICSMEAR_ERHIC_FORESTER_H_
// C(++) headers
#include <cmath>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
// ROOT headers
#include <Rtypes.h>
#include <TFile.h>
#include <TStopwatch.h>
#include <TTree.h>
// Other headers
#include "eicsmear/erhic/EventMC.h"
namespace erhic {
class FileType;
class VirtualEventFactory;
/**
Manages the creation of trees from plain-text Monte Carlo files.
Bad pun, I know, but the ROOT guys started it.
*/
class Forester : public TObject {
public:
/**
Default constructor.
*/
Forester();
/**
Destructor.
*/
virtual ~Forester();
/**
Processes a text file into a ROOT file.
Returns the number of events processed.
*/
Long64_t Plant();
/**
Sets the name of the input text file containing Monte Carlo data.
*/
void SetInputFileName(const std::string&);
/**
Sets the name of the ROOT tree file to create.
*/
void SetOutputFileName(const std::string&);
/**
Sets the name of the TTree to write to the file named by
SetOutputFileName().
*/
void SetTreeName(const std::string& = "EICTree");
/**
Sets the name of the TBranch containing event objects.
This is the only branch written to the TTree named by SetTreeName().
*/
void SetBranchName(const std::string& = "event");
/**
Returns the name of the input text file containing Monte Carlo data.
*/
std::string GetInputFileName() const;
/**
Returns the name of the ROOT tree file to create.
*/
std::string GetOutputFileName() const;
/**
Returns the name of the TTree to write to the file named by
SetOutputFileName().
*/
std::string GetTreeName() const;
/**
Returns the name of the TBranch containing event objects.
*/
std::string GetBranchName() const;
/**
Sets the maximum number of events to process. Processing will terminate
when this number of events or the end of the input file is reached,
whichever occurs first. A value <= 0 indicates to process all events in the
input file (this is the default).
*/
void SetMaxNEvents(Long64_t = 0);
/**
Returns the maximum number of events to process.
*/
Long64_t GetMaxNEvents() const;
/**
Sets the event count interval at which to print a status message.
A value <= 0 suppresses messages.
*/
void SetMessageInterval(Long64_t = 10000);
/**
Prints the current configuration to the requested output stream.
*/
void Print(std::ostream& stream) const;
/**
\overload
To avoid hiding TObject::Print()
*/
void Print(Option_t* = "not used") const;
/**
If set to true, prints messages during running.
If set to false, runs silently except in the case of critical errors.
*/
void SetBeVerbose(bool = false);
/**
Returns the verbosity i.e. whether to print status messages.
*/
bool BeVerbose() const;
/**
Returns the file type information for the last processed file.
Returns NULL if no input has been processed.
Do not delete the returned object.
*/
const erhic::FileType* GetFileType() const;
/**
Stores summary information about the last call to Forester::Plant().
KK: Made public for rootcint
*/
class Status{
public:
Status();
virtual ~Status();
virtual std::ostream& Print(std::ostream& os = std::cout) const;
protected:
virtual void StartTimer();
virtual void StopTimer();
virtual void ModifyEventCount(Long64_t count);
virtual void ModifyParticleCount(Long64_t count);
time_t mStartTime;
time_t mEndTime;
Long64_t mNEvents;
Long64_t mNParticles;
// The TStopwatch is mutable as "GetRealTime()" is non-const.
mutable TStopwatch mTimer;
friend class Forester;
ClassDef(Status, 1);
};
protected:
/**
Prints a summary of the last call to Plant()
to the requested output stream.
*/
const Status& GetGetStatus() const {
return mStatus;
}
/**
Opens the input file and checks that it was produced by a
supported Monte Carlo generator.
Returns true upon success or false upon and I/O error or
if the Monte Carlo generator is unsupported or cannot be determined.
*/
bool OpenInput();
/**
Opens the output ROOT file and creates the TTree ready for filling.
*/
bool SetupOutput();
/**
Writes output and takes end-of-file actions.
*/
void Finish();
/**
Allocate an event buffer for the TTree based on the generator type.
Returns false if the generator has not yet been successfully
determined.
*/
bool AllocateEvent();
/**
Aligns the input text file on the first line of the first event.
After a successful call, mLine stores the first line of the event
and true is returned.
If unsuccessful, mLine is blank and false is returned.
*/
bool FindFirstEvent();
/** Prints the status of the current Plant() call to the standard output. */
void PrintStatus() const;
/**
Prints the quit flag status. A return value of true indicates
that the input file has ended or the mMaxNEvents has been reached.
Processing the file will
quit after the end of the next call to FinishEvent().
*/
bool MustQuit() const;
/** Set the quit flag. */
void SetMustQuit(bool quit);
// Member variables.
// Those with comment //! will be treated as transient members by ROOT
// and won't be written to a file.
// IMPORTANT: There MUST be a space after //!
Bool_t mQuit; ///< Quit status. Set to true once EoF or max events reached
Bool_t mVerbose; ///< Verbosity flag
TTree* mTree; //! < Output TTree, owned by mRootFile
VirtualEvent* mEvent; //! < Stores event branch address
const erhic::FileType* mFile; //! < File type information
TFile* mRootFile; //! < Pointer to output ROOT file
Long64_t mMaxNEvents; ///< Maximum number of events to process
Long64_t mInterval; ///< Event interval between printing status messages
std::shared_ptr<std::istream> mTextFile; //! < Input text file
std::string mInputName; ///< Name of the input text file
std::string mOutputName; ///< Name of the output ROOT file
std::string mTreeName; ///< Name of the output TTree
std::string mBranchName; ///< Name of the event TBranch
std::string mLine; ///< Stores the latest text line read from the input file
Status mStatus; ///< Forester status information
VirtualEventFactory* mFactory; //! < Pointer to the event-builder object
ClassDef(Forester, 3)
};
inline void Forester::SetInputFileName(const std::string& name) {
mInputName = name;
}
inline void Forester::SetOutputFileName(const std::string& name) {
mOutputName = name;
}
inline void Forester::SetTreeName(const std::string& name) {
mTreeName = name;
}
inline void Forester::SetBranchName(const std::string& name) {
mBranchName = name;
}
inline std::string Forester::GetInputFileName() const {
return mInputName;
}
inline std::string Forester::GetOutputFileName() const {
return mOutputName;
}
inline std::string Forester::GetTreeName() const {
return mTreeName;
}
inline std::string Forester::GetBranchName() const {
return mBranchName;
}
inline void Forester::SetMaxNEvents(Long64_t number) {
mMaxNEvents = number;
}
inline Long64_t Forester::GetMaxNEvents() const {
return mMaxNEvents;
}
inline void Forester::SetMessageInterval(Long64_t number) {
mInterval = number;
}
inline bool Forester::MustQuit() const {
return mQuit;
}
inline void Forester::SetMustQuit(bool flag) {
mQuit = flag;
}
inline void Forester::SetBeVerbose(bool flag) {
mVerbose = flag;
}
inline bool Forester::BeVerbose() const {
return mVerbose;
}
inline const FileType* Forester::GetFileType() const {
return mFile;
}
} // namesce erhic
#endif // INCLUDE_EICSMEAR_ERHIC_FORESTER_H_