EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Forester.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Forester.h
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 
35 
40 class Forester : public TObject {
41  public:
45  Forester();
46 
50  virtual ~Forester();
51 
56  Long64_t Plant();
57 
61  void SetInputFileName(const std::string&);
62 
66  void SetOutputFileName(const std::string&);
67 
72  void SetTreeName(const std::string& = "EICTree");
73 
78  void SetBranchName(const std::string& = "event");
79 
83  std::string GetInputFileName() const;
84 
88  std::string GetOutputFileName() const;
89 
94  std::string GetTreeName() const;
95 
99  std::string GetBranchName() const;
100 
107  void SetMaxNEvents(Long64_t = 0);
108 
112  Long64_t GetMaxNEvents() const;
113 
118  void SetMessageInterval(Long64_t = 10000);
119 
123  void Print(std::ostream& stream) const;
124 
130  void Print(Option_t* = "not used") const;
131 
136  void SetBeVerbose(bool = false);
137 
141  bool BeVerbose() const;
142 
148  const erhic::FileType* GetFileType() const;
149 
154  class Status{
155  public:
156  Status();
157  virtual ~Status();
158  virtual std::ostream& Print(std::ostream& os = std::cout) const;
159 
160  protected:
161  virtual void StartTimer();
162  virtual void StopTimer();
163  virtual void ModifyEventCount(Long64_t count);
164  virtual void ModifyParticleCount(Long64_t count);
165 
166  time_t mStartTime;
167  time_t mEndTime;
168  Long64_t mNEvents;
169  Long64_t mNParticles;
170 
171  // The TStopwatch is mutable as "GetRealTime()" is non-const.
172  mutable TStopwatch mTimer;
173 
174  friend class Forester;
175 
176  ClassDef(Status, 1);
177  };
178 
179  protected:
184  const Status& GetGetStatus() const {
185  return mStatus;
186  }
187 
194  bool OpenInput();
195 
199  bool SetupOutput();
200 
204  void Finish();
205 
211  bool AllocateEvent();
212 
219  bool FindFirstEvent();
220 
222  void PrintStatus() const;
223 
230  bool MustQuit() const;
231 
233  void SetMustQuit(bool quit);
234 
235  // Member variables.
236  // Those with comment //! will be treated as transient members by ROOT
237  // and won't be written to a file.
238  // IMPORTANT: There MUST be a space after //!
239 
240  Bool_t mQuit;
241  Bool_t mVerbose;
242  TTree* mTree;
245  TFile* mRootFile;
246  Long64_t mMaxNEvents;
247  Long64_t mInterval;
248 
249  std::shared_ptr<std::istream> mTextFile;
250  std::string mInputName;
251  std::string mOutputName;
252  std::string mTreeName;
253  std::string mBranchName;
254  std::string mLine;
257 
258  ClassDef(Forester, 3)
259 };
260 
261 inline void Forester::SetInputFileName(const std::string& name) {
262  mInputName = name;
263 }
264 
265 inline void Forester::SetOutputFileName(const std::string& name) {
266  mOutputName = name;
267 }
268 
269 inline void Forester::SetTreeName(const std::string& name) {
270  mTreeName = name;
271 }
272 
273 inline void Forester::SetBranchName(const std::string& name) {
274  mBranchName = name;
275 }
276 
277 inline std::string Forester::GetInputFileName() const {
278  return mInputName;
279 }
280 
281 inline std::string Forester::GetOutputFileName() const {
282  return mOutputName;
283 }
284 
285 inline std::string Forester::GetTreeName() const {
286  return mTreeName;
287 }
288 
289 inline std::string Forester::GetBranchName() const {
290  return mBranchName;
291 }
292 
293 inline void Forester::SetMaxNEvents(Long64_t number) {
294  mMaxNEvents = number;
295 }
296 
297 inline Long64_t Forester::GetMaxNEvents() const {
298  return mMaxNEvents;
299 }
300 
301 inline void Forester::SetMessageInterval(Long64_t number) {
302  mInterval = number;
303 }
304 
305 inline bool Forester::MustQuit() const {
306  return mQuit;
307 }
308 
309 inline void Forester::SetMustQuit(bool flag) {
310  mQuit = flag;
311 }
312 
313 inline void Forester::SetBeVerbose(bool flag) {
314  mVerbose = flag;
315 }
316 
317 inline bool Forester::BeVerbose() const {
318  return mVerbose;
319 }
320 
321 inline const FileType* Forester::GetFileType() const {
322  return mFile;
323 }
324 
325 } // namesce erhic
326 
327 #endif // INCLUDE_EICSMEAR_ERHIC_FORESTER_H_