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;
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;
563 };
564 
565 } // namespace erhic
566 
567 #endif // INCLUDE_EICSMEAR_ERHIC_FILE_H_
erhic::LogReaderPythia::nEvents_
TObjString nEvents_
Total cross section in microbarns
Definition: File.h:108
erhic::LogReaderPepsi
Processes PEPSI log files.
Definition: File.h:125
erhic::LogReaderMilou::GetCrossSection
Double_t GetCrossSection() const
Returns the total cross section reported by the log file.
Definition: File.h:284
erhic::LogReaderDjangoh::Save
Int_t Save() const
Write the extracted information to the current file, if it is writeable.
Definition: File.cxx:234
erhic::LogReaderMilou::LogReaderMilou
LogReaderMilou()
Constructor.
Definition: File.h:226
erhic::LogReaderMilou::nEvents_
TObjString nEvents_
Cross section error in nb
Definition: File.h:271
erhic::File::CreateLogReader
virtual LogReader * CreateLogReader() const
Create a LogReader for this type of Monte Carlo file.
Definition: File.cxx:516
erhic::File::CreateEventFactory
virtual EventFromAsciiFactory< T > * CreateEventFactory(std::istream &is) const
Returns a new event factory instance.
Definition: File.h:507
erhic::FileFactory::GetFile
const FileType * GetFile(const std::string &generatorName) const
Returns a FileType object for the named generator.
Definition: File.cxx:525
erhic::LogReader::LogReader
LogReader()
Constructor.
Definition: File.h:41
erhic
Definition: EventDis.cxx:14
erhic::EventFromAsciiFactory
Creates events from an input plain text file containing appropriately formatted data.
Definition: erhic/EventFactory.h:86
erhic::LogReaderDjangoh::nEvents_
TObjString nEvents_
Total cross section in microbarns
Definition: File.h:204
erhic::LogReaderDjangoh::Extract
bool Extract(const std::string &file)
Extract data from the named log file.
Definition: File.cxx:154
EventPythia.h
erhic::LogReaderFactory::Map
std::map< std::string, LogReader * > Map
Definition: File.h:413
erhic::LogReader::Create
virtual LogReader * Create() const =0
Return a new LogReader instance.
erhic::LogReader::~LogReader
virtual ~LogReader()
Destructor.
Definition: File.h:46
erhic::LogReaderPepsi::nEvents_
TObjString nEvents_
Total cross section in microbarns
Definition: File.h:156
erhic::FileType::~FileType
virtual ~FileType()
Destructor.
Definition: File.h:429
erhic::LogReaderMilou::GetCrossSectionError
Double_t GetCrossSectionError() const
Returns the error on total cross section reported by the log file.
Definition: File.h:292
erhic::LogReaderPepsi::Extract
bool Extract(const std::string &file)
Extract data from the named log file.
Definition: File.cxx:90
erhic::LogReaderDjangoh::~LogReaderDjangoh
virtual ~LogReaderDjangoh()
Destructor.
Definition: File.cxx:152
erhic::LogReaderPythia::Save
Int_t Save() const
Write the extracted information to the current file, if it is writeable.
Definition: File.cxx:75
erhic::LogReader::Extract
virtual bool Extract(const std::string &file)=0
Extract data from the named log file.
erhic::FileType::CreateLogReader
virtual LogReader * CreateLogReader() const =0
Returns a reader to process the log file corresponding to this type of file.
EventBase.h
erhic::LogReaderMilou::GetNEvents
Int_t GetNEvents() const
Returns the number of events reported by the log file.
Definition: File.h:280
erhic::LogReaderDjangoh
Processes DJANGOH log files.
Definition: File.h:173
erhic::FileFactory::prototypes_
Map prototypes_
Definition: File.h:562
EventMilou.h
erhic::LogReaderMilou::Create
LogReaderMilou * Create() const
Return a new LogReaderMilou instance.
Definition: File.h:276
erhic::File::GetGeneratorName
virtual std::string GetGeneratorName() const
Returns the name of the generator.
Definition: File.cxx:505
erhic::File::File
File()
Constructor.
Definition: File.cxx:494
erhic::FileType::CreateEventFactory
virtual VirtualEventFactory * CreateEventFactory(std::istream &) const =0
Returns a new event object for the generator making this type of file.
erhic::LogReaderGmcTrans::GetNEvents
Int_t GetNEvents() const
Returns the number of events reported by the log file.
Definition: File.cxx:352
erhic::File::Create
virtual File< T > * Create() const
Returns a new File object.
Definition: File.h:525
erhic::LogReader
Base class for log file processors.
Definition: File.h:36
erhic::LogReaderGmcTrans::Create
LogReaderGmcTrans * Create() const
Return a new LogReaderGmcTrans instance.
Definition: File.cxx:305
erhic::File
Definition: File.h:464
erhic::LogReaderFactory::LogReaderFactory
LogReaderFactory()
Constructor.
Definition: File.cxx:474
erhic::FileType::Create
virtual FileType * Create() const =0
Returns a new FileType instance.
erhic::LogReaderPythia::crossSection_
TObjString crossSection_
Definition: File.h:107
erhic::LogReaderFactory::GetInstance
static LogReaderFactory & GetInstance()
Returns the single instance of LogReaderFactory.
Definition: File.cxx:360
erhic::LogReaderGmcTrans::mCrossSection
TObjString mCrossSection
Total cross section in microbarns.
Definition: File.h:348
erhic::LogReaderFactory::~LogReaderFactory
~LogReaderFactory()
Destructor.
Definition: File.cxx:486
erhic::LogReaderFactory::prototypes_
Map prototypes_
Definition: File.h:414
erhic::LogReaderPepsi::crossSection_
TObjString crossSection_
Definition: File.h:155
erhic::File::~File
virtual ~File()
Destructor.
Definition: File.cxx:497
erhic::LogReaderMilou::Extract
bool Extract(const std::string &file)
Extract data from the named log file.
Definition: File.cxx:241
erhic::FileFactory::~FileFactory
virtual ~FileFactory()
Destructor.
Definition: File.cxx:580
erhic::VirtualEventFactory
Abstract base class for event builders.
Definition: erhic/EventFactory.h:35
erhic::LogReaderFactory::CreateReader
LogReader * CreateReader(const EventBase &event) const
Returns a LogReader instance of the type for reading log files from the Monte Carlo generator event t...
Definition: File.cxx:371
erhic::LogReaderPythia::Create
LogReaderPythia * Create() const
Return a new LogReaderPythia instance.
Definition: File.h:113
erhic::LogReaderGmcTrans::Save
Int_t Save() const
Write the stored cross section and number of events to the active ROOT directory.
Definition: File.cxx:348
erhic::LogReaderPepsi::LogReaderPepsi
LogReaderPepsi()
Constructor.
Definition: File.cxx:86
erhic::FileType::AllocateEvent
virtual EventBase * AllocateEvent() const =0
Returns a new event object for the generator making this type of file.
erhic::LogReaderPepsi::~LogReaderPepsi
virtual ~LogReaderPepsi()
Destructor.
Definition: File.cxx:88
erhic::FileFactory
Factory class for Files.
Definition: File.h:533
erhic::FileType::GetGeneratorName
virtual std::string GetGeneratorName() const =0
Returns the name of the generator making this type of file.
erhic::LogReaderMilou::crossSection_
TObjString crossSection_
Definition: File.h:269
erhic::LogReaderDjangoh::crossSection_
TObjString crossSection_
Definition: File.h:203
erhic::FileFactory::Map
std::map< std::string, FileType * > Map
Definition: File.h:561
erhic::LogReaderPythia::LogReaderPythia
LogReaderPythia()
Constructor.
Definition: File.cxx:26
erhic::FileFactory::FileFactory
FileFactory()
Constructor.
Definition: File.cxx:561
erhic::File::t_
T * t_
Definition: File.h:512
erhic::LogReaderMilou::~LogReaderMilou
virtual ~LogReaderMilou()
Destructor.
Definition: File.h:231
erhic::LogReaderGmcTrans::GetCrossSection
Double_t GetCrossSection() const
Returns the total cross section reported by the log file.
Definition: File.cxx:356
erhic::LogReaderDjangoh::LogReaderDjangoh
LogReaderDjangoh()
Constructor.
Definition: File.cxx:150
erhic::FileFactory::GetInstance
static FileFactory & GetInstance()
Returns the single instance of FileFactory.
Definition: File.cxx:520
erhic::LogReaderGmcTrans::Extract
bool Extract(const std::string &filename)
Search the named file.
Definition: File.cxx:309
erhic::LogReaderMilou::crossSectionError_
TObjString crossSectionError_
Total cross section in nb
Definition: File.h:270
erhic::LogReaderGmcTrans::mNEvents
TObjString mNEvents
Number of generated events.
Definition: File.h:347
erhic::FileType
Abstract base class for Monte Carlo file types.
Definition: File.h:424
erhic::LogReaderMilou
Processes PYTHIA log files.
Definition: File.h:221
erhic::LogReader::Save
virtual Int_t Save() const =0
Saves the extracted data to the current file, if one is open and is writeable.
erhic::LogReaderGmcTrans::LogReaderGmcTrans
LogReaderGmcTrans()
Constructor.
Definition: File.cxx:297
erhic::LogReaderPythia::Extract
bool Extract(const std::string &file)
Extract data from the named log file.
Definition: File.cxx:30
erhic::LogReaderPythia
Processes PYTHIA log files.
Definition: File.h:77
EventFactory.h
erhic::LogReaderDjangoh::Create
LogReaderDjangoh * Create() const
Return a new LogReaderDjangoh instance.
Definition: File.h:209
erhic::LogReaderMilou::Save
Int_t Save() const
Write the extracted information to the current file, if it is writeable.
Definition: File.cxx:289
erhic::File::AllocateEvent
virtual T * AllocateEvent() const
Allocates an event of the type for this file.
Definition: File.h:520
erhic::LogReaderFactory::Locate
std::string Locate(const std::string &mcFile) const
Attempts to locate a log file corresponding to the named Monte Carlo file.
Definition: File.cxx:429
erhic::LogReaderFactory
Factory class for LogReaders.
Definition: File.h:360
erhic::LogReaderPythia::~LogReaderPythia
virtual ~LogReaderPythia()
Destructor.
Definition: File.cxx:28
erhic::LogReaderPepsi::Save
Int_t Save() const
Write the extracted information to the current file, if it is writeable.
Definition: File.cxx:140
erhic::LogReaderPepsi::Create
LogReaderPepsi * Create() const
Return a new LogReaderPepsi instance.
Definition: File.h:161
erhic::LogReaderGmcTrans
Processes gmc_trans log files.
Definition: File.h:302
erhic::EventMC
Abstract base class for DIS Monte Carlo events.
Definition: erhic/EventMC.h:30
erhic::LogReaderGmcTrans::~LogReaderGmcTrans
virtual ~LogReaderGmcTrans()
Destructor.
Definition: File.cxx:302