diff --git a/Control/AthenaExamples/AthExHive/AthExHive/IASCIICondDbSvc.h b/Control/AthenaExamples/AthExHive/AthExHive/IASCIICondDbSvc.h new file mode 100644 index 0000000000000000000000000000000000000000..a2578799264abeca4e33ee4fb37f919b17f7926d --- /dev/null +++ b/Control/AthenaExamples/AthExHive/AthExHive/IASCIICondDbSvc.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_IASCIICONDDBSVC_H +#define ATHEXHIVE_IASCIICONDDBSVC_H + +#include "GaudiKernel/IService.h" +#include "GaudiKernel/EventContext.h" +#include "GaudiKernel/EventIDRange.h" + +#include <string> + + +class GAUDI_API IASCIICondDbSvc: virtual public IService { +public: + DeclareInterfaceID(IASCIICondDbSvc, 1, 0); + + typedef float dbData_t; + + virtual ~IASCIICondDbSvc() = default; + + virtual StatusCode getRange(const std::string&, const EventContext& ctx, + EventIDRange& rng, dbData_t&) const = 0; + + virtual void dump() const = 0; + +}; + +#endif diff --git a/Control/AthenaExamples/AthExHive/share/CondAlgsOpts.py b/Control/AthenaExamples/AthExHive/share/CondAlgsOpts.py index 62be7f6ed687435626dc2fff3ccff1cc53e3ef0c..d9bb5fcd78c86725154992e634e86501ce6b4f90 100644 --- a/Control/AthenaExamples/AthExHive/share/CondAlgsOpts.py +++ b/Control/AthenaExamples/AthExHive/share/CondAlgsOpts.py @@ -56,9 +56,9 @@ svcMgr.ForwardSchedulerSvc.EnableConditions = True from IOVSvc.IOVSvcConf import CondSvc -svcMgr += CondSvc( OutputLevel=DEBUG, CondFile = "condDb.txt") +svcMgr += CondSvc( OutputLevel=DEBUG ) -#---------------------------------------------------------------------------------# +#-----------------------------------------------------------------------------# # ## Uncomment following to avoid long waits when segfaulting, @@ -67,7 +67,7 @@ svcMgr += CondSvc( OutputLevel=DEBUG, CondFile = "condDb.txt") # import ROOT # ROOT.SetSignalPolicy( ROOT.kSignalFast ) -#---------------------------------------------------------------------------------# +#-----------------------------------------------------------------------------# # from StoreGate.StoreGateConf import StoreGateSvc @@ -97,6 +97,8 @@ topSequence+=CondAlgX("CondAlgX2", OutputLevel=DEBUG, Key_CH="X2", Key_DB="X2") topSequence+=CondAlgY("CondAlgY1", OutputLevel=DEBUG, Key_CH1="Y1", Key_CH2="Y2", Key_DB1="Y1", Key_DB2="Y2") +svcMgr += ASCIICondDbSvc( OutputLevel=DEBUG, CondFile = "condDb.txt" ) + #-------------------------------------------------------------- # Event related parameters diff --git a/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.cxx b/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2e762cde239e23ff19e311aa529ab8d7fdc7e7df --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.cxx @@ -0,0 +1,251 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "ASCIICondDbSvc.h" +#include "AthenaKernel/CondCont.h" +#include "GaudiKernel/SvcFactory.h" + +#include <boost/tokenizer.hpp> +#include <boost/algorithm/string.hpp> +#include <boost/regex.hpp> + +#include <fstream> + +std::string r_t("\\[([0-9]+),([0-9]+)\\]"); +std::string r_r = "\\s*\\{" + r_t + "-" + r_t + "\\}\\s*"; +std::string r_e = "\\s*\\{" + r_t + "-" + r_t + "\\}=([0-9]+)\\s*"; +std::string r_ef = "\\s*\\{" + r_t + "-" + r_t + "\\}=(-*[0-9]*\\.*[0-9]*)\\s*"; +boost::regex rr(r_r); +boost::regex re(r_e); +boost::regex ref(r_ef); + + +//--------------------------------------------------------------------------- + +ASCIICondDbSvc::ASCIICondDbSvc( const std::string& name, ISvcLocator* svcLoc ): + base_class(name,svcLoc) +{ + + declareProperty("CondFile",m_file=""); + +} + +//--------------------------------------------------------------------------- + +ASCIICondDbSvc::~ASCIICondDbSvc() { + +} + +//--------------------------------------------------------------------------- + +StatusCode +ASCIICondDbSvc::initialize() { + + // Initialise mother class in order to print DEBUG messages during initialize() + StatusCode sc(AthService::initialize()); + msg().setLevel( m_outputLevel.value() ); + + if (!sc.isSuccess()) { + warning () << "Base class could not be initialized" << endmsg; + return StatusCode::FAILURE; + } + + if (m_file == "") { + ATH_MSG_DEBUG("db file not set"); + return StatusCode::SUCCESS; + } + + if (readDbFile(m_file).isFailure()) { + return StatusCode::FAILURE; + } + + std::ostringstream ost; + ost << " Printing CondDB registry"; + for (auto e : m_registry) { + ost << std::endl << " - id: " << e.first << " r:"; + for (auto r : e.second) { + ost << " " << r.range() << " :: " << *r.objPtr(); + } + } + + ATH_MSG_DEBUG( ost.str() ); + + return StatusCode::SUCCESS; + +} +//--------------------------------------------------------------------------- + +StatusCode +ASCIICondDbSvc::readDbFile(const std::string& fname) { + + StatusCode sc(StatusCode::SUCCESS); + + ATH_MSG_DEBUG("reading cond db from \"" << fname << "\""); + + std::ifstream ifs (fname); + std::string line; + if(ifs.is_open()) { + + typedef boost::tokenizer<boost::char_separator<char> > tokenizer; + boost::char_separator<char> sep(" "); + + IOVEntryT<IASCIICondDbSvc::dbData_t> ie; + + while( getline (ifs, line) ) { + + // ignore anything after a "#" and blank lines + size_t fh = line.find("#"); + if(fh != std::string::npos) + line.erase(fh,line.length()-fh); + if (line.length() == 0) continue; + + tokenizer tokens(line, sep); + auto it = tokens.begin(); + + std::string dbKey = *it; + + ++it; + + while (it != tokens.end()) { + if (parse(ie,*it)) { + m_registry[dbKey].push_back( ie ); + } else { + error() << "while reading " << fname << " problem parsing " << *it + << " in line\n" << line << endmsg; + sc = StatusCode::FAILURE; + } + ++it; + } + } + ifs.close(); + } else { + error() << "unable to open file " << m_file << endmsg; + sc = StatusCode::FAILURE; + } + + return sc; + +} +//--------------------------------------------------------------------------- + +void +ASCIICondDbSvc::dump() const { + + std::ostringstream ost; + dump(ost); + + info() << ost.str() << endmsg; + +} + + +//--------------------------------------------------------------------------- + +void +ASCIICondDbSvc::dump(std::ostringstream& ost) const { + + std::lock_guard<std::recursive_mutex> lock(m_lock); + + ost << "ASCIICondDbSvc::dump()"; + + ost << "\n"; + +} + +//--------------------------------------------------------------------------- + +StatusCode +ASCIICondDbSvc::finalize() { + + ATH_MSG_DEBUG( "ASCIICondDbSvc::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(); + ie.setPtr(0); + } + } + + + return StatusCode::SUCCESS; + +} + +//--------------------------------------------------------------------------- + +bool +ASCIICondDbSvc::parse(EventIDRange& t, const std::string& s) { + + boost::smatch m; + boost::regex_match(s,m,rr); + + // for (auto res : m) { + // cout << " - " << res << endl; + // } + + if (m.size() != 5) { return false; } + + t = EventIDRange( EventIDBase(std::stoi(m[1]),std::stoi(m[2])), + EventIDBase(std::stoi(m[3]), std::stoi(m[4]))); + + return true; + +} + +//--------------------------------------------------------------------------- + +bool +ASCIICondDbSvc::parse(IOVEntryT<IASCIICondDbSvc::dbData_t>& ie, const std::string& s) { + + boost::smatch m; + boost::regex_match(s,m,ref); + + if (m.size() != 6) { return false; } + + ie.setRange( EventIDRange( EventIDBase(std::stoi(m[1]), std::stoi(m[2])), + EventIDBase(std::stoi(m[3]), std::stoi(m[4])) ) ); + + IASCIICondDbSvc::dbData_t *v = new IASCIICondDbSvc::dbData_t( std::stof(m[5]) ); + ie.setPtr(v); + + return true; + +} + +//--------------------------------------------------------------------------- + +StatusCode +ASCIICondDbSvc::getRange(const std::string& dbKey , const EventContext& ctx, + EventIDRange& rng, IASCIICondDbSvc::dbData_t& val) const { + + std::lock_guard<std::recursive_mutex> lock(m_lock); + + registry_t::const_iterator itr = m_registry.find(dbKey); + + if (itr == m_registry.end()) { + error() << "getRange: no dbKey " << dbKey << " found in registry" + << endmsg; + return StatusCode::FAILURE; + } + + for (auto e : itr->second) { + if (e.range().isInRange(EventIDBase(ctx.eventID()))) { + rng = e.range(); + val = *(e.objPtr()); + return StatusCode::SUCCESS; + } + } + + error() << "getRange: no range for Time " << ctx.eventID() + << " found for dbKey " << dbKey << endmsg; + + return StatusCode::FAILURE; +} diff --git a/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.h b/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.h new file mode 100644 index 0000000000000000000000000000000000000000..79dbecd1f25ad335fa57466845263ebb6f6c9823 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/ASCIICondDbSvc.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ATHEXHIVE_ASCIICONDDBSVC_H +#define ATHEXHIVE_ASCIICONDDBSVC_H 1 + +#include "GaudiKernel/Service.h" +#include "GaudiKernel/EventIDBase.h" +#include "GaudiKernel/EventIDRange.h" +#include "AthenaBaseComps/AthService.h" +#include "AthenaBaseComps/AthService.h" + +#include "AthExHive/IASCIICondDbSvc.h" + +#include <map> +#include <set> +#include <vector> +#include <mutex> + +class ASCIICondDbSvc: public extends1<AthService, IASCIICondDbSvc> { +public: + + ASCIICondDbSvc(const std::string& name, ISvcLocator* svc); + ~ASCIICondDbSvc(); + + virtual StatusCode initialize(); + virtual StatusCode finalize(); + + // from IASCIICondDbSvc +public: + + virtual StatusCode getRange(const std::string&, const EventContext&, EventIDRange&, + IASCIICondDbSvc::dbData_t&) const; + + virtual void dump() const; + virtual void dump(std::ostringstream&) const; + +private: + + bool parse(EventIDRange& t, const std::string& s); + bool parse(IOVEntryT<IASCIICondDbSvc::dbData_t>& t, const std::string& s); + + StatusCode readDbFile(const std::string&); + + std::string m_file; + + typedef std::map<std::string, std::vector<IOVEntryT<IASCIICondDbSvc::dbData_t>>> registry_t; + registry_t m_registry; + + mutable std::recursive_mutex m_lock; + +}; + +#endif diff --git a/Control/AthenaExamples/AthExHive/src/CondAlgX.cxx b/Control/AthenaExamples/AthExHive/src/CondAlgX.cxx index 72a67242f9bc85e90486c31c6f35949da7464e2b..7bc17f750cdb85b91685e4d62f987d63b3b281d2 100644 --- a/Control/AthenaExamples/AthExHive/src/CondAlgX.cxx +++ b/Control/AthenaExamples/AthExHive/src/CondAlgX.cxx @@ -19,7 +19,8 @@ CondAlgX::CondAlgX( const std::string& name, ::AthAlgorithm( name, pSvcLocator ), m_evt("McEventInfo"), m_wchk("X2","X2"), - m_cs("CondSvc",name) + m_cs("CondSvc",name), + m_cds("ASCIICondDbSvc",name) { declareProperty("EvtInfo", m_evt); @@ -37,6 +38,10 @@ StatusCode CondAlgX::initialize() { ATH_MSG_ERROR("unable to retrieve CondSvc"); } + if (m_cds.retrieve().isFailure()) { + ATH_MSG_ERROR("unable to retrieve ASCIICondDbSvc"); + } + m_wchk.setDbKey(m_dbKey); if (m_wchk.initialize().isFailure()) { @@ -95,7 +100,7 @@ StatusCode CondAlgX::execute() { EventIDRange r; ICondSvc::dbData_t val; - if (m_cs->getRange(wch.dbKey(), &getContext(), r, val).isFailure()) { + if (m_cds->getRange(wch.dbKey(), getContext(), r, val).isFailure()) { ATH_MSG_ERROR(" could not find dbKey \"" << wch.dbKey() << "\" in CondSvc registry"); return StatusCode::FAILURE; diff --git a/Control/AthenaExamples/AthExHive/src/CondAlgX.h b/Control/AthenaExamples/AthExHive/src/CondAlgX.h index d8c0a14997126a7bdb28dc9a11e9cb2e33e315d8..7eac56e5d308a93d0f13dd71775f7e1ce57487b3 100644 --- a/Control/AthenaExamples/AthExHive/src/CondAlgX.h +++ b/Control/AthenaExamples/AthExHive/src/CondAlgX.h @@ -6,6 +6,7 @@ #include "StoreGate/WriteCondHandleKey.h" #include "AthExHive/CondDataObj.h" +#include "AthExHive/IASCIICondDbSvc.h" #include "EventInfo/EventInfo.h" #include "GaudiKernel/ICondSvc.h" @@ -30,6 +31,7 @@ private: SG::WriteCondHandleKey<CondDataObj> m_wchk; ServiceHandle<ICondSvc> m_cs; + ServiceHandle<IASCIICondDbSvc> m_cds; std::string m_dbKey; diff --git a/Control/AthenaExamples/AthExHive/src/CondAlgY.cxx b/Control/AthenaExamples/AthExHive/src/CondAlgY.cxx index 7adf76b1fb87a8d6977970e59382ec060e639990..f50887eee18d19f5ab9202faf6f441dd2383ea74 100644 --- a/Control/AthenaExamples/AthExHive/src/CondAlgY.cxx +++ b/Control/AthenaExamples/AthExHive/src/CondAlgY.cxx @@ -15,7 +15,8 @@ CondAlgY::CondAlgY( const std::string& name, ::AthAlgorithm( name, pSvcLocator ), m_wch1("Y1","Y1"), m_wch2("Y2","Y2"), m_dbk1("Y1"), m_dbk2("Y2"), - m_cs("CondSvc",name) + m_cs("CondSvc",name), + m_cds("ASCIICondDbSvc",name) { declareProperty("Key_CH1", m_wch1); @@ -35,6 +36,10 @@ StatusCode CondAlgY::initialize() { ATH_MSG_ERROR("unable to retrieve CondSvc"); } + if (m_cds.retrieve().isFailure()) { + ATH_MSG_ERROR("unable to retrieve ASCIICondDbSvc"); + } + m_wch1.setDbKey(m_dbk1); m_wch2.setDbKey(m_dbk2); @@ -89,7 +94,7 @@ StatusCode CondAlgY::execute() { EventIDRange r; ICondSvc::dbData_t val; - if (m_cs->getRange(wch1.dbKey(), &getContext(), r, val).isFailure()) { + if (m_cds->getRange(wch1.dbKey(), getContext(), r, val).isFailure()) { ATH_MSG_ERROR(" could not find dbKey \"" << wch1.dbKey() << "\" in CondSvc registry"); return StatusCode::FAILURE; @@ -119,7 +124,7 @@ StatusCode CondAlgY::execute() { EventIDRange r; ICondSvc::dbData_t val; - if (m_cs->getRange(wch2.dbKey(), &getContext(), r, val).isFailure()) { + if (m_cds->getRange(wch2.dbKey(), getContext(), r, val).isFailure()) { ATH_MSG_ERROR(" could not find dbKey \"" << wch2.dbKey() << "\" in CondSvc registry"); return StatusCode::FAILURE; diff --git a/Control/AthenaExamples/AthExHive/src/CondAlgY.h b/Control/AthenaExamples/AthExHive/src/CondAlgY.h index eb42156bd3ae64f5c812e1bcbafe13fbb3e06f28..8cb2b33e9724ceca2bd4e6f646ba212534d9d161 100644 --- a/Control/AthenaExamples/AthExHive/src/CondAlgY.h +++ b/Control/AthenaExamples/AthExHive/src/CondAlgY.h @@ -6,6 +6,7 @@ #include "StoreGate/WriteCondHandleKey.h" #include "AthExHive/CondDataObjY.h" +#include "AthExHive/IASCIICondDbSvc.h" #include "EventInfo/EventInfo.h" #include "GaudiKernel/ICondSvc.h" @@ -29,6 +30,7 @@ private: std::string m_dbk1, m_dbk2; ServiceHandle<ICondSvc> m_cs; + ServiceHandle<IASCIICondDbSvc> m_cds; }; diff --git a/Control/AthenaExamples/AthExHive/src/components/AthExHive_entries.cxx b/Control/AthenaExamples/AthExHive/src/components/AthExHive_entries.cxx index 7fa07ad2b759b97d72c54e11de4b07b6920061f0..bd15e338c6f7e82980df70507ea3fa05d8879dc3 100644 --- a/Control/AthenaExamples/AthExHive/src/components/AthExHive_entries.cxx +++ b/Control/AthenaExamples/AthExHive/src/components/AthExHive_entries.cxx @@ -12,6 +12,7 @@ #include "../HiveAlgV.h" #include "../HiveTool.h" #include "../HiveExSvc.h" +#include "../ASCIICondDbSvc.h" #ifdef REENTRANT_GAUDI #include "../HiveAlgR.h" @@ -56,4 +57,5 @@ DECLARE_TOOL_FACTORY( ThreadInitTool ) DECLARE_TOOL_FACTORY( HiveTool ) DECLARE_SERVICE_FACTORY( HiveExSvc ) +DECLARE_SERVICE_FACTORY( ASCIICondDbSvc ) diff --git a/Control/IOVSvc/IOVSvc/CondSvc.h b/Control/IOVSvc/IOVSvc/CondSvc.h index 42fd7110c14cf1a00e73693545bb66339b224a2b..a7c9d610f793ed98260f300034568a3125b8f653 100644 --- a/Control/IOVSvc/IOVSvc/CondSvc.h +++ b/Control/IOVSvc/IOVSvc/CondSvc.h @@ -32,18 +32,17 @@ public: virtual StatusCode regHandle(IAlgorithm* alg, const Gaudi::DataHandle& id, const std::string& key); - virtual bool getInvalidIDs(const EventContext*, DataObjIDColl& ids); - virtual bool getValidIDs(const EventContext*, DataObjIDColl& ids); - virtual bool getIDValidity(const EventContext*, DataObjIDColl& validIDs, + virtual bool getInvalidIDs(const EventContext&, DataObjIDColl& ids); + virtual bool getValidIDs(const EventContext&, DataObjIDColl& ids); + virtual bool getIDValidity(const EventContext&, DataObjIDColl& validIDs, DataObjIDColl& invalidIDs); - - virtual std::set<std::string> getUnchangedAlgs( const DataObjIDColl& ); - - virtual StatusCode getRange(const std::string&, const EventContext*, EventIDRange&, - ICondSvc::dbData_t&) const; + virtual bool isValidID(const EventContext&, const DataObjID&) const; virtual const std::set<IAlgorithm*>& condAlgs() const { return m_condAlgs; } + virtual bool isRegistered(const DataObjID&) const; + virtual const DataObjIDColl& conditionIDs() const; + virtual void dump() const; virtual void dump(std::ostringstream&) const; @@ -67,15 +66,8 @@ private: }; - bool parse(EventIDRange& t, const std::string& s); - bool parse(IOVEntryT<ICondSvc::dbData_t>& t, const std::string& s); - - StatusCode readDbFile(const std::string&); - ServiceHandle<StoreGateSvc> m_sgs; - std::string m_file; - typedef std::set<IAlgorithm*, iAlgHasher> IAlgHashSet; typedef std::map<DataObjID, IAlgHashSet> id_map_t; typedef std::map<IAlgorithm*, DataObjIDColl, iAlgHasher> alg_map_t; @@ -85,8 +77,7 @@ private: std::map<std::string, DataObjID> m_keyMap; std::set<IAlgorithm*> m_condAlgs; - typedef std::map<std::string, std::vector<IOVEntryT<ICondSvc::dbData_t>>> registry_t; - registry_t m_registry; + DataObjIDColl m_condIDs; mutable std::recursive_mutex m_lock; diff --git a/Control/IOVSvc/src/CondSvc.cxx b/Control/IOVSvc/src/CondSvc.cxx index 6069ad73b7e8090536b4eae5b345841ad9b173d2..5b8854c048f6c63c31ee091e72820e1b3fcdcfaf 100644 --- a/Control/IOVSvc/src/CondSvc.cxx +++ b/Control/IOVSvc/src/CondSvc.cxx @@ -1,37 +1,16 @@ /* Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ - #include "IOVSvc/CondSvc.h" #include "AthenaKernel/CondCont.h" #include "GaudiKernel/SvcFactory.h" -#include <boost/tokenizer.hpp> -#include <boost/algorithm/string.hpp> -#include <boost/regex.hpp> - -#include <fstream> - -// DECLARE_COMPONENT(CondSvc) - -std::string r_t("\\[([0-9]+),([0-9]+)\\]"); -std::string r_r = "\\s*\\{" + r_t + "-" + r_t + "\\}\\s*"; -std::string r_e = "\\s*\\{" + r_t + "-" + r_t + "\\}=([0-9]+)\\s*"; -std::string r_ef = "\\s*\\{" + r_t + "-" + r_t + "\\}=(-*[0-9]*\\.*[0-9]*)\\s*"; -boost::regex rr(r_r); -boost::regex re(r_e); -boost::regex ref(r_ef); - - //--------------------------------------------------------------------------- CondSvc::CondSvc( const std::string& name, ISvcLocator* svcLoc ): base_class(name,svcLoc), m_sgs("StoreGateSvc/ConditionStore", name) { - - declareProperty("CondFile",m_file=""); - } //--------------------------------------------------------------------------- @@ -59,84 +38,11 @@ CondSvc::initialize() { return StatusCode::FAILURE; } - if (m_file == "") { - ATH_MSG_DEBUG("db file not set"); - return StatusCode::SUCCESS; - } - - if (readDbFile(m_file).isFailure()) { - return StatusCode::FAILURE; - } - - std::ostringstream ost; - ost << " Printing CondDB registry"; - for (auto e : m_registry) { - ost << std::endl << " - id: " << e.first << " r:"; - for (auto r : e.second) { - ost << " " << r.range() << " :: " << *r.objPtr(); - } - } - - ATH_MSG_DEBUG( ost.str() ); - return StatusCode::SUCCESS; } //--------------------------------------------------------------------------- -StatusCode -CondSvc::readDbFile(const std::string& fname) { - - StatusCode sc(StatusCode::SUCCESS); - - ATH_MSG_DEBUG("reading cond db from \"" << fname << "\""); - - std::ifstream ifs (fname); - std::string line; - if(ifs.is_open()) { - - typedef boost::tokenizer<boost::char_separator<char> > tokenizer; - boost::char_separator<char> sep(" "); - - IOVEntryT<ICondSvc::dbData_t> ie; - - while( getline (ifs, line) ) { - - // ignore anything after a "#" and blank lines - size_t fh = line.find("#"); - if(fh != std::string::npos) - line.erase(fh,line.length()-fh); - if (line.length() == 0) continue; - - tokenizer tokens(line, sep); - auto it = tokens.begin(); - - std::string dbKey = *it; - - ++it; - - while (it != tokens.end()) { - if (parse(ie,*it)) { - m_registry[dbKey].push_back( ie ); - } else { - error() << "while reading " << fname << " problem parsing " << *it - << " in line\n" << line << endmsg; - sc = StatusCode::FAILURE; - } - ++it; - } - } - ifs.close(); - } else { - error() << "unable to open file " << m_file << endmsg; - sc = StatusCode::FAILURE; - } - - return sc; - -} -//--------------------------------------------------------------------------- - void CondSvc::dump() const { @@ -201,14 +107,6 @@ CondSvc::finalize() { ATH_MSG_DEBUG( ost.str() ); } - for ( auto e : m_registry ) { - for ( auto ie : e.second ) { - delete ie.objPtr(); - ie.setPtr(0); - } - } - - return StatusCode::SUCCESS; } @@ -247,6 +145,8 @@ CondSvc::regHandle(IAlgorithm* alg, const Gaudi::DataHandle& dh, m_keyMap[key] = dh.fullKey(); m_condAlgs.insert(alg); + m_condIDs.emplace( dh.fullKey() ); + // id_map_t::iterator itd2 = m_idMap.find(dh.fullKey()); if (itd2 != m_idMap.end()) { itd2->second.insert( alg ); @@ -268,13 +168,13 @@ CondSvc::regHandle(IAlgorithm* alg, const Gaudi::DataHandle& dh, //--------------------------------------------------------------------------- bool -CondSvc::getInvalidIDs(const EventContext* ctx, DataObjIDColl& invalidIDs) { +CondSvc::getInvalidIDs(const EventContext& ctx, DataObjIDColl& invalidIDs) { std::lock_guard<std::recursive_mutex> lock(m_lock); - EventIDBase now(ctx->eventID().run_number(), ctx->eventID().event_number()); + EventIDBase now(ctx.eventID().run_number(), ctx.eventID().event_number()); std::ostringstream ost; - ost << "getInvalidIDS " << ctx->eventID() + ost << "getInvalidIDS " << ctx.eventID() << ": retrieving all ConstIterator<CondContBase>"; SG::ConstIterator<CondContBase> cib, cie; if (m_sgs->retrieve(cib,cie).isSuccess()) { @@ -304,14 +204,14 @@ CondSvc::getInvalidIDs(const EventContext* ctx, DataObjIDColl& invalidIDs) { //--------------------------------------------------------------------------- bool -CondSvc::getIDValidity(const EventContext* ctx, DataObjIDColl& validIDs, +CondSvc::getIDValidity(const EventContext& ctx, DataObjIDColl& validIDs, DataObjIDColl& invalidIDs) { std::lock_guard<std::recursive_mutex> lock(m_lock); - EventIDBase now(ctx->eventID()); + EventIDBase now(ctx.eventID()); std::ostringstream ost; - ost << "getValidIDS " << ctx->eventID() + ost << "getValidIDS " << ctx.eventID() << ": retrieving all ConstIterator<CondContBase>"; SG::ConstIterator<CondContBase> cib, cie; if (m_sgs->retrieve(cib,cie).isSuccess()) { @@ -344,13 +244,13 @@ CondSvc::getIDValidity(const EventContext* ctx, DataObjIDColl& validIDs, //--------------------------------------------------------------------------- bool -CondSvc::getValidIDs(const EventContext* ctx, DataObjIDColl& validIDs) { +CondSvc::getValidIDs(const EventContext& ctx, DataObjIDColl& validIDs) { std::lock_guard<std::recursive_mutex> lock(m_lock); - EventIDBase now(ctx->eventID()); + EventIDBase now(ctx.eventID()); std::ostringstream ost; - ost << "getValidIDS " << ctx->eventID() + ost << "getValidIDS " << ctx.eventID() << ": retrieving all ConstIterator<CondContBase>"; SG::ConstIterator<CondContBase> cib, cie; if (m_sgs->retrieve(cib,cie).isSuccess()) { @@ -379,118 +279,36 @@ CondSvc::getValidIDs(const EventContext* ctx, DataObjIDColl& validIDs) { //--------------------------------------------------------------------------- -std::set<std::string> -CondSvc::getUnchangedAlgs(const DataObjIDColl& ids) { +bool +CondSvc::isValidID(const EventContext& ctx, const DataObjID& id) const { std::lock_guard<std::recursive_mutex> lock(m_lock); - std::ostringstream ost; - ost << "getUnchangedAlgs():"; - - std::set<std::string> algs; - id_map_t::const_iterator itr; - - for (auto id : ids) { - ost << "\n id: " << id; - itr = m_idMap.find(id); - if (itr == m_idMap.end()) { - ost << " does not belong to any Alg!!! this shouldn't happen"; - } else { - ost << " belongs to"; - // loop over all Algs registered to this obj - for (auto alg : itr->second) { - ost << " " << alg->name(); - - // loop over all objs registered against this alg, make sure they - // are ALL unchanged - bool match = true; - alg_map_t::const_iterator itr2 = m_algMap.find(alg); - for (auto id2 : itr2->second) { - if ( ids.find(id2) == ids.end()) { - ost << " but has obj " << id2 << " that is not valid"; - match = false; - } - } - - if (match) { - algs.insert( alg->name() ); - } - } - } - // ost << std::endl; - } - - ATH_MSG_DEBUG( ost.str() ); - - return algs; -} - -//--------------------------------------------------------------------------- - -bool -CondSvc::parse(EventIDRange& t, const std::string& s) { - - boost::smatch m; - boost::regex_match(s,m,rr); - - // for (auto res : m) { - // cout << " - " << res << endl; - // } + EventIDBase now(ctx.eventID()); - if (m.size() != 5) { return false; } - - t = EventIDRange( EventIDBase(std::stoi(m[1]),std::stoi(m[2])), - EventIDBase(std::stoi(m[3]), std::stoi(m[4]))); + CondContBase *cib; + if (m_sgs->retrieve(cib, id.key()).isSuccess()) { + return cib->valid(now); + } - return true; + return false; } //--------------------------------------------------------------------------- bool -CondSvc::parse(IOVEntryT<ICondSvc::dbData_t>& ie, const std::string& s) { - - boost::smatch m; - boost::regex_match(s,m,ref); - - if (m.size() != 6) { return false; } +CondSvc::isRegistered(const DataObjID& id) const { - ie.setRange( EventIDRange( EventIDBase(std::stoi(m[1]), std::stoi(m[2])), - EventIDBase(std::stoi(m[3]), std::stoi(m[4])) ) ); - - ICondSvc::dbData_t *v = new ICondSvc::dbData_t( std::stof(m[5]) ); - ie.setPtr(v); - - return true; + return (m_condIDs.find(id) != m_condIDs.end()); } //--------------------------------------------------------------------------- -StatusCode -CondSvc::getRange(const std::string& dbKey , const EventContext* ctx, - EventIDRange& rng, ICondSvc::dbData_t& val) const { +const DataObjIDColl& +CondSvc::conditionIDs() const { - std::lock_guard<std::recursive_mutex> lock(m_lock); + return m_condIDs; - registry_t::const_iterator itr = m_registry.find(dbKey); - - if (itr == m_registry.end()) { - error() << "getRange: no dbKey " << dbKey << " found in registry" - << endmsg; - return StatusCode::FAILURE; - } - - for (auto e : itr->second) { - if (e.range().isInRange(EventIDBase(ctx->eventID()))) { - rng = e.range(); - val = *(e.objPtr()); - return StatusCode::SUCCESS; - } - } - - error() << "getRange: no range for Time " << ctx->eventID() - << " found for dbKey " << dbKey << endmsg; - - return StatusCode::FAILURE; } + diff --git a/Projects/Athena/externals.txt b/Projects/Athena/externals.txt index b297974cf2f946a86c1cc9d130664636a72f3854..585ee8bc328f95f72785bb551a91b32f1009085a 100644 --- a/Projects/Athena/externals.txt +++ b/Projects/Athena/externals.txt @@ -6,4 +6,4 @@ # forbidden. AthenaExternalsVersion = 1.0.2 -GaudiVersion = v28r1.conditions.004 +GaudiVersion = v28r1.conditions.005