14 #include "boost/shared_ptr.hpp"
42 buildName( std::string
const & iRecordName ) {
43 return iRecordName + std::string(
"@NewProxy" );
46 std::string joinRecordAndLabel( std::string
const & iRecordName, std::string
const & iLabelName ) {
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};
138 std::string userconnect= iConfig.
getParameter<std::string>(
"connect");
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 ) {
154 nm.
recordname = itToGet->getParameter<std::string>(
"record" );
155 nm.
labelname = itToGet->getUntrackedParameter<std::string>(
"label",
"" );
156 nm.
tag = itToGet->getParameter<std::string>(
"tag" );
157 nm.
pfn = itToGet->getUntrackedParameter<std::string>(
"connect", userconnect );
160 replacement.insert( std::pair<std::string,cond::TagMetadata>( recordLabelKey, nm ) );
166 if( iConfig.
exists(
"globaltag" ) )
167 globaltag = iConfig.
getParameter<std::string>(
"globaltag" );
176 TagCollection::iterator it;
180 std::map<std::string, cond::DbSession> sessions;
190 std::vector<cond::DataProxyWrapperBase *> proxyWrappers(
m_tagCollection.size());
192 for(it=itBeg;it!=itEnd;++it){
193 proxyWrappers[ipb++] =
199 for(it=itBeg;it!=itEnd;++it){
200 std::map<std::string, cond::DbSession>::iterator p = sessions.find( it->second.pfn );
202 if (p==sessions.end()) {
206 sessions.insert(std::make_pair(it->second.pfn,nsess));
207 }
else nsess = (*p).second;
212 ProxyP proxy(proxyWrappers[ipb++]);
214 m_proxies.insert(std::make_pair(it->second.recordname, proxy));
219 proxy->lateInit(nsess,it->second.tag,
220 it->second.labelname, it->second.pfn);
225 CondGetterFromESSource visitor(
m_proxies );
228 for ( ;b !=
e; b++ ) {
230 (*b).second->proxy()->loadMore( visitor );
248 std::cout <<
"CondDBESSource Statistics" << std::endl
258 std::cout <<
"Global Proxy Statistics" << std::endl
267 for ( ;b !=
e; b++ ) {
268 dumpInfo(
std::cout, (*b).first, *(*b).second );
285 std::string recordname=iKey.
name();
287 edm::LogInfo(
"CondDBESSource" ) <<
"Getting data for record \""<< recordname
288 <<
"\" to be consumed by "<< iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
289 <<
"; from CondDBESSource::setIntervalFor";
304 bool doRefresh =
false;
307 std::map<std::string,unsigned int>::iterator iRec =
m_lastRecordRuns.find( recordname );
309 unsigned int lastRecordRun = iRec->second;
314 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
315 <<
"\" since there has been a transition from run "
316 << lastRecordRun <<
" to run " <<
m_lastRun
317 <<
"; from CondDBESSource::setIntervalFor";
322 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
324 <<
"; from CondDBESSource::setIntervalFor";
327 edm::LogInfo(
"CondDBESSource" ) <<
"Though enabled, refresh not needed for record \"" << recordname
329 <<
"; from CondDBESSource::setIntervalFor";
332 edm::LogInfo(
"CondDBESSource" ) <<
"Forcing refresh for record \"" << recordname
334 <<
"; from CondDBESSource::setIntervalFor";
345 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
346 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
347 if ( pmBegin == pmEnd ) {
348 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
349 <<
"\"; from CondDBESSource::setIntervalFor";
353 for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
355 edm::LogInfo(
"CondDBESSource" ) <<
"Processing record \"" << recordname
356 <<
"\" and label \""<< pmIter->second->label()
358 <<
"; from CondDBESSource::setIntervalFor";
360 timetype = (*pmIter).second->proxy()->timetype();
363 userTime = ( 0 == abtime );
367 if (userTime)
return;
373 std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
376 edm::LogInfo(
"CondDBESSource" ) <<
"No Tag found for record \""<< recordname
377 <<
"\" and label \""<< pmIter->second->label()
378 <<
"\"; from CondDBESSource::setIntervalFor";
384 edm::LogInfo(
"CondDBESSource" ) <<
"Checking if the session must be closed and re-opened for getting correct conditions"
385 <<
"; from CondDBESSource::setIntervalFor";
386 std::stringstream transId;
389 std::map<std::string,std::pair<cond::DbSession,std::string> >::iterator iSess =
m_sessionPool.find( tcIter->second.pfn );
393 if( iSess->second.second != transId.str() ) {
396 iSess->second.second = transId.str();
398 theSession = iSess->second.first;
402 m_sessionPool.insert(std::make_pair( tcIter->second.pfn,std::make_pair(theSession,transId.str()) ));
406 theSession.
openReadOnly( tcIter->second.pfn, transId.str() );
407 edm::LogInfo(
"CondDBESSource" ) <<
"Re-opening the session with connection string " << tcIter->second.pfn
408 <<
" and new transaction Id " << transId.str()
409 <<
"; from CondDBESSource::setIntervalFor";
412 edm::LogInfo(
"CondDBESSource" ) <<
"Reconnecting to \"" << tcIter->second.pfn
413 <<
"\" for getting new payload for record \"" << recordname
414 <<
"\" and label \""<< pmIter->second->label()
415 <<
"\" from IOV tag \"" << tcIter->second.tag
416 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
417 <<
"; from CondDBESSource::setIntervalFor";
418 bool isSizeIncreased = pmIter->second->proxy()->refresh( theSession );
419 if( isSizeIncreased )
420 edm::LogInfo(
"CondDBESSource" ) <<
"After reconnecting, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
421 <<
"\" was found; from CondDBESSource::setIntervalFor";
425 edm::LogInfo(
"CondDBESSource" ) <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tag
426 <<
"\" for getting new payload for record \"" << recordname
427 <<
"\" and label \""<< pmIter->second->label()
428 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
429 <<
"; from CondDBESSource::setIntervalFor";
430 bool isSizeIncreased = pmIter->second->proxy()->refresh();
431 if( isSizeIncreased )
432 edm::LogInfo(
"CondDBESSource" ) <<
"After refreshing, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
433 <<
"\" was found; from CondDBESSource::setIntervalFor";
452 edm::LogInfo(
"CondDBESSource" ) <<
"Validity coming from IOV sequence for record \"" << recordname
453 <<
"\" and label \""<< pmIter->second->label()
454 <<
"\": (" << validity.first <<
", " << validity.second
456 <<
"; from CondDBESSource::setIntervalFor";
458 recordValidity.first =
std::max(recordValidity.first,validity.first);
459 recordValidity.second =
std::min(recordValidity.second,validity.second);
464 edm::LogInfo(
"CondDBESSource" ) <<
"Validity for record \"" << recordname
465 <<
"\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
466 <<
", "<< recordValidity.first
467 <<
") as the last IOV element in the IOV sequence is infinity"
468 <<
"; from CondDBESSource::setIntervalFor";
473 if ( (!userTime) && recordValidity.second !=0 ) {
481 edm::LogInfo(
"CondDBESSource" ) <<
"Setting validity for record \"" << recordname
482 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID() <<
", timestamp: " << oInterval.
first().
time().
value()
485 <<
"; from CondDBESSource::setIntervalFor";
492 std::string recordname=iRecordKey.
name();
494 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
495 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
497 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
498 <<
"\"; from CondDBESSource::registerProxies";
502 for (ProxyMap::const_iterator p=b;p!=
e;++
p) {
503 if(0 != (*p).second.get()) {
524 const std::string &
prefix,
525 const std::string & postfix,
526 const std::string & roottag,
527 std::map<std::string,cond::TagMetadata>& replacement ) {
529 std::set< cond::TagMetadata > tagcoll;
531 if ( !roottag.empty() ) {
532 if ( coraldb.empty() )
533 throw cond::Exception( std::string(
"ESSource: requested global tag ") + roottag + std::string(
" but not connection string given" ) );
542 std::set<cond::TagMetadata>::iterator tagCollIter;
543 std::set<cond::TagMetadata>::iterator tagCollBegin = tagcoll.begin();
544 std::set<cond::TagMetadata>::iterator tagCollEnd = tagcoll.end();
547 for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
548 std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordname, tagCollIter->labelname );
549 std::map<std::string,cond::TagMetadata>::iterator
fid = replacement.find( recordLabelKey );
550 if( fid != replacement.end() ) {
552 tagMetadata.
recordname = tagCollIter->recordname;
553 tagMetadata.
labelname = tagCollIter->labelname;
554 tagMetadata.
pfn = fid->second.pfn;
555 tagMetadata.
tag = fid->second.tag;
556 tagMetadata.
objectname = tagCollIter->objectname;
557 m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
558 replacement.erase( fid );
559 edm::LogInfo(
"CondDBESSource" ) <<
"Replacing connection string \"" << tagCollIter->pfn
560 <<
"\" and tag \"" << tagCollIter->tag
561 <<
"\" for record \"" << tagMetadata.
recordname
562 <<
"\" and label \"" << tagMetadata.
labelname
563 <<
"\" with connection string \"" << tagMetadata.
pfn
564 <<
"\" and tag " << tagMetadata.
tag
565 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
567 m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
570 std::map<std::string,cond::TagMetadata>::iterator replacementIter;
571 std::map<std::string,cond::TagMetadata>::iterator replacementBegin = replacement.begin();
572 std::map<std::string,cond::TagMetadata>::iterator replacementEnd = replacement.end();
573 for( replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter ){
const TimeTypeSpecs timeTypeSpecs[]
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::IOVSyncValue limitedIOVSyncValue(cond::Time_t time, cond::TimeType timetype)
const EventID & eventID() const
DbTransaction & transaction()
void open(const std::string &connectionString, bool readOnly=false)
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)
void fillTagCollectionFromDB(const std::string &coraldb, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::map< std::string, cond::TagMetadata > &replacement)
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 &)
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