14 #include "boost/shared_ptr.hpp"
15 #include <boost/algorithm/string.hpp>
47 return iRecordName +
std::string(
"@" ) + iLabelName;
59 virtual ~CondGetterFromESSource(){}
62 CondDBESSource::ProxyMap::const_iterator
p = m_proxies.find(
name);
63 if ( p != m_proxies.end())
64 return (*p).second->proxy()->iov();
74 out << recName <<
" / " << proxy.
label() <<
": "
76 <<
state.size() <<
", " <<
state.revision() <<
", "
80 <<
"refresh " << proxy.
proxy()->stats.nRefresh
81 <<
"/" << proxy.
proxy()->stats.nArefresh
82 <<
", reconnect " << proxy.
proxy()->stats.nReconnect
83 <<
"/" << proxy.
proxy()->stats.nAreconnect
84 <<
", make " << proxy.
proxy()->stats.nMake
85 <<
", load " << proxy.
proxy()->stats.nLoad
87 if ( proxy.
proxy()->stats.nLoad>0) {
88 out <<
"\n oids,sinces:";
90 for (cond::BasePayloadProxy::ObjIds::const_iterator
id=ids.begin();
id!=ids.end(); ++id)
93 << (*id).oid1 <<
"-"<< (*id).oid2 <<
","
114 m_policy( NOREFRESH ),
115 m_doDump( iConfig.getUntrackedParameter<bool>(
"DumpStat",
false ) )
130 Stats s = {0,0,0,0,0,0,0,0};
148 std::map<std::string,cond::TagMetadata> replacement;
149 if( iConfig.
exists(
"toGet" ) ) {
150 typedef std::vector< edm::ParameterSet >
Parameters;
152 for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
157 nm.
pfn = itToGet->getUntrackedParameter<
std::string>(
"connect", userconnect );
160 replacement.insert( std::pair<std::string,cond::TagMetadata>( recordLabelKey, nm ) );
165 std::vector<std::string> globaltagList;
166 std::vector<std::string> connectList;
167 std::vector<std::string> pfnPrefixList;
168 std::vector<std::string> pfnPostfixList;
169 if( iConfig.
exists(
"globaltag" ) ) {
173 boost::split( globaltagList, globaltag, boost::is_any_of(
"|"), boost::token_compress_off );
174 fillList(userconnect, connectList, globaltagList.size(),
"connection");
175 fillList(pfnPrefix, pfnPrefixList, globaltagList.size(),
"pfnPrefix");
176 fillList(pfnPostfix, pfnPostfixList, globaltagList.size(),
"pfnPostfix");
185 TagCollection::iterator it;
189 std::map<std::string, cond::DbSession> sessions;
199 std::vector<cond::DataProxyWrapperBase *> proxyWrappers(
m_tagCollection.size());
201 for(it=itBeg;it!=itEnd;++it){
202 proxyWrappers[ipb++] =
208 for(it=itBeg;it!=itEnd;++it){
209 std::map<std::string, cond::DbSession>::iterator p = sessions.find( it->second.pfn );
211 if (p==sessions.end()) {
215 sessions.insert(std::make_pair(it->second.pfn,nsess));
216 }
else nsess = (*p).second;
221 ProxyP proxy(proxyWrappers[ipb++]);
223 m_proxies.insert(std::make_pair(it->second.recordname, proxy));
228 proxy->lateInit(nsess,it->second.tag,
229 it->second.labelname, it->second.pfn);
234 CondGetterFromESSource visitor(
m_proxies );
237 for ( ;b !=
e; b++ ) {
239 (*b).second->proxy()->loadMore( visitor );
255 boost::split( listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off );
257 if( listToFill.size() == 1 ) {
258 for(
unsigned int i=1;
i<listSize; ++
i ) {
259 listToFill.push_back(stringList);
263 else if( listSize != listToFill.size() ) {
264 throw cond::Exception(
std::string(
"ESSource: number of global tag components does not match number of "+type+
" strings" ) );
271 std::cout <<
"CondDBESSource Statistics" << std::endl
281 std::cout <<
"Global Proxy Statistics" << std::endl
290 for ( ;b !=
e; b++ ) {
291 dumpInfo(
std::cout, (*b).first, *(*b).second );
310 edm::LogInfo(
"CondDBESSource" ) <<
"Getting data for record \""<< recordname
311 <<
"\" to be consumed by "<< iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
312 <<
"; from CondDBESSource::setIntervalFor";
327 bool doRefresh =
false;
330 std::map<std::string,unsigned int>::iterator iRec =
m_lastRecordRuns.find( recordname );
332 unsigned int lastRecordRun = iRec->second;
337 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
338 <<
"\" since there has been a transition from run "
339 << lastRecordRun <<
" to run " <<
m_lastRun
340 <<
"; from CondDBESSource::setIntervalFor";
345 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
347 <<
"; from CondDBESSource::setIntervalFor";
350 edm::LogInfo(
"CondDBESSource" ) <<
"Though enabled, refresh not needed for record \"" << recordname
352 <<
"; from CondDBESSource::setIntervalFor";
355 edm::LogInfo(
"CondDBESSource" ) <<
"Forcing refresh for record \"" << recordname
357 <<
"; from CondDBESSource::setIntervalFor";
368 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
369 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
370 if ( pmBegin == pmEnd ) {
371 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
372 <<
"\"; from CondDBESSource::setIntervalFor";
376 for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
378 edm::LogInfo(
"CondDBESSource" ) <<
"Processing record \"" << recordname
379 <<
"\" and label \""<< pmIter->second->label()
381 <<
"; from CondDBESSource::setIntervalFor";
383 timetype = (*pmIter).second->proxy()->timetype();
386 userTime = ( 0 == abtime );
390 if (userTime)
return;
396 std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
399 edm::LogInfo(
"CondDBESSource" ) <<
"No Tag found for record \""<< recordname
400 <<
"\" and label \""<< pmIter->second->label()
401 <<
"\"; from CondDBESSource::setIntervalFor";
407 edm::LogInfo(
"CondDBESSource" ) <<
"Checking if the session must be closed and re-opened for getting correct conditions"
408 <<
"; from CondDBESSource::setIntervalFor";
409 std::stringstream transId;
412 std::map<std::string,std::pair<cond::DbSession,std::string> >::iterator iSess =
m_sessionPool.find( tcIter->second.pfn );
416 if( iSess->second.second != transId.str() ) {
419 iSess->second.second = transId.str();
421 theSession = iSess->second.first;
425 m_sessionPool.insert(std::make_pair( tcIter->second.pfn,std::make_pair(theSession,transId.str()) ));
429 theSession.
openReadOnly( tcIter->second.pfn, transId.str() );
430 edm::LogInfo(
"CondDBESSource" ) <<
"Re-opening the session with connection string " << tcIter->second.pfn
431 <<
" and new transaction Id " << transId.str()
432 <<
"; from CondDBESSource::setIntervalFor";
435 edm::LogInfo(
"CondDBESSource" ) <<
"Reconnecting to \"" << tcIter->second.pfn
436 <<
"\" for getting new payload for record \"" << recordname
437 <<
"\" and label \""<< pmIter->second->label()
438 <<
"\" from IOV tag \"" << tcIter->second.tag
439 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
440 <<
"; from CondDBESSource::setIntervalFor";
441 bool isSizeIncreased = pmIter->second->proxy()->refresh( theSession );
442 if( isSizeIncreased )
443 edm::LogInfo(
"CondDBESSource" ) <<
"After reconnecting, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
444 <<
"\" was found; from CondDBESSource::setIntervalFor";
448 edm::LogInfo(
"CondDBESSource" ) <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tag
449 <<
"\" for getting new payload for record \"" << recordname
450 <<
"\" and label \""<< pmIter->second->label()
451 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
452 <<
"; from CondDBESSource::setIntervalFor";
453 bool isSizeIncreased = pmIter->second->proxy()->refresh();
454 if( isSizeIncreased )
455 edm::LogInfo(
"CondDBESSource" ) <<
"After refreshing, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
456 <<
"\" was found; from CondDBESSource::setIntervalFor";
475 edm::LogInfo(
"CondDBESSource" ) <<
"Validity coming from IOV sequence for record \"" << recordname
476 <<
"\" and label \""<< pmIter->second->label()
477 <<
"\": (" << validity.first <<
", " << validity.second
479 <<
"; from CondDBESSource::setIntervalFor";
481 recordValidity.first =
std::max(recordValidity.first,validity.first);
482 recordValidity.second =
std::min(recordValidity.second,validity.second);
487 edm::LogInfo(
"CondDBESSource" ) <<
"Validity for record \"" << recordname
488 <<
"\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
489 <<
", "<< recordValidity.first
490 <<
") as the last IOV element in the IOV sequence is infinity"
491 <<
"; from CondDBESSource::setIntervalFor";
496 if ( (!userTime) && recordValidity.second !=0 ) {
504 edm::LogInfo(
"CondDBESSource" ) <<
"Setting validity for record \"" << recordname
505 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID() <<
", timestamp: " << oInterval.
first().
time().
value()
508 <<
"; from CondDBESSource::setIntervalFor";
517 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
518 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
520 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
521 <<
"\"; from CondDBESSource::registerProxies";
525 for (ProxyMap::const_iterator p=b;p!=
e;++
p) {
526 if(0 != (*p).second.get()) {
549 std::set< cond::TagMetadata > & tagcoll )
555 if ( !roottag.empty() ) {
556 if ( coraldb.empty() )
570 const std::vector<std::string> & prefixList,
571 const std::vector<std::string> & postfixList,
572 const std::vector<std::string> & roottagList,
573 std::map<std::string,cond::TagMetadata>& replacement )
575 std::set< cond::TagMetadata > tagcoll;
577 auto coraldb = coraldbList.begin();
578 auto prefix = prefixList.begin();
579 auto postfix = postfixList.begin();
580 for(
auto roottag = roottagList.begin(); roottag != roottagList.end(); ++roottag, ++coraldb, ++
prefix, ++postfix) {
584 std::set<cond::TagMetadata>::iterator tagCollIter;
585 std::set<cond::TagMetadata>::iterator tagCollBegin = tagcoll.begin();
586 std::set<cond::TagMetadata>::iterator tagCollEnd = tagcoll.end();
589 for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
590 std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordname, tagCollIter->labelname );
591 std::map<std::string,cond::TagMetadata>::iterator
fid = replacement.find( recordLabelKey );
592 if( fid != replacement.end() ) {
594 tagMetadata.
recordname = tagCollIter->recordname;
595 tagMetadata.
labelname = tagCollIter->labelname;
596 tagMetadata.
pfn = fid->second.pfn;
597 tagMetadata.
tag = fid->second.tag;
598 tagMetadata.
objectname = tagCollIter->objectname;
599 m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
600 replacement.erase( fid );
601 edm::LogInfo(
"CondDBESSource" ) <<
"Replacing connection string \"" << tagCollIter->pfn
602 <<
"\" and tag \"" << tagCollIter->tag
603 <<
"\" for record \"" << tagMetadata.
recordname
604 <<
"\" and label \"" << tagMetadata.
labelname
605 <<
"\" with connection string \"" << tagMetadata.
pfn
606 <<
"\" and tag " << tagMetadata.
tag
607 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
609 m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
612 std::map<std::string,cond::TagMetadata>::iterator replacementIter;
613 std::map<std::string,cond::TagMetadata>::iterator replacementBegin = replacement.begin();
614 std::map<std::string,cond::TagMetadata>::iterator replacementEnd = replacement.end();
615 for( replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter ){
const TimeTypeSpecs timeTypeSpecs[]
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
tuple start
Check for commandline option errors.
edm::IOVSyncValue limitedIOVSyncValue(cond::Time_t time, cond::TimeType timetype)
void fillTagCollectionFromGT(const std::string &coraldb, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::set< cond::TagMetadata > &tagcoll)
const EventID & eventID() const
DbTransaction & transaction()
void open(const std::string &connectionString, bool readOnly=false)
void fillTagCollectionFromDB(const std::vector< std::string > &coraldbList, const std::vector< std::string > &prefix, const std::vector< std::string > &postfix, const std::vector< std::string > &roottagList, std::map< std::string, cond::TagMetadata > &replacement)
std::map< std::string, std::pair< cond::DbSession, std::string > > m_sessionPool
virtual void registerProxies(const edm::eventsetup::EventSetupRecordKey &iRecordKey, KeyedProxies &aProxyList)
void getTagCollection(const std::string &globaltag, std::set< cond::TagMetadata > &result)
int commit()
commit transaction.
void openReadOnly(const std::string &connectionString, const std::string &id)
DbConnectionConfiguration & configuration()
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::pair< Time_t, Time_t > ValidityInterval
void usingRecordWithKey(const EventSetupRecordKey &)
virtual ProxyP proxy() const =0
cond::DbConnection m_connection
void setParameters(const edm::ParameterSet &connectionPset)
const IOVSyncValue & last() const
std::string const & timeTypeNames(int)
int start(bool readOnly=false)
start transaction
std::string const & label() const
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, cond::TimeType timetype, bool startOrStop)
unsigned long long Time_t
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
vector< ParameterSet > Parameters
const T & max(const T &a, const T &b)
std::map< std::string, unsigned int > m_lastRecordRuns
std::vector< std::pair< DataKey, boost::shared_ptr< DataProxy > > > KeyedProxies
const char * name() const
LuminosityBlockNumber_t luminosityBlockNumber() const
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
Container::value_type value_type
static const std::string COND_READER_ROLE
std::vector< ObjId > ObjIds
std::multimap< std::string, ProxyP > ProxyMap
std::string const & connString() const
TimeValue_t value() const
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
PoolDBESSource(const edm::ParameterSet &ps)
TagCollection m_tagCollection
DbSession createSession() const
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
std::string const & tag() const
heterocontainer::HCTypeTag TypeTag
const TypeTag & type() const
static const ValidityInterval & invalidInterval()
const Timestamp & time() const
virtual void newInterval(const edm::eventsetup::EventSetupRecordKey &iRecordType, const edm::ValidityInterval &iInterval)
called when a new interval of validity occurs for iRecordType
cond::Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, cond::TimeType timetype)
const IOVSyncValue & first() const
CondDBESSource(const edm::ParameterSet &)
boost::shared_ptr< cond::DataProxyWrapperBase > ProxyP
boost::posix_time::ptime to_boost(Time_t iValue)
T get(const Candidate &c)
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag