diff --git a/Event/ByteStreamCnvSvc/CMakeLists.txt b/Event/ByteStreamCnvSvc/CMakeLists.txt index 29681add519ac69b2461782923bed2d23a895ae0..f7ef468e3e0c99b22c96d927d0d0efdd6f6a1888 100644 --- a/Event/ByteStreamCnvSvc/CMakeLists.txt +++ b/Event/ByteStreamCnvSvc/CMakeLists.txt @@ -22,6 +22,7 @@ atlas_depends_on_subdirs( Database/AthenaPOOL/AthenaPoolUtilities Database/PersistentDataModel Event/EventInfo + Event/xAOD/xAODEventInfo Event/ByteStreamCnvSvcLegacy ) # External dependencies: @@ -39,7 +40,7 @@ atlas_add_library( ByteStreamCnvSvcLib ByteStreamCnvSvcBaseLib StoreGateLib rt PRIVATE_LINK_LIBRARIES ${TDAQ-COMMON_LIBRARIES} ${Boost_LIBRARIES} AthenaKernel SGTools CollectionBase FileCatalog - AthenaPoolUtilities PersistentDataModel EventInfo + AthenaPoolUtilities PersistentDataModel EventInfo xAODEventInfo ByteStreamCnvSvcLegacy ) atlas_add_component( ByteStreamCnvSvc diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx index 01a7d4549a2e4a4d3ae64c1cc2dae97eb0aef86a..34167f15f6590fc23869ad36ee82f6d57b0ee8ab 100644 --- a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx +++ b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #include "ByteStreamEventStorageInputSvc.h" @@ -19,9 +19,8 @@ #include "PersistentDataModel/DataHeader.h" #include "PersistentDataModel/Token.h" #include "StoreGate/StoreGateSvc.h" -#include "EventInfo/EventInfo.h" -//#include "xAODEventInfo/EventInfo.h" -//#include "xAODEventInfo/EventAuxInfo.h" +#include "xAODEventInfo/EventInfo.h" +#include "xAODEventInfo/EventAuxInfo.h" #include "eformat/HeaderMarker.h" #include "eformat/SourceIdentifier.h" @@ -526,28 +525,50 @@ StatusCode ByteStreamEventStorageInputSvc::generateDataHeader() //add the Dhe self reference to the object vector Dh->insert(Dhe); - if (m_sgSvc->contains<EventInfo>("ByteStreamEventInfo")) { - // Temporary event header pointer for retrieval of the old one , if exists - const EventInfo* Ei_temp = nullptr; - //Ei_temp = m_sgSvc->retrieve<EventInfo>("ByteStreamEventInfo"); - if (m_sgSvc->retrieve(Ei_temp,"ByteStreamEventInfo").isSuccess()) { + // Cleanup EventInfo from the previous event, if exists + if (m_sgSvc->contains<xAOD::EventInfo>("EventInfo")) { + // Temporary event info pointer for retrieval of the old one + const xAOD::EventInfo* Ei_temp{nullptr}; + if (m_sgSvc->retrieve(Ei_temp,"EventInfo").isSuccess()) { StatusCode sc = m_sgSvc->remove(Ei_temp); if (!sc.isSuccess()) { - ATH_MSG_ERROR("Failed to remove ByteStreamEventInfo"); + ATH_MSG_ERROR("Failed to remove EventInfo"); + } + } + } + if (m_sgSvc->contains<xAOD::EventAuxInfo>("EventInfoAux.")) { + // Temporary event info Aux store pointer for retrieval of the old one + const xAOD::EventAuxInfo* EiAux_temp{nullptr}; + if (m_sgSvc->retrieve(EiAux_temp,"EventInfoAux.").isSuccess()) { + StatusCode sc = m_sgSvc->remove(EiAux_temp); + if (!sc.isSuccess()) { + ATH_MSG_ERROR("Failed to remove EventAuxInfo"); } } } - // Now add ref to EventInfo objects - IOpaqueAddress* iop = new ByteStreamAddress(ClassID_traits<EventInfo>::ID(), "ByteStreamEventInfo", ""); - StatusCode ioc = m_sgSvc->recordAddress("ByteStreamEventInfo",iop); - if (ioc.isSuccess()) { - const SG::DataProxy* ptmp = m_sgSvc->transientProxy(ClassID_traits<EventInfo>::ID(), "ByteStreamEventInfo"); - if (ptmp !=0) { - DataHeaderElement DheEI(ptmp, 0, "ByteStreamEventInfo"); - Dh->insert(DheEI); + + // Now add ref to xAOD::EventInfo + IOpaqueAddress* iopx = new ByteStreamAddress(ClassID_traits<xAOD::EventInfo>::ID(), "EventInfo", ""); + StatusCode iocx = m_sgSvc->recordAddress("EventInfo",iopx); + if (iocx.isSuccess()) { + const SG::DataProxy* ptmpx = m_sgSvc->transientProxy(ClassID_traits<xAOD::EventInfo>::ID(), "EventInfo"); + if (ptmpx !=0) { + DataHeaderElement DheEIx(ptmpx, 0, "EventInfo"); + Dh->insert(DheEIx); } - //else ATH_MSG_ERROR("Failed to create EventInfo proxy " << ptmp); } + + // Now add ref to xAOD::EventAuxInfo + IOpaqueAddress* iopaux = new ByteStreamAddress(ClassID_traits<xAOD::EventAuxInfo>::ID(), "EventInfoAux.", ""); + StatusCode iocaux = m_sgSvc->recordAddress("EventInfoAux.",iopaux); + if (iocaux.isSuccess()) { + const SG::DataProxy* ptmpaux = m_sgSvc->transientProxy(ClassID_traits<xAOD::EventAuxInfo>::ID(), "EventInfoAux."); + if (ptmpaux !=0) { + DataHeaderElement DheEIAux(ptmpaux, 0, "EventInfoAux."); + Dh->insert(DheEIAux); + } + } + // Record new data header.Boolean flags will allow it's deletionin case // of skipped events. return m_sgSvc->record<DataHeader>(Dh, "ByteStreamDataHeader", true, false, true); diff --git a/Event/ByteStreamCnvSvc/src/EventInfoByteStreamAuxCnv.cxx b/Event/ByteStreamCnvSvc/src/EventInfoByteStreamAuxCnv.cxx new file mode 100644 index 0000000000000000000000000000000000000000..af7bea61ebc3fdb3ee40623e40e7f65df0c3bbf6 --- /dev/null +++ b/Event/ByteStreamCnvSvc/src/EventInfoByteStreamAuxCnv.cxx @@ -0,0 +1,290 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#include "EventInfoByteStreamAuxCnv.h" +#include "ByteStreamCnvSvc/ByteStreamCnvSvc.h" +#include "ByteStreamCnvSvcBase/ByteStreamAddress.h" +#include "ByteStreamCnvSvcBase/IROBDataProviderSvc.h" +#include "ByteStreamCnvSvc/ByteStreamInputSvc.h" + +#include "ByteStreamData/RawEvent.h" +#include "ByteStreamData/ByteStreamMetadata.h" +#include "ByteStreamData/ByteStreamMetadataContainer.h" + +#include "AthenaKernel/errorcheck.h" +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/StatusCode.h" +#include "GaudiKernel/DataObject.h" +#include "GaudiKernel/IRegistry.h" + +#include "xAODEventInfo/EventInfo.h" +#include "xAODEventInfo/EventAuxInfo.h" + +#include "StoreGate/StoreGateSvc.h" + +#include "eformat/StreamTag.h" + +#include <time.h> + +EventInfoByteStreamAuxCnv::EventInfoByteStreamAuxCnv(ISvcLocator* svcloc) + : Converter(storageType(), classID(), svcloc) + , AthMessaging(svcloc != nullptr ? msgSvc() : nullptr, "EventInfoByteStreamAuxCnv") + , m_ByteStreamCnvSvc(nullptr) + , m_robDataProvider("ROBDataProviderSvc", "EventInfoByteStreamAuxCnv") + , m_mdSvc("InputMetaDataStore", "EventInfoByteStreamAuxCnv") + , m_isSimulation(false) + , m_isTestbeam(false) + , m_isCalibration(false) +{ +} + +const CLID& EventInfoByteStreamAuxCnv::classID() +{ + return ClassID_traits<xAOD::EventAuxInfo>::ID(); +} + +long EventInfoByteStreamAuxCnv::storageType() +{ + return ByteStreamAddress::storageType(); +} + +StatusCode EventInfoByteStreamAuxCnv::initialize() +{ + ATH_MSG_DEBUG("Initialize"); + + CHECK(Converter::initialize()); + + // Check ByteStreamCnvSvc + IService* svc{nullptr}; + StatusCode sc = serviceLocator()->getService("ByteStreamCnvSvc", svc); + if (!sc.isSuccess()) { + ATH_MSG_ERROR("Cannot get ByteStreamCnvSvc "); + return sc; + } + m_ByteStreamCnvSvc = dynamic_cast<ByteStreamCnvSvc*>(svc); + if (!m_ByteStreamCnvSvc) { + ATH_MSG_ERROR("Cannot cast to ByteStreamCnvSvc"); + return StatusCode::FAILURE; + } + + CHECK(m_robDataProvider.retrieve()); + CHECK(m_mdSvc.retrieve()); + + SimpleProperty<bool> propIsSimulation("IsSimulation", m_isSimulation); + sc = m_ByteStreamCnvSvc->getProperty(&propIsSimulation); + if (sc.isSuccess()) { + m_isSimulation = propIsSimulation.value(); + ATH_MSG_INFO("IsSimulation : " << m_isSimulation); + } + else { + ATH_MSG_ERROR("Cannot get IsSimulation"); + return sc; + } + + SimpleProperty<bool> propIsTestbeam("IsTestbeam", m_isTestbeam); + sc = m_ByteStreamCnvSvc->getProperty(&propIsTestbeam); + if (sc.isSuccess()) { + m_isTestbeam = propIsTestbeam.value(); + ATH_MSG_INFO("IsTestbeam : " << m_isTestbeam); + } + else { + ATH_MSG_ERROR("Cannot get IsTestbeam"); + return sc; + } + + SimpleProperty<bool> propIsCalibration("IsCalibration", m_isCalibration); + sc = m_ByteStreamCnvSvc->getProperty(&propIsCalibration); + if (sc.isSuccess()) { + m_isCalibration = propIsCalibration.value(); + ATH_MSG_INFO("IsCalibration : " << m_isCalibration); + } + else { + ATH_MSG_ERROR("Cannot get IsCalibration"); + return sc; + } + + return StatusCode::SUCCESS; +} + +StatusCode EventInfoByteStreamAuxCnv::finalize() +{ + ATH_MSG_DEBUG("Finalize"); + + StatusCode sc = Converter::finalize(); + if (sc.isFailure()) { + ATH_MSG_WARNING("Converter::finalize() failed"); + } + return sc; +} + +StatusCode EventInfoByteStreamAuxCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) +{ + ByteStreamAddress *pRE_Addr{nullptr}; + pRE_Addr = dynamic_cast<ByteStreamAddress*>(pAddr); + if (!pRE_Addr) { + ATH_MSG_ERROR("Cannot cast to ByteStreamAddress "); + return StatusCode::FAILURE; + } + + ATH_MSG_DEBUG("Creating Objects"); + + // get RawEvent + const RawEvent* re = m_robDataProvider->getEvent(); + if (!re) { + ATH_MSG_ERROR("Can not get RawEvent "); + return StatusCode::FAILURE; + } + + // Run Number + int runNumber = re->run_no(); + + // Event Number + uint64_t eventNumber; + if (re->version() < 0x03010000) { + eventNumber=re->lvl1_id(); + } else { + eventNumber=re->global_id(); + } + + // Time Stamp + uint32_t bc_time_sec = re->bc_time_seconds(); + uint32_t bc_time_ns = re->bc_time_nanoseconds(); + // bc_time_ns should be lt 1e9. + if (bc_time_ns > 1000000000) { + if (runNumber < 20920) { + // In M4 we saw otherwise, because sec/ns was swapped in raw data. + uint32_t temp = bc_time_ns; + bc_time_ns = bc_time_sec; + bc_time_sec= temp; + ATH_MSG_DEBUG("bc_time second/nanosecond swapped, sec/ns = " << bc_time_sec << " " << bc_time_ns); + } + else { + // For later runs, the nanosecond clock sometimes is not reset, making it overrun 1e9. Round it off to 1e9 + ATH_MSG_WARNING("bc_time nanosecond number larger than 1e9, it is " << bc_time_ns << ", reset it to 1 sec"); + bc_time_ns = 1000000000; + } + } + + // luminosity block number + uint16_t lumiBlock = re->lumi_block(); + + // bunch crossing identifier + uint16_t bcID = re->bc_id(); + + unsigned int detMask0 = 0xFFFFFFFF, detMask1 = 0xFFFFFFFF, detMask2 = 0xFFFFFFFF, detMask3 = 0xFFFFFFFF; + // Get ByteStream Metadata from Input MetaData Store + const ByteStreamMetadataContainer* metadatacont{nullptr}; + StatusCode status = m_mdSvc->retrieve(metadatacont, "ByteStreamMetadata"); + if (!status.isSuccess()) { + ATH_MSG_WARNING("Unable to retrieve Input MetaData for ByteStream"); + } + else { + const ByteStreamMetadata* metadata = *(metadatacont->begin()); + uint64_t detectorMask = metadata->getDetectorMask(); + detMask0 = (unsigned int)(detectorMask & 0x00000000FFFFFFFF); + detMask1 = (unsigned int)(detectorMask >> 32); + uint64_t detectorMask2 = metadata->getDetectorMask2(); + detMask2 = (unsigned int)(detectorMask2 & 0x00000000FFFFFFFF); + detMask3 = (unsigned int)(detectorMask2 >> 32); + } + + + xAOD::EventInfo evtInfo; + xAOD::EventAuxInfo* pEvtInfoAux = new xAOD::EventAuxInfo(); + evtInfo.setStore(pEvtInfoAux); + + evtInfo.setRunNumber(runNumber); + evtInfo.setEventNumber(eventNumber); + evtInfo.setLumiBlock(lumiBlock); + evtInfo.setTimeStamp(bc_time_sec); + evtInfo.setTimeStampNSOffset(bc_time_ns); + evtInfo.setBCID(bcID); + evtInfo.setDetectorMask(detMask0,detMask1); + evtInfo.setDetectorMaskExt(detMask2,detMask3); + + // Set Event Type + uint32_t eventTypeBitmask{0}; + if (m_isSimulation) { + eventTypeBitmask |= xAOD::EventInfo::IS_SIMULATION; + } + if (m_isTestbeam) { + eventTypeBitmask |= xAOD::EventInfo::IS_TESTBEAM; + } + if (m_isCalibration) { + eventTypeBitmask |= xAOD::EventInfo::IS_CALIBRATION; + } + evtInfo.setEventTypeBitmask(eventTypeBitmask); + + // Trigger Info + const OFFLINE_FRAGMENTS_NAMESPACE::DataType* buffer; + // status element + re->status(buffer); + uint32_t statusElement = *buffer; + + // extended LVL1ID + uint32_t extendedLevel1ID = re->lvl1_id(); + + // LVL1 trigger type + uint32_t level1TriggerType = re->lvl1_trigger_type(); + + // stream tag + std::vector<xAOD::EventInfo::StreamTag> streamTags; + std::vector<eformat::helper::StreamTag> onl_streamTags; + re->stream_tag(buffer); + eformat::helper::decode(re->nstream_tag(), buffer, onl_streamTags); + for (const eformat::helper::StreamTag& onl_streamTag : onl_streamTags) { + std::set<uint32_t> tmp_off_dets = std::set<uint32_t>(); + if (!onl_streamTag.dets.empty()) { + std::set<eformat::SubDetector> tmp_onl_dets = onl_streamTag.dets; + for (const eformat::SubDetector& subdet : tmp_onl_dets) { + tmp_off_dets.insert((uint32_t) subdet); + } + } + streamTags.push_back(xAOD::EventInfo::StreamTag(onl_streamTag.name + , onl_streamTag.type + , onl_streamTag.obeys_lumiblock + , onl_streamTag.robs + , tmp_off_dets) + ); + } + + evtInfo.setStatusElement(statusElement); + evtInfo.setExtendedLevel1ID(extendedLevel1ID); + evtInfo.setLevel1TriggerType(level1TriggerType); + evtInfo.setStreamTags(streamTags); + + // record EventInfo + evtInfo.setEventFlags(xAOD::EventInfo::Core, m_robDataProvider->getEventStatus()); + pObj = StoreGateSvc::asStorable(pEvtInfoAux); + + ATH_MSG_DEBUG(" New xAOD::EventAuxInfo made, run/event= " << runNumber + << " " << eventNumber + << " Time stamp = " << ascTime(bc_time_sec) + ); + + return StatusCode::SUCCESS; +} + +StatusCode EventInfoByteStreamAuxCnv::createRep(DataObject* /*pObj*/, IOpaqueAddress*& /*pAddr*/) +{ + ATH_MSG_DEBUG("Nothing to be done for xAOD::EventAuxInfo createReps"); + return StatusCode::SUCCESS; +} + +const char* EventInfoByteStreamAuxCnv::ascTime(unsigned int tstamp) +{ + struct tm t; + t.tm_sec = tstamp; + t.tm_min = 0; + t.tm_hour = 0; + t.tm_mday = 0; + t.tm_mon = 0; + t.tm_year = 70; + t.tm_wday = 00; + t.tm_yday = 00; + t.tm_isdst = 0; + time_t ct = mktime(&t); + tm* t2 = gmtime(&ct); + return(asctime(t2)); +} diff --git a/Event/ByteStreamCnvSvc/src/EventInfoByteStreamAuxCnv.h b/Event/ByteStreamCnvSvc/src/EventInfoByteStreamAuxCnv.h new file mode 100644 index 0000000000000000000000000000000000000000..b201e9846f67de84433ac33eace9bbe54b80de56 --- /dev/null +++ b/Event/ByteStreamCnvSvc/src/EventInfoByteStreamAuxCnv.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef EVENTINFOBYTESTREAMAUXCNV_H +#define EVENTINFOBYTESTREAMAUXCNV_H + +/** + * @file EventInfoByteStreamAuxCnv.h + * + * @class EventInfoByteStreamAuxCnv + * + * @brief This is the class definition of ByteStream converter for xAOD::EventInfoAux + * Event Info is built from RawEvent when reading. Nothing is done when writing ByteStream + * + */ + +#include "GaudiKernel/Converter.h" +#include "GaudiKernel/ServiceHandle.h" +#include "AthenaBaseComps/AthMessaging.h" + +class ByteStreamCnvSvc; +class IROBDataProviderSvc; +class StoreGateSvc; + +// Abstract factory to create the converter +template <class TYPE> class CnvFactory; + +class EventInfoByteStreamAuxCnv : public Converter, public AthMessaging +{ + public: + EventInfoByteStreamAuxCnv(ISvcLocator* svcloc); + virtual ~EventInfoByteStreamAuxCnv() override {} + + virtual StatusCode initialize() override; + virtual StatusCode finalize() override; + + /// converter method to create object + virtual StatusCode createObj(IOpaqueAddress* pAddr, DataObject*& pObj) override; + /// converter method to write object + virtual StatusCode createRep(DataObject* pObj, IOpaqueAddress*& pAddr) override; + + /// Storage type and class ID + virtual long repSvcType() const override { return i_repSvcType(); } + static long storageType(); + static const CLID& classID(); + + private: + const char* ascTime(unsigned int t); //!< convert timestamp to ascii time. + ByteStreamCnvSvc* m_ByteStreamCnvSvc; //!< pointer to BS CnvSvc + ServiceHandle<IROBDataProviderSvc> m_robDataProvider; //!< RODDataProviderSvc handle + ServiceHandle<StoreGateSvc> m_mdSvc; //!< TDS handle + + // flags for EventType + bool m_isSimulation; + bool m_isTestbeam; + bool m_isCalibration; +}; + +#endif diff --git a/Event/ByteStreamCnvSvc/src/EventInfoByteStreamCnv.cxx b/Event/ByteStreamCnvSvc/src/EventInfoByteStreamCnv.cxx deleted file mode 100644 index fe6f552c2f4a0a1cbeda82d32ba103c4cf981f85..0000000000000000000000000000000000000000 --- a/Event/ByteStreamCnvSvc/src/EventInfoByteStreamCnv.cxx +++ /dev/null @@ -1,329 +0,0 @@ -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -#include "EventInfoByteStreamCnv.h" -#include "ByteStreamCnvSvc/ByteStreamCnvSvc.h" -#include "ByteStreamCnvSvcBase/ByteStreamAddress.h" -#include "ByteStreamCnvSvcBase/IROBDataProviderSvc.h" -#include "ByteStreamCnvSvc/ByteStreamInputSvc.h" - -#include "ByteStreamData/RawEvent.h" -#include "ByteStreamData/ByteStreamMetadata.h" -#include "ByteStreamData/ByteStreamMetadataContainer.h" - -#include "GaudiKernel/MsgStream.h" -#include "GaudiKernel/StatusCode.h" -#include "GaudiKernel/DataObject.h" -#include "GaudiKernel/IRegistry.h" -#include "GaudiKernel/ThreadLocalContext.h" - -#include "EventInfo/EventInfo.h" -#include "EventInfo/EventType.h" -#include "EventInfo/EventID.h" -#include "EventInfo/TriggerInfo.h" - -#include "StoreGate/StoreGateSvc.h" - -#include "AthenaPoolUtilities/CondAttrListCollection.h" - -#include "eformat/StreamTag.h" - -#include <time.h> - -// Instantiation of a static factory class used by clients to create -// instances of this service -// static CnvFactory<EventInfoByteStreamCnv> s_factory; -// const ICnvFactory& EventInfoByteStreamCnvFactory = s_factory; - -EventInfoByteStreamCnv::EventInfoByteStreamCnv(ISvcLocator* svcloc) - : Converter(storageType(), classID(), svcloc), - m_ByteStreamCnvSvc(0), - m_robDataProvider("ROBDataProviderSvc", "EventInfoByteStreamCnv"), - m_mdSvc("InputMetaDataStore", "EventInfoByteStreamCnv"), - m_isSimulation(false), - m_isTestbeam(false), - m_isCalibration(false) -{ -} - -const CLID& EventInfoByteStreamCnv::classID() { - return(ClassID_traits<EventInfo>::ID()); -} - -long EventInfoByteStreamCnv::storageType() { - return ByteStreamAddress::storageType(); -} - -StatusCode EventInfoByteStreamCnv::initialize() { - StatusCode sc = Converter::initialize(); - if (StatusCode::SUCCESS != sc) { - return sc; - } - - MsgStream log(msgSvc(), "EventInfoByteStreamCnv"); - log << MSG::DEBUG << " initialize" << endmsg; - - // Check ByteStreamCnvSvc - IService* svc; - sc = serviceLocator()->getService("ByteStreamCnvSvc", svc); - if (sc != StatusCode::SUCCESS) { - log << MSG::ERROR << " Cant get ByteStreamCnvSvc " << endmsg; - return sc; - } - m_ByteStreamCnvSvc = dynamic_cast<ByteStreamCnvSvc*>(svc); - if (m_ByteStreamCnvSvc == 0) { - log << MSG::ERROR << " Cant cast to ByteStreamCnvSvc" << endmsg; - return StatusCode::FAILURE; - } - - if (!m_robDataProvider.retrieve().isSuccess()) { - log << MSG::ERROR << " Cant get ROBDataProviderSvc" << endmsg; - // ATH_MSG_FATAL("Cannot get ROBDataProviderSvc"); - return(StatusCode::FAILURE); - } - if (!m_mdSvc.retrieve().isSuccess()) { - log << MSG::ERROR << " Cant get InputMetaDataStore" << endmsg; - // ATH_MSG_FATAL("Cannot get InputMetaDataStore"); - return(StatusCode::FAILURE); - } - - // EventType - SimpleProperty<std::string> propUserType("UserType", m_userType); - sc = m_ByteStreamCnvSvc->getProperty(&propUserType); - if (sc.isSuccess()) { - m_userType = propUserType.value(); - log << MSG::INFO << "UserType : " << m_userType << endmsg; - } else { - log << MSG::ERROR << "could not get UserType" << endmsg; - return sc; - } - - SimpleProperty<bool> propIsSimulation("IsSimulation", m_isSimulation); - sc = m_ByteStreamCnvSvc->getProperty(&propIsSimulation); - if (sc.isSuccess()) { - m_isSimulation = propIsSimulation.value(); - log << MSG::INFO << "IsSimulation : " << m_isSimulation << endmsg; - } else { - log << MSG::ERROR << "could not get IsSimulation" << endmsg; - return sc; - } - - SimpleProperty<bool> propIsTestbeam("IsTestbeam", m_isTestbeam); - sc = m_ByteStreamCnvSvc->getProperty(&propIsTestbeam); - if (sc.isSuccess()) { - m_isTestbeam = propIsTestbeam.value(); - log << MSG::INFO << "IsTestbeam : " << m_isTestbeam << endmsg; - } else { - log << MSG::ERROR << "could not get IsTestbeam" << endmsg; - return sc; - } - - SimpleProperty<bool> propIsCalibration("IsCalibration", m_isCalibration); - sc = m_ByteStreamCnvSvc->getProperty(&propIsCalibration); - if (sc.isSuccess()) { - m_isCalibration = propIsCalibration.value(); - log << MSG::INFO << "IsCalibration : " << m_isCalibration << endmsg; - } else { - log << MSG::ERROR << "could not get IsCalibration" << endmsg; - return sc; - } - return StatusCode::SUCCESS; -} - -StatusCode EventInfoByteStreamCnv::finalize() { - MsgStream log(msgSvc(), "EventInfoByteStreamCnv"); - log << MSG::INFO << "finalize " << endmsg; - - StatusCode status = Converter::finalize(); - if (status.isFailure()) { - log << MSG::WARNING << "Converter::finalize() failed" << endmsg; - } - return(status); -} - -StatusCode EventInfoByteStreamCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) { - MsgStream log(msgSvc(), "EventInfoByteStreamCnv"); - - ByteStreamAddress *pRE_Addr; - pRE_Addr = dynamic_cast<ByteStreamAddress*>(pAddr); - - // Did the cast work? - if (!pRE_Addr) { - log << MSG::ERROR << " Can not cast to ByteStreamAddress " << endmsg; - return StatusCode::FAILURE; - } - // Did it provide a valid EventContext? - if (!(Gaudi::Hive::currentContext().valid())) { - log << MSG::INFO << " EventContext not valid " << endmsg; - } - - log << MSG::DEBUG << " Creating Objects" << endmsg; - - // get RawEvent - const RawEvent* re = m_robDataProvider->getEvent(); - if (re == 0) { - log << MSG::ERROR << " Can not get RawEvent " << endmsg; - return StatusCode::FAILURE; - } - - // Run Number - int runNumber = re->run_no(); - - // Event Number - uint64_t eventNumber; - if (re->version() < 0x03010000) { - eventNumber=re->lvl1_id(); - } else { - eventNumber=re->global_id(); - } - - // Time Stamp - uint32_t bc_time_sec = re->bc_time_seconds(); - uint32_t bc_time_ns = re->bc_time_nanoseconds(); - // bc_time_ns should be lt 1e9. - if (bc_time_ns > 1000000000) { - if (runNumber < 20920) { - // In M4 we saw otherwise, because sec/ns was swapped in raw data. - uint32_t temp = bc_time_ns; - bc_time_ns = bc_time_sec; - bc_time_sec= temp; - log << MSG::DEBUG << " bc_time second/nanosecond swapped, sec/ns = " << bc_time_sec << " " << bc_time_ns << endmsg; - } else { // for later runs, the nanosecond clock sometimes is not reset, making it overrun 1e9. - // round it off to 1e9 - log << MSG::WARNING << " bc_time nanosecond number larger than 1e9, it is " << bc_time_ns << ", reset it to 1 sec" << endmsg; - bc_time_ns = 1000000000; - } - } - - // luminosity block number - uint16_t lumiBlock = re->lumi_block(); - - // bunch crossing identifier - uint16_t bcID = re->bc_id(); - - unsigned int detMask0 = 0xFFFFFFFF, detMask1 = 0xFFFFFFFF, detMask2 = 0xFFFFFFFF, detMask3 = 0xFFFFFFFF; - // Get ByteStream Metadata from Input MetaData Store - const ByteStreamMetadataContainer* metadatacont = 0; - StatusCode status = m_mdSvc->retrieve(metadatacont, "ByteStreamMetadata"); - if (!status.isSuccess()) { - log << MSG::WARNING << "Unable to retrieve Input MetaData for ByteStream" << endmsg; - } else { - const ByteStreamMetadata* metadata = *(metadatacont->begin()); - uint64_t detectorMask = metadata->getDetectorMask(); - detMask0 = (unsigned int)(detectorMask & 0x00000000FFFFFFFF); - detMask1 = (unsigned int)(detectorMask >> 32); - uint64_t detectorMask2 = metadata->getDetectorMask2(); - detMask2 = (unsigned int)(detectorMask2 & 0x00000000FFFFFFFF); - detMask3 = (unsigned int)(detectorMask2 >> 32); - } - EventID* evtId = new EventID(runNumber, eventNumber, bc_time_sec, bc_time_ns, lumiBlock, bcID, detMask0, detMask1,detMask2,detMask3); - - // Event Type - EventType* evtType = new EventType(); - if (m_isSimulation) { - evtType->add_type(EventType::IS_SIMULATION); - } - if (m_isTestbeam) { - evtType->add_type(EventType::IS_TESTBEAM); - } - if (m_isCalibration) { - evtType->add_type(EventType::IS_CALIBRATION); - } - evtType->set_user_type(m_userType); - - // Trigger Info - const OFFLINE_FRAGMENTS_NAMESPACE::DataType* buffer; - // status element - re->status(buffer); - TriggerInfo::number_type statusElement = *buffer; - - // extended LVL1ID - TriggerInfo::number_type extendedLevel1ID = re->lvl1_id(); - - // LVL1 trigger type - TriggerInfo::number_type level1TriggerType = re->lvl1_trigger_type(); - - // LVL1 trigger info - std::vector<TriggerInfo::number_type> level1TriggerInfo; - re->lvl1_trigger_info(buffer); - for (uint32_t iT1 = 0; iT1 < re->nlvl1_trigger_info(); ++iT1) { - level1TriggerInfo.push_back(*buffer); - ++buffer; - } - - // LVL2 trigger info - std::vector<TriggerInfo::number_type> level2TriggerInfo; - re->lvl2_trigger_info(buffer); - for (uint32_t iT2 = 0; iT2 < re->nlvl2_trigger_info(); ++iT2) { - level2TriggerInfo.push_back(*buffer); - ++buffer; - } - - // EF info - std::vector<TriggerInfo::number_type> eventFilterInfo; - re->event_filter_info(buffer); - for (uint32_t iEF = 0; iEF < re->nevent_filter_info(); ++iEF) { - eventFilterInfo.push_back(*buffer); - ++buffer; - } - - // stream tag - std::vector<TriggerInfo::StreamTag> streamTags; - std::vector<eformat::helper::StreamTag> onl_streamTags; - re->stream_tag(buffer); - eformat::helper::decode(re->nstream_tag(), buffer, onl_streamTags); - for (std::vector<eformat::helper::StreamTag>::const_iterator itS = onl_streamTags.begin(), - itSE = onl_streamTags.end(); itS != itSE; ++itS) { - std::set<TriggerInfo::number_type> tmp_off_dets = std::set<TriggerInfo::number_type>(); - if (!((itS->dets).empty())) { - std::set<eformat::SubDetector> tmp_onl_dets = itS->dets; - for (std::set<eformat::SubDetector>::const_iterator it_det = tmp_onl_dets.begin(); - it_det != tmp_onl_dets.end(); ++it_det) { - tmp_off_dets.insert((TriggerInfo::number_type) *it_det); - } - } - streamTags.push_back(TriggerInfo::StreamTag(itS->name, itS->type, itS->obeys_lumiblock, itS->robs, tmp_off_dets)); - } - - TriggerInfo* trigInfo = new TriggerInfo(statusElement, - extendedLevel1ID, - level1TriggerType, - level1TriggerInfo, - level2TriggerInfo, - eventFilterInfo, - streamTags); - - // record EventInfo - EventInfo* evtInfo = new EventInfo(evtId, evtType, trigInfo); - evtInfo->setEventFlags(EventInfo::Core, m_robDataProvider->getEventStatus()); - pObj = StoreGateSvc::asStorable(evtInfo); - - log << MSG::DEBUG << " New EventInfo made, run/event= " << runNumber << " " << eventNumber - << " Time stamp = " << ascTime(bc_time_sec) << endmsg; - - return StatusCode::SUCCESS; -} - -StatusCode EventInfoByteStreamCnv::createRep(DataObject* /*pObj*/, IOpaqueAddress*& /*pAddr*/) { - StatusCode sc = StatusCode::SUCCESS; - MsgStream log(msgSvc(), "EventInfoByteStreamCnv"); - log << MSG::DEBUG << " Nothing to be done for EventInfo createReps" << endmsg; - return sc; -} - -const char* EventInfoByteStreamCnv::ascTime(unsigned int tstamp) { - struct tm t; - t.tm_sec = tstamp; - t.tm_min = 0; - t.tm_hour = 0; - t.tm_mday = 0; - t.tm_mon = 0; - t.tm_year = 70; - t.tm_wday = 00; - t.tm_yday = 00; - t.tm_isdst = 0; - time_t ct = mktime(&t); - tm* t2 = gmtime(&ct); - return(asctime(t2)); -} diff --git a/Event/ByteStreamCnvSvc/src/EventInfoByteStreamCnv.h b/Event/ByteStreamCnvSvc/src/EventInfoByteStreamCnv.h deleted file mode 100644 index 90f726f44cc7260ecd2dc8c41abc3ca785df3e80..0000000000000000000000000000000000000000 --- a/Event/ByteStreamCnvSvc/src/EventInfoByteStreamCnv.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -#ifndef EVENTINFOBYTESTREAMCNV_H -#define EVENTINFOBYTESTREAMCNV_H - -/** @file EventInfoByteStreamCnv.h - * @brief This file contains the class definition for the EventInfoByteStreamCnv class. - * @author Peter van Gemmeren <gemmeren@anl.gov> - **/ - -#include "GaudiKernel/Converter.h" -#include "GaudiKernel/ServiceHandle.h" - -#include "ByteStreamData/RawEvent.h" - -#include <string> - -class IOpaqueAddress; -class ByteStreamCnvSvc; -class IROBDataProviderSvc; -class StoreGateSvc; - -// Abstract factory to create the converter -template <class TYPE> class CnvFactory; - - -/** @class EventInfoByteStreamCnv - * @brief This class implements the ByteStream Converter for EventInfo. - * EventInfo is built from RawEvent when reading and does nothing when writing ByteStream - **/ -class EventInfoByteStreamCnv : public Converter { - -public: - EventInfoByteStreamCnv(ISvcLocator* svcloc); - - virtual StatusCode initialize() override; - virtual StatusCode finalize() override; - - /// converter method to create object - virtual StatusCode createObj(IOpaqueAddress* pAddr, DataObject*& pObj) override; - /// converter method to write object - virtual StatusCode createRep(DataObject* pObj, IOpaqueAddress*& pAddr) override; - - /// Storage type and class ID - virtual long repSvcType() const override { return i_repSvcType(); } - static long storageType(); - static const CLID& classID(); - -private: - const char* ascTime(unsigned int t); //!< convert timestamp to ascii time. - ByteStreamCnvSvc* m_ByteStreamCnvSvc; //!< pointer to BS CnvSvc - ServiceHandle<IROBDataProviderSvc> m_robDataProvider; //!< RODDataProviderSvc handle - ServiceHandle<StoreGateSvc> m_mdSvc; //!< TDS handle - - // flags for EventType - bool m_isSimulation; - bool m_isTestbeam; - bool m_isCalibration; - - std::string m_userType; -}; - -#endif diff --git a/Event/ByteStreamCnvSvc/src/EventInfoByteStreamxAODCnv.cxx b/Event/ByteStreamCnvSvc/src/EventInfoByteStreamxAODCnv.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ef975b84dbefbfb5bc2b61f11e896d8d0d57851c --- /dev/null +++ b/Event/ByteStreamCnvSvc/src/EventInfoByteStreamxAODCnv.cxx @@ -0,0 +1,81 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#include "EventInfoByteStreamxAODCnv.h" +#include "ByteStreamCnvSvcBase/ByteStreamAddress.h" + +#include "AthenaKernel/errorcheck.h" +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/StatusCode.h" +#include "GaudiKernel/DataObject.h" +#include "GaudiKernel/IRegistry.h" + +#include "xAODEventInfo/EventInfo.h" +#include "xAODEventInfo/EventAuxInfo.h" + +#include "StoreGate/StoreGateSvc.h" + +EventInfoByteStreamxAODCnv::EventInfoByteStreamxAODCnv(ISvcLocator* svcloc) + : Converter(storageType(), classID(), svcloc) + , AthMessaging(svcloc != nullptr ? msgSvc() : nullptr, "EventInfoByteStreamxAODCnv") +{ +} + +const CLID& EventInfoByteStreamxAODCnv::classID() +{ + return ClassID_traits<xAOD::EventInfo>::ID(); +} + +long EventInfoByteStreamxAODCnv::storageType() +{ + return ByteStreamAddress::storageType(); +} + +StatusCode EventInfoByteStreamxAODCnv::initialize() +{ + ATH_MSG_DEBUG("Initialize"); + CHECK(Converter::initialize()); + return StatusCode::SUCCESS; +} + +StatusCode EventInfoByteStreamxAODCnv::finalize() +{ + ATH_MSG_DEBUG("Finalize"); + + StatusCode sc = Converter::finalize(); + if (sc.isFailure()) { + ATH_MSG_WARNING("Converter::finalize() failed"); + } + return sc; +} + +StatusCode EventInfoByteStreamxAODCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) +{ + ByteStreamAddress *pRE_Addr{nullptr}; + pRE_Addr = dynamic_cast<ByteStreamAddress*>(pAddr); + if (!pRE_Addr) { + ATH_MSG_ERROR("Cannot cast to ByteStreamAddress "); + return StatusCode::FAILURE; + } + + ATH_MSG_DEBUG("Creating Objects"); + + const std::string nm = *(pRE_Addr->par()); + const std::string nmAux = nm + "Aux."; + + xAOD::EventInfo* pEvtInfo = new xAOD::EventInfo(); + DataLink<xAOD::EventAuxInfo> link(nmAux); + pEvtInfo->setStore(link); + pObj = StoreGateSvc::asStorable(pEvtInfo); + + ATH_MSG_DEBUG(" New EventInfo made, run/event= " << pEvtInfo->runNumber() << " " << pEvtInfo->eventNumber()); + + return StatusCode::SUCCESS; +} + +StatusCode EventInfoByteStreamxAODCnv::createRep(DataObject* /*pObj*/, IOpaqueAddress*& /*pAddr*/) +{ + ATH_MSG_DEBUG("Nothing to be done for xAOD::EventInfo createReps"); + return StatusCode::SUCCESS; +} diff --git a/Event/ByteStreamCnvSvc/src/EventInfoByteStreamxAODCnv.h b/Event/ByteStreamCnvSvc/src/EventInfoByteStreamxAODCnv.h new file mode 100644 index 0000000000000000000000000000000000000000..2c398ae6730d7415e84f295d0a980e1ee4b447b8 --- /dev/null +++ b/Event/ByteStreamCnvSvc/src/EventInfoByteStreamxAODCnv.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef EVENTINFOBYTESTREAMXAODCNV_H +#define EVENTINFOBYTESTREAMXAODCNV_H + +/** + * @file EventInfoByteStreamxAODCnv.h + * + * @class EventInfoByteStreamxAODCnv + * + * @brief This is the class definition of ByteStream converter for xAOD::EventInfo + * Event Info is built from RawEvent when reading. Nothing is done when writing ByteStream + * + */ + +#include "GaudiKernel/Converter.h" +#include "AthenaBaseComps/AthMessaging.h" + +// Abstract factory to create the converter +template <class TYPE> class CnvFactory; + +class EventInfoByteStreamxAODCnv : public Converter, public AthMessaging +{ + public: + EventInfoByteStreamxAODCnv(ISvcLocator* svcloc); + virtual ~EventInfoByteStreamxAODCnv() override {} + + virtual StatusCode initialize() override; + virtual StatusCode finalize() override; + + /// converter method to create object + virtual StatusCode createObj(IOpaqueAddress* pAddr, DataObject*& pObj) override; + /// converter method to write object + virtual StatusCode createRep(DataObject* pObj, IOpaqueAddress*& pAddr) override; + + /// Storage type and class ID + virtual long repSvcType() const override { return i_repSvcType(); } + static long storageType(); + static const CLID& classID(); + +}; + +#endif diff --git a/Event/ByteStreamCnvSvc/src/components/ByteStreamCnvSvc_entries.cxx b/Event/ByteStreamCnvSvc/src/components/ByteStreamCnvSvc_entries.cxx index df2aafb192db8976c80544e12978660d1ae4b3de..a1dbb13243f4bb0172a9bd982896f5684a86e4c7 100644 --- a/Event/ByteStreamCnvSvc/src/components/ByteStreamCnvSvc_entries.cxx +++ b/Event/ByteStreamCnvSvc/src/components/ByteStreamCnvSvc_entries.cxx @@ -1,7 +1,8 @@ #include "ByteStreamCnvSvc/ByteStreamCnvSvc.h" #include "../EventSelectorByteStream.h" #include "../ByteStreamMergeOutputSvc.h" -#include "../EventInfoByteStreamCnv.h" +#include "../EventInfoByteStreamxAODCnv.h" +#include "../EventInfoByteStreamAuxCnv.h" #include "../ByteStreamRDP_OutputSvc.h" #include "../ByteStreamEventStorageInputSvc.h" #include "../ByteStreamEventStorageOutputSvc.h" @@ -11,9 +12,10 @@ #include "../ByteStreamMetadataTool.h" #include "../ByteStreamAttListMetadataSvc.h" -DECLARE_CONVERTER( EventInfoByteStreamCnv ) DECLARE_COMPONENT( ByteStreamCnvSvc ) DECLARE_COMPONENT( EventSelectorByteStream ) +DECLARE_CONVERTER( EventInfoByteStreamxAODCnv ) +DECLARE_CONVERTER( EventInfoByteStreamAuxCnv ) DECLARE_COMPONENT( ByteStreamMergeOutputSvc ) DECLARE_COMPONENT( ByteStreamRDP_OutputSvc ) DECLARE_COMPONENT( ByteStreamEventStorageInputSvc ) diff --git a/Reconstruction/RecExample/RecExCommon/share/RecExCommon_topOptions.py b/Reconstruction/RecExample/RecExCommon/share/RecExCommon_topOptions.py index c72b124d83bef80dca26b7af428eed6698559f74..df0372175f279b133b371e4d5ef0dcd91235953d 100644 --- a/Reconstruction/RecExample/RecExCommon/share/RecExCommon_topOptions.py +++ b/Reconstruction/RecExample/RecExCommon/share/RecExCommon_topOptions.py @@ -468,7 +468,8 @@ topSequence+=EventCounter(Frequency=100) from AthenaCommon.AlgSequence import AthSequencer condSeq = AthSequencer("AthCondSeq") -if( ( not objKeyStore.isInInput( "xAOD::EventInfo") ) and \ +if( not globalflags.InputFormat.is_bytestream() and \ + ( not objKeyStore.isInInput( "xAOD::EventInfo") ) and \ ( not hasattr( topSequence, "xAODMaker::EventInfoCnvAlg" ) ) ): from xAODEventInfoCnv.xAODEventInfoCreator import xAODMaker__EventInfoCnvAlg condSeq+=xAODMaker__EventInfoCnvAlg()