ATLAS Offline Software
EventInfoByteStreamAuxCnv.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
14 
16 #include "GaudiKernel/MsgStream.h"
17 #include "GaudiKernel/StatusCode.h"
18 #include "GaudiKernel/DataObject.h"
19 #include "GaudiKernel/IRegistry.h"
20 
23 
24 #include "StoreGate/StoreGateSvc.h"
25 
26 #include "eformat/StreamTag.h"
27 
28 #include <time.h>
29 
31  : Converter(storageType(), classID(), svcloc)
32  , AthMessaging(svcloc != nullptr ? msgSvc() : nullptr, "EventInfoByteStreamAuxCnv")
33  , m_ByteStreamCnvSvc(nullptr)
34  , m_robDataProvider("ROBDataProviderSvc", "EventInfoByteStreamAuxCnv")
35  , m_mdSvc("InputMetaDataStore", "EventInfoByteStreamAuxCnv")
36  , m_isSimulation(false)
37  , m_isTestbeam(false)
38  , m_isCalibration(false)
39 {
40 }
41 
43 {
45 }
46 
48 {
50 }
51 
53 {
54  ATH_MSG_DEBUG("Initialize");
55 
57 
58  // Check ByteStreamCnvSvc
59  IService* svc{nullptr};
60  StatusCode sc = serviceLocator()->getService("ByteStreamCnvSvc", svc);
61  if (!sc.isSuccess()) {
62  ATH_MSG_ERROR("Cannot get ByteStreamCnvSvc ");
63  return sc;
64  }
66  if (!m_ByteStreamCnvSvc) {
67  ATH_MSG_ERROR("Cannot cast to ByteStreamCnvSvcBase");
68  return StatusCode::FAILURE;
69  }
70 
71  CHECK(m_robDataProvider.retrieve());
72  CHECK(m_mdSvc.retrieve());
73 
74  SimpleProperty<bool> propIsSimulation("IsSimulation", m_isSimulation);
75  sc = m_ByteStreamCnvSvc->getProperty(&propIsSimulation);
76  if (sc.isSuccess()) {
77  m_isSimulation = propIsSimulation.value();
78  ATH_MSG_INFO("IsSimulation : " << m_isSimulation);
79  }
80  else {
81  ATH_MSG_ERROR("Cannot get IsSimulation");
82  return sc;
83  }
84 
85  SimpleProperty<bool> propIsTestbeam("IsTestbeam", m_isTestbeam);
86  sc = m_ByteStreamCnvSvc->getProperty(&propIsTestbeam);
87  if (sc.isSuccess()) {
88  m_isTestbeam = propIsTestbeam.value();
89  ATH_MSG_INFO("IsTestbeam : " << m_isTestbeam);
90  }
91  else {
92  ATH_MSG_ERROR("Cannot get IsTestbeam");
93  return sc;
94  }
95 
96  SimpleProperty<bool> propIsCalibration("IsCalibration", m_isCalibration);
97  sc = m_ByteStreamCnvSvc->getProperty(&propIsCalibration);
98  if (sc.isSuccess()) {
99  m_isCalibration = propIsCalibration.value();
100  ATH_MSG_INFO("IsCalibration : " << m_isCalibration);
101  }
102  else {
103  ATH_MSG_ERROR("Cannot get IsCalibration");
104  return sc;
105  }
106 
107  return StatusCode::SUCCESS;
108 }
109 
111 {
112  ATH_MSG_DEBUG("Finalize");
113 
115  if (sc.isFailure()) {
116  ATH_MSG_WARNING("Converter::finalize() failed");
117  }
118  return sc;
119 }
120 
121 StatusCode EventInfoByteStreamAuxCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
122 {
123  ByteStreamAddress *pRE_Addr{nullptr};
124  pRE_Addr = dynamic_cast<ByteStreamAddress*>(pAddr);
125  if (!pRE_Addr) {
126  ATH_MSG_ERROR("Cannot cast to ByteStreamAddress ");
127  return StatusCode::FAILURE;
128  }
129 
130  ATH_MSG_DEBUG("Creating Objects");
131 
132  // get RawEvent
133  const RawEvent* re = m_robDataProvider->getEvent();
134  if (!re) {
135  ATH_MSG_ERROR("Can not get RawEvent ");
136  return StatusCode::FAILURE;
137  }
138 
139  // Run Number
140  int runNumber = re->run_no();
141 
142  // Event Number
144  if (re->version() < 0x03010000) {
145  eventNumber=re->lvl1_id();
146  } else {
147  eventNumber=re->global_id();
148  }
149 
150  // Time Stamp
151  uint32_t bc_time_sec = re->bc_time_seconds();
152  uint32_t bc_time_ns = re->bc_time_nanoseconds();
153  // bc_time_ns should be lt 1e9.
154  if (bc_time_ns > 1000000000) {
155  if (runNumber < 20920) {
156  // In M4 we saw otherwise, because sec/ns was swapped in raw data.
157  uint32_t temp = bc_time_ns;
158  bc_time_ns = bc_time_sec;
159  bc_time_sec= temp;
160  ATH_MSG_DEBUG("bc_time second/nanosecond swapped, sec/ns = " << bc_time_sec << " " << bc_time_ns);
161  }
162  else {
163  // For later runs, the nanosecond clock sometimes is not reset, making it overrun 1e9. Round it off to 1e9
164  ATH_MSG_WARNING("bc_time nanosecond number larger than 1e9, it is " << bc_time_ns << ", reset it to 1 sec");
165  bc_time_ns = 1000000000;
166  }
167  }
168 
169  // luminosity block number
170  uint16_t lumiBlock = re->lumi_block();
171 
172  // bunch crossing identifier
173  uint16_t bcID = re->bc_id();
174 
175  unsigned int detMask0 = 0xFFFFFFFF, detMask1 = 0xFFFFFFFF, detMask2 = 0xFFFFFFFF, detMask3 = 0xFFFFFFFF;
176  // Get ByteStream Metadata from Input MetaData Store
177  const ByteStreamMetadataContainer* metadatacont{nullptr};
178  StatusCode status = m_mdSvc->retrieve(metadatacont, "ByteStreamMetadata");
179  if (!status.isSuccess()) {
180  ATH_MSG_WARNING("Unable to retrieve Input MetaData for ByteStream");
181  }
182  else {
183  const ByteStreamMetadata* metadata = *(metadatacont->begin());
184  uint64_t detectorMask = metadata->getDetectorMask();
185  detMask0 = (unsigned int)(detectorMask & 0x00000000FFFFFFFF);
186  detMask1 = (unsigned int)(detectorMask >> 32);
187  uint64_t detectorMask2 = metadata->getDetectorMask2();
188  detMask2 = (unsigned int)(detectorMask2 & 0x00000000FFFFFFFF);
189  detMask3 = (unsigned int)(detectorMask2 >> 32);
190  }
191 
192 
193  xAOD::EventInfo evtInfo;
194  xAOD::EventAuxInfo* pEvtInfoAux = new xAOD::EventAuxInfo();
195  evtInfo.setStore(pEvtInfoAux);
196 
197  evtInfo.setRunNumber(runNumber);
198  evtInfo.setEventNumber(eventNumber);
199  evtInfo.setLumiBlock(lumiBlock);
200  evtInfo.setTimeStamp(bc_time_sec);
201  evtInfo.setTimeStampNSOffset(bc_time_ns);
202  evtInfo.setBCID(bcID);
203  evtInfo.setDetectorMask(detMask0,detMask1);
204  evtInfo.setDetectorMaskExt(detMask2,detMask3);
205 
206  // The following values were implicitly set by the BS converter of the legacy EventInfo
207  // Setting them here too
208  evtInfo.setMCChannelNumber(0);
209  evtInfo.setMCEventNumber(0);
210  evtInfo.setMCEventWeights(std::vector<float>(1,1));
211 
212  // Set Event Type
213  uint32_t eventTypeBitmask{0};
214  if (m_isSimulation) {
215  eventTypeBitmask |= xAOD::EventInfo::IS_SIMULATION;
216  }
217  if (m_isTestbeam) {
218  eventTypeBitmask |= xAOD::EventInfo::IS_TESTBEAM;
219  }
220  if (m_isCalibration) {
221  eventTypeBitmask |= xAOD::EventInfo::IS_CALIBRATION;
222  }
223  evtInfo.setEventTypeBitmask(eventTypeBitmask);
224 
225  // Trigger Info
227  // status element
228  re->status(buffer);
229  uint32_t statusElement = *buffer;
230 
231  // extended LVL1ID
232  uint32_t extendedLevel1ID = re->lvl1_id();
233 
234  // LVL1 trigger type
235  uint32_t level1TriggerType = re->lvl1_trigger_type();
236 
237  // stream tag
238  std::vector<xAOD::EventInfo::StreamTag> streamTags;
239  std::vector<eformat::helper::StreamTag> onl_streamTags;
240  re->stream_tag(buffer);
241  eformat::helper::decode(re->nstream_tag(), buffer, onl_streamTags);
242  for (const eformat::helper::StreamTag& onl_streamTag : onl_streamTags) {
243  std::set<uint32_t> tmp_off_dets = std::set<uint32_t>();
244  if (!onl_streamTag.dets.empty()) {
245  std::set<eformat::SubDetector> tmp_onl_dets = onl_streamTag.dets;
246  for (const eformat::SubDetector& subdet : tmp_onl_dets) {
247  tmp_off_dets.insert((uint32_t) subdet);
248  }
249  }
250  streamTags.push_back(xAOD::EventInfo::StreamTag(onl_streamTag.name
251  , onl_streamTag.type
252  , onl_streamTag.obeys_lumiblock
253  , onl_streamTag.robs
254  , tmp_off_dets)
255  );
256  }
257 
258  evtInfo.setStatusElement(statusElement);
259  evtInfo.setExtendedLevel1ID(extendedLevel1ID);
260  evtInfo.setLevel1TriggerType(level1TriggerType);
261  evtInfo.setStreamTags(streamTags);
262 
263  // record EventInfo
264  evtInfo.setEventFlags(xAOD::EventInfo::Core, m_robDataProvider->getEventStatus());
265  pObj = SG::asStorable(pEvtInfoAux);
266 
267  ATH_MSG_DEBUG(" New xAOD::EventAuxInfo made, run/event= " << runNumber
268  << " " << eventNumber
269  << " Time stamp = " << ascTime(bc_time_sec)
270  );
271 
272  return StatusCode::SUCCESS;
273 }
274 
275 StatusCode EventInfoByteStreamAuxCnv::createRep(DataObject* /*pObj*/, IOpaqueAddress*& /*pAddr*/)
276 {
277  ATH_MSG_DEBUG("Nothing to be done for xAOD::EventAuxInfo createReps");
278  return StatusCode::SUCCESS;
279 }
280 
281 std::string EventInfoByteStreamAuxCnv::ascTime(unsigned int tstamp)
282 {
283  struct tm t;
284  t.tm_sec = tstamp;
285  t.tm_min = 0;
286  t.tm_hour = 0;
287  t.tm_mday = 0;
288  t.tm_mon = 0;
289  t.tm_year = 70;
290  t.tm_wday = 00;
291  t.tm_yday = 00;
292  t.tm_isdst = 0;
293  time_t ct = mktime(&t);
294  struct tm t2;
295  gmtime_r(&ct, &t2);
296  char buf[32];
297  asctime_r (&t2, buf);
298  return std::string (buf);
299 }
ByteStreamMetadata.h
This file contains the class definition for the ByteStreamMetadata class.
ByteStreamInputSvc.h
This file contains the class definition for the ByteStreamInputSvc class.
EventInfoByteStreamAuxCnv.h
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
EventInfoByteStreamAuxCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj) override
converter method to create object
Definition: EventInfoByteStreamAuxCnv.cxx:121
EventInfoByteStreamAuxCnv::ascTime
std::string ascTime(unsigned int t)
convert timestamp to ascii time.
Definition: EventInfoByteStreamAuxCnv.cxx:281
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
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py: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.
SG::asStorable
DataObject * asStorable(T *pObject)
Definition: StorableConversions.h:158
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:56
EventInfoByteStreamAuxCnv::EventInfoByteStreamAuxCnv
EventInfoByteStreamAuxCnv(ISvcLocator *svcloc)
Definition: EventInfoByteStreamAuxCnv.cxx:30
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
ClassID_traits::ID
static const CLID & ID()
the CLID of T
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:50
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:52
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:88
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:221
EventInfoByteStreamAuxCnv::m_isSimulation
bool m_isSimulation
Definition: EventInfoByteStreamAuxCnv.h:55
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
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
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:47
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:51
ByteStreamAddress::storageType
static constexpr long storageType()
Definition: ByteStreamAddress.h:51
EventAuxInfo.h
Converter
Definition: Converter.h:27
python.PerfMonSerializer.decode
def decode(s)
Definition: PerfMonSerializer.py:388
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:110
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:57
ByteStreamCnvSvcBase
The base class for offline and HLT ByteStream conversion services.
Definition: ByteStreamCnvSvcBase.h:19
EventInfoByteStreamAuxCnv::m_ByteStreamCnvSvc
ByteStreamCnvSvcBase * m_ByteStreamCnvSvc
pointer to BS CnvSvc
Definition: EventInfoByteStreamAuxCnv.h:50
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
merge.status
status
Definition: merge.py:17
EventInfoByteStreamAuxCnv::classID
static const CLID & classID()
Definition: EventInfoByteStreamAuxCnv.cxx:42
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:275
EventInfoByteStreamAuxCnv::initialize
virtual StatusCode initialize() override
Definition: EventInfoByteStreamAuxCnv.cxx:52
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.