|
||||
File indexing completed on 2024-11-16 09:02:04
0001 /** 0002 \file 0003 Declaration of class erhic::EventFactory. 0004 0005 \author Thomas Burton 0006 \date 2011-10-31 0007 \copyright 2011 Brookhaven National Lab 0008 */ 0009 0010 #ifndef INCLUDE_EICSMEAR_ERHIC_EVENTFACTORY_H_ 0011 #define INCLUDE_EICSMEAR_ERHIC_EVENTFACTORY_H_ 0012 0013 #include <iostream> 0014 #include <memory> 0015 #include <string> 0016 #include <vector> 0017 #include <map> 0018 0019 #include <TBranch.h> 0020 #include <TTree.h> 0021 0022 #include "eicsmear/functions.h" 0023 #include "eicsmear/erhic/VirtualEvent.h" 0024 #include "eicsmear/erhic/EventHepMC.h" 0025 #include "eicsmear/erhic/EventPythia.h" 0026 #include "eicsmear/smear/EventSmear.h" 0027 0028 0029 namespace erhic { 0030 0031 class ParticleMC; 0032 0033 /** 0034 Abstract base class for event builders. 0035 Due to how ROOT handles allocating branch objects, 0036 we take care of creating and filling branches in this 0037 class also. 0038 */ 0039 class VirtualEventFactory : public TObject { 0040 public: 0041 /** 0042 Destructor. 0043 */ 0044 virtual ~VirtualEventFactory() { } 0045 0046 /** 0047 Returns a new event instance. 0048 */ 0049 virtual VirtualEvent* Create() = 0; 0050 0051 /** 0052 Returns a pointer to the event buffer. 0053 */ 0054 virtual VirtualEvent* GetEvBufferPtr() { return 0; } 0055 0056 /** 0057 Returns a string with the full (including namespace) class name 0058 of the event type produced. 0059 This is important for use with ROOT TTree to ensure the correct 0060 event type in branches. 0061 */ 0062 virtual std::string EventName() const = 0; 0063 0064 /** 0065 if we need to skip lines to get to the first event 0066 */ 0067 virtual void FindFirstEvent() {} 0068 0069 /** 0070 Add a branch named "name" for the event type generated 0071 by this factory to a ROOT TTree. 0072 Returns a pointer to the branch, or NULL in the case of an error. 0073 */ 0074 virtual TBranch* Branch(TTree&, const std::string&) { 0075 return NULL; 0076 } 0077 /** 0078 Calls Create() to generate an event and fills the provided 0079 branch with that event. 0080 Resets the branch address in doing so. 0081 */ 0082 virtual void Fill(TBranch&) { } 0083 0084 /** run information (like cross section) is usually saved with 0085 a LogReader that parses a separate file and is completely independent from the 0086 factory, forester, Plant() mechanism, only connected in BuildTree.cxx. 0087 For some formats (like HepMC), that won't work; the best information is gained from the last event. 0088 A hacky but flexible fix: Allow factories to maintain a TObjArray of things to write at the end. 0089 Side effect: Could also be used for QA histos or the like. 0090 **/ 0091 typedef std::pair <TString, TObject*> NamedObjects; 0092 std::vector<NamedObjects> mObjectsToWriteAtTheEnd; 0093 0094 /** Additional reader information as a name-value map. 0095 Also very hacky. But should at least have small footprint 0096 **/ 0097 std::map<std::string, std::string> mAdditionalInformation; 0098 0099 ClassDef(VirtualEventFactory, 3) 0100 }; 0101 0102 /** 0103 Creates events from an input plain text file containing 0104 appropriately formatted data. 0105 Templated for all the types inheriting from EventMC 0106 (any event class implementing a Parse() method to 0107 populate the event's variables from a string will work.) 0108 */ 0109 template<typename T> 0110 class EventFromAsciiFactory : public VirtualEventFactory { 0111 public: 0112 /** 0113 Constructor. 0114 */ 0115 EventFromAsciiFactory() { } 0116 0117 /** 0118 Destructor. 0119 */ 0120 virtual ~EventFromAsciiFactory() { } 0121 0122 /** 0123 Initialise the factory from an input stream. 0124 */ 0125 explicit EventFromAsciiFactory(std::istream& is) 0126 : mInput(&is) 0127 , mEvent(nullptr) { 0128 } 0129 0130 /** 0131 Returns a new event instance. 0132 */ 0133 virtual T* Create(); 0134 0135 /** 0136 Returns the name of the event class created by this factory. 0137 */ 0138 virtual std::string EventName() const; 0139 0140 virtual void FindFirstEvent(); 0141 0142 protected: 0143 std::istream* mInput; //! 0144 std::string mLine; //! 0145 std::unique_ptr<T> mEvent; //! 0146 0147 /** 0148 Returns true when an end-of-event marker is encountered in the input stream. 0149 */ 0150 bool AtEndOfEvent() const; 0151 0152 /** 0153 Perform end-of-event operations. 0154 */ 0155 Int_t FinishEvent(); 0156 0157 /** 0158 Create a new particle from the last data read from the input stream. 0159 */ 0160 bool AddParticle(); 0161 0162 // Warning: explicitly putting the erhic:: namespace before the class 0163 // name doesn't seen to work for template classes. 0164 ClassDef(EventFromAsciiFactory, 2) 0165 }; 0166 0167 /** 0168 Creates events from an input plain text file containing 0169 appropriately formatted data. 0170 Templated for all the types inheriting from EventMC 0171 (any event class implementing a Parse() method to 0172 populate the event's variables from a string will work.) 0173 */ 0174 0175 0176 } // namespace erhic 0177 0178 #endif // INCLUDE_EICSMEAR_ERHIC_EVENTFACTORY_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |