ATLAS Offline Software
EventInfoAttListTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /*****************************************************************************
6 Name : EventInfoAttListTool.cxx
7 Author : Jack Cranshaw
8 Created : January 2017
9 Purpose : create a EventInfoAttList - The Tag information associated to the event
10  is built here
11 
12 *****************************************************************************/
13 
14 #include "EventInfoAttListTool.h"
15 
16 #include "GaudiKernel/MsgStream.h"
17 #include "Gaudi/Property.h"
18 
20 #include "EventInfo/EventInfo.h"
21 #include "EventInfo/EventID.h"
22 #include "EventInfo/EventType.h"
23 #include "CoralBase/AttributeListSpecification.h"
25 
26 #include <sstream>
27 
28 
29 //using xAOD::EventInfo;
30 
33  std::string& name, const IInterface* parent) :
35 {
36  declareInterface<EventInfoAttListTool>( this );
37 }
38 
41  ATH_MSG_DEBUG("in initialize()");
42 
43  m_attribListSpec = new coral::AttributeListSpecification();
44  // Note: for any attribute added here, please confirm the corresponding EventInfo member being
45  // retained in DAOD smart slimming:
46  // PhysicsAnalysis/DerivationFramework/DerivationFrameworkCore/python/EventInfoContent.py
47  m_attribListSpec->extend("IsSimulation", "bool");
48  m_attribListSpec->extend("IsCalibration", "bool");
49  m_attribListSpec->extend("IsTestBeam", "bool");
50  m_attribListSpec->extend("McChannel", "unsigned int");
51  m_attribListSpec->extend("RunNumber", "unsigned int");
52  m_attribListSpec->extend("EventNumber", "unsigned long long");
53  m_attribListSpec->extend("LumiBlockN", "unsigned int");
54  m_attribListSpec->extend("ConditionsRun", "unsigned int");
55  m_attribListSpec->extend("EventTime", "unsigned int");
56  m_attribListSpec->extend("EventTimeNanoSec","unsigned int");
57  m_attribListSpec->extend("BunchId", "unsigned int");
58  m_attribListSpec->extend("EventWeight", "float");
59 
60  return AthAlgTool::initialize();
61 }
62 
63 
64 /* Build attribute list from EventInfo object */
66 
67  // Create attributeList with appropriate attributes
69 
70  StatusCode sc = this->eventTag (eventTag, eventInfo);
71  if (sc.isFailure()) {
72  ATH_MSG_WARNING("Unable to build Tag Fragments for the Event");
73  }
74 
75  ATH_MSG_DEBUG("EventInfoAttListTool - getAttributeList() return success");
76 
77  return eventTag;
78 }
79 
80 
81 /* Build attribute list from EventInfo object */
83 
84  // Create attributeList with appropriate attributes
86 
87  StatusCode sc = this->eventTag (eventTag, eventInfo);
88  if (sc.isFailure()) {
89  ATH_MSG_WARNING("Unable to build Tag Fragments for the Event");
90  }
91 
92  ATH_MSG_DEBUG("EventInfoAttListTool - getAttributeList() return success");
93 
94  return eventTag;
95 }
96 
97 /* Build attribute list from EventInfo object */
98 std::unique_ptr<AthenaAttributeList>
100 {
101  // Create attributeList with appropriate attributes
102  auto eventTag = std::make_unique<AthenaAttributeList> ( *m_attribListSpec );
103 
104  StatusCode sc = this->eventTag (*eventTag, eventInfo);
105  if (sc.isFailure()) {
106  ATH_MSG_WARNING("Unable to build Tag Fragments for the Event");
107  }
108 
109  ATH_MSG_DEBUG("EventInfoAttListTool - getAttributeList() return success");
110 
111  return eventTag;
112 }
113 
114 
117  const xAOD::EventInfo& eventInfo)
118 {
119  // Note: for any attribute added here, please confirm the corresponding EventInfo member being
120  // retained in DAOD smart slimming:
121  // PhysicsAnalysis/DerivationFramework/DerivationFrameworkCore/python/EventInfoContent.py
122 
124  bool isSimulation = eventInfo.eventType(xAOD::EventInfo::IS_SIMULATION);
125  bool isTestBeam = eventInfo.eventType(xAOD::EventInfo::IS_TESTBEAM);
126  bool isCalibration = eventInfo.eventType(xAOD::EventInfo::IS_CALIBRATION);
127  eventTag["IsSimulation"] .data<bool>() = isSimulation;
128  eventTag["IsCalibration"].data<bool>() = isCalibration;
129  eventTag["IsTestBeam"] .data<bool>() = isTestBeam;
130 
131  // run number and Event number
132  unsigned int runNumber = eventInfo.runNumber();
133  unsigned int condRunNumber = runNumber;
134  unsigned long long eventNumber = eventInfo.eventNumber();
135  unsigned int lumiBlock = eventInfo.lumiBlock();
136  unsigned int mcChannel = 0;
137  if (isSimulation) mcChannel = eventInfo.mcChannelNumber();
138  eventTag["McChannel"] .data<unsigned int>() = mcChannel;
139  eventTag["RunNumber"] .data<unsigned int>() = runNumber;
140  eventTag["EventNumber"] .data<unsigned long long>() = eventNumber;
141  eventTag["LumiBlockN"] .data<unsigned int>() = lumiBlock;
142  eventTag["ConditionsRun"].data<unsigned int>() = condRunNumber;
143 
144  unsigned long timeStamp = eventInfo.timeStamp();
145  unsigned long timeStampNS = eventInfo.timeStampNSOffset();
146  unsigned long bunchId = eventInfo.bcid();
147  eventTag["EventTime"] .data<unsigned int>() = timeStamp;
148  eventTag["EventTimeNanoSec"].data<unsigned int>() = timeStampNS;
149  eventTag["BunchId"] .data<unsigned int>() = bunchId;
150 
151  // event weight
152  // used for event weighting in monte carlo or just an event count in data
153  float evweight = 1;
154  if (isSimulation) evweight = eventInfo.mcEventWeight();
155  eventTag["EventWeight"].data<float>() = evweight;
156 
157  return StatusCode::SUCCESS;
158 
159 }
160 
163  const EventInfo& eventInfo)
164 {
165 
167  bool isSimulation = eventInfo.event_type()->test(EventType::IS_SIMULATION);
168  bool isTestBeam = eventInfo.event_type()->test(EventType::IS_TESTBEAM);
169  bool isCalibration = eventInfo.event_type()->test(EventType::IS_CALIBRATION);
170  eventTag["IsSimulation"] .data<bool>() = isSimulation;
171  eventTag["IsCalibration"].data<bool>() = isCalibration;
172  eventTag["IsTestBeam"] .data<bool>() = isTestBeam;
173 
174  // run number and Event number
175  unsigned int runNumber = eventInfo.event_ID()->run_number();
176  unsigned int condRunNumber = runNumber;
177  unsigned long long eventNumber = eventInfo.event_ID()->event_number();
178  unsigned int lumiBlock = eventInfo.event_ID()->lumi_block();
179  unsigned int mcChannel = 0;
180  if (isSimulation) mcChannel = eventInfo.event_type()->mc_channel_number();;
181  eventTag["McChannel"] .data<unsigned int>() = mcChannel;
182  eventTag["RunNumber"] .data<unsigned int>() = runNumber;
183  eventTag["EventNumber"] .data<unsigned long long>() = eventNumber;
184  eventTag["LumiBlockN"] .data<unsigned int>() = lumiBlock;
185  eventTag["ConditionsRun"].data<unsigned int>() = condRunNumber;
186 
187  unsigned long timeStamp = eventInfo.event_ID()->time_stamp();
188  unsigned long timeStampNS = eventInfo.event_ID()->time_stamp_ns_offset();
189  unsigned long bunchId = eventInfo.event_ID()->bunch_crossing_id();
190  eventTag["EventTime"] .data<unsigned int>() = timeStamp;
191  eventTag["EventTimeNanoSec"].data<unsigned int>() = timeStampNS;
192  eventTag["BunchId"] .data<unsigned int>() = bunchId;
193 
194  // event weight
195  // used for event weighting in monte carlo or just an event count in data
196  float evweight = 1;
197  if (isSimulation) evweight = eventInfo.event_type()->mc_event_weight();
198  eventTag["EventWeight"].data<float>() = evweight;
199 
200  return StatusCode::SUCCESS;
201 
202 }
203 
206  ATH_MSG_DEBUG("in finalize()");
207  m_attribListSpec->release();
208  m_attribListSpec = nullptr;
209  return AthAlgTool::finalize();
210 }
EventInfoAttListTool::EventInfoAttListTool
EventInfoAttListTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: EventInfoAttListTool.cxx:32
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
EventInfoAttListTool.h
initialize
void initialize()
Definition: run_EoverP.cxx:894
xAOD::EventInfo_v1::IS_CALIBRATION
@ IS_CALIBRATION
true: calibration, false: physics
Definition: EventInfo_v1.h:155
EventInfoAttListTool::initialize
StatusCode initialize() override
Overriding initialize, finalize and execute.
Definition: EventInfoAttListTool.cxx:40
EventType.h
This class provides general information about an event. It extends EventInfo with a list of sub-evts ...
EventInfoAttListTool::finalize
StatusCode finalize() override
finialize - called once at the end
Definition: EventInfoAttListTool.cxx:205
xAOD::EventInfo_v1::timeStampNSOffset
uint32_t timeStampNSOffset() const
Nanosecond time offset wrt. the time stamp.
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
EventType::mc_event_weight
float mc_event_weight(unsigned int iweight=0) const
Access to MC weight.
Definition: EventType.cxx:175
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
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
EventInfoAttListTool::getAttributeList
const AthenaAttributeList getAttributeList(const xAOD::EventInfo &einfo)
Definition: EventInfoAttListTool.cxx:65
xAOD::EventInfo_v1::mcChannelNumber
uint32_t mcChannelNumber() const
The MC generator's channel number.
EventID.h
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
EventType::IS_CALIBRATION
static const EventTypeCode IS_CALIBRATION
true: IS_CALIBRATION, false: IS_PHYSICS
Definition: EventType.h:157
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
EventInfo::event_ID
EventID * event_ID()
the unique identification of the event.
Definition: EventInfo/EventInfo/EventInfo.h:224
test_pyathena.parent
parent
Definition: test_pyathena.py:15
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
EventInfoAttListTool::getAttributeListPtr
std::unique_ptr< AthenaAttributeList > getAttributeListPtr(const xAOD::EventInfo &einfo)
Definition: EventInfoAttListTool.cxx:99
xAOD::EventInfo_v1::lumiBlock
uint32_t lumiBlock() const
The current event's luminosity block number.
EventType::IS_SIMULATION
static const EventTypeCode IS_SIMULATION
true: IS_SIMULATION, false: IS_DATA
Definition: EventType.h:151
EventInfoAttListTool::eventTag
StatusCode eventTag(AthenaAttributeList &eventTagCol, const xAOD::EventInfo &eventInfo)
the various components to build their own fragments of tag
Definition: EventInfoAttListTool.cxx:116
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
EventInfo
This class provides general information about an event. Event information is provided by the accessor...
Definition: EventInfo/EventInfo/EventInfo.h:43
AthenaAttributeList.h
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
EventInfo.h
xAOD::timeStamp
setEventNumber timeStamp
Definition: EventInfo_v1.cxx:128
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
EventType::IS_TESTBEAM
static const EventTypeCode IS_TESTBEAM
true: IS_TESTBEAM, false: IS_FROM_ATLAS_DET
Definition: EventType.h:154
EventType::test
bool test(EventTypeCode type_code) const
Tests for standard characteristics.
Definition: EventType.cxx:62
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::EventInfo_v1::timeStamp
uint32_t timeStamp() const
POSIX time in seconds from 1970. January 1st.
xAOD::EventInfo_v1::mcEventWeight
float mcEventWeight(size_t i=0) const
The weight of one specific MC event used in the simulation.
Definition: EventInfo_v1.cxx:203
AthAlgTool
Definition: AthAlgTool.h:26
xAOD::EventInfo_v1::bcid
uint32_t bcid() const
The bunch crossing ID of the event.
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
xAOD::EventInfo_v1::IS_TESTBEAM
@ IS_TESTBEAM
true: testbeam, false: full detector
Definition: EventInfo_v1.h:153
EventInfoAttListTool::m_attribListSpec
coral::AttributeListSpecification * m_attribListSpec
Definition: EventInfoAttListTool.h:60
EventInfo::event_type
EventType * event_type()
the type of the event, e.g. simulation, testbeam, etc
Definition: EventInfo/EventInfo/EventInfo.h:234
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.