ATLAS Offline Software
Loading...
Searching...
No Matches
EventInfoCnv.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11#include "EventInfo/EventType.h"
12#include "EventInfoCnv.h"
14#include "EventInfo/EventID.h"
20
25
26EventInfoCnv::EventInfoCnv(ISvcLocator* svcloc)
27 :
28 EventInfoCnvBase(svcloc),
35 m_timeStamp(0),
37 m_evtIdModSvc(svcloc->service("EvtIdModifierSvc", /*createif*/false))
38{
39}
40
42 MsgStream log(msgSvc(), "EventInfoCnv" );
43 EventInfo_PERS *persObj = TPconverter_p4.createPersistentConst( transObj, log );
44 log << MSG::DEBUG << "EventInfo write Success" << endmsg;
45 return persObj;
46}
47
49
50 static const pool::Guid p4_guid("C634FDB6-CC4B-4BA2-B8F9-A84BE6A786C7");
51 static const pool::Guid p3_guid("3E240CA8-5124-405B-9059-FAFC4C5954C6");
52 static const pool::Guid p2_guid("22006E19-F0DA-4EFB-AF55-6FBDA421BF06");
53 static const pool::Guid p1_guid("A3053CD9-47F4-4C0F-B73A-A6F93F5CC7B7");
54 static const pool::Guid p0_guid("380D8BB9-B34F-470F-92CC-06C3D60F7BE4");
55 if( compareClassGuid(p4_guid) ) {
56 // using unique_ptr ensures deletion of the persistent object
57 std::unique_ptr< EventInfo_p4 > col_vect( poolReadObject< EventInfo_p4 >() );
58 MsgStream log(msgSvc(), "EventInfoCnv" );
59 //log << MSG::DEBUG << "Reading EventInfo_p4" << endmsg;
60 return massageEventInfo(TPconverter_p4.createTransientConst( col_vect.get(), log ));
61 }
62 else if( compareClassGuid(p3_guid) ) {
63 // using unique_ptr ensures deletion of the persistent object
64 std::unique_ptr< EventInfo_p3 > col_vect( poolReadObject< EventInfo_p3 >() );
65 MsgStream log(msgSvc(), "EventInfoCnv" );
66 //log << MSG::DEBUG << "Reading EventInfo_p3" << endmsg;
67 return massageEventInfo(TPconverter_p3.createTransientConst( col_vect.get(), log ));
68 }
69 else if( compareClassGuid(p2_guid) ) {
70 // using unique_ptr ensures deletion of the persistent object
71 std::unique_ptr< EventInfo_p2 > col_vect( poolReadObject< EventInfo_p2 >() );
72 MsgStream log(msgSvc(), "EventInfoCnv" );
73 // log << MSG::DEBUG << "ILIJA Reading EventInfo_p2" << endmsg;
74 return massageEventInfo(TPconverter_p2.createTransientConst( col_vect.get(), log ));
75 }
76 else if( compareClassGuid(p1_guid) ) {
77 // using unique_ptr ensures deletion of the persistent object
78 std::unique_ptr< EventInfo_p1 > col_vect( poolReadObject< EventInfo_p1 >() );
79 MsgStream log(msgSvc(), "EventInfoCnv" );
80 //log << MSG::DEBUG << "Reading EventInfo_p1" << endmsg;
81 return massageEventInfo(TPconverter_p1.createTransientConst( col_vect.get(), log ));
82 }
83 else if( compareClassGuid(p0_guid) ) {
84 // regular object from before TP separation, just return it
86
87 // Fill MC event weight in transient EventType from
88 // TriggerInfo. This is only needed for MC events: if the
89 // weight is zero, and TriggerInfo exists - was stored at end
90 // of eventFilterInfo
91 if (ei->trigger_info() &&
92 ei->event_type()->mc_event_weight() == 0 &&
93 ei->trigger_info()->eventFilterInfo().size()) {
95 }
96 else {
97 // default weight = 1.0
99 }
100 return massageEventInfo(ei);
101 }
102 throw std::runtime_error("Unsupported persistent version of EventInfo");
103}
104
105
106EventInfo*
108{
109 // We allow the run number, etc. to be modified EITHER by the
110 // IEvtIdModifierSvc OR via the event selector via its
111 // OverrideRunNumberFromInput property. Only one method is allowed
112 // to modify EventInfo.
113
114 if (m_evtIdModSvc) {
115 // Modify EventInfo with the IEvtIdModifierSvc
116 // Copy (save old) run/event numbers into EventType
117
118 // We only do so if mc_channel_number has not already be set
119 // either previously or elsewhere!!
120 if (ei->event_type()->mc_channel_number() == 0) {
121 ei->event_type()->set_mc_channel_number(ei->event_ID()->run_number());
122 ei->event_type()->set_mc_event_number (ei->event_ID()->event_number());
123 }
124 m_evtIdModSvc->modify_evtid(*ei->event_ID(), EventInfoCnvParams::eventIndex, true);
125 return (ei);
126 }
127
128 // Allow modification via the EventSelector:
129
130 // When reading in simulation events, one may want to reset the
131 // run number to allow conditions to be used with simulation
132 // events. The run number is set via the (AthenaPool)EventSelector.
133
134 // Check is reset is requested, if not return
135 if (m_checkedEventSelector && !m_overrideRunNumber) return (ei);
136
138 // Get run number parameter from the EventSelector
140 MsgStream log(msgSvc(), "EventInfoCnv" );
141 log << MSG::DEBUG << "massageEventInfo: check if tag is set in jobOpts" << endmsg;
142
143 // Get name of event selector from the application manager to
144 // make sure we get the one for MC signal events
145 SmartIF<IProperty> appMgr{serviceLocator()->service("ApplicationMgr")};
146 if (!appMgr) {
147 log << MSG::ERROR << "massageEventInfo: Cannot get ApplicationMgr " << endmsg;
148 throw std::runtime_error("Cannot get ApplicationMgr");
149 }
150 StringProperty property("EvtSel", "");
151 StatusCode sc = appMgr->getProperty(&property);
152 if (!sc.isSuccess()) {
153 log << MSG::ERROR << "unable to get EvtSel: found " << property.value() << endmsg;
154 throw std::runtime_error("Cannot get property EvtSel from the ApplicationMgr");
155 }
156 // Get EventSelector for ApplicationMgr
157 std::string eventSelector = property.value();
158 SmartIF<IProperty> evtSel{serviceLocator()->service(eventSelector)};
159 if (!evtSel) {
160 log << MSG::ERROR << "massageEventInfo: Cannot get EventSelector " << eventSelector << endmsg;
161 throw std::runtime_error("Cannot get EventSelector");
162 }
163 BooleanProperty overrideRunNumber("OverrideRunNumberFromInput", false);
164 sc = evtSel->getProperty(&overrideRunNumber);
165 if (!sc.isSuccess()) {
166 // Not all EventSelectors have this property, so we must be tolerant
167 ATH_MSG_INFO("massageEventInfo: unable to get OverrideRunNumberFromInput property from EventSelector ");
168 return (ei);
169 }
170 m_overrideRunNumber = overrideRunNumber.value();
172 IntegerProperty runNumber("RunNumber", 0);
173 sc = evtSel->getProperty(&runNumber);
174 if (!sc.isSuccess()) {
175 log << MSG::ERROR << "massageEventInfo: unable to get RunNumber from EventSelector: found "
176 << runNumber.value()
177 << endmsg;
178 throw std::runtime_error("Cannot get RunNumber");
179 }
180 else {
181 m_simRunNumber = (unsigned int)runNumber.value();
182 log << MSG::DEBUG << "massageEventInfo: Run number: " << m_simRunNumber
183 << " obtained from " << eventSelector << endmsg;
184 }
185 IntegerProperty lumiBlockNumber("FirstLB", 0);
186 sc = evtSel->getProperty(&lumiBlockNumber);
187 if (!sc.isSuccess()) {
188 log << MSG::INFO << "massageEventInfo: unable to get FirstLB from EventSelector. Using "
190 }
191 else {
192 m_lumiBlockNumber = (unsigned int)lumiBlockNumber.value();
193 log << MSG::DEBUG << "massageEventInfo: LumiBlock number: " << m_lumiBlockNumber
194 << " obtained from " << eventSelector << endmsg;
195 }
196 IntegerProperty evtsPerLumiBlock("EventsPerLB", 0);
197 sc = evtSel->getProperty(&evtsPerLumiBlock);
198 if (!sc.isSuccess()) {
199 log << MSG::INFO << "massageEventInfo: unable to get EventsPerLB from EventSelector. Using "
201 }
202 else {
203 m_evtsPerLumiBlock = (unsigned int)evtsPerLumiBlock.value();
204 log << MSG::DEBUG << "massageEventInfo: EventsPerLB: " << m_evtsPerLumiBlock
205 << " obtained from " << eventSelector << endmsg;
206 }
207 IntegerProperty timeStamp("InitialTimeStamp", 0);
208 sc = evtSel->getProperty(&timeStamp);
209 if (!sc.isSuccess()) {
210 log << MSG::INFO << "massageEventInfo: unable to get InitialTimeStamp from EventSelector. Using "
211 << m_timeStamp << endmsg;
212 }
213 else {
214 m_timeStamp = (unsigned int)timeStamp.value();
215 log << MSG::DEBUG << "massageEventInfo: InitialTimeStamp: " << m_timeStamp
216 << " obtained from " << eventSelector << endmsg;
217 }
218 IntegerProperty timeStampInterval("TimeStampInterval", 0);
219 sc = evtSel->getProperty(&timeStampInterval);
220 if (!sc.isSuccess()) {
221 log << MSG::INFO << "massageEventInfo: unable to get TimeStampInterval from EventSelector. Using "
223 }
224 else {
225 m_timeStampInterval = (unsigned int)timeStampInterval.value();
226 log << MSG::DEBUG << "massageEventInfo: TimeStampInterval: " << m_timeStampInterval
227 << " obtained from " << eventSelector << endmsg;
228 }
229 }
230 else {
231 log << MSG::DEBUG << "massageEventInfo: OverrideRunNumberFromInput from EventSelector is false "
232 << endmsg;
233 }
234 }
235
237 // Reset run number, and copy run number into EventType
238
239 // First make sure we're dealing with simulation events - if not, this is an error
241 MsgStream log(msgSvc(), "EventInfoCnv" );
242 log << MSG::ERROR << "massageEventInfo: trying to reset run number for data!!! " << endmsg;
243 log << MSG::ERROR << " Job option EventSelector.RunNumber should NOT be set, found it set to: " << m_simRunNumber << endmsg;
244 throw std::runtime_error("Trying to reset run number for DATA!!!");
245 }
246
247 // Copy run/event numbers into EventType
248 // We only do so if mc_channel_number has not already be set
249 // either previously or elsewhere!!
250 if (ei->event_type()->mc_channel_number() == 0) {
251 ei->event_type()->set_mc_channel_number(ei->event_ID()->run_number());
252 ei->event_type()->set_mc_event_number (ei->event_ID()->event_number());
253 }
254
255 // Override run and other numbers
256 if (m_evtsPerLumiBlock > 0) {
260 m_lbEvtCounter = 1;
261 }
262 }
263 ei->event_ID()->set_run_number(m_simRunNumber);
264 ei->event_ID()->set_lumi_block(m_lumiBlockNumber);
265 ei->event_ID()->set_time_stamp(m_timeStamp);
267 }
268
269
270 return (ei);
271}
272
273
274
275
276
#define endmsg
#define ATH_MSG_INFO(x)
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
static const EventInfoCnv_p1 TPconverter_p1
static const EventInfoCnv_p3 TPconverter_p3
static const EventInfoCnv_p2 TPconverter_p2
static const EventInfoCnv_p4 TPconverter_p4
AthenaPool converter for EventInfo.
EventInfo_p4 EventInfo_PERS
T_AthenaPoolCustomCnv< EventInfo, EventInfo_PERS > EventInfoCnvBase
This class is the persistent representation of EventInfo.
This class provides general information about an event.
static Double_t sc
This class contains trigger related information.
EventInfoCnv(ISvcLocator *svcloc)
bool m_checkedEventSelector
unsigned int m_simRunNumber
bool m_overrideRunNumber
unsigned int m_evtsPerLumiBlock
unsigned int m_lbEvtCounter
unsigned int m_timeStamp
SmartIF< IEvtIdModifierSvc > m_evtIdModSvc
unsigned int m_timeStampInterval
virtual EventInfo * createTransient()
EventInfo * massageEventInfo(EventInfo *ei)
virtual EventInfo_PERS * createPersistent(EventInfo *transObj)
unsigned int m_lumiBlockNumber
EventID * event_ID()
the unique identification of the event.
TriggerInfo * trigger_info()
trigger information (ptr may be NULL)
EventType * event_type()
the type of the event, e.g. simulation, testbeam, etc
float mc_event_weight(unsigned int iweight=0) const
Access to MC weight.
void set_mc_event_weight(float weight, unsigned int iweight=0, unsigned int nWeightsMax=0)
Add in MC weight. For more than 1 weight, add with iweight > 0.
void set_mc_channel_number(number_type chan)
Add in the MC generator channel number (aka gen run number)
number_type mc_channel_number() const
Access to the MC generator channel number (was used as run number for generator events)
void set_mc_event_number(uint64_t evt)
Add in the MC generator event number.
static const EventTypeCode IS_SIMULATION
true: IS_SIMULATION, false: IS_DATA
Definition EventType.h:156
bool test(EventTypeCode type_code) const
Tests for standard characteristics.
Definition EventType.cxx:62
virtual bool compareClassGuid(const Guid &clid) const
const std::vector< number_type > & eventFilterInfo() const
get event filter trigger info
thread_local event_number_t eventIndex