17#include "GaudiKernel/MsgStream.h"
18#include "GaudiKernel/StatusCode.h"
19#include "GaudiKernel/DataObject.h"
20#include "GaudiKernel/IRegistry.h"
27#include "eformat/StreamTag.h"
33 ,
AthMessaging(svcloc != nullptr ? msgSvc() : nullptr,
"EventInfoByteStreamAuxCnv")
35 ,
m_mdSvc(
"InputMetaDataStore",
"EventInfoByteStreamAuxCnv")
56 CHECK(Converter::initialize());
61 SmartIF<IProperty> byteStreamCnvSvc(service(
"ByteStreamCnvSvc"));
62 CHECK( byteStreamCnvSvc.isValid() );
64 SimpleProperty<bool> propIsSimulation(
"IsSimulation",
m_isSimulation);
65 StatusCode
sc = byteStreamCnvSvc->getProperty(&propIsSimulation);
75 SimpleProperty<bool> propIsTestbeam(
"IsTestbeam",
m_isTestbeam);
76 sc = byteStreamCnvSvc->getProperty(&propIsTestbeam);
86 SimpleProperty<bool> propIsCalibration(
"IsCalibration",
m_isCalibration);
87 sc = byteStreamCnvSvc->getProperty(&propIsCalibration);
100 ATH_MSG_WARNING(
"Failed to retrieve MCEventInfoByteStreamTool - MC EventInfo will use default values");
103 ATH_MSG_DEBUG(
"MCEventInfoByteStreamTool retrieved successfully");
109 return StatusCode::SUCCESS;
116 StatusCode
sc = Converter::finalize();
117 if (
sc.isFailure()) {
135 return StatusCode::FAILURE;
139 int runNumber =
re->run_no();
142 uint64_t eventNumber;
143 if (
re->version() < 0x03010000) {
144 eventNumber=
re->lvl1_id();
146 eventNumber=
re->global_id();
150 uint32_t bc_time_sec =
re->bc_time_seconds();
151 uint32_t bc_time_ns =
re->bc_time_nanoseconds();
153 if (bc_time_ns > 1000000000) {
154 if (runNumber < 20920) {
156 uint32_t temp = bc_time_ns;
157 bc_time_ns = bc_time_sec;
159 ATH_MSG_DEBUG(
"bc_time second/nanosecond swapped, sec/ns = " << bc_time_sec <<
" " << bc_time_ns);
163 ATH_MSG_WARNING(
"bc_time nanosecond number larger than 1e9, it is " << bc_time_ns <<
", reset it to 1 sec");
164 bc_time_ns = 1000000000;
169 uint16_t lumiBlock =
re->lumi_block();
172 uint16_t bcID =
re->bc_id();
174 unsigned int detMask0 = 0xFFFFFFFF, detMask1 = 0xFFFFFFFF, detMask2 = 0xFFFFFFFF, detMask3 = 0xFFFFFFFF;
177 StatusCode status =
m_mdSvc->retrieve(metadatacont,
"ByteStreamMetadata");
178 if (!status.isSuccess()) {
183 uint64_t detectorMask = metadata->getDetectorMask();
184 detMask0 = (
unsigned int)(detectorMask & 0x00000000FFFFFFFF);
185 detMask1 = (
unsigned int)(detectorMask >> 32);
186 uint64_t detectorMask2 = metadata->getDetectorMask2();
187 detMask2 = (
unsigned int)(detectorMask2 & 0x00000000FFFFFFFF);
188 detMask3 = (
unsigned int)(detectorMask2 >> 32);
194 evtInfo.setStore(pEvtInfoAux);
211 uint32_t eventTypeBitmask{0};
224 bool mcEventInfoDecoded =
false;
228 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> mcRobFragments;
229 m_robDataProvider->getROBData(ctx, mcRobIds, mcRobFragments,
"EventInfoByteStreamAuxCnv");
231 if (!mcRobFragments.empty()) {
232 ATH_MSG_DEBUG(
"Found MC EventInfo ROB fragment, decoding...");
234 if (
sc.isFailure()) {
235 ATH_MSG_WARNING(
"Failed to decode MC EventInfo from ROB fragment, using default values");
237 ATH_MSG_DEBUG(
"Successfully decoded MC EventInfo from ROB fragment");
238 mcEventInfoDecoded =
true;
241 ATH_MSG_DEBUG(
"No MC EventInfo ROB fragment found, using default values");
249 uint32_t statusElement = *buffer;
252 uint32_t extendedLevel1ID =
re->lvl1_id();
255 uint32_t level1TriggerType =
re->lvl1_trigger_type();
258 std::vector<xAOD::EventInfo::StreamTag> streamTags;
259 std::vector<eformat::helper::StreamTag> onl_streamTags;
260 re->stream_tag(buffer);
261 eformat::helper::decode(
re->nstream_tag(), buffer, onl_streamTags);
262 for (
const eformat::helper::StreamTag& onl_streamTag : onl_streamTags) {
263 std::set<uint32_t> tmp_off_dets = std::set<uint32_t>();
264 if (!onl_streamTag.dets.empty()) {
265 std::set<eformat::SubDetector> tmp_onl_dets = onl_streamTag.dets;
266 for (
const eformat::SubDetector& subdet : tmp_onl_dets) {
267 tmp_off_dets.insert((uint32_t) subdet);
272 , onl_streamTag.obeys_lumiblock
281 if (!mcEventInfoDecoded) {
291 ATH_MSG_DEBUG(
" New xAOD::EventAuxInfo made, run/event= " << runNumber
292 <<
" " << eventNumber
293 <<
" Time stamp = " <<
ascTime(bc_time_sec)
296 return StatusCode::SUCCESS;
305 ATH_MSG_DEBUG(
"Creating MC EventInfo ROB fragment for simulation");
308 SmartIF<IByteStreamEventAccess> byteStreamCnvSvc(service(
"ByteStreamCnvSvc"));
309 if (!byteStreamCnvSvc.isValid()) {
311 return StatusCode::FAILURE;
316 return StatusCode::FAILURE;
320 std::vector<OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment*> mcRobs;
324 for (
auto* rob : mcRobs) {
326 rob->rod_lvl1_id(
re->lvl1_id());
327 rob->rod_lvl1_type(
re->lvl1_trigger_type());
329 ATH_MSG_DEBUG(
"Added MC EventInfo ROB fragment to output event");
333 return StatusCode::SUCCESS;
348 time_t ct = mktime(&t);
352 asctime_r (&t2, buf);
353 return std::string (buf);
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
uint32_t CLID
The Class ID type.
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::FullEventFragment RawEventWrite
data type for writing raw event
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
IOpaqueAddress for ByteStreamCnvSvc, with ROB ids.
const EventContext & getEventContext() const
static constexpr long storageType()
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj) override
converter method to create object
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr) override
converter method to write object
virtual StatusCode finalize() override
std::string ascTime(unsigned int t)
convert timestamp to ascii time.
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
RODDataProviderSvc handle.
virtual StatusCode initialize() override
ServiceHandle< StoreGateSvc > m_mdSvc
TDS handle.
static long storageType()
EventInfoByteStreamAuxCnv(ISvcLocator *svcloc)
ToolHandle< IMCEventInfoByteStreamTool > m_mcEventInfoTool
Tool for decoding MC EventInfo from ROB.
Class describing a stream tag on the event.
void setBCID(uint32_t value)
Set the bunch crossing ID of the event.
void setDetectorMask(uint32_t mask0, uint32_t mask1)
Set the bit fields indicating with TTC timezones were present.
void setTimeStampNSOffset(uint32_t value)
Set the nanosecond offset wrt. the time stamp.
void setMCEventNumber(uint64_t value)
Set the MC generator's event number.
@ Core
Core flags describing the event.
void setStreamTags(const std::vector< StreamTag > &value)
Set the streams that the event was put in.
void setTimeStamp(uint32_t value)
Set the POSIX time of the event.
void setLevel1TriggerType(uint16_t value)
Set the Level-1 trigger type.
bool setEventFlags(EventFlagSubDet subDet, uint32_t flags)
Set the event flags for a particular sub-detector.
void setDetectorMaskExt(uint32_t mask2, uint32_t mask3)
Set the bit fields indicating with TTC timezones were present.
void setEventNumber(uint64_t value)
Set the current event's event number.
void setEventTypeBitmask(uint32_t value)
Set the event type bitmask.
void setMCChannelNumber(uint32_t value)
Set the MC generator's channel number.
void setExtendedLevel1ID(uint32_t value)
Set the extended Level-1 identifier.
void setMCEventWeights(const std::vector< float > &value)
Set the weights of all the MC events used in the simulation.
void setRunNumber(uint32_t value)
Set the current event's run number.
@ IS_CALIBRATION
true: calibration, false: physics
@ IS_SIMULATION
true: simulation, false: data
@ IS_TESTBEAM
true: testbeam, false: full detector
void setStatusElement(uint32_t value)
Set the trigger status element.
void setLumiBlock(uint32_t value)
Set the current event's luminosity block number.
DataObject * asStorable(SG::DataObjectSharedPtr< T > pObject)
EventInfo_v1 EventInfo
Definition of the latest event info version.
EventAuxInfo_v3 EventAuxInfo
Definition of the latest event auxiliary info version.
static constexpr CLID ID()