ATLAS Offline Software
EventInfoCnv.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
21 static const EventInfoCnv_p4 TPconverter_p4;
22 static const EventInfoCnv_p3 TPconverter_p3;
23 static const EventInfoCnv_p2 TPconverter_p2;
24 static const EventInfoCnv_p1 TPconverter_p1;
25 
26 EventInfoCnv::EventInfoCnv(ISvcLocator* svcloc)
27  :
28  EventInfoCnvBase(svcloc),
29  m_checkedEventSelector(false),
30  m_overrideRunNumber(false),
31  m_simRunNumber(0),
32  m_lumiBlockNumber(1),
33  m_evtsPerLumiBlock(0),
34  m_lbEvtCounter(0),
35  m_timeStamp(0),
36  m_timeStampInterval(0)
37 {
38  m_evtIdModSvc = svcloc->service("EvtIdModifierSvc", /*createif*/false);
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
85  EventInfo* ei = poolReadObject< EventInfo >();
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
98  ei->event_type()->set_mc_event_weight(1.0);
99  }
100  return massageEventInfo(ei);
101  }
102  throw std::runtime_error("Unsupported persistent version of EventInfo");
103 }
104 
105 
106 EventInfo*
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 
137  if (!m_checkedEventSelector) {
138  // Get run number parameter from the EventSelector
139  m_checkedEventSelector = true;
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 = IntegerProperty("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();
171  if (m_overrideRunNumber) {
172  IntegerProperty runNumber = IntegerProperty("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 = IntegerProperty("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 = IntegerProperty("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 = IntegerProperty("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 = IntegerProperty("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 
236  if (m_overrideRunNumber) {
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
240  if (!(ei->event_type()->test(EventType::IS_SIMULATION))) {
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) {
257  m_lbEvtCounter++;
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 
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 ...
EventInfoCnv::m_evtIdModSvc
SmartIF< IEvtIdModifierSvc > m_evtIdModSvc
Definition: EventInfoCnv.h:49
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...
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:224
EventInfoCnv_p1.h
EventInfoCnv::massageEventInfo
EventInfo * massageEventInfo(EventInfo *ei)
Definition: EventInfoCnv.cxx:107
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:45
EventInfoCnv::EventInfoCnv
EventInfoCnv(ISvcLocator *svcloc)
Definition: EventInfoCnv.cxx:26
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:41
EventInfoCnv::m_checkedEventSelector
bool m_checkedEventSelector
Definition: EventInfoCnv.h:40
EventInfoCnv::createTransient
virtual EventInfo * createTransient()
Definition: EventInfoCnv.cxx:48
EventInfo
This class provides general information about an event. Event information is provided by the accessor...
Definition: EventInfo/EventInfo/EventInfo.h:43
EventInfoCnv_p3.h
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:244
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:234
EventInfoCnvParams::eventIndex
thread_local event_number_t eventIndex
Definition: IEvtIdModifierSvc.h:34