Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
EventInfoByteStreamAuxCnv.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 
13 
15 #include "GaudiKernel/MsgStream.h"
16 #include "GaudiKernel/StatusCode.h"
17 #include "GaudiKernel/DataObject.h"
18 #include "GaudiKernel/IRegistry.h"
19 
22 
23 #include "StoreGate/StoreGateSvc.h"
24 
25 #include "eformat/StreamTag.h"
26 
27 #include <time.h>
28 
30  : Converter(storageType(), classID(), svcloc)
31  , AthMessaging(svcloc != nullptr ? msgSvc() : nullptr, "EventInfoByteStreamAuxCnv")
32  , m_robDataProvider("ROBDataProviderSvc", "EventInfoByteStreamAuxCnv")
33  , m_mdSvc("InputMetaDataStore", "EventInfoByteStreamAuxCnv")
34  , m_isSimulation(false)
35  , m_isTestbeam(false)
36  , m_isCalibration(false)
37 {
38 }
39 
41 {
43 }
44 
46 {
48 }
49 
51 {
52  ATH_MSG_DEBUG("Initialize");
53 
55 
56  CHECK(m_robDataProvider.retrieve());
57  CHECK(m_mdSvc.retrieve());
58 
59  SmartIF<IProperty> byteStreamCnvSvc(service("ByteStreamCnvSvc"));
60  CHECK( byteStreamCnvSvc.isValid() );
61 
62  SimpleProperty<bool> propIsSimulation("IsSimulation", m_isSimulation);
63  StatusCode sc = byteStreamCnvSvc->getProperty(&propIsSimulation);
64  if (sc.isSuccess()) {
65  m_isSimulation = propIsSimulation.value();
66  ATH_MSG_INFO("IsSimulation : " << m_isSimulation);
67  }
68  else {
69  ATH_MSG_ERROR("Cannot get IsSimulation");
70  return sc;
71  }
72 
73  SimpleProperty<bool> propIsTestbeam("IsTestbeam", m_isTestbeam);
74  sc = byteStreamCnvSvc->getProperty(&propIsTestbeam);
75  if (sc.isSuccess()) {
76  m_isTestbeam = propIsTestbeam.value();
77  ATH_MSG_INFO("IsTestbeam : " << m_isTestbeam);
78  }
79  else {
80  ATH_MSG_ERROR("Cannot get IsTestbeam");
81  return sc;
82  }
83 
84  SimpleProperty<bool> propIsCalibration("IsCalibration", m_isCalibration);
85  sc = byteStreamCnvSvc->getProperty(&propIsCalibration);
86  if (sc.isSuccess()) {
87  m_isCalibration = propIsCalibration.value();
88  ATH_MSG_INFO("IsCalibration : " << m_isCalibration);
89  }
90  else {
91  ATH_MSG_ERROR("Cannot get IsCalibration");
92  return sc;
93  }
94 
95  return StatusCode::SUCCESS;
96 }
97 
99 {
100  ATH_MSG_DEBUG("Finalize");
101 
103  if (sc.isFailure()) {
104  ATH_MSG_WARNING("Converter::finalize() failed");
105  }
106  return sc;
107 }
108 
109 StatusCode EventInfoByteStreamAuxCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
110 {
111  ByteStreamAddress *pRE_Addr{nullptr};
112  pRE_Addr = dynamic_cast<ByteStreamAddress*>(pAddr);
113  if (!pRE_Addr) {
114  ATH_MSG_ERROR("Cannot cast to ByteStreamAddress ");
115  return StatusCode::FAILURE;
116  }
117 
118  ATH_MSG_DEBUG("Creating Objects");
119 
120  // get RawEvent
121  const RawEvent* re = m_robDataProvider->getEvent(Gaudi::Hive::currentContext());
122  if (!re) {
123  ATH_MSG_ERROR("Can not get RawEvent ");
124  return StatusCode::FAILURE;
125  }
126 
127  // Run Number
128  int runNumber = re->run_no();
129 
130  // Event Number
132  if (re->version() < 0x03010000) {
133  eventNumber=re->lvl1_id();
134  } else {
135  eventNumber=re->global_id();
136  }
137 
138  // Time Stamp
139  uint32_t bc_time_sec = re->bc_time_seconds();
140  uint32_t bc_time_ns = re->bc_time_nanoseconds();
141  // bc_time_ns should be lt 1e9.
142  if (bc_time_ns > 1000000000) {
143  if (runNumber < 20920) {
144  // In M4 we saw otherwise, because sec/ns was swapped in raw data.
145  uint32_t temp = bc_time_ns;
146  bc_time_ns = bc_time_sec;
147  bc_time_sec= temp;
148  ATH_MSG_DEBUG("bc_time second/nanosecond swapped, sec/ns = " << bc_time_sec << " " << bc_time_ns);
149  }
150  else {
151  // For later runs, the nanosecond clock sometimes is not reset, making it overrun 1e9. Round it off to 1e9
152  ATH_MSG_WARNING("bc_time nanosecond number larger than 1e9, it is " << bc_time_ns << ", reset it to 1 sec");
153  bc_time_ns = 1000000000;
154  }
155  }
156 
157  // luminosity block number
158  uint16_t lumiBlock = re->lumi_block();
159 
160  // bunch crossing identifier
161  uint16_t bcID = re->bc_id();
162 
163  unsigned int detMask0 = 0xFFFFFFFF, detMask1 = 0xFFFFFFFF, detMask2 = 0xFFFFFFFF, detMask3 = 0xFFFFFFFF;
164  // Get ByteStream Metadata from Input MetaData Store
165  const ByteStreamMetadataContainer* metadatacont{nullptr};
166  StatusCode status = m_mdSvc->retrieve(metadatacont, "ByteStreamMetadata");
167  if (!status.isSuccess()) {
168  ATH_MSG_WARNING("Unable to retrieve Input MetaData for ByteStream");
169  }
170  else {
171  const ByteStreamMetadata* metadata = *(metadatacont->begin());
172  uint64_t detectorMask = metadata->getDetectorMask();
173  detMask0 = (unsigned int)(detectorMask & 0x00000000FFFFFFFF);
174  detMask1 = (unsigned int)(detectorMask >> 32);
175  uint64_t detectorMask2 = metadata->getDetectorMask2();
176  detMask2 = (unsigned int)(detectorMask2 & 0x00000000FFFFFFFF);
177  detMask3 = (unsigned int)(detectorMask2 >> 32);
178  }
179 
180 
181  xAOD::EventInfo evtInfo;
182  xAOD::EventAuxInfo* pEvtInfoAux = new xAOD::EventAuxInfo();
183  evtInfo.setStore(pEvtInfoAux);
184 
185  evtInfo.setRunNumber(runNumber);
186  evtInfo.setEventNumber(eventNumber);
187  evtInfo.setLumiBlock(lumiBlock);
188  evtInfo.setTimeStamp(bc_time_sec);
189  evtInfo.setTimeStampNSOffset(bc_time_ns);
190  evtInfo.setBCID(bcID);
191  evtInfo.setDetectorMask(detMask0,detMask1);
192  evtInfo.setDetectorMaskExt(detMask2,detMask3);
193 
194  // The following values were implicitly set by the BS converter of the legacy EventInfo
195  // Setting them here too
196  evtInfo.setMCChannelNumber(0);
197  evtInfo.setMCEventNumber(0);
198  evtInfo.setMCEventWeights(std::vector<float>(1,1));
199 
200  // Set Event Type
201  uint32_t eventTypeBitmask{0};
202  if (m_isSimulation) {
203  eventTypeBitmask |= xAOD::EventInfo::IS_SIMULATION;
204  }
205  if (m_isTestbeam) {
206  eventTypeBitmask |= xAOD::EventInfo::IS_TESTBEAM;
207  }
208  if (m_isCalibration) {
209  eventTypeBitmask |= xAOD::EventInfo::IS_CALIBRATION;
210  }
211  evtInfo.setEventTypeBitmask(eventTypeBitmask);
212 
213  // Trigger Info
215  // status element
216  re->status(buffer);
217  uint32_t statusElement = *buffer;
218 
219  // extended LVL1ID
220  uint32_t extendedLevel1ID = re->lvl1_id();
221 
222  // LVL1 trigger type
223  uint32_t level1TriggerType = re->lvl1_trigger_type();
224 
225  // stream tag
226  std::vector<xAOD::EventInfo::StreamTag> streamTags;
227  std::vector<eformat::helper::StreamTag> onl_streamTags;
228  re->stream_tag(buffer);
229  eformat::helper::decode(re->nstream_tag(), buffer, onl_streamTags);
230  for (const eformat::helper::StreamTag& onl_streamTag : onl_streamTags) {
231  std::set<uint32_t> tmp_off_dets = std::set<uint32_t>();
232  if (!onl_streamTag.dets.empty()) {
233  std::set<eformat::SubDetector> tmp_onl_dets = onl_streamTag.dets;
234  for (const eformat::SubDetector& subdet : tmp_onl_dets) {
235  tmp_off_dets.insert((uint32_t) subdet);
236  }
237  }
238  streamTags.push_back(xAOD::EventInfo::StreamTag(onl_streamTag.name
239  , onl_streamTag.type
240  , onl_streamTag.obeys_lumiblock
241  , onl_streamTag.robs
242  , tmp_off_dets)
243  );
244  }
245 
246  evtInfo.setStatusElement(statusElement);
247  evtInfo.setExtendedLevel1ID(extendedLevel1ID);
248  evtInfo.setLevel1TriggerType(level1TriggerType);
249  evtInfo.setStreamTags(streamTags);
250 
251  // record EventInfo
252  evtInfo.setEventFlags(xAOD::EventInfo::Core, m_robDataProvider->getEventStatus(Gaudi::Hive::currentContext()));
253  pObj = SG::asStorable(pEvtInfoAux);
254 
255  ATH_MSG_DEBUG(" New xAOD::EventAuxInfo made, run/event= " << runNumber
256  << " " << eventNumber
257  << " Time stamp = " << ascTime(bc_time_sec)
258  );
259 
260  return StatusCode::SUCCESS;
261 }
262 
263 StatusCode EventInfoByteStreamAuxCnv::createRep(DataObject* /*pObj*/, IOpaqueAddress*& /*pAddr*/)
264 {
265  ATH_MSG_DEBUG("Nothing to be done for xAOD::EventAuxInfo createReps");
266  return StatusCode::SUCCESS;
267 }
268 
269 std::string EventInfoByteStreamAuxCnv::ascTime(unsigned int tstamp)
270 {
271  struct tm t;
272  t.tm_sec = tstamp;
273  t.tm_min = 0;
274  t.tm_hour = 0;
275  t.tm_mday = 0;
276  t.tm_mon = 0;
277  t.tm_year = 70;
278  t.tm_wday = 00;
279  t.tm_yday = 00;
280  t.tm_isdst = 0;
281  time_t ct = mktime(&t);
282  struct tm t2;
283  gmtime_r(&ct, &t2);
284  char buf[32];
285  asctime_r (&t2, buf);
286  return std::string (buf);
287 }
ByteStreamMetadata.h
This file contains the class definition for the ByteStreamMetadata class.
AtlasMcWeight::decode
double decode(number_type binnedWeight)
Convert weight from unsigned to double.
Definition: AtlasMcWeight.cxx:32
EventInfoByteStreamAuxCnv.h
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
EventInfoByteStreamAuxCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj) override
converter method to create object
Definition: EventInfoByteStreamAuxCnv.cxx:109
EventInfoByteStreamAuxCnv::ascTime
std::string ascTime(unsigned int t)
convert timestamp to ascii time.
Definition: EventInfoByteStreamAuxCnv.cxx:269
xAOD::EventInfo_v1::setEventNumber
void setEventNumber(uint64_t value)
Set the current event's event number.
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
OFFLINE_FRAGMENTS_NAMESPACE::DataType
uint32_t DataType
Definition: RawEvent.h:24
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
initialize
void initialize()
Definition: run_EoverP.cxx:894
xAOD::EventAuxInfo_v3
Auxiliary information about the event.
Definition: EventAuxInfo_v3.h:28
xAOD::EventInfo_v1::IS_CALIBRATION
@ IS_CALIBRATION
true: calibration, false: physics
Definition: EventInfo_v1.h:155
RawEvent
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Definition: RawEvent.h:37
ByteStreamMetadataContainer.h
This file contains the class definition for the ByteStreamMetadataContainer class.
xAOD::EventInfo_v1::setExtendedLevel1ID
void setExtendedLevel1ID(uint32_t value)
Set the extended Level-1 identifier.
ByteStreamMetadata
This class is the StoreGate data object for bytestream metadata.
Definition: ByteStreamMetadata.h:25
EventInfoByteStreamAuxCnv::m_isTestbeam
bool m_isTestbeam
Definition: EventInfoByteStreamAuxCnv.h:55
EventInfoByteStreamAuxCnv::EventInfoByteStreamAuxCnv
EventInfoByteStreamAuxCnv(ISvcLocator *svcloc)
Definition: EventInfoByteStreamAuxCnv.cxx:29
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
python.checkMetadata.metadata
metadata
Definition: checkMetadata.py:175
xAOD::EventInfo_v1::setEventFlags
bool setEventFlags(EventFlagSubDet subDet, uint32_t flags)
Set the event flags for a particular sub-detector.
Definition: EventInfo_v1.cxx:719
SG::asStorable
DataObject * asStorable(SG::DataObjectSharedPtr< T > pObject)
Definition: DataObjectSharedPtr.h:65
xAOD::EventInfo_v1::setStreamTags
void setStreamTags(const std::vector< StreamTag > &value)
Set the streams that the event was put in.
Definition: EventInfo_v1.cxx:342
xAOD::EventInfo_v1::setLevel1TriggerType
void setLevel1TriggerType(uint16_t value)
Set the Level-1 trigger type.
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
EventInfoByteStreamAuxCnv::m_mdSvc
ServiceHandle< StoreGateSvc > m_mdSvc
TDS handle.
Definition: EventInfoByteStreamAuxCnv.h:51
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::EventInfo_v1::setMCEventNumber
void setMCEventNumber(uint64_t value)
Set the MC generator's event number.
xAOD::EventInfo_v1::setEventTypeBitmask
void setEventTypeBitmask(uint32_t value)
Set the event type bitmask.
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
ByteStreamMetadataContainer
This class is the StoreGate data object for bytestream metadata.
Definition: ByteStreamMetadataContainer.h:22
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
SG::AuxElement::setStore
void setStore(const SG::IConstAuxStore *store)
Set the store associated with this object.
Definition: AuxElement.cxx:241
EventInfoByteStreamAuxCnv::m_isSimulation
bool m_isSimulation
Definition: EventInfoByteStreamAuxCnv.h:54
xAOD::EventInfo_v1::setDetectorMask
void setDetectorMask(uint32_t mask0, uint32_t mask1)
Set the bit fields indicating with TTC timezones were present.
Definition: EventInfo_v1.cxx:149
RawEvent.h
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
ByteStreamAddress
IOpaqueAddress for ByteStreamCnvSvc, with ROB ids.
Definition: ByteStreamAddress.h:28
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
ByteStreamAddress.h
xAOD::EventInfo_v1::setStatusElement
void setStatusElement(uint32_t value)
Set the trigger status element.
xAOD::EventInfo_v1::setTimeStamp
void setTimeStamp(uint32_t value)
Set the POSIX time of the event.
xAOD::EventInfo_v1::setBCID
void setBCID(uint32_t value)
Set the bunch crossing ID of the event.
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
EventInfoByteStreamAuxCnv::storageType
static long storageType()
Definition: EventInfoByteStreamAuxCnv.cxx:45
calibdata.ct
ct
Definition: calibdata.py:418
xAOD::EventAuxInfo
EventAuxInfo_v3 EventAuxInfo
Definition of the latest event auxiliary info version.
Definition: EventAuxInfo.h:15
EventInfoByteStreamAuxCnv::m_robDataProvider
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
RODDataProviderSvc handle.
Definition: EventInfoByteStreamAuxCnv.h:50
ByteStreamAddress::storageType
static constexpr long storageType()
Definition: ByteStreamAddress.h:51
EventAuxInfo.h
Converter
Definition: Converter.h:27
xAOD::EventInfo_v1::setDetectorMaskExt
void setDetectorMaskExt(uint32_t mask2, uint32_t mask3)
Set the bit fields indicating with TTC timezones were present.
Definition: EventInfo_v1.cxx:170
EventInfoByteStreamAuxCnv::finalize
virtual StatusCode finalize() override
Definition: EventInfoByteStreamAuxCnv.cxx:98
errorcheck.h
Helpers for checking error return status codes and reporting errors.
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
xAOD::EventInfo_v1::setTimeStampNSOffset
void setTimeStampNSOffset(uint32_t value)
Set the nanosecond offset wrt. the time stamp.
xAOD::EventInfo_v1::setMCChannelNumber
void setMCChannelNumber(uint32_t value)
Set the MC generator's channel number.
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
EventInfoByteStreamAuxCnv::m_isCalibration
bool m_isCalibration
Definition: EventInfoByteStreamAuxCnv.h:56
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::EventInfo_v1::setRunNumber
void setRunNumber(uint32_t value)
Set the current event's run number.
re
const boost::regex re(r_e)
ByteStreamCnvSvcBase.h
ClassID_traits::ID
static CLID ID()
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:44
merge.status
status
Definition: merge.py:17
EventInfoByteStreamAuxCnv::classID
static const CLID & classID()
Definition: EventInfoByteStreamAuxCnv.cxx:40
xAOD::EventInfo_v1::setLumiBlock
void setLumiBlock(uint32_t value)
Set the current event's luminosity block number.
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
EventInfoByteStreamAuxCnv::createRep
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr) override
converter method to write object
Definition: EventInfoByteStreamAuxCnv.cxx:263
EventInfoByteStreamAuxCnv::initialize
virtual StatusCode initialize() override
Definition: EventInfoByteStreamAuxCnv.cxx:50
StoreGateSvc.h
xAOD::EventInfo_v1::IS_TESTBEAM
@ IS_TESTBEAM
true: testbeam, false: full detector
Definition: EventInfo_v1.h:153
xAOD::EventInfo_v1::Core
@ Core
Core flags describing the event.
Definition: EventInfo_v1.h:339
IROBDataProviderSvc.h
xAOD::EventInfo_v1::StreamTag
Class describing a stream tag on the event.
Definition: EventInfo_v1.h:190
xAOD::EventInfo_v1::setMCEventWeights
void setMCEventWeights(const std::vector< float > &value)
Set the weights of all the MC events used in the simulation.