/
EventFactory.h
178 lines (146 loc) · 4.36 KB
/
EventFactory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
\file
Declaration of class erhic::EventFactory.
\author Thomas Burton
\date 2011-10-31
\copyright 2011 Brookhaven National Lab
*/
#ifndef INCLUDE_EICSMEAR_ERHIC_EVENTFACTORY_H_
#define INCLUDE_EICSMEAR_ERHIC_EVENTFACTORY_H_
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <TBranch.h>
#include <TTree.h>
#include "eicsmear/functions.h"
#include "eicsmear/erhic/VirtualEvent.h"
#include "eicsmear/erhic/EventHepMC.h"
#include "eicsmear/erhic/EventPythia.h"
#include "eicsmear/smear/EventSmear.h"
namespace erhic {
class ParticleMC;
/**
Abstract base class for event builders.
Due to how ROOT handles allocating branch objects,
we take care of creating and filling branches in this
class also.
*/
class VirtualEventFactory : public TObject {
public:
/**
Destructor.
*/
virtual ~VirtualEventFactory() { }
/**
Returns a new event instance.
*/
virtual VirtualEvent* Create() = 0;
/**
Returns a pointer to the event buffer.
*/
virtual VirtualEvent* GetEvBufferPtr() { return 0; }
/**
Returns a string with the full (including namespace) class name
of the event type produced.
This is important for use with ROOT TTree to ensure the correct
event type in branches.
*/
virtual std::string EventName() const = 0;
/**
if we need to skip lines to get to the first event
*/
virtual void FindFirstEvent() {}
/**
Add a branch named "name" for the event type generated
by this factory to a ROOT TTree.
Returns a pointer to the branch, or NULL in the case of an error.
*/
virtual TBranch* Branch(TTree&, const std::string&) {
return NULL;
}
/**
Calls Create() to generate an event and fills the provided
branch with that event.
Resets the branch address in doing so.
*/
virtual void Fill(TBranch&) { }
/** run information (like cross section) is usually saved with
a LogReader that parses a separate file and is completely independent from the
factory, forester, Plant() mechanism, only connected in BuildTree.cxx.
For some formats (like HepMC), that won't work; the best information is gained from the last event.
A hacky but flexible fix: Allow factories to maintain a TObjArray of things to write at the end.
Side effect: Could also be used for QA histos or the like.
**/
typedef std::pair <TString, TObject*> NamedObjects;
std::vector<NamedObjects> mObjectsToWriteAtTheEnd;
/** Additional reader information as a name-value map.
Also very hacky. But should at least have small footprint
**/
std::map<std::string, std::string> mAdditionalInformation;
ClassDef(VirtualEventFactory, 3)
};
/**
Creates events from an input plain text file containing
appropriately formatted data.
Templated for all the types inheriting from EventMC
(any event class implementing a Parse() method to
populate the event's variables from a string will work.)
*/
template<typename T>
class EventFromAsciiFactory : public VirtualEventFactory {
public:
/**
Constructor.
*/
EventFromAsciiFactory() { }
/**
Destructor.
*/
virtual ~EventFromAsciiFactory() { }
/**
Initialise the factory from an input stream.
*/
explicit EventFromAsciiFactory(std::istream& is)
: mInput(&is)
, mEvent(nullptr) {
}
/**
Returns a new event instance.
*/
virtual T* Create();
/**
Returns the name of the event class created by this factory.
*/
virtual std::string EventName() const;
virtual void FindFirstEvent();
protected:
std::istream* mInput; //!
std::string mLine; //!
std::unique_ptr<T> mEvent; //!
/**
Returns true when an end-of-event marker is encountered in the input stream.
*/
bool AtEndOfEvent() const;
/**
Perform end-of-event operations.
*/
Int_t FinishEvent();
/**
Create a new particle from the last data read from the input stream.
*/
bool AddParticle();
// Warning: explicitly putting the erhic:: namespace before the class
// name doesn't seen to work for template classes.
ClassDef(EventFromAsciiFactory, 2)
};
/**
Creates events from an input plain text file containing
appropriately formatted data.
Templated for all the types inheriting from EventMC
(any event class implementing a Parse() method to
populate the event's variables from a string will work.)
*/
} // namespace erhic
#endif // INCLUDE_EICSMEAR_ERHIC_EVENTFACTORY_H_