diff --git a/Control/IOVSvc/CMakeLists.txt b/Control/IOVSvc/CMakeLists.txt index 45c3b65760c52fcc7880977407e561db9b63c743..05ec344b8172a2efd00f01f4ddb88e7052f0c144 100644 --- a/Control/IOVSvc/CMakeLists.txt +++ b/Control/IOVSvc/CMakeLists.txt @@ -14,7 +14,8 @@ atlas_depends_on_subdirs( PUBLIC GaudiKernel PRIVATE AtlasTest/TestTools - Event/EventInfo ) + Event/EventInfo + Event/xAOD/xAODEventInfo ) # External dependencies: find_package( Boost COMPONENTS filesystem thread system ) diff --git a/Control/IOVSvc/IOVSvc/CondSvc.h b/Control/IOVSvc/IOVSvc/CondSvc.h index 1375044f4edd74c290dddc73a28e473c7358bfe6..42fd7110c14cf1a00e73693545bb66339b224a2b 100644 --- a/Control/IOVSvc/IOVSvc/CondSvc.h +++ b/Control/IOVSvc/IOVSvc/CondSvc.h @@ -45,6 +45,7 @@ public: virtual const std::set<IAlgorithm*>& condAlgs() const { return m_condAlgs; } virtual void dump() const; + virtual void dump(std::ostringstream&) const; private: diff --git a/Control/IOVSvc/src/CondInputLoader.cxx b/Control/IOVSvc/src/CondInputLoader.cxx index 6b06471a8096efeb91aa1d22b984d9417d153875..417de8f32c91621cb8f6d5c6b515780c80ab4550 100644 --- a/Control/IOVSvc/src/CondInputLoader.cxx +++ b/Control/IOVSvc/src/CondInputLoader.cxx @@ -15,8 +15,10 @@ #include "AthenaKernel/errorcheck.h" #include "AthenaKernel/IOVTime.h" #include "AthenaKernel/IOVRange.h" +#include "AthenaKernel/IIOVDbSvc.h" +#include "AthenaKernel/IIOVSvc.h" - +#include "xAODEventInfo/EventInfo.h" /////////////////////////////////////////////////////////////////// // Public methods: @@ -35,7 +37,8 @@ CondInputLoader::CondInputLoader( const std::string& name, // // Property declaration // - declareProperty( "Load", m_load)->declareUpdateHandler(&CondInputLoader::loader, this); + declareProperty( "Load", m_load); + //->declareUpdateHandler(&CondInputLoader::loader, this); declareProperty( "ShowEventDump", m_dump=false); } @@ -64,8 +67,81 @@ CondInputLoader::initialize() return StatusCode::FAILURE; } - StatusCode sc(StatusCode::SUCCESS); + // Trigger read of IOV database + ServiceHandle<IIOVSvc> ivs("IOVSvc",name()); + if (!ivs.isValid()) { + ATH_MSG_FATAL("unable to retrieve IOVSvc"); + return StatusCode::FAILURE; + } + + // Update the SG keys if different from Folder Names + ServiceHandle<IIOVDbSvc> idb("IOVDbSvc",name()); + if (!idb.isValid()) { + ATH_MSG_FATAL("unable to retrieve IOVDbSvc"); + return StatusCode::FAILURE; + } + + std::vector<std::string> keys = idb->getKeyList(); + std::string folderName, tg; + IOVRange range; + bool retrieved; + unsigned long long br; + float rt; + DataObjIDColl m_loadCopy; + + std::map<std::string,std::string> folderKeyMap; + for (auto key : keys) { + if (idb->getKeyInfo(key, folderName, tg, range, retrieved, br, rt)) { + folderKeyMap[folderName] = key; + m_keyFolderMap[key] = folderName; + } else { + ATH_MSG_WARNING("unable to retrieve keyInfo for " << key ); + } + } + + std::map<std::string,std::string>::const_iterator itr; + for (auto id : m_load) { + itr = folderKeyMap.find(id.key()); + if (itr != folderKeyMap.end() && id.key() != itr->second) { + ATH_MSG_DEBUG(" mapping folder " << id.key() << " to SGkey " + << itr->second); + id.updateKey( itr->second ); + // } else { + // ATH_MSG_DEBUG(" not remapping folder " << id.key()); + } + m_loadCopy.insert(id); + } + + // for (auto key : keys) { + // if (idb->getKeyInfo(key, folderName, tg, range, retrieved, br, rt)) { + // ATH_MSG_VERBOSE("folder: " << folderName << " key: " << key); + // for (auto id : m_load) { + // if (id.key() == folderName) { + // ATH_MSG_DEBUG(" mapping folder " << folderName << " to SGkey " << key ); + // id.updateKey( key ); + // m_loadCopy.insert(id); + // m_keyFolderMap[key] = folderName; + // break; + // } + // } + // } else { + // ATH_MSG_WARNING("unable to retrieve keyInfo for " << key ); + // } + // } + + m_load = m_loadCopy; + + // Update the properties, set the ExtraOutputs for Alg deps + const Property &p = getProperty("Load"); + + ATH_MSG_DEBUG("setting prop ExtraOutputs to " << p.toString()); + if (!setProperty("ExtraOutputs", p).isSuccess()) { + ATH_MSG_ERROR("failed setting property ExtraOutputs"); + return StatusCode::FAILURE; + } + + StatusCode sc(StatusCode::SUCCESS); std::ostringstream str; str << "Will create WriteCondHandle dependencies for the following DataObjects:"; for (auto &e : m_load) { @@ -79,10 +155,6 @@ CondInputLoader::initialize() ATH_MSG_ERROR("Unable to register WriteCondHandle " << dh.fullKey()); sc = StatusCode::FAILURE; } - // if (m_condSvc->regCondHandle(this, dh, e.key()).isFailure()) { - // ATH_MSG_ERROR("Unable to register managed handle " << dh.fullKey()); - // sc = StatusCode::FAILURE; - // } m_IOVSvc->ignoreProxy(dh.fullKey().clid(), e.key()); } } @@ -109,36 +181,6 @@ CondInputLoader::execute() { ATH_MSG_DEBUG ("Executing " << name() << "..."); -#ifdef ATHENAHIVE - - // if (m_first) { - // StatusCode sc(StatusCode::SUCCESS); - // auto managedIDs = m_condSvc->managedIDs(); - // for (auto id : managedIDs) { - // if (m_load.find(id) == m_load.end()) { - // ATH_MSG_ERROR(" not configured to provide WriteCondHandle for " - // << id); - // sc = StatusCode::FAILURE; - // } - // } - - // DataObjIDColl::iterator itr; - // for (itr = m_load.begin(); itr != m_load.end(); ) { - // if ( managedIDs.find( *itr )== managedIDs.end() ) { - // ATH_MSG_DEBUG(" removing ID " << *itr - // << " from Loader list as it's not used"); - // itr = m_load.erase(itr); - // } else { - // ++itr; - // } - // } - - // m_first = false; - - // if (sc.isFailure()) { return sc; } - - // } - if (m_first) { DataObjIDColl::iterator itr; for (itr = m_load.begin(); itr != m_load.end(); ) { @@ -155,15 +197,26 @@ CondInputLoader::execute() } m_first = false; } - - - - EventIDBase now( getContext()->eventID() ); + EventIDBase now; + if(getContext()==nullptr) { + const xAOD::EventInfo* thisEventInfo; + if(evtStore()->retrieve(thisEventInfo)!=StatusCode::SUCCESS) { + ATH_MSG_ERROR("Unable to get Event Info"); + return StatusCode::FAILURE; + } + now.set_run_number(thisEventInfo->runNumber()); + now.set_event_number(thisEventInfo->eventNumber()); + now.set_time_stamp(thisEventInfo->timeStamp()); + } + else { + now.set_run_number(getContext()->eventID().run_number()); + now.set_event_number(getContext()->eventID().event_number()); + now.set_time_stamp(getContext()->eventID().time_stamp()); + } IOVTime t(now.run_number(), now.event_number(), now.time_stamp()); EventIDRange r; - StatusCode sc; std::string tag; // for (auto &obj: extraOutputDeps()) { for (auto &obj: m_load) { @@ -185,77 +238,17 @@ CondInputLoader::execute() } + std::string dbKey = m_keyFolderMap[obj.key()]; if (m_IOVSvc->createCondObj( ccb, obj, now ).isFailure()) { - ATH_MSG_ERROR("unable to create Cond object for " << obj); + ATH_MSG_ERROR("unable to create Cond object for " << obj << " dbKey: " + << dbKey); return StatusCode::FAILURE; } else { evtStore()->addedNewTransObject(obj.clid(), obj.key()); } - // IOVRange range; - // IOpaqueAddress* ioa; - - // if (m_IOVSvc-> getRangeFromDB(obj.clid(), obj.key(), - // t, range, tag, ioa).isFailure()) { - // ATH_MSG_ERROR( "unable to get range from db for " - // << obj.clid() << " " << obj.key() ); - // continue; - // } - - // ATH_MSG_INFO( " new range: " << range ); - - // if (ccb->proxy() == nullptr) { - // SG::DataProxy *dp = m_condSvc->getProxy( obj ); - // ccb->setProxy(dp); - // } - - // // this will talk to the IOVDbSvc, get current run/event from EventInfo - // // object, load - // SG::DataProxy* dp = ccb->proxy(); - // DataObject* dobj(0); - // void* v(0); - - // if (dp->loader()->createObj(ioa, dobj).isFailure()) { - // ATH_MSG_ERROR(" could not create a new DataObject "); - // } else { - // ATH_MSG_INFO(" created new obj at " << dobj ); - - // v = SG::Storable_cast(dobj, obj.clid()); - - // } - - // // v = SG::DataProxy_cast(ccb->proxy(), obj.clid()); - // DataObject *d2 = static_cast<DataObject*>(v); - - // ATH_MSG_INFO( " obj: " << d2 ); - - // EventIDRange r2(EventIDBase(range.start().run(), range.start().event()), - // EventIDBase(range.stop().run(), range.stop().event())); - - // ccb->insert( r2, d2); - - // ATH_MSG_INFO ("inserted new object at " << d2 ); - - // evtStore()->addedNewTransObject(obj.clid(), obj.key()); - - // ATH_MSG_INFO ("addedNewTransObj"); - - - // SG::DataProxy* dp = evtStore()->proxy(obj.clid(), obj.key()); - // if (dp != 0) { - // ATH_MSG_DEBUG("loading obj " << obj); - // if (dp->transientAddress()->provider() == 0) { - // ATH_MSG_DEBUG(" obj " << obj << " has no provider, and is only Transient" ); - // } - // evtStore()->addedNewTransObject(obj.clid(), obj.key()); - // } else { - // ATH_MSG_ERROR("unable to get proxy for " << obj); - // } - } -#endif - if (m_dump) { ATH_MSG_DEBUG(evtStore()->dump()); } @@ -266,12 +259,3 @@ CondInputLoader::execute() //----------------------------------------------------------------------------- -void -CondInputLoader::loader(Property& p ) { - - ATH_MSG_DEBUG("setting prop ExtraOutputs to " << p.toString()); - - if (!setProperty("ExtraOutputs", p).isSuccess()) { - ATH_MSG_WARNING("failed setting property ExtraOutputs"); - } -} diff --git a/Control/IOVSvc/src/CondInputLoader.h b/Control/IOVSvc/src/CondInputLoader.h index 2f723bd67b5418b5d7b8cde84cc9c1cf31e3c455..ea584ff862aef62e60d2001cb5be02ffb43a110e 100644 --- a/Control/IOVSvc/src/CondInputLoader.h +++ b/Control/IOVSvc/src/CondInputLoader.h @@ -22,6 +22,8 @@ #include "StoreGate/StoreGateSvc.h" #include "AthenaBaseComps/AthAlgorithm.h" +#include <string> +#include <map> class CondInputLoader @@ -65,20 +67,19 @@ class CondInputLoader /// Default constructor: // CondInputLoader(); - void loader(Property&); + // void loader(Property&); /// Containers DataObjIDColl m_load; bool m_dump; -#ifdef ATHENAHIVE bool m_first { true }; -#endif ServiceHandle<StoreGateSvc> m_condStore; ServiceHandle<ICondSvc> m_condSvc; ServiceHandle<IIOVSvc> m_IOVSvc; + std::map<std::string,std::string> m_keyFolderMap; }; diff --git a/Control/IOVSvc/src/CondSvc.cxx b/Control/IOVSvc/src/CondSvc.cxx index 20e73e93ff33eda8fe1393a5d0f143adb29a0919..6069ad73b7e8090536b4eae5b345841ad9b173d2 100644 --- a/Control/IOVSvc/src/CondSvc.cxx +++ b/Control/IOVSvc/src/CondSvc.cxx @@ -140,27 +140,50 @@ CondSvc::readDbFile(const std::string& fname) { void CondSvc::dump() const { + std::ostringstream ost; + dump(ost); + + info() << ost.str() << endmsg; + +} + + +//--------------------------------------------------------------------------- + +void +CondSvc::dump(std::ostringstream& ost) const { + std::lock_guard<std::recursive_mutex> lock(m_lock); - info() << "CondSvc::dump()"; + ost << "CondSvc::dump()"; - info() << "\ndumping id->alg map\n"; + ost << "\ndumping id->alg map\n"; for (auto ent : m_idMap) { - info() << std::endl << " + " << ent.first << " : "; + ost << std::endl << " + " << ent.first << " : "; for (auto a : ent.second) { - info() << " " << a->name(); + ost << " " << a->name(); } } - info() << "\n\ndumping alg->id map\n"; + ost << "\n\ndumping alg->id map\n"; for (auto ent : m_algMap) { - info() << std::endl << " + " << ent.first->name() << " : "; + ost << std::endl << " + " << ent.first->name() << " : "; for (auto a : ent.second) { - info() << " " << a; + ost << " " << a; } } + ost << "\n\ndumping ConditionStore:\n\n"; - info() << std::endl << endmsg; + SG::ConstIterator<CondContBase> cib,cie; + if (m_sgs->retrieve(cib,cie).isSuccess()) { + while (cib != cie) { + ost << " + "; + cib->list(ost); + ++cib; + } + } + + ost << "\n"; } @@ -171,6 +194,13 @@ CondSvc::finalize() { ATH_MSG_DEBUG( "CondSvc::finalize()" ); + if (msgLvl(MSG::DEBUG)) { + std::ostringstream ost; + dump(ost); + + ATH_MSG_DEBUG( ost.str() ); + } + for ( auto e : m_registry ) { for ( auto ie : e.second ) { delete ie.objPtr(); @@ -178,6 +208,7 @@ CondSvc::finalize() { } } + return StatusCode::SUCCESS; } diff --git a/Control/IOVSvc/src/IOVSvc.cxx b/Control/IOVSvc/src/IOVSvc.cxx index f101a22640899d9308c9ec5559b4f89501039421..9e3e7bfcfdcea39fe69c472c50136c84f80a0ac8 100755 --- a/Control/IOVSvc/src/IOVSvc.cxx +++ b/Control/IOVSvc/src/IOVSvc.cxx @@ -864,7 +864,8 @@ IOVSvc::createCondObj(CondContBase* ccb, const DataObjID& id, return StatusCode::FAILURE; } - ATH_MSG_DEBUG( " new range for ID " << id << " : " << range ); + ATH_MSG_DEBUG( " new range for ID " << id << " : " << range + << " IOA: " << ioa); if (ccb->proxy() == nullptr) { // SG::DataProxy *dp = p_condSvc->getProxy( id ); @@ -876,10 +877,9 @@ IOVSvc::createCondObj(CondContBase* ccb, const DataObjID& id, ATH_MSG_ERROR ( "Could not get DataProxy from ProxyProviderSvc for " << id ); return StatusCode::FAILURE; - } else { - ATH_MSG_DEBUG( " found DataProxy " << dp << " for " << id ); } + ATH_MSG_DEBUG( " found DataProxy " << dp << " for " << id ); ccb->setProxy(dp); } @@ -899,19 +899,19 @@ IOVSvc::createCondObj(CondContBase* ccb, const DataObjID& id, v = SG::Storable_cast(dobj, id.clid()); } - // v = SG::DataProxy_cast(ccb->proxy(), id.clid()); - DataObject *d2 = static_cast<DataObject*>(v); + // DataObject *d2 = static_cast<DataObject*>(v); - ATH_MSG_DEBUG( " SG::Storable_cast to obj: " << d2 ); + ATH_MSG_DEBUG( " SG::Storable_cast to obj: " << v ); EventIDRange r2(EventIDBase(range.start().run(), range.start().event()), EventIDBase(range.stop().run(), range.stop().event())); - ccb->insert( r2, d2); - - // p_sgs->addedNewTransObject(id.clid(), id.key()); - // ATH_MSG_DEBUG ("addedNewTransObj"); - + if (!ccb->insert( r2, v)) { + ATH_MSG_ERROR("unable to insert Object at " << v << " into CondCont " + << ccb->id() << " for range " << r2 ); + return StatusCode::FAILURE; + } + return StatusCode::SUCCESS; }