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" ) ){
139 if( !snapshotTimeString.empty() ) snapshotTime = boost::posix_time::time_from_string( snapshotTimeString );
143 if( iConfig.
exists(
"DBParameters") ) {
150 std::map<std::string,cond::GTEntry_t> replacements;
151 std::map<std::string,boost::posix_time::ptime> specialSnapshots;
152 if( iConfig.
exists(
"toGet" ) ) {
153 typedef std::vector< edm::ParameterSet >
Parameters;
155 for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
157 if( recordname.empty() )
throw cond::Exception(
"ESSource: The record name has not been provided in a \"toGet\" entry." );
163 if( itToGet->exists(
"tag") ) {
168 if( itToGet->exists(
"snapshotTime") ) tagSnapshotTime = boost::posix_time::time_from_string( itToGet->getParameter<
std::string>(
"snapshotTime" ) );
169 std::string recordLabelKey = joinRecordAndLabel( recordname, labelname );
170 replacements.insert( std::make_pair( recordLabelKey,
cond::GTEntry_t( std::make_tuple(recordname, labelname, fqTag ) ) ) );
171 specialSnapshots.insert( std::make_pair( recordLabelKey, tagSnapshotTime ) );
176 std::vector<std::string> globaltagList;
177 std::vector<std::string> connectList;
178 std::vector<std::string> pfnPrefixList;
179 std::vector<std::string> pfnPostfixList;
180 if( !globaltag.empty() ) {
183 boost::split( globaltagList, globaltag, boost::is_any_of(
"|"), boost::token_compress_off );
185 fillList(pfnPrefix, pfnPrefixList, globaltagList.size(),
"pfnPrefix");
186 fillList(pfnPostfix, pfnPostfixList, globaltagList.size(),
"pfnPostfix");
197 if(snapshotTime.is_not_a_date_time())
200 TagCollection::iterator it;
204 std::map<std::string, cond::persistency::Session> sessions;
214 std::vector<cond::DataProxyWrapperBase *> proxyWrappers(
m_tagCollection.size());
216 for(it=itBeg;it!=itEnd;++it){
217 proxyWrappers[ipb++] =
224 for(it=itBeg;it!=itEnd;++it){
228 if( !tagParams.second.empty() ) {
229 connStr = tagParams.second;
230 tag = tagParams.first;
232 std::map<std::string, cond::persistency::Session>::iterator p = sessions.find( connStr );
234 if (p == sessions.end()) {
239 if( (dbService ==
"cms_orcon_prod" || dbService ==
"cms_orcon_adg") && dbAccount !=
"CMS_CONDITIONS" )
240 edm::LogWarning(
"CondDBESSource" )<<
"[WARNING] You are reading tag \""<<tag<<
"\" from V1 account \""<<connStr<<
"\". The concerned Conditions might be out of date."<<std::endl;
243 sessions.insert(std::make_pair( connStr, nsess));
244 }
else nsess = (*p).second;
247 ProxyP proxy(proxyWrappers[ipb++]);
249 m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
251 boost::posix_time::ptime tagSnapshotTime = snapshotTime;
252 auto tagSnapshotIter = specialSnapshots.find( it->first );
253 if( tagSnapshotIter != specialSnapshots.end() ) tagSnapshotTime = tagSnapshotIter->second;
256 tagSnapshotTime = boost::posix_time::ptime();
258 proxy->lateInit(nsess, tag, tagSnapshotTime, it->second.recordLabel(), connStr);
262 CondGetterFromESSource visitor(
m_proxies );
265 for ( ;b !=
e; b++ ) {
267 (*b).second->proxy()->loadMore( visitor );
283 boost::split( listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off );
285 if( listToFill.size() == 1 ) {
286 for(
unsigned int i=1;
i<listSize; ++
i ) {
287 listToFill.push_back(stringList);
291 else if( listSize != listToFill.size() ) {
292 throw cond::Exception(
std::string(
"ESSource: number of global tag components does not match number of "+type+
" strings" ) );
299 std::cout <<
"CondDBESSource Statistics" << std::endl
313 for ( ;b !=
e; b++ ) {
314 dumpInfo(
std::cout, (*b).first, *(*b).second );
333 edm::LogInfo(
"CondDBESSource" ) <<
"Getting data for record \""<< recordname
334 <<
"\" to be consumed by "<< iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
335 <<
"; from CondDBESSource::setIntervalFor";
350 bool doRefresh =
false;
353 std::map<std::string,unsigned int>::iterator iRec =
m_lastRecordRuns.find( recordname );
355 unsigned int lastRecordRun = iRec->second;
360 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
361 <<
"\" since there has been a transition from run "
362 << lastRecordRun <<
" to run " <<
m_lastRun
363 <<
"; from CondDBESSource::setIntervalFor";
368 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
370 <<
"; from CondDBESSource::setIntervalFor";
373 edm::LogInfo(
"CondDBESSource" ) <<
"Though enabled, refresh not needed for record \"" << recordname
375 <<
"; from CondDBESSource::setIntervalFor";
378 edm::LogInfo(
"CondDBESSource" ) <<
"Forcing refresh for record \"" << recordname
380 <<
"; from CondDBESSource::setIntervalFor";
391 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
392 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
393 if ( pmBegin == pmEnd ) {
394 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
395 <<
"\"; from CondDBESSource::setIntervalFor";
399 for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
401 edm::LogInfo(
"CondDBESSource" ) <<
"Processing record \"" << recordname
402 <<
"\" and label \""<< pmIter->second->label()
404 <<
"; from CondDBESSource::setIntervalFor";
406 timetype = (*pmIter).second->proxy()->timeType();
409 userTime = ( 0 == abtime );
411 if (userTime)
return;
415 std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
418 edm::LogInfo(
"CondDBESSource" ) <<
"No Tag found for record \""<< recordname
419 <<
"\" and label \""<< pmIter->second->label()
420 <<
"\"; from CondDBESSource::setIntervalFor";
426 edm::LogInfo(
"CondDBESSource" ) <<
"Checking if the session must be closed and re-opened for getting correct conditions"
427 <<
"; from CondDBESSource::setIntervalFor";
428 std::stringstream transId;
433 if( !tagParams.second.empty() ) connStr = tagParams.second;
437 if( iSess->second.second != transId.str() ) {
440 iSess->second.second = transId.str();
449 edm::LogInfo(
"CondDBESSource" ) <<
"Re-opening the session with connection string " << connStr
450 <<
" and new transaction Id " << transId.str()
451 <<
"; from CondDBESSource::setIntervalFor";
454 edm::LogInfo(
"CondDBESSource" ) <<
"Reconnecting to \"" << connStr
455 <<
"\" for getting new payload for record \"" << recordname
456 <<
"\" and label \""<< pmIter->second->label()
457 <<
"\" from IOV tag \"" << tcIter->second.tagName()
458 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
459 <<
"; from CondDBESSource::setIntervalFor";
460 pmIter->second->proxy()->setUp( iSess->second.first );
461 pmIter->second->proxy()->reload();
468 edm::LogInfo(
"CondDBESSource" ) <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
469 <<
"\" for getting new payload for record \"" << recordname
470 <<
"\" and label \""<< pmIter->second->label()
471 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
472 <<
"; from CondDBESSource::setIntervalFor";
473 pmIter->second->proxy()->reload();
495 edm::LogInfo(
"CondDBESSource" ) <<
"Validity coming from IOV sequence for record \"" << recordname
496 <<
"\" and label \""<< pmIter->second->label()
497 <<
"\": (" << validity.first <<
", " << validity.second
499 <<
"; from CondDBESSource::setIntervalFor";
501 recordValidity.first =
std::max(recordValidity.first,validity.first);
502 recordValidity.second =
std::min(recordValidity.second,validity.second);
507 edm::LogInfo(
"CondDBESSource" ) <<
"Validity for record \"" << recordname
508 <<
"\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
509 <<
", "<< recordValidity.first
510 <<
") as the last IOV element in the IOV sequence is infinity"
511 <<
"; from CondDBESSource::setIntervalFor";
516 if ( (!userTime) && recordValidity.second !=0 ) {
524 edm::LogInfo(
"CondDBESSource" ) <<
"Setting validity for record \"" << recordname
525 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID() <<
", timestamp: " << oInterval.
first().
time().
value()
528 <<
"; from CondDBESSource::setIntervalFor";
537 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
538 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
540 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
541 <<
"\"; from CondDBESSource::registerProxies";
545 for (ProxyMap::const_iterator p=b;p!=
e;++
p) {
546 if(0 != (*p).second.get()) {
569 std::set< cond::GTEntry_t > & tagcoll,
572 if ( !roottag.empty() ) {
573 if ( connectionString.empty() )
576 if( std::get<2>( connPars ) ==
"CMS_COND_31X_GLOBALTAG" ){
577 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;
578 }
else if( roottag.rfind(
"::All")!=std::string::npos && std::get<2>( connPars ) ==
"CMS_CONDITIONS" ){
579 edm::LogWarning(
"CondDBESSource" )<<
"[WARNING] You are trying to read Global Tag \""<<roottag<<
"\" - postfix \"::All\" should not be used for V2."<<std::endl;
585 for(
const auto& gte : gtp ){
586 tagcoll.insert( gte );
595 const std::vector<std::string> & prefixList,
596 const std::vector<std::string> & postfixList,
597 const std::vector<std::string> & roottagList,
598 std::map<std::string,cond::GTEntry_t>& replacement,
601 std::set< cond::GTEntry_t > tagcoll;
604 auto prefix = prefixList.begin();
605 auto postfix = postfixList.begin();
606 for(
auto roottag = roottagList.begin(); roottag != roottagList.end(); ++roottag, ++
connectionString, ++
prefix, ++postfix) {
610 std::set<cond::GTEntry_t>::iterator tagCollIter;
611 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
612 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
615 for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
616 std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordName(), tagCollIter->recordLabel() );
617 std::map<std::string,cond::GTEntry_t>::iterator
fid = replacement.find( recordLabelKey );
618 if( fid != replacement.end() ) {
619 if( !fid->second.tagName().empty() ){
620 cond::GTEntry_t tagMetadata( std::make_tuple( tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName() ) );
621 m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
622 edm::LogInfo(
"CondDBESSource" ) <<
"Replacing tag \"" << tagCollIter->tagName()
623 <<
"\" for record \"" << tagMetadata.
recordName()
625 <<
"\" with tag " << tagMetadata.
tagName()
626 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
628 m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
630 replacement.erase( fid );
632 m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
635 std::map<std::string,cond::GTEntry_t>::iterator replacementIter;
636 std::map<std::string,cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
637 std::map<std::string,cond::GTEntry_t>::iterator replacementEnd = replacement.end();
638 for( replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter ){
639 if( replacementIter->second.tagName().empty() ){
640 std::stringstream
msg;
641 msg <<
"ESSource: no tag provided for record " << replacementIter->second.recordName();
642 if( !replacementIter->second.recordLabel().empty() ) msg <<
" and label "<<replacementIter->second.recordLabel();
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