CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes
CondDBESSource Class Reference

#include <CondDBESSource.h>

Inheritance diagram for CondDBESSource:
edm::eventsetup::DataProxyProvider edm::EventSetupRecordIntervalFinder PoolDBESSource

Classes

struct  Stats
 

Public Types

typedef std::multimap
< std::string, ProxyP
ProxyMap
 
typedef boost::shared_ptr
< cond::DataProxyWrapperBase
ProxyP
 
enum  RefreshPolicy {
  NOREFRESH, REFRESH_ALWAYS, REFRESH_OPEN_IOVS, REFRESH_EACH_RUN,
  RECONNECT_EACH_RUN
}
 
- Public Types inherited from edm::eventsetup::DataProxyProvider
typedef std::vector< std::pair
< DataKey, boost::shared_ptr
< DataProxy > > > 
KeyedProxies
 
typedef std::vector
< EventSetupRecordKey
Keys
 
typedef std::map
< EventSetupRecordKey,
KeyedProxies
RecordProxies
 

Public Member Functions

 CondDBESSource (const edm::ParameterSet &)
 
 ~CondDBESSource ()
 
- Public Member Functions inherited from edm::eventsetup::DataProxyProvider
 DataProxyProvider ()
 
const ComponentDescriptiondescription () const
 
bool isUsingRecord (const EventSetupRecordKey &) const
 
const KeyedProxieskeyedProxies (const EventSetupRecordKey &iRecordKey) const
 
void resetProxies (const EventSetupRecordKey &iRecordType)
 
void resetProxiesIfTransient (const EventSetupRecordKey &iRecordType)
 
void setAppendToDataLabel (const edm::ParameterSet &)
 
void setDescription (const ComponentDescription &iDescription)
 
std::set< EventSetupRecordKeyusingRecords () const
 
virtual ~DataProxyProvider ()
 
- Public Member Functions inherited from edm::EventSetupRecordIntervalFinder
const
eventsetup::ComponentDescription
descriptionForFinder () const
 
 EventSetupRecordIntervalFinder ()
 
std::set
< eventsetup::EventSetupRecordKey
findingForRecords () const
 
const ValidityIntervalfindIntervalFor (const eventsetup::EventSetupRecordKey &, const IOVSyncValue &)
 
void setDescriptionForFinder (const eventsetup::ComponentDescription &iDescription)
 
virtual ~EventSetupRecordIntervalFinder ()
 

Protected Member Functions

virtual void newInterval (const edm::eventsetup::EventSetupRecordKey &iRecordType, const edm::ValidityInterval &iInterval)
 called when a new interval of validity occurs for iRecordType More...
 
virtual void registerProxies (const edm::eventsetup::EventSetupRecordKey &iRecordKey, KeyedProxies &aProxyList)
 
virtual void setIntervalFor (const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
 
- Protected Member Functions inherited from edm::eventsetup::DataProxyProvider
void eraseAll (const EventSetupRecordKey &iRecordKey)
 deletes all the Proxies in aStream More...
 
void invalidateProxies (const EventSetupRecordKey &iRecordKey)
 
template<class T >
void usingRecord ()
 
void usingRecordWithKey (const EventSetupRecordKey &)
 
- Protected Member Functions inherited from edm::EventSetupRecordIntervalFinder
template<class T >
void findingRecord ()
 
void findingRecordWithKey (const eventsetup::EventSetupRecordKey &)
 

Private Types

typedef std::map< std::string,
cond::GTEntry_t
TagCollection
 

Private Member Functions

void fillList (const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
 
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)
 
void fillTagCollectionFromGT (const std::string &connectionString, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::set< cond::GTEntry_t > &tagcoll)
 

Private Attributes

cond::persistency::ConnectionPool m_connection
 
std::string m_connectionString
 
bool m_doDump
 
unsigned int m_lastLumi
 
std::map< std::string,
unsigned int > 
m_lastRecordRuns
 
unsigned int m_lastRun
 
RefreshPolicy m_policy
 
ProxyMap m_proxies
 
std::map< std::string,
std::pair
< cond::persistency::Session,
std::string > > 
m_sessionPool
 
Stats m_stats
 
TagCollection m_tagCollection
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::eventsetup::DataProxyProvider
static void prevalidate (ConfigurationDescriptions &)
 

Detailed Description

Definition at line 32 of file CondDBESSource.h.

Member Typedef Documentation

typedef std::multimap< std::string, ProxyP> CondDBESSource::ProxyMap

Definition at line 36 of file CondDBESSource.h.

Definition at line 35 of file CondDBESSource.h.

typedef std::map< std::string, cond::GTEntry_t > CondDBESSource::TagCollection
private

Definition at line 64 of file CondDBESSource.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

CondDBESSource::CondDBESSource ( const edm::ParameterSet iConfig)
explicit

required by eventsetup

Definition at line 114 of file CondDBESSource.cc.

References b, cond::persistency::ConnectionPool::configure(), cond::persistency::ConnectionPool::createReadOnlySession(), alignCSCRings::e, edm::ParameterSet::exists(), fillList(), fillTagCollectionFromDB(), edm::EventSetupRecordIntervalFinder::findingRecordWithKey(), edm::eventsetup::heterocontainer::HCTypeTag::findType(), reco::get(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), align_cfg::globaltag, m_connection, m_connectionString, m_policy, m_proxies, m_stats, m_tagCollection, CondDBESSource::Stats::nData, dbtoconf::pfn, RECONNECT_EACH_RUN, REFRESH_ALWAYS, REFRESH_EACH_RUN, REFRESH_OPEN_IOVS, alignCSCRings::s, cond::persistency::ConnectionPool::setParameters(), split, AlCaHLTBitMon_QueryRunRegistry::string, convertSQLitetoXML_cfg::toGet, edm::eventsetup::EventSetupRecordKey::type(), and edm::eventsetup::DataProxyProvider::usingRecordWithKey().

114  :
115  m_connection(),
116  m_connectionString(""),
117  m_lastRun(0), // for the stat
118  m_lastLumi(0), // for the stat
119  m_policy( NOREFRESH ),
120  m_doDump( iConfig.getUntrackedParameter<bool>( "DumpStat", false ) )
121 {
122  if( iConfig.getUntrackedParameter<bool>( "RefreshAlways", false ) ) {
124  }
125  if( iConfig.getUntrackedParameter<bool>( "RefreshOpenIOVs", false ) ) {
127  }
128  if( iConfig.getUntrackedParameter<bool>( "RefreshEachRun", false ) ) {
130  }
131  if( iConfig.getUntrackedParameter<bool>( "ReconnectEachRun", false ) ) {
133  }
134 
135  Stats s = {0,0,0,0,0,0,0,0};
136  m_stats = s;
137  /*parameter set parsing and pool environment setting
138  */
139 
140  // default connection string
141  // inproduction used for the global tag
142  m_connectionString= iConfig.getParameter<std::string>("connect");
143 
144 
145  // connection configuration
146  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>( "DBParameters" );
147  m_connection.setParameters( connectionPset );
149 
150  // load additional record/tag info it will overwrite the global tag
151  std::map<std::string,cond::GTEntry_t> replacements;
152  if( iConfig.exists( "toGet" ) ) {
153  typedef std::vector< edm::ParameterSet > Parameters;
154  Parameters toGet = iConfig.getParameter<Parameters>( "toGet" );
155  for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
156  std::string recordname = itToGet->getParameter<std::string>( "record" );
157  std::string labelname = itToGet->getUntrackedParameter<std::string>( "label", "" );
158  std::string tag = itToGet->getParameter<std::string>( "tag" );
159  std::string pfn = itToGet->getUntrackedParameter<std::string>( "connect", m_connectionString );
160  std::string recordLabelKey = joinRecordAndLabel( recordname, labelname );
161  std::string fullyQualifiedTag = tag+"@["+pfn+"]";
162  replacements.insert( std::make_pair( recordLabelKey, cond::GTEntry_t( std::make_tuple(recordname, labelname, fullyQualifiedTag ) ) ) );
163  }
164  }
165 
166  // get the global tag, merge with "replacement" store in "tagCollection"
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" ) ) {
172  std::string pfnPrefix(iConfig.getUntrackedParameter<std::string>( "pfnPrefix", "" ));
173  std::string pfnPostfix(iConfig.getUntrackedParameter<std::string>( "pfnPostfix", "" ));
174  std::string globaltag(iConfig.getParameter<std::string>( "globaltag" ));
175  boost::split( globaltagList, globaltag, boost::is_any_of("|"), boost::token_compress_off );
176  fillList(m_connectionString, connectList, globaltagList.size(), "connection");
177  fillList(pfnPrefix, pfnPrefixList, globaltagList.size(), "pfnPrefix");
178  fillList(pfnPostfix, pfnPostfixList, globaltagList.size(), "pfnPostfix");
179  }
180 
181  fillTagCollectionFromDB(connectList,
182  pfnPrefixList,
183  pfnPostfixList,
184  globaltagList,
185  replacements);
186 
187  TagCollection::iterator it;
188  TagCollection::iterator itBeg = m_tagCollection.begin();
189  TagCollection::iterator itEnd = m_tagCollection.end();
190 
191  std::map<std::string, cond::persistency::Session> sessions;
192 
193  /* load DataProxy Plugin (it is strongly typed due to EventSetup ideosyncrasis)
194  * construct proxy
195  * contrary to EventSetup the "object-name" is not used as identifier: multiple entries in a record are
196  * dinstinguished only by their label...
197  * done in two step: first create ProxyWrapper loading ALL required dictionaries
198  * this will allow to initialize POOL in one go for each "database"
199  * The real initialization of the Data-Proxies is done in the second loop
200  */
201  std::vector<cond::DataProxyWrapperBase *> proxyWrappers(m_tagCollection.size());
202  size_t ipb=0;
203  for(it=itBeg;it!=itEnd;++it){
204  proxyWrappers[ipb++] =
205  cond::ProxyFactory::get()->create(buildName(it->second.recordName()));
206  }
207 
208  // now all required libraries have been loaded
209  // init sessions and DataProxies
210  ipb=0;
211  for(it=itBeg;it!=itEnd;++it){
213  std::string tag = it->second.tagName();
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;
218  }
219  std::map<std::string, cond::persistency::Session>::iterator p = sessions.find( connStr );
221  if (p == sessions.end()) {
222  //open db get tag info (i.e. the IOV token...)
223  nsess = m_connection.createReadOnlySession( connStr, "" );
224  sessions.insert(std::make_pair( connStr, nsess));
225  } else nsess = (*p).second;
226 
227  // ownership...
228  ProxyP proxy(proxyWrappers[ipb++]);
229  // instert in the map
230  m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
231  // initialize
232  proxy->lateInit(nsess, tag, it->second.recordLabel(), connStr);
233  }
234 
235  // one loaded expose all other tags to the Proxy!
236  CondGetterFromESSource visitor( m_proxies );
237  ProxyMap::iterator b = m_proxies.begin();
238  ProxyMap::iterator e = m_proxies.end();
239  for ( ;b != e; b++ ) {
240 
241  (*b).second->proxy()->loadMore( visitor );
242 
245  if( recordKey.type() != edm::eventsetup::EventSetupRecordKey::TypeTag() ) {
246  findingRecordWithKey( recordKey );
247  usingRecordWithKey( recordKey );
248  }
249  }
250 
251  m_stats.nData=m_proxies.size();
252 
253 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
list pfn
Definition: dbtoconf.py:76
list globaltag
Definition: align_cfg.py:7
bool exists(std::string const &parameterName) const
checks if a parameter exists
void usingRecordWithKey(const EventSetupRecordKey &)
RefreshPolicy m_policy
void setParameters(const edm::ParameterSet &connectionPset)
vector< ParameterSet > Parameters
cond::persistency::ConnectionPool m_connection
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
TagCollection m_tagCollection
double b
Definition: hdecay.h:120
heterocontainer::HCTypeTag TypeTag
std::string m_connectionString
ProxyMap m_proxies
unsigned int m_lastRun
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
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)
unsigned int m_lastLumi
double split
Definition: MVATrainer.cc:139
boost::shared_ptr< cond::DataProxyWrapperBase > ProxyP
T get(const Candidate &c)
Definition: component.h:55
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
Definition: HCTypeTag.cc:125
CondDBESSource::~CondDBESSource ( )

Definition at line 270 of file CondDBESSource.cc.

References b, gather_cfg::cout, alignCSCRings::e, m_doDump, m_proxies, m_stats, CondDBESSource::Stats::nActualReconnect, CondDBESSource::Stats::nActualRefresh, CondDBESSource::Stats::nData, CondDBESSource::Stats::nLumi, CondDBESSource::Stats::nReconnect, CondDBESSource::Stats::nRefresh, CondDBESSource::Stats::nRun, and CondDBESSource::Stats::nSet.

270  {
271  //dump info FIXME: find a more suitable place...
272  if (m_doDump) {
273  std::cout << "CondDBESSource Statistics" << std::endl
274  << "DataProxy " << m_stats.nData
275  << " setInterval " << m_stats.nSet
276  << " Runs " << m_stats.nRun
277  << " Lumis " << m_stats.nLumi
278  << " Refresh " << m_stats.nRefresh
279  << " Actual Refresh " << m_stats.nActualRefresh
280  << " Reconnect " << m_stats.nReconnect
281  << " Actual Reconnect " << m_stats.nActualReconnect;
282  std::cout << std::endl;
283 
284 
285  ProxyMap::iterator b= m_proxies.begin();
286  ProxyMap::iterator e= m_proxies.end();
287  for ( ;b != e; b++ ) {
288  dumpInfo( std::cout, (*b).first, *(*b).second );
289  std::cout << "\n" << std::endl;
290  }
291 
292  // FIXME
293  // We shall eventually close transaction and session...
294  }
295 }
double b
Definition: hdecay.h:120
ProxyMap m_proxies
tuple cout
Definition: gather_cfg.py:121

Member Function Documentation

void CondDBESSource::fillList ( const std::string &  pfn,
std::vector< std::string > &  pfnList,
const unsigned int  listSize,
const std::string &  type 
)
private

Definition at line 255 of file CondDBESSource.cc.

References edm::hlt::Exception, i, split, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by CondDBESSource().

256 {
257  boost::split( listToFill, stringList, boost::is_any_of("|"), boost::token_compress_off );
258  // If it is one clone it for each GT
259  if( listToFill.size() == 1 ) {
260  for( unsigned int i=1; i<listSize; ++i ) {
261  listToFill.push_back(stringList);
262  }
263  }
264  // else if they don't match the number of GTs throw an exception
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" ) );
267  }
268 }
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
double split
Definition: MVATrainer.cc:139
void CondDBESSource::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 
)
private

Definition at line 564 of file CondDBESSource.cc.

References NewTree::fid, fillTagCollectionFromGT(), m_tagCollection, prof2calltree::prefix, cond::GTEntry_t::recordLabel(), cond::GTEntry_t::recordName(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::GTEntry_t::tagName().

Referenced by CondDBESSource().

569 {
570  std::set< cond::GTEntry_t > tagcoll;
571 
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) {
576  fillTagCollectionFromGT(*connectionString, *prefix, *postfix, *roottag, tagcoll);
577  }
578 
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();
582 
583  // FIXME the logic is a bit perverse: can be surely linearized (at least simplified!) ....
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()
593  << "\" and label \"" << tagMetadata.recordLabel()
594  << "\" with tag " << tagMetadata.tagName()
595  << "\"; from CondDBESSource::fillTagCollectionFromDB";
596  } else {
597  m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
598  }
599  }
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 ){
604  // std::cout<<"appending"<<std::endl;
605  // std::cout<<"pfn "<<replacementIter->second.pfn<<std::endl;
606  // std::cout<<"objectname "<<replacementIter->second.objectname<<std::endl;
607  // std::cout<<"tag "<<replacementIter->second.tag<<std::endl;
608  // std::cout<<"recordname "<<replacementIter->second.recordname<<std::endl;
609  m_tagCollection.insert( *replacementIter );
610  }
611 }
void fillTagCollectionFromGT(const std::string &connectionString, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::set< cond::GTEntry_t > &tagcoll)
TagCollection m_tagCollection
list fid
Definition: NewTree.py:51
void CondDBESSource::fillTagCollectionFromGT ( const std::string &  connectionString,
const std::string &  prefix,
const std::string &  postfix,
const std::string &  roottag,
std::set< cond::GTEntry_t > &  tagcoll 
)
private

Definition at line 543 of file CondDBESSource.cc.

References cond::persistency::Transaction::commit(), cond::persistency::ConnectionPool::createSession(), m_connection, cond::persistency::Session::readGlobalTag(), python.CommonUtils::session, cond::persistency::Transaction::start(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::persistency::Session::transaction().

Referenced by fillTagCollectionFromDB().

548 {
549  if ( !roottag.empty() ) {
550  if ( connectionString.empty() )
551  throw cond::Exception( std::string( "ESSource: requested global tag ") + roottag + std::string( " but not connection string given" ) );
553  session.transaction().start( true );
554  cond::persistency::GTProxy gtp = session.readGlobalTag( roottag, prefix, postfix );
555  for( const auto& gte : gtp ){
556  tagcoll.insert( gte );
557  }
558  session.transaction().commit();
559  }
560 }
void start(bool readOnly=true)
Definition: Session.cc:22
Transaction & transaction()
Definition: Session.cc:71
cond::persistency::ConnectionPool m_connection
Session createSession(const std::string &connectionString, bool writeCapable=false)
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:147
void CondDBESSource::newInterval ( const edm::eventsetup::EventSetupRecordKey iRecordType,
const edm::ValidityInterval iInterval 
)
protectedvirtual

called when a new interval of validity occurs for iRecordType

Implements edm::eventsetup::DataProxyProvider.

Definition at line 534 of file CondDBESSource.cc.

References edm::eventsetup::DataProxyProvider::invalidateProxies().

536 {
537  //LogDebug ("CondDBESSource")<<"newInterval";
538  invalidateProxies(iRecordType);
539 }
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
void CondDBESSource::registerProxies ( const edm::eventsetup::EventSetupRecordKey iRecordKey,
KeyedProxies aProxyList 
)
protectedvirtual

Implements edm::eventsetup::DataProxyProvider.

Definition at line 512 of file CondDBESSource.cc.

References b, alignCSCRings::e, combine::key, m_proxies, edm::eventsetup::EventSetupRecordKey::name(), AlCaHLTBitMon_ParallelJobs::p, and AlCaHLTBitMon_QueryRunRegistry::string.

512  {
513  std::string recordname=iRecordKey.name();
514 
515  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
516  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
517  if ( b == e) {
518  edm::LogInfo( "CondDBESSource" ) << "No DataProxy (Pluging) found for record \""<< recordname
519  << "\"; from CondDBESSource::registerProxies";
520  return;
521  }
522 
523  for (ProxyMap::const_iterator p=b;p!=e;++p) {
524  if(0 != (*p).second.get()) {
525  edm::eventsetup::TypeTag type = (*p).second->type();
526  edm::eventsetup::DataKey key( type, edm::eventsetup::IdTags((*p).second->label().c_str()) );
527  aProxyList.push_back(KeyedProxies::value_type(key,(*p).second->edmProxy()));
528  }
529  }
530 }
type
Definition: HCALResponse.h:21
Container::value_type value_type
double b
Definition: hdecay.h:120
ProxyMap m_proxies
list key
Definition: combine.py:13
void CondDBESSource::setIntervalFor ( const edm::eventsetup::EventSetupRecordKey iKey,
const edm::IOVSyncValue iTime,
edm::ValidityInterval oInterval 
)
protectedvirtual

Implements edm::EventSetupRecordIntervalFinder.

Definition at line 303 of file CondDBESSource.cc.

References cond::persistency::ConnectionPool::createReadOnlySession(), cond::TimeTypeSpecs::endValue, edm::IOVSyncValue::eventID(), edm::ValidityInterval::first(), first, cond::time::fromIOVSyncValue(), edm::ValidityInterval::invalidInterval(), edm::ValidityInterval::last(), cond::time::limitedIOVSyncValue(), edm::IOVSyncValue::luminosityBlockNumber(), m_connection, m_connectionString, m_lastLumi, m_lastRecordRuns, m_lastRun, m_policy, m_proxies, m_sessionPool, m_stats, m_tagCollection, python.multivaluedict::map(), max(), bookConverter::min, edm::eventsetup::EventSetupRecordKey::name(), CondDBESSource::Stats::nLumi, CondDBESSource::Stats::nReconnect, CondDBESSource::Stats::nRefresh, CondDBESSource::Stats::nRun, CondDBESSource::Stats::nSet, RECONNECT_EACH_RUN, REFRESH_ALWAYS, REFRESH_EACH_RUN, REFRESH_OPEN_IOVS, edm::EventID::run(), dqm_diff::start, AlCaHLTBitMon_QueryRunRegistry::string, edm::IOVSyncValue::time(), cond::TIMELIMIT(), dtNoiseCalibration_cfg::timetype, cond::timeTypeNames(), cond::timeTypeSpecs, cond::time::toIOVSyncValue(), and edm::Timestamp::value().

303  {
304 
305  std::string recordname=iKey.name();
306 
307  edm::LogInfo( "CondDBESSource" ) << "Getting data for record \""<< recordname
308  << "\" to be consumed by "<< iTime.eventID() << ", timestamp: " << iTime.time().value()
309  << "; from CondDBESSource::setIntervalFor";
310 
311  m_stats.nSet++;
312  //{
313  // not really required, keep here for the time being
314  if(iTime.eventID().run()!=m_lastRun) {
315  m_lastRun=iTime.eventID().run();
316  m_stats.nRun++;
317  }
318  if(iTime.luminosityBlockNumber()!=m_lastLumi) {
320  m_stats.nLumi++;
321  }
322  //}
323 
324  bool doRefresh = false;
326  // find out the last run number for the proxy of the specified record
327  std::map<std::string,unsigned int>::iterator iRec = m_lastRecordRuns.find( recordname );
328  if( iRec != m_lastRecordRuns.end() ){
329  unsigned int lastRecordRun = iRec->second;
330  if( lastRecordRun != m_lastRun ){
331  // a refresh is required!
332  doRefresh = true;
333  iRec->second = m_lastRun;
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";
338  }
339  } else {
340  doRefresh = true;
341  m_lastRecordRuns.insert( std::make_pair( recordname, m_lastRun ) );
342  edm::LogInfo( "CondDBESSource" ) << "Preparing refresh for record \"" << recordname
343  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
344  << "; from CondDBESSource::setIntervalFor";
345  }
346  if ( !doRefresh )
347  edm::LogInfo( "CondDBESSource" ) << "Though enabled, refresh not needed for record \"" << recordname
348  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
349  << "; from CondDBESSource::setIntervalFor";
350  } else if( m_policy == REFRESH_ALWAYS || m_policy == REFRESH_OPEN_IOVS ) {
351  doRefresh = true;
352  edm::LogInfo( "CondDBESSource" ) << "Forcing refresh for record \"" << recordname
353  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
354  << "; from CondDBESSource::setIntervalFor";
355  }
356 
358 
359  // compute the smallest interval (assume all objects have the same timetype....)
360  cond::ValidityInterval recordValidity(1,cond::TIMELIMIT);
362  bool userTime=true;
363 
364  //FIXME use equal_range
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";
370  return;
371  }
372 
373  for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
374 
375  edm::LogInfo( "CondDBESSource" ) << "Processing record \"" << recordname
376  << "\" and label \""<< pmIter->second->label()
377  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
378  << "; from CondDBESSource::setIntervalFor";
379 
380  timetype = (*pmIter).second->proxy()->timeType();
381 
382  cond::Time_t abtime = cond::time::fromIOVSyncValue( iTime, timetype );
383  userTime = ( 0 == abtime );
384 
385  //std::cout<<"abtime "<<abtime<<std::endl;
386 
387  if (userTime) return; // oInterval invalid to avoid that make is called...
388 
389 
390 
391  if( doRefresh ) {
392 
393  std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
394  TagCollection::const_iterator tcIter = m_tagCollection.find( recKey );
395  if ( tcIter == m_tagCollection.end() ) {
396  edm::LogInfo( "CondDBESSource" ) << "No Tag found for record \""<< recordname
397  << "\" and label \""<< pmIter->second->label()
398  << "\"; from CondDBESSource::setIntervalFor";
399  return;
400  }
401 
402  // first reconnect if required
403  if( m_policy == RECONNECT_EACH_RUN ) {
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;
407  //transId << "long" << m_lastRun;
408  transId << m_lastRun;
410  std::pair<std::string,std::string> tagParams = parseTag( tcIter->second.tagName() );
411  if( !tagParams.second.empty() ) connStr = tagParams.second;
412  std::map<std::string,std::pair<cond::persistency::Session,std::string> >::iterator iSess = m_sessionPool.find( connStr );
413  bool reopen = false;
414  if( iSess != m_sessionPool.end() ){
415  if( iSess->second.second != transId.str() ) {
416  // the available session is open for a different run: reopen
417  reopen = true;
418  iSess->second.second = transId.str();
419  }
420  } else {
421  // no available session: probably first run analysed...
422  iSess = m_sessionPool.insert(std::make_pair( connStr, std::make_pair( cond::persistency::Session(),transId.str()) )).first;
423  reopen = true;
424  }
425  if( reopen ){
426  iSess->second.first = m_connection.createReadOnlySession( connStr, 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";
430  }
431 
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();
440  //if( isSizeIncreased )
441  //edm::LogInfo( "CondDBESSource" ) << "After reconnecting, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
442  // << "\" was found; from CondDBESSource::setIntervalFor";
443  //m_stats.nActualReconnect += isSizeIncreased;
445  } else {
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();
452  //if( isSizeIncreased )
453  // edm::LogInfo( "CondDBESSource" ) << "After refreshing, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
454  // << "\" was found; from CondDBESSource::setIntervalFor";
455  //m_stats.nActualRefresh += isSizeIncreased;
456  m_stats.nRefresh++;
457  }
458 
459  }
460 
461  /*
462  // make oInterval valid For Ever
463  {
464  oInterval = edm::ValidityInterval(cond::toIOVSyncValue(recordValidity.first, cond::runnumber, true),
465  cond::toIOVSyncValue(recordValidity.second, cond::runnumber, false));
466  return;
467  }
468  */
469 
470  //query the IOVSequence
471  cond::ValidityInterval validity = (*pmIter).second->proxy()->setIntervalFor( abtime );
472 
473  edm::LogInfo( "CondDBESSource" ) << "Validity coming from IOV sequence for record \"" << recordname
474  << "\" and label \""<< pmIter->second->label()
475  << "\": (" << validity.first << ", " << validity.second
476  << ") for time (type: "<< cond::timeTypeNames( timetype ) << ") " << abtime
477  << "; from CondDBESSource::setIntervalFor";
478 
479  recordValidity.first = std::max(recordValidity.first,validity.first);
480  recordValidity.second = std::min(recordValidity.second,validity.second);
481  }
482 
483  if( m_policy == REFRESH_OPEN_IOVS ) {
484  doRefresh = ( recordValidity.second == cond::timeTypeSpecs[timetype].endValue );
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";
490  }
491 
492  // to force refresh we set end-value to the minimum such an IOV can extend to: current run or lumiblock
493 
494  if ( (!userTime) && recordValidity.second !=0 ) {
495  edm::IOVSyncValue start = cond::time::toIOVSyncValue(recordValidity.first, timetype, true);
496  edm::IOVSyncValue stop = doRefresh ? cond::time::limitedIOVSyncValue (iTime, timetype)
497  : cond::time::toIOVSyncValue(recordValidity.second, timetype, false);
498 
499  oInterval = edm::ValidityInterval( start, stop );
500  }
501 
502  edm::LogInfo( "CondDBESSource" ) << "Setting validity for record \"" << recordname
503  << "\" and corresponding label(s): starting at " << oInterval.first().eventID() << ", timestamp: " << oInterval.first().time().value()
504  << ", ending at "<< oInterval.last().eventID() << ", timestamp: " << oInterval.last().time().value()
505  << ", for "<< iTime.eventID() << ", timestamp: " << iTime.time().value()
506  << "; from CondDBESSource::setIntervalFor";
507 }
RunNumber_t run() const
Definition: EventID.h:42
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
const EventID & eventID() const
Definition: IOVSyncValue.h:42
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
RefreshPolicy m_policy
TimeType
Definition: Time.h:21
const IOVSyncValue & last() const
U second(std::pair< T, U > const &p)
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
Definition: Time.cc:74
std::string const & timeTypeNames(int)
Definition: Time.cc:15
unsigned long long Time_t
Definition: Time.h:16
const T & max(const T &a, const T &b)
std::map< std::string, unsigned int > m_lastRecordRuns
cond::persistency::ConnectionPool m_connection
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, TimeType timetype, bool startOrStop)
Definition: Time.cc:52
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:43
bool first
Definition: L1TdeRCT.cc:79
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
TagCollection m_tagCollection
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
std::string m_connectionString
ProxyMap m_proxies
unsigned int m_lastRun
static const ValidityInterval & invalidInterval()
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
const Timestamp & time() const
Definition: IOVSyncValue.h:44
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
Definition: Time.cc:91
volatile std::atomic< bool > shutdown_flag false
const IOVSyncValue & first() const
Time_t endValue
Definition: Time.h:46
unsigned int m_lastLumi
TimeValue_t value() const
Definition: Timestamp.h:56

Member Data Documentation

cond::persistency::ConnectionPool CondDBESSource::m_connection
private

Definition at line 57 of file CondDBESSource.h.

Referenced by CondDBESSource(), fillTagCollectionFromGT(), and setIntervalFor().

std::string CondDBESSource::m_connectionString
private

Definition at line 58 of file CondDBESSource.h.

Referenced by CondDBESSource(), and setIntervalFor().

bool CondDBESSource::m_doDump
private

Definition at line 87 of file CondDBESSource.h.

Referenced by ~CondDBESSource().

unsigned int CondDBESSource::m_lastLumi
private

Definition at line 84 of file CondDBESSource.h.

Referenced by setIntervalFor().

std::map<std::string,unsigned int> CondDBESSource::m_lastRecordRuns
private

Definition at line 68 of file CondDBESSource.h.

Referenced by setIntervalFor().

unsigned int CondDBESSource::m_lastRun
private

Definition at line 83 of file CondDBESSource.h.

Referenced by setIntervalFor().

RefreshPolicy CondDBESSource::m_policy
private

Definition at line 85 of file CondDBESSource.h.

Referenced by CondDBESSource(), and setIntervalFor().

ProxyMap CondDBESSource::m_proxies
private

Definition at line 61 of file CondDBESSource.h.

Referenced by CondDBESSource(), registerProxies(), setIntervalFor(), and ~CondDBESSource().

std::map<std::string,std::pair<cond::persistency::Session,std::string> > CondDBESSource::m_sessionPool
private

Definition at line 67 of file CondDBESSource.h.

Referenced by setIntervalFor().

Stats CondDBESSource::m_stats
private

Definition at line 81 of file CondDBESSource.h.

Referenced by CondDBESSource(), setIntervalFor(), and ~CondDBESSource().

TagCollection CondDBESSource::m_tagCollection
private

Definition at line 66 of file CondDBESSource.h.

Referenced by CondDBESSource(), fillTagCollectionFromDB(), and setIntervalFor().