diff --git a/Event/EventInfoMgt/src/TagInfoMgr.cxx b/Event/EventInfoMgt/src/TagInfoMgr.cxx index c710c665db032d637ba2bd88d61717a6292ffe2d..dc50fbc4fad928af2f18d62bebe232c92cd7a708 100755 --- a/Event/EventInfoMgt/src/TagInfoMgr.cxx +++ b/Event/EventInfoMgt/src/TagInfoMgr.cxx @@ -48,15 +48,7 @@ long TagInfoMgr_StorageType = 0x50; // Constructor with parameters: TagInfoMgr::TagInfoMgr(const std::string &name, ISvcLocator *pSvcLocator) : - AthCnvSvc(name, pSvcLocator, TagInfoMgr_StorageType), - m_storeGate("StoreGateSvc", name), - m_detStore("DetectorStore", name), - m_iovDbSvc("IOVDbSvc", name), - m_metaDataTool("IOVDbMetaDataTool"), - m_isFirstBeginRun(true), - m_conditionsRun(EventIDBase::UNDEFNUM), - m_newFileIncidentSeen(false), - m_lastIOVRange(IOVRange(IOVTime(),IOVTime())) + AthCnvSvc(name, pSvcLocator, TagInfoMgr_StorageType) {} TagInfoMgr::~TagInfoMgr() @@ -138,7 +130,7 @@ StatusCode TagInfoMgr::initialize() } // To copy TagInfo to EventInfo, we set listener to the - // IncidentSvc for BeginEvent and BeginRun + // IncidentSvc for BeginRun and BeginInputFile ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", name()); long int pri=1000; @@ -146,12 +138,11 @@ StatusCode TagInfoMgr::initialize() // file meta data incSvc->addListener( this, "BeginRun", pri); - // Add BeginEvent to trigger refilling meta data store after a new - // input file - incSvc->addListener( this, "BeginEvent", pri); - - // Set to be listener for BeginInputFile - incSvc->addListener(this, "BeginInputFile", 50); // pri has to be < 50 to be after IOVDbMetaDataTool. + // Add BeginInputFile to trigger refilling meta data store after a new input + // file - priority has to be < 50 to be run after IOVDbMetaDataTool, which + // has mergeing into the output file medat data the input meta data of the + // new file. + incSvc->addListener(this, "BeginInputFile", 50); // return StatusCode::SUCCESS; } @@ -297,7 +288,7 @@ TagInfoMgr::fillTagInfo(const CondAttrListCollection* tagInfoCond, TagInfo* tagI EventType::NameTagPairVec pairs1; evtH->event_type()->get_detdescr_tags(pairs1); - if (msgLevel() <= MSG::DEBUG) { + if (msgLvl(MSG::DEBUG)) { if(pairs1.size()) { ATH_MSG_DEBUG( "fillTagInfo: Pairs from EventType:"); } @@ -351,9 +342,9 @@ TagInfoMgr::fillTagInfo(const CondAttrListCollection* tagInfoCond, TagInfo* tagI } // Dump out contents of TagInfo - if (msgLevel() <= MSG::DEBUG) { - MsgStream log1(Athena::getMessageSvc(), "TagInfo"); - tagInfo->printTags(log1); + if (msgLvl(MSG::DEBUG)) { + ATH_MSG_DEBUG( "fillTagInfo: print out tags before adding extra tags"); + ATH_MSG_DEBUG(tagInfo->str()); } @@ -373,9 +364,9 @@ TagInfoMgr::fillTagInfo(const CondAttrListCollection* tagInfoCond, TagInfo* tagI } // Dump out contents of TagInfo - if( msgLevel() <= MSG::DEBUG ) { - MsgStream log1(Athena::getMessageSvc(), "TagInfo"); - tagInfo->printTags(log1); + if (msgLvl(MSG::DEBUG)) { + ATH_MSG_DEBUG( "fillTagInfo: print out tags"); + ATH_MSG_DEBUG(tagInfo->str()); } return StatusCode::SUCCESS; @@ -388,31 +379,16 @@ TagInfoMgr::fillMetaData (const TagInfo* tagInfo, const CondAttrListCollection // fillMetaData is called at the beginning of the job and for each // new file being read in. // - // Fill IOV object in metadata store with information from tag // info. - // For the IOV, we have two choices: // - // 1) If there are input tags from file meta data, then we use - // the IOV from the input conditions. For the first input - // file, we use the incoming IOV if the current run falls - // within the IOV range. If not we set the IOV to runNumber - // to runNumber + 1. For subsequent input files, if the - // runNumber falls within the previous IOV range, then we set - // the new IOV to [runNumber, lastStop), otherwise the IOV is - // set to [runNumber, runNumber+1). This latter is used for - // the zerobias overlaying. - // - // 2) If we are taking them from the incoming events, then we - // simply assume that the tags are valid for one run. (This - // is the old way of doing things, no longer valid since - // storing TagInfo in the MetaData - // - // Notes: - // - // The add of tags to the file meta data will merge different - // IOVs together if the payloads are identical, so doing this - // run by run is ok for 2) + // For the IOV we use the IOV from the input conditions. For the first input + // file, we use the incoming IOV if the current run falls within the IOV + // range. If not we set the IOV to runNumber to runNumber + 1. For + // subsequent input files, if the runNumber falls within the previous IOV + // range, then we set the new IOV to [runNumber, lastStop), otherwise the + // IOV is set to [runNumber, runNumber+1). This latter is used for the + // zerobias overlaying. // ATH_MSG_DEBUG( "entering fillMetaData"); @@ -450,6 +426,7 @@ TagInfoMgr::fillMetaData (const TagInfo* tagInfo, const CondAttrListCollection CondAttrListCollection* attrListColl = new CondAttrListCollection(true); attrListColl->add(0, attrList); // Set IOV: + if (tagInfoCond) { // set to the IOV of the incoming conditions // if run num is in previous IOV, set new IOV to be [runNum, lastStop) @@ -568,22 +545,24 @@ void TagInfoMgr::handle(const Incident& inc) { /** - - ** This method is called at the BeginRun incident: + ** This method is called at the both the BeginRun and BeginInputFile incidents: ** ** 1) For the first begin run, we retrieve the TagInfo and set ** up IOVDbSvc so that is can use TagInfo to define its ** hierarchical tags. + ** Note: the detector store 'retrieve' of the TagInfo will call + ** TagInfoMgr::createObj to do the first creation and filling it + ** accordingly. And this also fills the output file metadata with + ** contents of the TagInfo object. ** - ** 2) For (old) input files where the TagInfo is stored in each - ** event, subsequent begin runs will fill the file meta data - ** for output. This is done because the IOV is incremented by - ** one each run. + ** 2) Then whenever a new file is opened (BeginInputFile), we + ** use the TagInfo object from the detector store to "re-fill" + ** and override the newly merged TagInfo meta data in the output + ** meta data store. We receive BeginInputFile AFTER the + ** IOVDbMetaDataTool has done this automatic merging, so that we + ** can safely overwrite with the desired TagInfo information for + ** this job/run. ** - ** Note that if the input has TagInfo in the file meta data, the - ** output will be written via the checkTagInfo callback - called - ** each time the input TagInfo object changes. - ** **/ // Get the messaging service, print where you are @@ -591,8 +570,9 @@ TagInfoMgr::handle(const Incident& inc) { << " from " << inc.source()); // Return quickly for BeginEvent if not needed - if (!m_newFileIncidentSeen && inc.type() == IncidentType::BeginEvent) return; + if (!m_isFirstBeginRun && inc.type() == IncidentType::BeginEvent) return; + // At first BeginRun we retrieve TagInfo and trigger IOVDbSvc to // use it if (inc.type() == IncidentType::BeginRun && m_isFirstBeginRun) { @@ -600,9 +580,6 @@ TagInfoMgr::handle(const Incident& inc) { // No longer first BeginRun m_isFirstBeginRun = false; - // reset flags - m_newFileIncidentSeen = false; - // get conditionsRun from the Context - can be used if no EventID in the SG (for HLT) m_conditionsRun = Atlas::getExtendedEventContext(inc.context()).conditionsRun(); @@ -610,7 +587,7 @@ TagInfoMgr::handle(const Incident& inc) { // can't use a ref here! const EventIDBase eventID = inc.context().eventID(); - if (msgLevel() <= MSG::DEBUG) { + if (msgLvl(MSG::DEBUG)) { msg() << MSG::DEBUG << "handle: First BeginRun incident - Event ID: [" << eventID.run_number() << "," << eventID.event_number() << ":" @@ -656,7 +633,6 @@ TagInfoMgr::handle(const Incident& inc) { ATH_MSG_DEBUG( "handle: Try dropping /TagInfo - " << sc); if (m_detStore->retrieve( tagInfo, m_tagInfoKeyValue ).isFailure() ) { ATH_MSG_ERROR( "handle: Could not retrieve TagInfo object from the detector store"); - return; } } @@ -670,53 +646,11 @@ TagInfoMgr::handle(const Incident& inc) { ATH_MSG_DEBUG( "handle: TagInfo successfully processed by IOVDbSvc to register callback"); } } - else if (inc.type() == IncidentType::BeginRun) { - // For subsequent BeginRuns, check whether the /TagInfo folder - // exists, and if so return. We only treat the case where - // TagInfo is coming in with each event. In this case we fill - // file meta data and increment IOV to cover each run - - // reset flags - m_newFileIncidentSeen = false; - // Return if /TagInfo exists - const CondAttrListCollection* attrListColl = 0; - if (m_detStore->contains<CondAttrListCollection>("/TagInfo")) { - ATH_MSG_DEBUG( "handle: TagInfo input from meta data - no need to fill output file meta data"); - return; - } - - const TagInfo* tagInfo = 0; - if (m_detStore->retrieve( tagInfo, m_tagInfoKeyValue ).isFailure() ) { - ATH_MSG_ERROR( "handle: Could not retrieve TagInfo object from the detector store"); - throw GaudiException( "Could not retrieve TagInfo object from the detector store", "TagInfoMgr::handle", StatusCode::FAILURE ); - } - - // Copy TagInfo to meta data store for writing to file meta data - if (StatusCode::SUCCESS != fillMetaData(tagInfo, attrListColl)) { - ATH_MSG_ERROR( "handle: Unable to write TagInfo to MetaDataStore !"); - throw GaudiException( "Unable to write TagInfo to MetaDataStore !", "TagInfoMgr::handle", StatusCode::FAILURE ); - } - else { - ATH_MSG_DEBUG( "handle: Wrote TagInfo to MetaDataStore "); - } - } else if (inc.type() == "BeginInputFile" && !m_isFirstBeginRun) { - // We must keep track of BeginInputFile incidents because they - // will override the TagInfo in the file meta data. This flag - // will be used to restore the TagInfo folder in the meta data - // store at the next BeginEvent if and only if BeginRun has - // NOT already been called. (BeginRun will also reset the - // TagInfo in the meta data store.) - m_newFileIncidentSeen = true; - } - else if (m_newFileIncidentSeen && inc.type() == "BeginEvent") { - // If a new file incident has been seen and there is NOT a - // BeginRun before the next BeginEvent, then we "refill" the + // For a new file incident, we must "refill" the // meta data store with the current value of the TagInfo // folder in the detector store. - // reset flags - m_newFileIncidentSeen = false; // Return if /TagInfo does NOT exists const CondAttrListCollection* attrListColl = 0; if (m_detStore->contains<CondAttrListCollection>("/TagInfo")) { @@ -911,7 +845,7 @@ TagInfoMgr::createObj(IOpaqueAddress* addr, DataObject*& dataObj) { // most likely not used anymore. RDS 08/2012). if (attrListColl && attrListColl->size() == 0) { tagInfo = std::make_unique<TagInfo>(m_lastTagInfo); - if (msgLevel() <= MSG::DEBUG) { + if (msgLvl(MSG::DEBUG)) { ATH_MSG_DEBUG( "createObj: recreate tagInfo from saved info"); if (msgLevel()>=MSG::DEBUG) { MsgStream log1(Athena::getMessageSvc(), "TagInfo"); @@ -925,7 +859,7 @@ TagInfoMgr::createObj(IOpaqueAddress* addr, DataObject*& dataObj) { ATH_MSG_DEBUG( "createObj: Unable to fill TagInfo !"); return StatusCode::FAILURE; } - if (msgLevel() <= MSG::DEBUG) { + if (msgLvl(MSG::DEBUG)) { if (attrListColl) ATH_MSG_DEBUG( "createObj: Filled TagInfo from file meta data "); else ATH_MSG_DEBUG( "createObj: Filled TagInfo from input event "); } @@ -943,7 +877,7 @@ TagInfoMgr::createObj(IOpaqueAddress* addr, DataObject*& dataObj) { // Do standard conversion to data object dataObj = SG::asStorable(std::move(tagInfo)); - if (outputLevel() <= MSG::DEBUG) { + if (msgLvl(MSG::DEBUG)) { ATH_MSG_DEBUG( "createObj: created new TagInfo object "); } return StatusCode::SUCCESS; diff --git a/Event/EventInfoMgt/src/TagInfoMgr.h b/Event/EventInfoMgt/src/TagInfoMgr.h index 09a29d7c3125f202b14266f37feb6d227096ac74..32aab1c333270b9b4c3a9441fbccb0f61470c0f2 100755 --- a/Event/EventInfoMgt/src/TagInfoMgr.h +++ b/Event/EventInfoMgt/src/TagInfoMgr.h @@ -28,17 +28,16 @@ #include "GaudiKernel/IIncidentListener.h" #include "AthenaKernel/IAddressProvider.h" #include "AthenaKernel/IOVRange.h" +#include "AthenaKernel/IIOVDbSvc.h" #include "GaudiKernel/MsgStream.h" #include "EventInfo/TagInfo.h" +#include "IOVDbMetaDataTools/IIOVDbMetaDataTool.h" #include <map> //<<<<<< PUBLIC TYPES >>>>>> class StoreGateSvc; -class TagInfo; -class IIOVDbSvc; -class IIOVDbMetaDataTool; class CondAttrListCollection; //<<<<<< CLASS DECLARATIONS >>>>>> @@ -192,11 +191,11 @@ private: /// Flag to add override the tags from EventInfo from other /// sources - Gaudi::Property<bool> m_overrideEventInfoTags{this,"OverrideEventInfoTags",true,"Override tags yes/no"}; + Gaudi::Property<bool> m_overrideEventInfoTags { this, "OverrideEventInfoTags", true, "Override tags yes/no" }; /// Extra tags/values pairs added in my jobOptions Gaudi::Property<std::map<std::string,std::string> > - m_extraTagValuePairs{this,"ExtraTagValuePairs",{},"key/value pairs to be added", "mapMergeNoReplace<T,T>"}; + m_extraTagValuePairs { this, "ExtraTagValuePairs", {}, "key/value pairs to be added", "mapMergeNoReplace<T,T>" }; /// Extra tags/values pairs added in via interface std::map<std::string,std::string> m_extraTagValuePairsViaInterface; @@ -205,33 +204,30 @@ private: std::set<std::string> m_tagsToBeRemoved; /// The StoreGate key for the TagInfo - Gaudi::Property<std::string> m_tagInfoKey{this,"TagInfoKey","ProcessingTags","SG key for TagInfo"}; + Gaudi::Property<std::string> m_tagInfoKey{ this, "TagInfoKey", "ProcessingTags", "SG key for TagInfo" }; std::string m_tagInfoKeyValue; /// The event store - ServiceHandle<StoreGateSvc> m_storeGate; + ServiceHandle<StoreGateSvc> m_storeGate { this, "StoreGateSvc", "StoreGateSvc" }; /// The detector store - ServiceHandle<StoreGateSvc> m_detStore; + ServiceHandle<StoreGateSvc> m_detStore { this, "DetectorStore", "DetectorStore" }; /// Access to IOVDbSvc interface - used to register callback - ServiceHandle<IIOVDbSvc> m_iovDbSvc; + ServiceHandle<IIOVDbSvc> m_iovDbSvc { this, "IOVDbSvc", "IOVDbSvc" }; /// Access to iov meta data tool - ToolHandle<IIOVDbMetaDataTool> m_metaDataTool; + ToolHandle<IIOVDbMetaDataTool> m_metaDataTool { this, "IOVDbMetaDataTool", "IOVDbMetaDataTool" }; /// Flag to identify the first BeginRun incident - bool m_isFirstBeginRun; + bool m_isFirstBeginRun { true }; /// conditionsRun from the first BeginRun incident (HLT) - EventIDBase::number_type m_conditionsRun; - - /// Flag to identify a new file incident - bool m_newFileIncidentSeen; + EventIDBase::number_type m_conditionsRun { EventIDBase::UNDEFNUM }; /// IOVRange of last TagInfo added to the file meta data - IOVRange m_lastIOVRange; + IOVRange m_lastIOVRange { IOVRange(IOVTime(), IOVTime()) }; /// Last TagInfo added to the detector store TagInfo m_lastTagInfo;