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::TagMetadata
TagCollection
 

Private Member Functions

void fillTagCollectionFromDB (const std::string &coraldb, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::map< std::string, cond::TagMetadata > &replacement)
 

Private Attributes

cond::DbConnection m_connection
 
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::DbSession,
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 34 of file CondDBESSource.h.

Member Typedef Documentation

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

Definition at line 38 of file CondDBESSource.h.

Definition at line 37 of file CondDBESSource.h.

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

Definition at line 65 of file CondDBESSource.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

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

required by eventsetup

Definition at line 110 of file CondDBESSource.cc.

References b, cond::DbConnection::configuration(), cond::DbConnection::configure(), cond::DbConnection::createSession(), alignCSCRings::e, edm::ParameterSet::exists(), fillTagCollectionFromDB(), edm::EventSetupRecordIntervalFinder::findingRecordWithKey(), edm::eventsetup::heterocontainer::HCTypeTag::findType(), reco::get(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), align_cfg::globaltag, cond::TagMetadata::labelname, m_connection, m_policy, m_proxies, m_stats, m_tagCollection, CondDBESSource::Stats::nData, cond::DbSession::openReadOnly(), cond::TagMetadata::pfn, RECONNECT_EACH_RUN, cond::TagMetadata::recordname, REFRESH_ALWAYS, REFRESH_EACH_RUN, REFRESH_OPEN_IOVS, alignCSCRings::s, cond::DbConnectionConfiguration::setParameters(), cond::TagMetadata::tag, convertSQLitetoXML_cfg::toGet, edm::eventsetup::EventSetupRecordKey::type(), and edm::eventsetup::DataProxyProvider::usingRecordWithKey().

110  :
111  m_connection(),
112  m_lastRun(0), // for the stat
113  m_lastLumi(0), // for the stat
114  m_policy( NOREFRESH ),
115  m_doDump( iConfig.getUntrackedParameter<bool>( "DumpStat", false ) )
116 {
117  if( iConfig.getUntrackedParameter<bool>( "RefreshAlways", false ) ) {
119  }
120  if( iConfig.getUntrackedParameter<bool>( "RefreshOpenIOVs", false ) ) {
122  }
123  if( iConfig.getUntrackedParameter<bool>( "RefreshEachRun", false ) ) {
125  }
126  if( iConfig.getUntrackedParameter<bool>( "ReconnectEachRun", false ) ) {
128  }
129 
130  Stats s = {0,0,0,0,0,0,0,0};
131  m_stats = s;
132  //std::cout<<"CondDBESSource::CondDBESSource"<<std::endl;
133  /*parameter set parsing and pool environment setting
134  */
135 
136  // default connection string
137  // inproduction used for the global tag
138  std::string userconnect= iConfig.getParameter<std::string>("connect");
139 
140 
141  // connection configuration
142  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>( "DBParameters" );
143  m_connection.configuration().setParameters( connectionPset );
145 
146 
147  // load additional record/tag info it will overwrite the global tag
148  std::map<std::string,cond::TagMetadata> replacement;
149  if( iConfig.exists( "toGet" ) ) {
150  typedef std::vector< edm::ParameterSet > Parameters;
151  Parameters toGet = iConfig.getParameter<Parameters>( "toGet" );
152  for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
154  nm.recordname = itToGet->getParameter<std::string>( "record" );
155  nm.labelname = itToGet->getUntrackedParameter<std::string>( "label", "" );
156  nm.tag = itToGet->getParameter<std::string>( "tag" );
157  nm.pfn = itToGet->getUntrackedParameter<std::string>( "connect", userconnect );
158  // nm.objectname=itFound->second;
159  std::string recordLabelKey = joinRecordAndLabel( nm.recordname, nm.labelname );
160  replacement.insert( std::pair<std::string,cond::TagMetadata>( recordLabelKey, nm ) );
161  }
162  }
163 
164  // get the global tag, merge with "replacement" store in "tagCollection"
165  std::string globaltag;
166  if( iConfig.exists( "globaltag" ) )
167  globaltag = iConfig.getParameter<std::string>( "globaltag" );
168 
169  fillTagCollectionFromDB(userconnect,
170  iConfig.getUntrackedParameter<std::string>( "pfnPrefix", "" ),
171  iConfig.getUntrackedParameter<std::string>( "pfnPostfix", "" ),
172  globaltag,
173  replacement);
174 
175 
176  TagCollection::iterator it;
177  TagCollection::iterator itBeg = m_tagCollection.begin();
178  TagCollection::iterator itEnd = m_tagCollection.end();
179 
180  std::map<std::string, cond::DbSession> sessions;
181 
182  /* load DataProxy Plugin (it is strongly typed due to EventSetup ideosyncrasis)
183  * construct proxy
184  * contrary to EventSetup the "object-name" is not used as identifier: multiple entries in a record are
185  * dinstinguished only by their label...
186  * done in two step: first create ProxyWrapper loading ALL required dictionaries
187  * this will allow to initialize POOL in one go for each "database"
188  * The real initialization of the Data-Proxies is done in the second loop
189  */
190  std::vector<cond::DataProxyWrapperBase *> proxyWrappers(m_tagCollection.size());
191  size_t ipb=0;
192  for(it=itBeg;it!=itEnd;++it){
193  proxyWrappers[ipb++] =
194  cond::ProxyFactory::get()->create(buildName(it->second.recordname));
195  }
196  // now all required libraries have been loaded
197  // init sessions and DataProxies
198  ipb=0;
199  for(it=itBeg;it!=itEnd;++it){
200  std::map<std::string, cond::DbSession>::iterator p = sessions.find( it->second.pfn );
201  cond::DbSession nsess;
202  if (p==sessions.end()) {
203  //open db get tag info (i.e. the IOV token...)
204  nsess = m_connection.createSession();
205  nsess.openReadOnly( it->second.pfn, "" );
206  sessions.insert(std::make_pair(it->second.pfn,nsess));
207  } else nsess = (*p).second;
208  //cond::MetaData metadata(nsess);
209  //nsess.transaction().start(true);
210  //std::string iovtoken = metadata.getToken(it->tag);
211  // owenship...
212  ProxyP proxy(proxyWrappers[ipb++]);
213  // instert in the map
214  m_proxies.insert(std::make_pair(it->second.recordname, proxy));
215  // initialize
216  //proxy->lateInit(nsess,iovtoken,
217  // it->labelname, it->pfn, it->tag
218  // );
219  proxy->lateInit(nsess,it->second.tag,
220  it->second.labelname, it->second.pfn);
221  //nsess.transaction().commit();
222  }
223 
224  // one loaded expose all other tags to the Proxy!
225  CondGetterFromESSource visitor( m_proxies );
226  ProxyMap::iterator b = m_proxies.begin();
227  ProxyMap::iterator e = m_proxies.end();
228  for ( ;b != e; b++ ) {
229 
230  (*b).second->proxy()->loadMore( visitor );
231 
234  if( recordKey.type() != edm::eventsetup::EventSetupRecordKey::TypeTag() ) {
235  findingRecordWithKey( recordKey );
236  usingRecordWithKey( recordKey );
237  }
238  }
239 
240  m_stats.nData=m_proxies.size();
241 
242 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
list globaltag
Definition: align_cfg.py:7
void openReadOnly(const std::string &connectionString, const std::string &id)
Definition: DbSession.cc:155
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:89
bool exists(std::string const &parameterName) const
checks if a parameter exists
void usingRecordWithKey(const EventSetupRecordKey &)
cond::DbConnection m_connection
RefreshPolicy m_policy
void setParameters(const edm::ParameterSet &connectionPset)
void fillTagCollectionFromDB(const std::string &coraldb, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::map< std::string, cond::TagMetadata > &replacement)
std::string labelname
Definition: TagMetadata.h:11
std::string tag
Definition: TagMetadata.h:8
vector< ParameterSet > Parameters
TagCollection m_tagCollection
DbSession createSession() const
Definition: DbConnection.cc:72
double b
Definition: hdecay.h:120
std::string pfn
Definition: TagMetadata.h:9
heterocontainer::HCTypeTag TypeTag
ProxyMap m_proxies
unsigned int m_lastRun
std::string recordname
Definition: TagMetadata.h:10
unsigned int m_lastLumi
boost::shared_ptr< cond::DataProxyWrapperBase > ProxyP
T get(const Candidate &c)
Definition: component.h:56
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:129
CondDBESSource::~CondDBESSource ( )

Definition at line 245 of file CondDBESSource.cc.

References b, gather_cfg::cout, alignCSCRings::e, cond::BasePayloadProxy::gstats, 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.

245  {
246  //dump info FIXME: find a more suitable place...
247  if (m_doDump) {
248  std::cout << "CondDBESSource Statistics" << std::endl
249  << "DataProxy " << m_stats.nData
250  << " setInterval " << m_stats.nSet
251  << " Runs " << m_stats.nRun
252  << " Lumis " << m_stats.nLumi
253  << " Refresh " << m_stats.nRefresh
254  << " Actual Refresh " << m_stats.nActualRefresh
255  << " Reconnect " << m_stats.nReconnect
256  << " Actual Reconnect " << m_stats.nActualReconnect;
257  std::cout << std::endl;
258  std::cout << "Global Proxy Statistics" << std::endl
259  << "proxy " << cond::BasePayloadProxy::gstats.nProxy
260  << " make " << cond::BasePayloadProxy::gstats.nMake
261  << " load " << cond::BasePayloadProxy::gstats.nLoad;
262  std::cout << std::endl;
263 
264 
265  ProxyMap::iterator b= m_proxies.begin();
266  ProxyMap::iterator e= m_proxies.end();
267  for ( ;b != e; b++ ) {
268  dumpInfo( std::cout, (*b).first, *(*b).second );
269  std::cout << "\n" << std::endl;
270  }
271 
272  // FIXME
273  // We shall eventually close transaction and session...
274  }
275 }
double b
Definition: hdecay.h:120
ProxyMap m_proxies
tuple cout
Definition: gather_cfg.py:121

Member Function Documentation

void CondDBESSource::fillTagCollectionFromDB ( const std::string &  coraldb,
const std::string &  prefix,
const std::string &  postfix,
const std::string &  roottag,
std::map< std::string, cond::TagMetadata > &  replacement 
)
private

Definition at line 523 of file CondDBESSource.cc.

References cond::DbTransaction::commit(), cond::Auth::COND_READER_ROLE, cond::DbConnection::createSession(), NewTree::fid, cond::TagCollectionRetriever::getTagCollection(), cond::TagMetadata::labelname, m_connection, m_tagCollection, cond::TagMetadata::objectname, cond::DbSession::open(), cond::TagMetadata::pfn, cond::TagMetadata::recordname, python.CommonUtils::session, cond::DbTransaction::start(), cond::TagMetadata::tag, and cond::DbSession::transaction().

Referenced by CondDBESSource().

527  {
528 
529  std::set< cond::TagMetadata > tagcoll;
530 
531  if ( !roottag.empty() ) {
532  if ( coraldb.empty() )
533  throw cond::Exception( std::string( "ESSource: requested global tag ") + roottag + std::string( " but not connection string given" ) );
535  session.open( coraldb, cond::Auth::COND_READER_ROLE, true );
536  session.transaction().start( true );
537  cond::TagCollectionRetriever tagRetriever( session, prefix, postfix );
538  tagRetriever.getTagCollection( roottag,tagcoll );
539  session.transaction().commit();
540  }
541 
542  std::set<cond::TagMetadata>::iterator tagCollIter;
543  std::set<cond::TagMetadata>::iterator tagCollBegin = tagcoll.begin();
544  std::set<cond::TagMetadata>::iterator tagCollEnd = tagcoll.end();
545 
546  // FIXME the logic is a bit perverse: can be surely linearized (at least simplified!) ....
547  for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
548  std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordname, tagCollIter->labelname );
549  std::map<std::string,cond::TagMetadata>::iterator fid = replacement.find( recordLabelKey );
550  if( fid != replacement.end() ) {
551  cond::TagMetadata tagMetadata;
552  tagMetadata.recordname = tagCollIter->recordname;
553  tagMetadata.labelname = tagCollIter->labelname;
554  tagMetadata.pfn = fid->second.pfn;
555  tagMetadata.tag = fid->second.tag;
556  tagMetadata.objectname = tagCollIter->objectname;
557  m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
558  replacement.erase( fid );
559  edm::LogInfo( "CondDBESSource" ) << "Replacing connection string \"" << tagCollIter->pfn
560  << "\" and tag \"" << tagCollIter->tag
561  << "\" for record \"" << tagMetadata.recordname
562  << "\" and label \"" << tagMetadata.labelname
563  << "\" with connection string \"" << tagMetadata.pfn
564  << "\" and tag " << tagMetadata.tag
565  << "\"; from CondDBESSource::fillTagCollectionFromDB";
566  } else {
567  m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
568  }
569  }
570  std::map<std::string,cond::TagMetadata>::iterator replacementIter;
571  std::map<std::string,cond::TagMetadata>::iterator replacementBegin = replacement.begin();
572  std::map<std::string,cond::TagMetadata>::iterator replacementEnd = replacement.end();
573  for( replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter ){
574  //std::cout<<"appending"<<std::endl;
575  //std::cout<<"pfn "<<replacementIter->second.pfn<<std::endl;
576  //std::cout<<"objectname "<<replacementIter->second.objectname<<std::endl;
577  //std::cout<<"tag "<<replacementIter->second.tag<<std::endl;
578  //std::cout<<"recordname "<<replacementIter->second.recordname<<std::endl;
579  m_tagCollection.insert( *replacementIter );
580  }
581 }
DbTransaction & transaction()
Definition: DbSession.cc:189
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:144
int commit()
commit transaction.
std::string objectname
Definition: TagMetadata.h:12
cond::DbConnection m_connection
std::string labelname
Definition: TagMetadata.h:11
int start(bool readOnly=false)
start transaction
std::string tag
Definition: TagMetadata.h:8
static const std::string COND_READER_ROLE
Definition: Auth.h:19
TagCollection m_tagCollection
DbSession createSession() const
Definition: DbConnection.cc:72
std::string pfn
Definition: TagMetadata.h:9
std::string recordname
Definition: TagMetadata.h:10
list fid
Definition: NewTree.py:51
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 513 of file CondDBESSource.cc.

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

515 {
516  //LogDebug ("CondDBESSource")<<"newInterval";
517  invalidateProxies(iRecordType);
518 }
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
void CondDBESSource::registerProxies ( const edm::eventsetup::EventSetupRecordKey iRecordKey,
KeyedProxies aProxyList 
)
protectedvirtual

Implements edm::eventsetup::DataProxyProvider.

Definition at line 491 of file CondDBESSource.cc.

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

491  {
492  std::string recordname=iRecordKey.name();
493 
494  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
495  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
496  if ( b == e) {
497  edm::LogInfo( "CondDBESSource" ) << "No DataProxy (Pluging) found for record \""<< recordname
498  << "\"; from CondDBESSource::registerProxies";
499  return;
500  }
501 
502  for (ProxyMap::const_iterator p=b;p!=e;++p) {
503  if(0 != (*p).second.get()) {
504  edm::eventsetup::TypeTag type = (*p).second->type();
505  edm::eventsetup::DataKey key( type, edm::eventsetup::IdTags((*p).second->label().c_str()) );
506  aProxyList.push_back(KeyedProxies::value_type(key,(*p).second->edmProxy()));
507  }
508  }
509 }
type
Definition: HCALResponse.h:22
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 283 of file CondDBESSource.cc.

References cond::DbConnection::createSession(), cond::TimeTypeSpecs::endValue, edm::IOVSyncValue::eventID(), edm::ValidityInterval::first(), cond::fromIOVSyncValue(), edm::ValidityInterval::invalidInterval(), edm::ValidityInterval::last(), cond::limitedIOVSyncValue(), edm::IOVSyncValue::luminosityBlockNumber(), m_connection, m_lastLumi, m_lastRecordRuns, m_lastRun, m_policy, m_proxies, m_sessionPool, m_stats, m_tagCollection, max(), min, CondDBESSource::Stats::nActualReconnect, CondDBESSource::Stats::nActualRefresh, edm::eventsetup::EventSetupRecordKey::name(), CondDBESSource::Stats::nLumi, CondDBESSource::Stats::nReconnect, CondDBESSource::Stats::nRefresh, CondDBESSource::Stats::nRun, CondDBESSource::Stats::nSet, cond::DbSession::openReadOnly(), RECONNECT_EACH_RUN, REFRESH_ALWAYS, REFRESH_EACH_RUN, REFRESH_OPEN_IOVS, edm::EventID::run(), errorMatrix2Lands_multiChannel::start, edm::IOVSyncValue::time(), cond::TIMELIMIT(), dtNoiseCalibration_cfg::timetype, cond::timeTypeNames(), cond::timeTypeSpecs, cond::toIOVSyncValue(), and edm::Timestamp::value().

283  {
284 
285  std::string recordname=iKey.name();
286 
287  edm::LogInfo( "CondDBESSource" ) << "Getting data for record \""<< recordname
288  << "\" to be consumed by "<< iTime.eventID() << ", timestamp: " << iTime.time().value()
289  << "; from CondDBESSource::setIntervalFor";
290 
291  m_stats.nSet++;
292  //{
293  // not really required, keep here for the time being
294  if(iTime.eventID().run()!=m_lastRun) {
295  m_lastRun=iTime.eventID().run();
296  m_stats.nRun++;
297  }
298  if(iTime.luminosityBlockNumber()!=m_lastLumi) {
300  m_stats.nLumi++;
301  }
302  //}
303 
304  bool doRefresh = false;
306  // find out the last run number for the proxy of the specified record
307  std::map<std::string,unsigned int>::iterator iRec = m_lastRecordRuns.find( recordname );
308  if( iRec != m_lastRecordRuns.end() ){
309  unsigned int lastRecordRun = iRec->second;
310  if( lastRecordRun != m_lastRun ){
311  // a refresh is required!
312  doRefresh = true;
313  iRec->second = m_lastRun;
314  edm::LogInfo( "CondDBESSource" ) << "Preparing refresh for record \"" << recordname
315  << "\" since there has been a transition from run "
316  << lastRecordRun << " to run " << m_lastRun
317  << "; from CondDBESSource::setIntervalFor";
318  }
319  } else {
320  doRefresh = true;
321  m_lastRecordRuns.insert( std::make_pair( recordname, m_lastRun ) );
322  edm::LogInfo( "CondDBESSource" ) << "Preparing refresh for record \"" << recordname
323  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
324  << "; from CondDBESSource::setIntervalFor";
325  }
326  if ( !doRefresh )
327  edm::LogInfo( "CondDBESSource" ) << "Though enabled, refresh not needed for record \"" << recordname
328  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
329  << "; from CondDBESSource::setIntervalFor";
330  } else if( m_policy == REFRESH_ALWAYS || m_policy == REFRESH_OPEN_IOVS ) {
331  doRefresh = true;
332  edm::LogInfo( "CondDBESSource" ) << "Forcing refresh for record \"" << recordname
333  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
334  << "; from CondDBESSource::setIntervalFor";
335  }
336 
338 
339  // compute the smallest interval (assume all objects have the same timetype....)
340  cond::ValidityInterval recordValidity(1,cond::TIMELIMIT);
342  bool userTime=true;
343 
344  //FIXME use equal_range
345  ProxyMap::const_iterator pmBegin = m_proxies.lower_bound(recordname);
346  ProxyMap::const_iterator pmEnd = m_proxies.upper_bound(recordname);
347  if ( pmBegin == pmEnd ) {
348  edm::LogInfo( "CondDBESSource" ) << "No DataProxy (Pluging) found for record \""<< recordname
349  << "\"; from CondDBESSource::setIntervalFor";
350  return;
351  }
352 
353  for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
354 
355  edm::LogInfo( "CondDBESSource" ) << "Processing record \"" << recordname
356  << "\" and label \""<< pmIter->second->label()
357  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
358  << "; from CondDBESSource::setIntervalFor";
359 
360  timetype = (*pmIter).second->proxy()->timetype();
361 
362  cond::Time_t abtime = cond::fromIOVSyncValue( iTime, timetype );
363  userTime = ( 0 == abtime );
364 
365  //std::cout<<"abtime "<<abtime<<std::endl;
366 
367  if (userTime) return; // oInterval invalid to avoid that make is called...
368 
369 
370 
371  if( doRefresh ) {
372 
373  std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
374  TagCollection::const_iterator tcIter = m_tagCollection.find( recKey );
375  if ( tcIter == m_tagCollection.end() ) {
376  edm::LogInfo( "CondDBESSource" ) << "No Tag found for record \""<< recordname
377  << "\" and label \""<< pmIter->second->label()
378  << "\"; from CondDBESSource::setIntervalFor";
379  return;
380  }
381 
382  // first reconnect if required
383  if( m_policy == RECONNECT_EACH_RUN ) {
384  edm::LogInfo( "CondDBESSource" ) << "Checking if the session must be closed and re-opened for getting correct conditions"
385  << "; from CondDBESSource::setIntervalFor";
386  std::stringstream transId;
387  //transId << "long" << m_lastRun;
388  transId << m_lastRun;
389  std::map<std::string,std::pair<cond::DbSession,std::string> >::iterator iSess = m_sessionPool.find( tcIter->second.pfn );
390  cond::DbSession theSession;
391  bool reopen = false;
392  if( iSess != m_sessionPool.end() ){
393  if( iSess->second.second != transId.str() ) {
394  // the available session is open for a different run: reopen
395  reopen = true;
396  iSess->second.second = transId.str();
397  }
398  theSession = iSess->second.first;
399  } else {
400  // no available session: probably first run analysed...
401  theSession = m_connection.createSession();
402  m_sessionPool.insert(std::make_pair( tcIter->second.pfn,std::make_pair(theSession,transId.str()) ));
403  reopen = true;
404  }
405  if( reopen ){
406  theSession.openReadOnly( tcIter->second.pfn, transId.str() );
407  edm::LogInfo( "CondDBESSource" ) << "Re-opening the session with connection string " << tcIter->second.pfn
408  << " and new transaction Id " << transId.str()
409  << "; from CondDBESSource::setIntervalFor";
410  }
411 
412  edm::LogInfo( "CondDBESSource" ) << "Reconnecting to \"" << tcIter->second.pfn
413  << "\" for getting new payload for record \"" << recordname
414  << "\" and label \""<< pmIter->second->label()
415  << "\" from IOV tag \"" << tcIter->second.tag
416  << "\" to be consumed by " << iTime.eventID() << ", timestamp: " << iTime.time().value()
417  << "; from CondDBESSource::setIntervalFor";
418  bool isSizeIncreased = pmIter->second->proxy()->refresh( theSession );
419  if( isSizeIncreased )
420  edm::LogInfo( "CondDBESSource" ) << "After reconnecting, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
421  << "\" was found; from CondDBESSource::setIntervalFor";
422  m_stats.nActualReconnect += isSizeIncreased;
424  } else {
425  edm::LogInfo( "CondDBESSource" ) << "Refreshing IOV sequence labeled by tag \"" << tcIter->second.tag
426  << "\" for getting new payload for record \"" << recordname
427  << "\" and label \""<< pmIter->second->label()
428  << "\" to be consumed by " << iTime.eventID() << ", timestamp: " << iTime.time().value()
429  << "; from CondDBESSource::setIntervalFor";
430  bool isSizeIncreased = pmIter->second->proxy()->refresh();
431  if( isSizeIncreased )
432  edm::LogInfo( "CondDBESSource" ) << "After refreshing, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
433  << "\" was found; from CondDBESSource::setIntervalFor";
434  m_stats.nActualRefresh += isSizeIncreased;
435  m_stats.nRefresh++;
436  }
437 
438  }
439 
440  /*
441  // make oInterval valid For Ever
442  {
443  oInterval = edm::ValidityInterval(cond::toIOVSyncValue(recordValidity.first, cond::runnumber, true),
444  cond::toIOVSyncValue(recordValidity.second, cond::runnumber, false));
445  return;
446  }
447  */
448 
449  //query the IOVSequence
450  cond::ValidityInterval validity = (*pmIter).second->proxy()->setIntervalFor( abtime );
451 
452  edm::LogInfo( "CondDBESSource" ) << "Validity coming from IOV sequence for record \"" << recordname
453  << "\" and label \""<< pmIter->second->label()
454  << "\": (" << validity.first << ", " << validity.second
455  << ") for time (type: "<< cond::timeTypeNames( timetype ) << ") " << abtime
456  << "; from CondDBESSource::setIntervalFor";
457 
458  recordValidity.first = std::max(recordValidity.first,validity.first);
459  recordValidity.second = std::min(recordValidity.second,validity.second);
460  }
461 
462  if( m_policy == REFRESH_OPEN_IOVS ) {
463  doRefresh = ( recordValidity.second == cond::timeTypeSpecs[timetype].endValue );
464  edm::LogInfo( "CondDBESSource" ) << "Validity for record \"" << recordname
465  << "\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
466  << ", "<< recordValidity.first
467  << ") as the last IOV element in the IOV sequence is infinity"
468  << "; from CondDBESSource::setIntervalFor";
469  }
470 
471  // to force refresh we set end-value to the minimum such an IOV can extend to: current run or lumiblock
472 
473  if ( (!userTime) && recordValidity.second !=0 ) {
474  edm::IOVSyncValue start = cond::toIOVSyncValue(recordValidity.first, timetype, true);
475  edm::IOVSyncValue stop = doRefresh ? cond::limitedIOVSyncValue (iTime, timetype)
476  : cond::toIOVSyncValue(recordValidity.second, timetype, false);
477 
478  oInterval = edm::ValidityInterval( start, stop );
479  }
480 
481  edm::LogInfo( "CondDBESSource" ) << "Setting validity for record \"" << recordname
482  << "\" and corresponding label(s): starting at " << oInterval.first().eventID() << ", timestamp: " << oInterval.first().time().value()
483  << ", ending at "<< oInterval.last().eventID() << ", timestamp: " << oInterval.last().time().value()
484  << ", for "<< iTime.eventID() << ", timestamp: " << iTime.time().value()
485  << "; from CondDBESSource::setIntervalFor";
486 }
RunNumber_t run() const
Definition: EventID.h:42
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
edm::IOVSyncValue limitedIOVSyncValue(cond::Time_t time, cond::TimeType timetype)
const EventID & eventID() const
Definition: IOVSyncValue.h:42
std::map< std::string, std::pair< cond::DbSession, std::string > > m_sessionPool
void openReadOnly(const std::string &connectionString, const std::string &id)
Definition: DbSession.cc:155
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
#define min(a, b)
Definition: mlp_lapack.h:161
cond::DbConnection m_connection
RefreshPolicy m_policy
TimeType
Definition: Time.h:21
const IOVSyncValue & last() const
U second(std::pair< T, U > const &p)
std::string const & timeTypeNames(int)
Definition: Time.cc:15
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, cond::TimeType timetype, bool startOrStop)
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
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:43
TimeValue_t value() const
Definition: Timestamp.cc:72
TagCollection m_tagCollection
DbSession createSession() const
Definition: DbConnection.cc:72
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
ProxyMap m_proxies
unsigned int m_lastRun
static const ValidityInterval & invalidInterval()
const Timestamp & time() const
Definition: IOVSyncValue.h:44
cond::Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, cond::TimeType timetype)
const IOVSyncValue & first() const
Time_t endValue
Definition: Time.h:46
unsigned int m_lastLumi

Member Data Documentation

cond::DbConnection CondDBESSource::m_connection
private

Definition at line 59 of file CondDBESSource.h.

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

bool CondDBESSource::m_doDump
private

Definition at line 88 of file CondDBESSource.h.

Referenced by ~CondDBESSource().

unsigned int CondDBESSource::m_lastLumi
private

Definition at line 85 of file CondDBESSource.h.

Referenced by setIntervalFor().

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

Definition at line 69 of file CondDBESSource.h.

Referenced by setIntervalFor().

unsigned int CondDBESSource::m_lastRun
private

Definition at line 84 of file CondDBESSource.h.

Referenced by setIntervalFor().

RefreshPolicy CondDBESSource::m_policy
private

Definition at line 86 of file CondDBESSource.h.

Referenced by CondDBESSource(), and setIntervalFor().

ProxyMap CondDBESSource::m_proxies
private

Definition at line 62 of file CondDBESSource.h.

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

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

Definition at line 68 of file CondDBESSource.h.

Referenced by setIntervalFor().

Stats CondDBESSource::m_stats
private

Definition at line 82 of file CondDBESSource.h.

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

TagCollection CondDBESSource::m_tagCollection
private

Definition at line 67 of file CondDBESSource.h.

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