15 #include "boost/shared_ptr.hpp"
16 #include <boost/algorithm/string.hpp>
42 return iRecordName +
std::string(
"@" ) + iLabelName;
54 virtual ~CondGetterFromESSource(){}
57 CondDBESSource::ProxyMap::const_iterator
p = m_proxies.find(
name);
58 if ( p != m_proxies.end())
59 return (*p).second->proxy()->iov();
70 out << recName <<
" / " << proxy.
label() <<
": "
84 out <<
"Time look up, payloadIds:" <<std::endl;
85 const auto& pids = proxy.
proxy()->requests();
87 out <<
" "<<
id.since <<
" - "<<
id.till <<
" : "<<
id.payloadId<<std::endl;
103 m_connectionString(
""),
106 m_policy( NOREFRESH ),
107 m_doDump( iConfig.getUntrackedParameter<bool>(
"DumpStat",
false ) )
122 Stats s = {0,0,0,0,0,0,0,0};
128 if( iConfig.
exists(
"globaltag" ) ) {
132 }
else if( iConfig.
exists(
"connect") )
136 boost::posix_time::ptime snapshotTime;
137 if( iConfig.
exists(
"snapshotTime" ) )
141 if( iConfig.
exists(
"DBParameters") ) {
148 std::map<std::string,cond::GTEntry_t> replacements;
149 if( iConfig.
exists(
"toGet" ) ) {
150 typedef std::vector< edm::ParameterSet >
Parameters;
152 for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
158 std::string recordLabelKey = joinRecordAndLabel( recordname, labelname );
160 replacements.insert( std::make_pair( recordLabelKey,
cond::GTEntry_t( std::make_tuple(recordname, labelname, fqTag ) ) ) );
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( !globaltag.empty() ) {
172 boost::split( globaltagList, globaltag, boost::is_any_of(
"|"), boost::token_compress_off );
174 fillList(pfnPrefix, pfnPrefixList, globaltagList.size(),
"pfnPrefix");
175 fillList(pfnPostfix, pfnPostfixList, globaltagList.size(),
"pfnPostfix");
186 if(snapshotTime.is_not_a_date_time())
190 snapshotTime = boost::posix_time::ptime();
192 TagCollection::iterator it;
196 std::map<std::string, cond::persistency::Session> sessions;
206 std::vector<cond::DataProxyWrapperBase *> proxyWrappers(
m_tagCollection.size());
208 for(it=itBeg;it!=itEnd;++it){
209 proxyWrappers[ipb++] =
216 for(it=itBeg;it!=itEnd;++it){
220 if( !tagParams.second.empty() ) {
221 connStr = tagParams.second;
222 tag = tagParams.first;
224 std::map<std::string, cond::persistency::Session>::iterator p = sessions.find( connStr );
226 if (p == sessions.end()) {
231 if( (dbService ==
"cms_orcon_prod" || dbService ==
"cms_orcon_adg") && dbAccount !=
"CMS_CONDITIONS" )
232 edm::LogWarning(
"CondDBESSource" )<<
"[WARNING] You are reading tag \""<<tag<<
"\" from V1 account \""<<connStr<<
"\". The concerned Conditions might be out of date."<<std::endl;
235 sessions.insert(std::make_pair( connStr, nsess));
236 }
else nsess = (*p).second;
239 ProxyP proxy(proxyWrappers[ipb++]);
241 m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
243 proxy->lateInit(nsess, tag, snapshotTime, it->second.recordLabel(), connStr);
247 CondGetterFromESSource visitor(
m_proxies );
250 for ( ;b !=
e; b++ ) {
252 (*b).second->proxy()->loadMore( visitor );
268 boost::split( listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off );
270 if( listToFill.size() == 1 ) {
271 for(
unsigned int i=1;
i<listSize; ++
i ) {
272 listToFill.push_back(stringList);
276 else if( listSize != listToFill.size() ) {
277 throw cond::Exception(
std::string(
"ESSource: number of global tag components does not match number of "+type+
" strings" ) );
284 std::cout <<
"CondDBESSource Statistics" << std::endl
298 for ( ;b !=
e; b++ ) {
299 dumpInfo(
std::cout, (*b).first, *(*b).second );
318 edm::LogInfo(
"CondDBESSource" ) <<
"Getting data for record \""<< recordname
319 <<
"\" to be consumed by "<< iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
320 <<
"; from CondDBESSource::setIntervalFor";
335 bool doRefresh =
false;
338 std::map<std::string,unsigned int>::iterator iRec =
m_lastRecordRuns.find( recordname );
340 unsigned int lastRecordRun = iRec->second;
345 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
346 <<
"\" since there has been a transition from run "
347 << lastRecordRun <<
" to run " <<
m_lastRun
348 <<
"; from CondDBESSource::setIntervalFor";
353 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
355 <<
"; from CondDBESSource::setIntervalFor";
358 edm::LogInfo(
"CondDBESSource" ) <<
"Though enabled, refresh not needed for record \"" << recordname
360 <<
"; from CondDBESSource::setIntervalFor";
363 edm::LogInfo(
"CondDBESSource" ) <<
"Forcing refresh for record \"" << recordname
365 <<
"; from CondDBESSource::setIntervalFor";
376 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
377 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
378 if ( pmBegin == pmEnd ) {
379 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
380 <<
"\"; from CondDBESSource::setIntervalFor";
384 for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
386 edm::LogInfo(
"CondDBESSource" ) <<
"Processing record \"" << recordname
387 <<
"\" and label \""<< pmIter->second->label()
389 <<
"; from CondDBESSource::setIntervalFor";
391 timetype = (*pmIter).second->proxy()->timeType();
394 userTime = ( 0 == abtime );
396 if (userTime)
return;
400 std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
403 edm::LogInfo(
"CondDBESSource" ) <<
"No Tag found for record \""<< recordname
404 <<
"\" and label \""<< pmIter->second->label()
405 <<
"\"; from CondDBESSource::setIntervalFor";
411 edm::LogInfo(
"CondDBESSource" ) <<
"Checking if the session must be closed and re-opened for getting correct conditions"
412 <<
"; from CondDBESSource::setIntervalFor";
413 std::stringstream transId;
418 if( !tagParams.second.empty() ) connStr = tagParams.second;
422 if( iSess->second.second != transId.str() ) {
425 iSess->second.second = transId.str();
434 edm::LogInfo(
"CondDBESSource" ) <<
"Re-opening the session with connection string " << connStr
435 <<
" and new transaction Id " << transId.str()
436 <<
"; from CondDBESSource::setIntervalFor";
439 edm::LogInfo(
"CondDBESSource" ) <<
"Reconnecting to \"" << connStr
440 <<
"\" for getting new payload for record \"" << recordname
441 <<
"\" and label \""<< pmIter->second->label()
442 <<
"\" from IOV tag \"" << tcIter->second.tagName()
443 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
444 <<
"; from CondDBESSource::setIntervalFor";
445 pmIter->second->proxy()->setUp( iSess->second.first );
446 pmIter->second->proxy()->reload();
453 edm::LogInfo(
"CondDBESSource" ) <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
454 <<
"\" for getting new payload for record \"" << recordname
455 <<
"\" and label \""<< pmIter->second->label()
456 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
457 <<
"; from CondDBESSource::setIntervalFor";
458 pmIter->second->proxy()->reload();
480 edm::LogInfo(
"CondDBESSource" ) <<
"Validity coming from IOV sequence for record \"" << recordname
481 <<
"\" and label \""<< pmIter->second->label()
482 <<
"\": (" << validity.first <<
", " << validity.second
484 <<
"; from CondDBESSource::setIntervalFor";
486 recordValidity.first =
std::max(recordValidity.first,validity.first);
487 recordValidity.second =
std::min(recordValidity.second,validity.second);
492 edm::LogInfo(
"CondDBESSource" ) <<
"Validity for record \"" << recordname
493 <<
"\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
494 <<
", "<< recordValidity.first
495 <<
") as the last IOV element in the IOV sequence is infinity"
496 <<
"; from CondDBESSource::setIntervalFor";
501 if ( (!userTime) && recordValidity.second !=0 ) {
509 edm::LogInfo(
"CondDBESSource" ) <<
"Setting validity for record \"" << recordname
510 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID() <<
", timestamp: " << oInterval.
first().
time().
value()
513 <<
"; from CondDBESSource::setIntervalFor";
522 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
523 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
525 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
526 <<
"\"; from CondDBESSource::registerProxies";
530 for (ProxyMap::const_iterator p=b;p!=
e;++
p) {
531 if(0 != (*p).second.get()) {
554 std::set< cond::GTEntry_t > & tagcoll,
557 if ( !roottag.empty() ) {
558 if ( connectionString.empty() )
561 if( std::get<2>( connPars ) ==
"CMS_COND_31X_GLOBALTAG" ){
562 edm::LogWarning(
"CondDBESSource" )<<
"[WARNING] You are reading Global Tag \""<<roottag<<
"\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date."<<std::endl;
563 }
else if( roottag.rfind(
"::All")!=std::string::npos && std::get<2>( connPars ) ==
"CMS_CONDITIONS" ){
564 edm::LogWarning(
"CondDBESSource" )<<
"[WARNING] You are trying to read Global Tag \""<<roottag<<
"\" - postfix \"::All\" should not be used for V2."<<std::endl;
570 for(
const auto& gte : gtp ){
571 tagcoll.insert( gte );
580 const std::vector<std::string> & prefixList,
581 const std::vector<std::string> & postfixList,
582 const std::vector<std::string> & roottagList,
583 std::map<std::string,cond::GTEntry_t>& replacement,
586 std::set< cond::GTEntry_t > tagcoll;
588 auto connectionString = connectionStringList.begin();
589 auto prefix = prefixList.begin();
590 auto postfix = postfixList.begin();
591 for(
auto roottag = roottagList.begin(); roottag != roottagList.end(); ++roottag, ++connectionString, ++
prefix, ++postfix) {
595 std::set<cond::GTEntry_t>::iterator tagCollIter;
596 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
597 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
600 for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
601 std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordName(), tagCollIter->recordLabel() );
602 std::map<std::string,cond::GTEntry_t>::iterator
fid = replacement.find( recordLabelKey );
603 if( fid != replacement.end() ) {
604 cond::GTEntry_t tagMetadata( std::make_tuple( tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName() ) );
605 m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
606 replacement.erase( fid );
607 edm::LogInfo(
"CondDBESSource" ) <<
"Replacing tag \"" << tagCollIter->tagName()
608 <<
"\" for record \"" << tagMetadata.
recordName()
610 <<
"\" with tag " << tagMetadata.
tagName()
611 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
613 m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
616 std::map<std::string,cond::GTEntry_t>::iterator replacementIter;
617 std::map<std::string,cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
618 std::map<std::string,cond::GTEntry_t>::iterator replacementEnd = replacement.end();
619 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
static constexpr const char *const MAX_TIMESTAMP
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, cond::GTMetadata_t >Metadata)
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
std::string const & timeTypeNames(int)
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
std::string const & label() const
unsigned long long Time_t
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
vector< ParameterSet > Parameters
std::string convertoToOracleConnection(const std::string &input)
std::pair< std::string, std::string > parseTag(const std::string &tag)
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
boost::posix_time::ptime snapshotTime() const
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
std::string fullyQualifiedTag(const std::string &tag, const std::string &connectionString)
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
Container::value_type value_type
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
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
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, cond::GTMetadata_t >Metadata)
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
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