eic-smear  1.0.3
A collection of ROOT classes for Monte Carlo events and a fast-smearing code simulating detector effects for the Electron-Ion Collider task force
Forester.h
Go to the documentation of this file.
1 
10 #ifndef INCLUDE_EICSMEAR_ERHIC_FORESTER_H_
11 #define INCLUDE_EICSMEAR_ERHIC_FORESTER_H_
12 
13 // C(++) headers
14 #include <cmath>
15 #include <ctime>
16 #include <fstream>
17 #include <iomanip>
18 #include <iostream>
19 #include <string>
20 
21 // ROOT headers
22 #include <Rtypes.h>
23 #include <TFile.h>
24 #include <TStopwatch.h>
25 #include <TTree.h>
26 
27 // Other headers
28 #include "eicsmear/erhic/EventMC.h"
29 
30 namespace erhic {
31 
32 class FileType;
33 class VirtualEventFactory;
34 
39 class Forester : public TObject {
40  public:
44  Forester();
45 
49  virtual ~Forester();
50 
55  Long64_t Plant();
56 
60  void SetInputFileName(const std::string&);
61 
65  void SetOutputFileName(const std::string&);
66 
71  void SetTreeName(const std::string& = "EICTree");
72 
77  void SetBranchName(const std::string& = "event");
78 
82  std::string GetInputFileName() const;
83 
87  std::string GetOutputFileName() const;
88 
93  std::string GetTreeName() const;
94 
98  std::string GetBranchName() const;
99 
106  void SetMaxNEvents(Long64_t = 0);
107 
111  Long64_t GetMaxNEvents() const;
112 
117  void SetMessageInterval(Long64_t = 10000);
118 
122  void Print(std::ostream& stream) const;
123 
129  void Print(Option_t* = "not used") const;
130 
135  void SetBeVerbose(bool = false);
136 
140  bool BeVerbose() const;
141 
147  const erhic::FileType* GetFileType() const;
148 
149  protected:
153  class Status {
154  public:
155  Status()
156  : mNEvents(0)
157  , mNParticles(0) {
158  // Initialise the start and end time to the creation time and reset
159  // the timer to ensure it is at zero.
160  std::time(&mStartTime);
161  mEndTime = mStartTime;
162  mTimer.Reset();
163  }
164 
165  virtual ~Status() { }
166 
167  virtual std::ostream& Print(std::ostream& os = std::cout) const {
168  // Put start and end times in different os <<... otherwise I get
169  // the same time for each...
170  os << "Began on " << std::ctime(&mStartTime);
171  os << "Ended on " << std::ctime(&mEndTime);
172  os << "Processed " << mNEvents << " events containing "
173  << mNParticles << " particles in "
174  << mTimer.RealTime() << " seconds "
175  << '(' << mTimer.RealTime()/mNEvents <<" sec/event)" << std::endl;
176  return os;
177  }
178 
179  protected:
180  virtual void StartTimer() {
181  std::time(&mStartTime);
182  mTimer.Start();
183  }
184 
185  virtual void StopTimer() {
186  std::time(&mEndTime);
187  mTimer.Stop();
188  }
189 
190  virtual void ModifyEventCount(Long64_t count) {
191  mNEvents += count;
192  }
193 
194  virtual void ModifyParticleCount(Long64_t count) {
195  mNParticles += count;
196  }
197 
198  time_t mStartTime;
199  time_t mEndTime;
200  Long64_t mNEvents;
201  Long64_t mNParticles;
202 
203  // The TStopwatch is mutable as "GetRealTime()" is non-const.
204  mutable TStopwatch mTimer;
205 
206  friend class Forester;
207 
208  ClassDef(Status, 1)
209  };
210 
211  // End of class Status
212 
217  const Status& GetGetStatus() const {
218  return mStatus;
219  }
220 
227  bool OpenInput();
228 
232  bool SetupOutput();
233 
237  void Finish();
238 
244  bool AllocateEvent();
245 
252  bool FindFirstEvent();
253 
255  void PrintStatus() const;
256 
263  bool MustQuit() const;
264 
266  void SetMustQuit(bool quit);
267 
268  // Member variables.
269  // Those with comment //!< will be treated as transient members by ROOT
270  // and won't be written to a file.
271 
272  Bool_t mQuit;
273  Bool_t mVerbose;
274  TTree* mTree;
277  TFile* mRootFile;
278  Long64_t mMaxNEvents;
279  Long64_t mInterval;
280  std::ifstream* mTextFile;
281  std::string mInputName;
282  std::string mOutputName;
283  std::string mTreeName;
284  std::string mBranchName;
285  std::string mLine;
288 
289  ClassDef(Forester, 1)
290 };
291 
292 inline void Forester::SetInputFileName(const std::string& name) {
293  mInputName = name;
294 }
295 
296 inline void Forester::SetOutputFileName(const std::string& name) {
297  mOutputName = name;
298 }
299 
300 inline void Forester::SetTreeName(const std::string& name) {
301  mTreeName = name;
302 }
303 
304 inline void Forester::SetBranchName(const std::string& name) {
305  mBranchName = name;
306 }
307 
308 inline std::string Forester::GetInputFileName() const {
309  return mInputName;
310 }
311 
312 inline std::string Forester::GetOutputFileName() const {
313  return mOutputName;
314 }
315 
316 inline std::string Forester::GetTreeName() const {
317  return mTreeName;
318 }
319 
320 inline std::string Forester::GetBranchName() const {
321  return mBranchName;
322 }
323 
324 inline void Forester::SetMaxNEvents(Long64_t number) {
325  mMaxNEvents = number;
326 }
327 
328 inline Long64_t Forester::GetMaxNEvents() const {
329  return mMaxNEvents;
330 }
331 
332 inline void Forester::SetMessageInterval(Long64_t number) {
333  mInterval = number;
334 }
335 
336 inline bool Forester::MustQuit() const {
337  return mQuit;
338 }
339 
340 inline void Forester::SetMustQuit(bool flag) {
341  mQuit = flag;
342 }
343 
344 inline void Forester::SetBeVerbose(bool flag) {
345  mVerbose = flag;
346 }
347 
348 inline bool Forester::BeVerbose() const {
349  return mVerbose;
350 }
351 
352 inline const FileType* Forester::GetFileType() const {
353  return mFile;
354 }
355 
356 } // namespace erhic
357 
358 #endif // INCLUDE_EICSMEAR_ERHIC_FORESTER_H_
Status mStatus
Forester status information.
Definition: Forester.h:286
const Status & GetGetStatus() const
Definition: Forester.h:217
std::string mLine
Stores the latest text line read from the input file.
Definition: Forester.h:285
std::ifstream * mTextFile
Input text file.
Definition: Forester.h:280
void SetMessageInterval(Long64_t=10000)
Definition: Forester.h:332
void SetBranchName(const std::string &="event")
Definition: Forester.h:304
std::string mOutputName
Name of the output ROOT file.
Definition: Forester.h:282
std::string mBranchName
Name of the event TBranch.
Definition: Forester.h:284
TFile * mRootFile
Pointer to output ROOT file.
Definition: Forester.h:277
std::string GetInputFileName() const
Definition: Forester.h:308
Long64_t Plant()
Definition: Forester.cxx:67
void Print(std::ostream &stream) const
Definition: Forester.cxx:241
const erhic::FileType * mFile
File type information.
Definition: Forester.h:276
Bool_t mQuit
Quit status. Set to true once EoF or max events reached.
Definition: Forester.h:272
std::string GetOutputFileName() const
Definition: Forester.h:312
std::string mInputName
Name of the input text file.
Definition: Forester.h:281
VirtualEvent * mEvent
Stores event branch address.
Definition: Forester.h:275
const erhic::FileType * GetFileType() const
Definition: Forester.h:352
std::string GetTreeName() const
Definition: Forester.h:316
Abstract base class for a physics event.
Definition: VirtualEvent.h:25
bool FindFirstEvent()
Definition: Forester.cxx:228
Long64_t mInterval
Event interval between printing status messages.
Definition: Forester.h:279
Long64_t GetMaxNEvents() const
Definition: Forester.h:328
std::string GetBranchName() const
Definition: Forester.h:320
virtual ~Forester()
Definition: Forester.cxx:42
Bool_t mVerbose
Verbosity flag.
Definition: Forester.h:273
VirtualEventFactory * mFactory
Pointer to the event-builder object.
Definition: Forester.h:287
bool BeVerbose() const
Definition: Forester.h:348
void SetInputFileName(const std::string &)
Definition: Forester.h:292
Long64_t mMaxNEvents
Maximum number of events to process.
Definition: Forester.h:278
void SetMaxNEvents(Long64_t=0)
Definition: Forester.h:324
void SetOutputFileName(const std::string &)
Definition: Forester.h:296
void SetBeVerbose(bool=false)
Definition: Forester.h:344
std::string mTreeName
Name of the output TTree.
Definition: Forester.h:283
void SetTreeName(const std::string &="EICTree")
Definition: Forester.h:300
bool SetupOutput()
Definition: Forester.cxx:158
TTree * mTree
Output TTree, owned by mRootFile.
Definition: Forester.h:274
bool AllocateEvent()
Definition: Forester.cxx:213
void SetMustQuit(bool quit)
Definition: Forester.h:340
bool MustQuit() const
Definition: Forester.h:336
bool OpenInput()
Definition: Forester.cxx:130
void PrintStatus() const