15 #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};
127 if( iConfig.
exists(
"globaltag" ) ) {
131 }
else if( iConfig.
exists(
"connect") )
135 boost::posix_time::ptime snapshotTime;
136 if( iConfig.
exists(
"snapshotTime" ) ){
138 if( !snapshotTimeString.empty() ) snapshotTime = boost::posix_time::time_from_string( snapshotTimeString );
142 if( iConfig.
exists(
"DBParameters") ) {
149 std::map<std::string,cond::GTEntry_t> replacements;
150 std::map<std::string,boost::posix_time::ptime> specialSnapshots;
151 if( iConfig.
exists(
"toGet" ) ) {
152 typedef std::vector< edm::ParameterSet >
Parameters;
154 for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
156 if( recordname.empty() )
throw cond::Exception(
"ESSource: The record name has not been provided in a \"toGet\" entry." );
162 if( itToGet->exists(
"tag") ) {
167 if( itToGet->exists(
"snapshotTime") ) tagSnapshotTime = boost::posix_time::time_from_string( itToGet->getParameter<
std::string>(
"snapshotTime" ) );
168 std::string recordLabelKey = joinRecordAndLabel( recordname, labelname );
169 replacements.insert( std::make_pair( recordLabelKey,
cond::GTEntry_t( std::make_tuple(recordname, labelname, fqTag ) ) ) );
170 specialSnapshots.insert( std::make_pair( recordLabelKey, tagSnapshotTime ) );
175 std::vector<std::string> globaltagList;
176 std::vector<std::string> connectList;
177 std::vector<std::string> pfnPrefixList;
178 std::vector<std::string> pfnPostfixList;
179 if( !globaltag.empty() ) {
182 boost::split( globaltagList, globaltag, boost::is_any_of(
"|"), boost::token_compress_off );
184 fillList(pfnPrefix, pfnPrefixList, globaltagList.size(),
"pfnPrefix");
185 fillList(pfnPostfix, pfnPostfixList, globaltagList.size(),
"pfnPostfix");
196 if(snapshotTime.is_not_a_date_time())
199 TagCollection::iterator it;
203 std::map<std::string, cond::persistency::Session> sessions;
213 std::vector<cond::DataProxyWrapperBase *> proxyWrappers(
m_tagCollection.size());
215 for(it=itBeg;it!=itEnd;++it){
216 proxyWrappers[ipb++] =
223 for(it=itBeg;it!=itEnd;++it){
227 if( !tagParams.second.empty() ) {
228 connStr = tagParams.second;
229 tag = tagParams.first;
231 std::map<std::string, cond::persistency::Session>::iterator p = sessions.find( connStr );
233 if (p == sessions.end()) {
238 if( (dbService ==
"cms_orcon_prod" || dbService ==
"cms_orcon_adg") && dbAccount !=
"CMS_CONDITIONS" )
239 edm::LogWarning(
"CondDBESSource" )<<
"[WARNING] You are reading tag \""<<tag<<
"\" from V1 account \""<<connStr<<
"\". The concerned Conditions might be out of date."<<std::endl;
242 sessions.insert(std::make_pair( connStr, nsess));
243 }
else nsess = (*p).second;
246 ProxyP proxy(proxyWrappers[ipb++]);
248 m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
250 boost::posix_time::ptime tagSnapshotTime = snapshotTime;
251 auto tagSnapshotIter = specialSnapshots.find( it->first );
252 if( tagSnapshotIter != specialSnapshots.end() ) tagSnapshotTime = tagSnapshotIter->second;
255 tagSnapshotTime = boost::posix_time::ptime();
257 proxy->lateInit(nsess, tag, tagSnapshotTime, it->second.recordLabel(), connStr);
261 CondGetterFromESSource visitor(
m_proxies );
264 for ( ;b !=
e; b++ ) {
266 (*b).second->proxy()->loadMore( visitor );
282 boost::split( listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off );
284 if( listToFill.size() == 1 ) {
285 for(
unsigned int i=1;
i<listSize; ++
i ) {
286 listToFill.push_back(stringList);
290 else if( listSize != listToFill.size() ) {
291 throw cond::Exception(
std::string(
"ESSource: number of global tag components does not match number of "+type+
" strings" ) );
298 std::cout <<
"CondDBESSource Statistics" << std::endl
312 for ( ;b !=
e; b++ ) {
313 dumpInfo(
std::cout, (*b).first, *(*b).second );
332 edm::LogInfo(
"CondDBESSource" ) <<
"Getting data for record \""<< recordname
333 <<
"\" to be consumed by "<< iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
334 <<
"; from CondDBESSource::setIntervalFor";
349 bool doRefresh =
false;
352 std::map<std::string,unsigned int>::iterator iRec =
m_lastRecordRuns.find( recordname );
354 unsigned int lastRecordRun = iRec->second;
359 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
360 <<
"\" since there has been a transition from run "
361 << lastRecordRun <<
" to run " <<
m_lastRun
362 <<
"; from CondDBESSource::setIntervalFor";
367 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
369 <<
"; from CondDBESSource::setIntervalFor";
372 edm::LogInfo(
"CondDBESSource" ) <<
"Though enabled, refresh not needed for record \"" << recordname
374 <<
"; from CondDBESSource::setIntervalFor";
377 edm::LogInfo(
"CondDBESSource" ) <<
"Forcing refresh for record \"" << recordname
379 <<
"; from CondDBESSource::setIntervalFor";
390 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
391 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
392 if ( pmBegin == pmEnd ) {
393 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
394 <<
"\"; from CondDBESSource::setIntervalFor";
398 for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
400 edm::LogInfo(
"CondDBESSource" ) <<
"Processing record \"" << recordname
401 <<
"\" and label \""<< pmIter->second->label()
403 <<
"; from CondDBESSource::setIntervalFor";
405 timetype = (*pmIter).second->proxy()->timeType();
408 userTime = ( 0 == abtime );
410 if (userTime)
return;
414 std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
417 edm::LogInfo(
"CondDBESSource" ) <<
"No Tag found for record \""<< recordname
418 <<
"\" and label \""<< pmIter->second->label()
419 <<
"\"; from CondDBESSource::setIntervalFor";
425 edm::LogInfo(
"CondDBESSource" ) <<
"Checking if the session must be closed and re-opened for getting correct conditions"
426 <<
"; from CondDBESSource::setIntervalFor";
427 std::stringstream transId;
432 if( !tagParams.second.empty() ) connStr = tagParams.second;
433 std::map<
std::string,std::pair<cond::persistency::Session,std::string> >::iterator iSess =
m_sessionPool.find( connStr );
436 if( iSess->second.second != transId.str() ) {
439 iSess->second.second = transId.str();
448 edm::LogInfo(
"CondDBESSource" ) <<
"Re-opening the session with connection string " << connStr
449 <<
" and new transaction Id " << transId.str()
450 <<
"; from CondDBESSource::setIntervalFor";
453 edm::LogInfo(
"CondDBESSource" ) <<
"Reconnecting to \"" << connStr
454 <<
"\" for getting new payload for record \"" << recordname
455 <<
"\" and label \""<< pmIter->second->label()
456 <<
"\" from IOV tag \"" << tcIter->second.tagName()
457 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
458 <<
"; from CondDBESSource::setIntervalFor";
459 pmIter->second->proxy()->setUp( iSess->second.first );
460 pmIter->second->proxy()->reload();
467 edm::LogInfo(
"CondDBESSource" ) <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
468 <<
"\" for getting new payload for record \"" << recordname
469 <<
"\" and label \""<< pmIter->second->label()
470 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
471 <<
"; from CondDBESSource::setIntervalFor";
472 pmIter->second->proxy()->reload();
494 edm::LogInfo(
"CondDBESSource" ) <<
"Validity coming from IOV sequence for record \"" << recordname
495 <<
"\" and label \""<< pmIter->second->label()
496 <<
"\": (" << validity.first <<
", " << validity.second
498 <<
"; from CondDBESSource::setIntervalFor";
500 recordValidity.first =
std::max(recordValidity.first,validity.first);
501 recordValidity.second =
std::min(recordValidity.second,validity.second);
506 edm::LogInfo(
"CondDBESSource" ) <<
"Validity for record \"" << recordname
507 <<
"\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
508 <<
", "<< recordValidity.first
509 <<
") as the last IOV element in the IOV sequence is infinity"
510 <<
"; from CondDBESSource::setIntervalFor";
515 if ( (!userTime) && recordValidity.second !=0 ) {
523 edm::LogInfo(
"CondDBESSource" ) <<
"Setting validity for record \"" << recordname
524 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID() <<
", timestamp: " << oInterval.
first().
time().
value()
527 <<
"; from CondDBESSource::setIntervalFor";
536 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
537 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
539 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
540 <<
"\"; from CondDBESSource::registerProxies";
544 for (ProxyMap::const_iterator p=b;p!=
e;++
p) {
545 if(0 != (*p).second.get()) {
568 std::set< cond::GTEntry_t > & tagcoll,
571 if ( !roottag.empty() ) {
572 if ( connectionString.empty() )
575 if( std::get<2>( connPars ) ==
"CMS_COND_31X_GLOBALTAG" ){
576 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;
577 }
else if( roottag.rfind(
"::All")!=std::string::npos && std::get<2>( connPars ) ==
"CMS_CONDITIONS" ){
578 edm::LogWarning(
"CondDBESSource" )<<
"[WARNING] You are trying to read Global Tag \""<<roottag<<
"\" - postfix \"::All\" should not be used for V2."<<std::endl;
584 for(
const auto& gte : gtp ){
585 tagcoll.insert( gte );
594 const std::vector<std::string> & prefixList,
595 const std::vector<std::string> & postfixList,
596 const std::vector<std::string> & roottagList,
597 std::map<std::string,cond::GTEntry_t>& replacement,
600 std::set< cond::GTEntry_t > tagcoll;
603 auto prefix = prefixList.begin();
604 auto postfix = postfixList.begin();
605 for(
auto roottag = roottagList.begin(); roottag != roottagList.end(); ++roottag, ++
connectionString, ++prefix, ++postfix) {
609 std::set<cond::GTEntry_t>::iterator tagCollIter;
610 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
611 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
614 for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
615 std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordName(), tagCollIter->recordLabel() );
616 std::map<std::string,cond::GTEntry_t>::iterator fid = replacement.find( recordLabelKey );
617 if( fid != replacement.end() ) {
618 if( !fid->second.tagName().empty() ){
619 cond::GTEntry_t tagMetadata( std::make_tuple( tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName() ) );
620 m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
621 edm::LogInfo(
"CondDBESSource" ) <<
"Replacing tag \"" << tagCollIter->tagName()
622 <<
"\" for record \"" << tagMetadata.
recordName()
624 <<
"\" with tag " << tagMetadata.
tagName()
625 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
627 m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
629 replacement.erase( fid );
631 m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
634 std::map<std::string,cond::GTEntry_t>::iterator replacementIter;
635 std::map<std::string,cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
636 std::map<std::string,cond::GTEntry_t>::iterator replacementEnd = replacement.end();
637 for( replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter ){
638 if( replacementIter->second.tagName().empty() ){
639 std::stringstream
msg;
640 msg <<
"ESSource: no tag provided for record " << replacementIter->second.recordName();
641 if( !replacementIter->second.recordLabel().empty() ) msg <<
" and label "<<replacementIter->second.recordLabel();
persistency::Exception Exception
const TimeTypeSpecs timeTypeSpecs[]
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
tuple start
Check for commandline option errors.
Base exception class for the object to relational access.
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()
std::vector< std::pair< DataKey, edm::propagate_const< std::shared_ptr< DataProxy > > > > KeyedProxies
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
Container::value_type value_type
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
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
Session createSession(const std::string &connectionString, bool writeCapable=false)
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)
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::shared_ptr< cond::DataProxyWrapperBase > ProxyP
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
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