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
File.h
Go to the documentation of this file.
1 
10 #ifndef INCLUDE_EICSMEAR_ERHIC_FILE_H_
11 #define INCLUDE_EICSMEAR_ERHIC_FILE_H_
12 
13 #include <iostream>
14 #include <map>
15 #include <string>
16 
17 #include <TObject.h>
18 #include <TObjString.h>
19 #include <TString.h>
20 
25 
26 namespace erhic {
27 
36 class LogReader : public TObject {
37  public:
41  LogReader() { }
42 
46  virtual ~LogReader() { }
47 
51  virtual LogReader* Create() const = 0;
52 
56  virtual bool Extract(const std::string& file) = 0;
57 
64  virtual Int_t Save() const = 0;
65 
66  ClassDef(erhic::LogReader, 1)
67 };
68 
77 class LogReaderPythia : public LogReader {
78  public:
83 
87  virtual ~LogReaderPythia();
88 
92  LogReaderPythia* Create() const;
93 
97  bool Extract(const std::string& file);
98 
104  Int_t Save() const;
105 
106  protected:
107  TObjString crossSection_;
108  TObjString nEvents_;
109 
110  ClassDef(erhic::LogReaderPythia, 1)
111 };
112 
114  return new LogReaderPythia;
115 }
116 
125 class LogReaderPepsi : public LogReader {
126  public:
130  LogReaderPepsi();
131 
135  virtual ~LogReaderPepsi();
136 
140  LogReaderPepsi* Create() const;
141 
145  bool Extract(const std::string& file);
146 
152  Int_t Save() const;
153 
154  protected:
155  TObjString crossSection_;
156  TObjString nEvents_;
157 
158  ClassDef(erhic::LogReaderPepsi, 1)
159 };
160 
162  return new LogReaderPepsi;
163 }
164 
173 class LogReaderDjangoh : public LogReader {
174  public:
179 
183  virtual ~LogReaderDjangoh();
184 
188  LogReaderDjangoh* Create() const;
189 
193  bool Extract(const std::string& file);
194 
200  Int_t Save() const;
201 
202  protected:
203  TObjString crossSection_;
204  TObjString nEvents_;
205 
206  ClassDef(erhic::LogReaderDjangoh, 1)
207 };
208 
210  return new LogReaderDjangoh;
211 }
212 
221 class LogReaderMilou : public LogReader {
222  public:
227 
231  virtual ~LogReaderMilou() { }
232 
236  LogReaderMilou* Create() const;
237 
241  bool Extract(const std::string& file);
242 
248  Int_t Save() const;
249 
254  Int_t GetNEvents() const;
255 
260  Double_t GetCrossSection() const;
261 
266  Double_t GetCrossSectionError() const;
267 
268  protected:
269  TObjString crossSection_;
270  TObjString crossSectionError_;
271  TObjString nEvents_;
272 
273  ClassDef(erhic::LogReaderMilou, 1)
274 };
275 
277  return new LogReaderMilou;
278 }
279 
280 inline Int_t LogReaderMilou::GetNEvents() const {
281  return nEvents_.GetString().Atoi();
282 }
283 
284 inline Double_t LogReaderMilou::GetCrossSection() const {
285  return crossSection_.GetString().Atof();
286 }
287 
292 inline Double_t LogReaderMilou::GetCrossSectionError() const {
293  return crossSectionError_.GetString().Atof();
294 }
295 
302 class LogReaderGmcTrans : public LogReader {
303  public:
308 
312  virtual ~LogReaderGmcTrans();
313 
317  LogReaderGmcTrans* Create() const;
318 
324  bool Extract(const std::string& filename);
325 
332  Int_t Save() const;
333 
338  Int_t GetNEvents() const;
339 
344  Double_t GetCrossSection() const;
345 
346  protected:
347  TObjString mNEvents;
348  TObjString mCrossSection;
349 
350  ClassDef(erhic::LogReaderGmcTrans, 1)
351 };
352 
361  public:
365  static LogReaderFactory& GetInstance();
366 
373  LogReader* CreateReader(const EventBase& event) const;
374 
381  LogReader* CreateReader(const std::string& name) const;
382 
390  LogReader* CreateReader(std::istream&) const;
391 
400  std::string Locate(const std::string& mcFile) const;
401 
402  protected:
407 
412 
413  typedef std::map<std::string, LogReader*> Map;
414  Map prototypes_;
415 
416  ClassDef(erhic::LogReaderFactory, 1)
417 };
418 
424 class FileType : public TObject {
425  public:
429  virtual ~FileType() { }
430 
434  virtual FileType* Create() const = 0;
435 
439  virtual EventBase* AllocateEvent() const = 0;
440 
444  virtual std::string GetGeneratorName() const = 0;
445 
449  virtual LogReader* CreateLogReader() const = 0;
450 
454  virtual VirtualEventFactory* CreateEventFactory(std::istream&) const = 0;
455 
456  ClassDef(erhic::FileType, 1)
457 };
458 
459 /*
460  Templated file descriptor class, valid for Monte Carlo event classes.
461  e.g. File<EventPythia> describes a Pythia event file.
462  */
463 template<typename T>
464 class File : public FileType {
465  public:
472  File();
473 
477  virtual ~File();
478 
482  virtual File<T>* Create() const;
483 
487  virtual T* AllocateEvent() const;
488 
493  virtual std::string GetGeneratorName() const;
494 
501  virtual LogReader* CreateLogReader() const;
502 
506  virtual EventFromAsciiFactory<T>*
507  CreateEventFactory(std::istream& is) const {
508  return new EventFromAsciiFactory<T>(is);
509  }
510 
511  protected:
512  T* t_;
513 
514  // Warning: explicitly putting the erhic:: namespace before the class
515  // name doesn't seen to work for template classes.
516  ClassDef(File, 1)
517 };
518 
519 template<typename T>
520 inline T* File<T>::AllocateEvent() const {
521  return new T;
522 }
523 
524 template<typename T>
525 inline File<T>* File<T>::Create() const {
526  return new File<T>();
527 }
528 
533 class FileFactory {
534  public:
538  static FileFactory& GetInstance();
539 
543  const FileType* GetFile(const std::string& generatorName) const;
544 
548  const FileType* GetFile(std::istream&) const;
549 
550  protected:
554  FileFactory();
555 
559  virtual ~FileFactory();
560 
561  typedef std::map<std::string, FileType*> Map;
562  Map prototypes_;
563 };
564 
565 } // namespace erhic
566 
567 #endif // INCLUDE_EICSMEAR_ERHIC_FILE_H_
virtual ~LogReader()
Definition: File.h:46
Double_t GetCrossSectionError() const
Definition: File.h:292
Double_t GetCrossSection() const
Definition: File.h:284
virtual EventBase * AllocateEvent() const =0
virtual LogReader * CreateLogReader() const =0
std::string Locate(const std::string &mcFile) const
Definition: File.cxx:427
LogReaderDjangoh * Create() const
Definition: File.h:209
bool Extract(const std::string &file)
Definition: File.cxx:241
Int_t Save() const
Definition: File.cxx:348
virtual ~LogReaderGmcTrans()
Definition: File.cxx:302
TObjString nEvents_
Cross section error in nb
Definition: File.h:271
bool Extract(const std::string &file)
Definition: File.cxx:90
TObjString mCrossSection
Total cross section in microbarns.
Definition: File.h:348
LogReaderGmcTrans * Create() const
Definition: File.cxx:305
TObjString nEvents_
Total cross section in microbarns
Definition: File.h:108
virtual ~File()
Definition: File.cxx:495
static FileFactory & GetInstance()
Definition: File.cxx:518
Int_t Save() const
Definition: File.cxx:140
virtual std::string GetGeneratorName() const =0
virtual LogReader * Create() const =0
virtual ~LogReaderPythia()
Definition: File.cxx:28
bool Extract(const std::string &file)
Definition: File.cxx:30
bool Extract(const std::string &file)
Definition: File.cxx:154
static LogReaderFactory & GetInstance()
Definition: File.cxx:360
LogReaderPepsi * Create() const
Definition: File.h:161
Int_t GetNEvents() const
Definition: File.cxx:352
virtual T * AllocateEvent() const
Definition: File.h:520
virtual ~LogReaderMilou()
Definition: File.h:231
TObjString crossSectionError_
Total cross section in nb
Definition: File.h:270
virtual ~LogReaderDjangoh()
Definition: File.cxx:152
const FileType * GetFile(const std::string &generatorName) const
Definition: File.cxx:523
Int_t Save() const
Definition: File.cxx:234
virtual bool Extract(const std::string &file)=0
LogReaderMilou * Create() const
Definition: File.h:276
bool Extract(const std::string &filename)
Definition: File.cxx:309
Int_t Save() const
Definition: File.cxx:75
TObjString mNEvents
Number of generated events.
Definition: File.h:347
virtual ~FileType()
Definition: File.h:429
LogReader * CreateReader(const EventBase &event) const
Definition: File.cxx:371
virtual Int_t Save() const =0
LogReaderPythia * Create() const
Definition: File.h:113
virtual ~LogReaderPepsi()
Definition: File.cxx:88
virtual LogReader * CreateLogReader() const
Definition: File.cxx:514
TObjString nEvents_
Total cross section in microbarns
Definition: File.h:156
virtual std::string GetGeneratorName() const
Definition: File.cxx:503
virtual File< T > * Create() const
Definition: File.h:525
Int_t Save() const
Definition: File.cxx:289
TObjString nEvents_
Total cross section in microbarns
Definition: File.h:204
virtual VirtualEventFactory * CreateEventFactory(std::istream &) const =0
virtual ~FileFactory()
Definition: File.cxx:572
Double_t GetCrossSection() const
Definition: File.cxx:356
virtual FileType * Create() const =0
Int_t GetNEvents() const
Definition: File.h:280
virtual EventFromAsciiFactory< T > * CreateEventFactory(std::istream &is) const
Definition: File.h:507