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