15 #include "boost/shared_ptr.hpp"
16 #include <boost/algorithm/string.hpp>
41 return iRecordName +
std::string(
"@" ) + iLabelName;
53 virtual ~CondGetterFromESSource(){}
56 CondDBESSource::ProxyMap::const_iterator
p = m_proxies.find(
name);
57 if ( p != m_proxies.end())
58 return (*p).second->proxy()->iov();
69 out << recName <<
" / " << proxy.
label() <<
": "
83 out <<
"Time look up, payloadIds:" <<std::endl;
84 const auto& pids = proxy.
proxy()->requests();
86 out <<
" "<<
id.since <<
" - "<<
id.till <<
" : "<<
id.payloadId<<std::endl;
102 m_connectionString(
""),
105 m_policy( NOREFRESH ),
106 m_doDump( iConfig.getUntrackedParameter<bool>(
"DumpStat",
false ) )
121 Stats s = {0,0,0,0,0,0,0,0};
137 std::map<std::string,cond::GTEntry_t> replacements;
138 if( iConfig.
exists(
"toGet" ) ) {
139 typedef std::vector< edm::ParameterSet >
Parameters;
141 for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
146 std::string recordLabelKey = joinRecordAndLabel( recordname, labelname );
148 replacements.insert( std::make_pair( recordLabelKey,
cond::GTEntry_t( std::make_tuple(recordname, labelname, fullyQualifiedTag ) ) ) );
153 std::vector<std::string> globaltagList;
154 std::vector<std::string> connectList;
155 std::vector<std::string> pfnPrefixList;
156 std::vector<std::string> pfnPostfixList;
157 if( iConfig.
exists(
"globaltag" ) ) {
161 boost::split( globaltagList, globaltag, boost::is_any_of(
"|"), boost::token_compress_off );
163 fillList(pfnPrefix, pfnPrefixList, globaltagList.size(),
"pfnPrefix");
164 fillList(pfnPostfix, pfnPostfixList, globaltagList.size(),
"pfnPostfix");
173 TagCollection::iterator it;
177 std::map<std::string, cond::persistency::Session> sessions;
187 std::vector<cond::DataProxyWrapperBase *> proxyWrappers(
m_tagCollection.size());
189 for(it=itBeg;it!=itEnd;++it){
190 proxyWrappers[ipb++] =
197 for(it=itBeg;it!=itEnd;++it){
201 if( !tagParams.second.empty() ) {
202 connStr = tagParams.second;
203 tag = tagParams.first;
205 std::map<std::string, cond::persistency::Session>::iterator p = sessions.find( connStr );
207 if (p == sessions.end()) {
210 sessions.insert(std::make_pair( connStr, nsess));
211 }
else nsess = (*p).second;
214 ProxyP proxy(proxyWrappers[ipb++]);
216 m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
218 proxy->lateInit(nsess, tag, it->second.recordLabel(), connStr);
222 CondGetterFromESSource visitor(
m_proxies );
225 for ( ;b !=
e; b++ ) {
227 (*b).second->proxy()->loadMore( visitor );
243 boost::split( listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off );
245 if( listToFill.size() == 1 ) {
246 for(
unsigned int i=1;
i<listSize; ++
i ) {
247 listToFill.push_back(stringList);
251 else if( listSize != listToFill.size() ) {
252 throw cond::Exception(
std::string(
"ESSource: number of global tag components does not match number of "+type+
" strings" ) );
259 std::cout <<
"CondDBESSource Statistics" << std::endl
273 for ( ;b !=
e; b++ ) {
274 dumpInfo(
std::cout, (*b).first, *(*b).second );
293 edm::LogInfo(
"CondDBESSource" ) <<
"Getting data for record \""<< recordname
294 <<
"\" to be consumed by "<< iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
295 <<
"; from CondDBESSource::setIntervalFor";
310 bool doRefresh =
false;
313 std::map<std::string,unsigned int>::iterator iRec =
m_lastRecordRuns.find( recordname );
315 unsigned int lastRecordRun = iRec->second;
320 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
321 <<
"\" since there has been a transition from run "
322 << lastRecordRun <<
" to run " <<
m_lastRun
323 <<
"; from CondDBESSource::setIntervalFor";
328 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
330 <<
"; from CondDBESSource::setIntervalFor";
333 edm::LogInfo(
"CondDBESSource" ) <<
"Though enabled, refresh not needed for record \"" << recordname
335 <<
"; from CondDBESSource::setIntervalFor";
338 edm::LogInfo(
"CondDBESSource" ) <<
"Forcing refresh for record \"" << recordname
340 <<
"; from CondDBESSource::setIntervalFor";
351 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
352 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
353 if ( pmBegin == pmEnd ) {
354 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
355 <<
"\"; from CondDBESSource::setIntervalFor";
359 for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
361 edm::LogInfo(
"CondDBESSource" ) <<
"Processing record \"" << recordname
362 <<
"\" and label \""<< pmIter->second->label()
364 <<
"; from CondDBESSource::setIntervalFor";
366 timetype = (*pmIter).second->proxy()->timeType();
369 userTime = ( 0 == abtime );
373 if (userTime)
return;
379 std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
382 edm::LogInfo(
"CondDBESSource" ) <<
"No Tag found for record \""<< recordname
383 <<
"\" and label \""<< pmIter->second->label()
384 <<
"\"; from CondDBESSource::setIntervalFor";
390 edm::LogInfo(
"CondDBESSource" ) <<
"Checking if the session must be closed and re-opened for getting correct conditions"
391 <<
"; from CondDBESSource::setIntervalFor";
392 std::stringstream transId;
397 if( !tagParams.second.empty() ) connStr = tagParams.second;
401 if( iSess->second.second != transId.str() ) {
404 iSess->second.second = transId.str();
413 edm::LogInfo(
"CondDBESSource" ) <<
"Re-opening the session with connection string " << connStr
414 <<
" and new transaction Id " << transId.str()
415 <<
"; from CondDBESSource::setIntervalFor";
418 edm::LogInfo(
"CondDBESSource" ) <<
"Reconnecting to \"" << connStr
419 <<
"\" for getting new payload for record \"" << recordname
420 <<
"\" and label \""<< pmIter->second->label()
421 <<
"\" from IOV tag \"" << tcIter->second.tagName()
422 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
423 <<
"; from CondDBESSource::setIntervalFor";
424 pmIter->second->proxy()->setUp( iSess->second.first );
425 pmIter->second->proxy()->reload();
432 edm::LogInfo(
"CondDBESSource" ) <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
433 <<
"\" for getting new payload for record \"" << recordname
434 <<
"\" and label \""<< pmIter->second->label()
435 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
436 <<
"; from CondDBESSource::setIntervalFor";
437 pmIter->second->proxy()->reload();
459 edm::LogInfo(
"CondDBESSource" ) <<
"Validity coming from IOV sequence for record \"" << recordname
460 <<
"\" and label \""<< pmIter->second->label()
461 <<
"\": (" << validity.first <<
", " << validity.second
463 <<
"; from CondDBESSource::setIntervalFor";
465 recordValidity.first =
std::max(recordValidity.first,validity.first);
466 recordValidity.second =
std::min(recordValidity.second,validity.second);
471 edm::LogInfo(
"CondDBESSource" ) <<
"Validity for record \"" << recordname
472 <<
"\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
473 <<
", "<< recordValidity.first
474 <<
") as the last IOV element in the IOV sequence is infinity"
475 <<
"; from CondDBESSource::setIntervalFor";
480 if ( (!userTime) && recordValidity.second !=0 ) {
488 edm::LogInfo(
"CondDBESSource" ) <<
"Setting validity for record \"" << recordname
489 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID() <<
", timestamp: " << oInterval.
first().
time().
value()
492 <<
"; from CondDBESSource::setIntervalFor";
501 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
502 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
504 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
505 <<
"\"; from CondDBESSource::registerProxies";
509 for (ProxyMap::const_iterator p=b;p!=
e;++
p) {
510 if(0 != (*p).second.get()) {
533 std::set< cond::GTEntry_t > & tagcoll )
535 if ( !roottag.empty() ) {
536 if ( connectionString.empty() )
541 for(
const auto& gte : gtp ){
542 tagcoll.insert( gte );
551 const std::vector<std::string> & prefixList,
552 const std::vector<std::string> & postfixList,
553 const std::vector<std::string> & roottagList,
554 std::map<std::string,cond::GTEntry_t>& replacement )
556 std::set< cond::GTEntry_t > tagcoll;
558 auto connectionString = connectionStringList.begin();
559 auto prefix = prefixList.begin();
560 auto postfix = postfixList.begin();
561 for(
auto roottag = roottagList.begin(); roottag != roottagList.end(); ++roottag, ++connectionString, ++
prefix, ++postfix) {
565 std::set<cond::GTEntry_t>::iterator tagCollIter;
566 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
567 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
570 for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
571 std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordName(), tagCollIter->recordLabel() );
572 std::map<std::string,cond::GTEntry_t>::iterator
fid = replacement.find( recordLabelKey );
573 if( fid != replacement.end() ) {
574 cond::GTEntry_t tagMetadata( std::make_tuple( tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName() ) );
575 m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
576 replacement.erase( fid );
577 edm::LogInfo(
"CondDBESSource" ) <<
"Replacing tag \"" << tagCollIter->tagName()
578 <<
"\" for record \"" << tagMetadata.
recordName()
580 <<
"\" with tag " << tagMetadata.
tagName()
581 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
583 m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
586 std::map<std::string,cond::GTEntry_t>::iterator replacementIter;
587 std::map<std::string,cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
588 std::map<std::string,cond::GTEntry_t>::iterator replacementEnd = replacement.end();
589 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.
const EventID & eventID() const
virtual void registerProxies(const edm::eventsetup::EventSetupRecordKey &iRecordKey, KeyedProxies &aProxyList)
void start(bool readOnly=true)
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
Transaction & transaction()
void setParameters(const edm::ParameterSet &connectionPset)
const IOVSyncValue & last() const
void fillTagCollectionFromGT(const std::string &connectionString, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::set< cond::GTEntry_t > &tagcoll)
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
std::string const & timeTypeNames(int)
std::string const & label() const
unsigned long long Time_t
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
vector< ParameterSet > Parameters
std::pair< std::string, std::string > parseTag(const std::string &tag)
const T & max(const T &a, const T &b)
std::map< std::string, unsigned int > m_lastRecordRuns
Session createSession(const std::string &connectionString, bool writeCapable=false, BackendType backType=DEFAULT_DB)
std::vector< std::pair< DataKey, boost::shared_ptr< DataProxy > > > KeyedProxies
cond::persistency::ConnectionPool m_connection
const char * name() const
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, TimeType timetype, bool startOrStop)
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
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
const std::string & recordLabel() const
std::multimap< std::string, ProxyP > ProxyMap
std::string const & connString() const
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
PoolDBESSource(const edm::ParameterSet &ps)
TagCollection m_tagCollection
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
std::string const & tag() const
heterocontainer::HCTypeTag TypeTag
std::string m_connectionString
const TypeTag & type() const
const std::string & recordName() const
static const ValidityInterval & invalidInterval()
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
const std::string & tagName() const
const Timestamp & time() const
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
virtual void newInterval(const edm::eventsetup::EventSetupRecordKey &iRecordType, const edm::ValidityInterval &iInterval)
called when a new interval of validity occurs for iRecordType
volatile std::atomic< bool > shutdown_flag false
const IOVSyncValue & first() const
void fillTagCollectionFromDB(const std::vector< std::string > &connectionStringList, const std::vector< std::string > &prefixList, const std::vector< std::string > &postfixList, const std::vector< std::string > &roottagList, std::map< std::string, cond::GTEntry_t > &replacement)
CondDBESSource(const edm::ParameterSet &)
GTProxy readGlobalTag(const std::string &name)
TimeValue_t value() const
boost::shared_ptr< cond::DataProxyWrapperBase > ProxyP
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