15 #include "boost/shared_ptr.hpp"
16 #include <boost/algorithm/string.hpp>
41 return iRecordName +
std::string(
"@" ) + iLabelName;
45 std::pair<std::string,std::string> parseTag(
const std::string&
tag ){
48 size_t pos = tag.rfind(
'@');
49 if( pos != std::string::npos && tag.size() >= pos+3 ){
50 if( tag[pos+1]==
'[' && tag[tag.size()-1]==
']' ) {
51 pfn = tag.substr( pos+2,tag.size()-pos-3 );
52 t = tag.substr( 0, pos );
55 return std::make_pair(
t,
pfn );
67 virtual ~CondGetterFromESSource(){}
70 CondDBESSource::ProxyMap::const_iterator
p = m_proxies.find(
name);
71 if ( p != m_proxies.end())
72 return (*p).second->proxy()->iov();
83 out << recName <<
" / " << proxy.
label() <<
": "
97 out <<
"Time look up, payloadIds:" <<std::endl;
98 const auto& pids = proxy.
proxy()->requests();
100 out <<
" "<<
id.since <<
" - "<<
id.till <<
" : "<<
id.payloadId<<std::endl;
116 m_connectionString(
""),
119 m_policy( NOREFRESH ),
120 m_doDump( iConfig.getUntrackedParameter<bool>(
"DumpStat",
false ) )
135 Stats s = {0,0,0,0,0,0,0,0};
151 std::map<std::string,cond::GTEntry_t> replacements;
152 if( iConfig.
exists(
"toGet" ) ) {
153 typedef std::vector< edm::ParameterSet >
Parameters;
155 for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
160 std::string recordLabelKey = joinRecordAndLabel( recordname, labelname );
162 replacements.insert( std::make_pair( recordLabelKey,
cond::GTEntry_t( std::make_tuple(recordname, labelname, fullyQualifiedTag ) ) ) );
167 std::vector<std::string> globaltagList;
168 std::vector<std::string> connectList;
169 std::vector<std::string> pfnPrefixList;
170 std::vector<std::string> pfnPostfixList;
171 if( iConfig.
exists(
"globaltag" ) ) {
175 boost::split( globaltagList, globaltag, boost::is_any_of(
"|"), boost::token_compress_off );
177 fillList(pfnPrefix, pfnPrefixList, globaltagList.size(),
"pfnPrefix");
178 fillList(pfnPostfix, pfnPostfixList, globaltagList.size(),
"pfnPostfix");
187 TagCollection::iterator it;
191 std::map<std::string, cond::persistency::Session> sessions;
201 std::vector<cond::DataProxyWrapperBase *> proxyWrappers(
m_tagCollection.size());
203 for(it=itBeg;it!=itEnd;++it){
204 proxyWrappers[ipb++] =
211 for(it=itBeg;it!=itEnd;++it){
214 std::pair<std::string,std::string> tagParams = parseTag( it->second.tagName() );
215 if( !tagParams.second.empty() ) {
216 connStr = tagParams.second;
217 tag = tagParams.first;
219 std::map<std::string, cond::persistency::Session>::iterator p = sessions.find( connStr );
221 if (p == sessions.end()) {
224 sessions.insert(std::make_pair( connStr, nsess));
225 }
else nsess = (*p).second;
228 ProxyP proxy(proxyWrappers[ipb++]);
230 m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
232 proxy->lateInit(nsess, tag, it->second.recordLabel(), connStr);
236 CondGetterFromESSource visitor(
m_proxies );
239 for ( ;b !=
e; b++ ) {
241 (*b).second->proxy()->loadMore( visitor );
257 boost::split( listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off );
259 if( listToFill.size() == 1 ) {
260 for(
unsigned int i=1;
i<listSize; ++
i ) {
261 listToFill.push_back(stringList);
265 else if( listSize != listToFill.size() ) {
266 throw cond::Exception(
std::string(
"ESSource: number of global tag components does not match number of "+type+
" strings" ) );
273 std::cout <<
"CondDBESSource Statistics" << std::endl
287 for ( ;b !=
e; b++ ) {
288 dumpInfo(
std::cout, (*b).first, *(*b).second );
307 edm::LogInfo(
"CondDBESSource" ) <<
"Getting data for record \""<< recordname
308 <<
"\" to be consumed by "<< iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
309 <<
"; from CondDBESSource::setIntervalFor";
324 bool doRefresh =
false;
327 std::map<std::string,unsigned int>::iterator iRec =
m_lastRecordRuns.find( recordname );
329 unsigned int lastRecordRun = iRec->second;
334 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
335 <<
"\" since there has been a transition from run "
336 << lastRecordRun <<
" to run " <<
m_lastRun
337 <<
"; from CondDBESSource::setIntervalFor";
342 edm::LogInfo(
"CondDBESSource" ) <<
"Preparing refresh for record \"" << recordname
344 <<
"; from CondDBESSource::setIntervalFor";
347 edm::LogInfo(
"CondDBESSource" ) <<
"Though enabled, refresh not needed for record \"" << recordname
349 <<
"; from CondDBESSource::setIntervalFor";
352 edm::LogInfo(
"CondDBESSource" ) <<
"Forcing refresh for record \"" << recordname
354 <<
"; from CondDBESSource::setIntervalFor";
365 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
366 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
367 if ( pmBegin == pmEnd ) {
368 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
369 <<
"\"; from CondDBESSource::setIntervalFor";
373 for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
375 edm::LogInfo(
"CondDBESSource" ) <<
"Processing record \"" << recordname
376 <<
"\" and label \""<< pmIter->second->label()
378 <<
"; from CondDBESSource::setIntervalFor";
380 timetype = (*pmIter).second->proxy()->timeType();
383 userTime = ( 0 == abtime );
387 if (userTime)
return;
393 std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
396 edm::LogInfo(
"CondDBESSource" ) <<
"No Tag found for record \""<< recordname
397 <<
"\" and label \""<< pmIter->second->label()
398 <<
"\"; from CondDBESSource::setIntervalFor";
404 edm::LogInfo(
"CondDBESSource" ) <<
"Checking if the session must be closed and re-opened for getting correct conditions"
405 <<
"; from CondDBESSource::setIntervalFor";
406 std::stringstream transId;
410 std::pair<std::string,std::string> tagParams = parseTag( tcIter->second.tagName() );
411 if( !tagParams.second.empty() ) connStr = tagParams.second;
415 if( iSess->second.second != transId.str() ) {
418 iSess->second.second = transId.str();
427 edm::LogInfo(
"CondDBESSource" ) <<
"Re-opening the session with connection string " << connStr
428 <<
" and new transaction Id " << transId.str()
429 <<
"; from CondDBESSource::setIntervalFor";
432 edm::LogInfo(
"CondDBESSource" ) <<
"Reconnecting to \"" << connStr
433 <<
"\" for getting new payload for record \"" << recordname
434 <<
"\" and label \""<< pmIter->second->label()
435 <<
"\" from IOV tag \"" << tcIter->second.tagName()
436 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
437 <<
"; from CondDBESSource::setIntervalFor";
438 pmIter->second->proxy()->setUp( iSess->second.first );
439 pmIter->second->proxy()->reload();
446 edm::LogInfo(
"CondDBESSource" ) <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
447 <<
"\" for getting new payload for record \"" << recordname
448 <<
"\" and label \""<< pmIter->second->label()
449 <<
"\" to be consumed by " << iTime.
eventID() <<
", timestamp: " << iTime.
time().
value()
450 <<
"; from CondDBESSource::setIntervalFor";
451 pmIter->second->proxy()->reload();
473 edm::LogInfo(
"CondDBESSource" ) <<
"Validity coming from IOV sequence for record \"" << recordname
474 <<
"\" and label \""<< pmIter->second->label()
475 <<
"\": (" << validity.first <<
", " << validity.second
477 <<
"; from CondDBESSource::setIntervalFor";
479 recordValidity.first =
std::max(recordValidity.first,validity.first);
480 recordValidity.second =
std::min(recordValidity.second,validity.second);
485 edm::LogInfo(
"CondDBESSource" ) <<
"Validity for record \"" << recordname
486 <<
"\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
487 <<
", "<< recordValidity.first
488 <<
") as the last IOV element in the IOV sequence is infinity"
489 <<
"; from CondDBESSource::setIntervalFor";
494 if ( (!userTime) && recordValidity.second !=0 ) {
502 edm::LogInfo(
"CondDBESSource" ) <<
"Setting validity for record \"" << recordname
503 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID() <<
", timestamp: " << oInterval.
first().
time().
value()
506 <<
"; from CondDBESSource::setIntervalFor";
515 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
516 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
518 edm::LogInfo(
"CondDBESSource" ) <<
"No DataProxy (Pluging) found for record \""<< recordname
519 <<
"\"; from CondDBESSource::registerProxies";
523 for (ProxyMap::const_iterator p=b;p!=
e;++
p) {
524 if(0 != (*p).second.get()) {
547 std::set< cond::GTEntry_t > & tagcoll )
549 if ( !roottag.empty() ) {
550 if ( connectionString.empty() )
555 for(
const auto& gte : gtp ){
556 tagcoll.insert( gte );
565 const std::vector<std::string> & prefixList,
566 const std::vector<std::string> & postfixList,
567 const std::vector<std::string> & roottagList,
568 std::map<std::string,cond::GTEntry_t>& replacement )
570 std::set< cond::GTEntry_t > tagcoll;
572 auto connectionString = connectionStringList.begin();
573 auto prefix = prefixList.begin();
574 auto postfix = postfixList.begin();
575 for(
auto roottag = roottagList.begin(); roottag != roottagList.end(); ++roottag, ++connectionString, ++
prefix, ++postfix) {
579 std::set<cond::GTEntry_t>::iterator tagCollIter;
580 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
581 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
584 for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
585 std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordName(), tagCollIter->recordLabel() );
586 std::map<std::string,cond::GTEntry_t>::iterator
fid = replacement.find( recordLabelKey );
587 if( fid != replacement.end() ) {
588 cond::GTEntry_t tagMetadata( std::make_tuple( tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName() ) );
589 m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
590 replacement.erase( fid );
591 edm::LogInfo(
"CondDBESSource" ) <<
"Replacing tag \"" << tagCollIter->tagName()
592 <<
"\" for record \"" << tagMetadata.
recordName()
594 <<
"\" with tag " << tagMetadata.
tagName()
595 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
597 m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
600 std::map<std::string,cond::GTEntry_t>::iterator replacementIter;
601 std::map<std::string,cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
602 std::map<std::string,cond::GTEntry_t>::iterator replacementEnd = replacement.end();
603 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
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
cond::persistency::ConnectionPool m_connection
const char * name() const
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, TimeType timetype, bool startOrStop)
LuminosityBlockNumber_t luminosityBlockNumber() const
Session createSession(const std::string &connectionString, bool writeCapable=false)
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