CMS 3D CMS Logo

CondDBESSource.h
Go to the documentation of this file.
1 #ifndef CondCore_ESSources_CondDBESSource_h
2 #define CondCore_ESSources_CondDBESSource_h
3 //
4 // Package: CondCore/ESSources
5 // Class: CondDBESSource
6 //
7 /*
8  Description: EventSetup source module for serving data from offline database
9 */
10 //
11 // Author: Zhen Xie
12 //
13 
14 // Some comments on concurrency. Several things are working together
15 // to prevent concurrency issues when this module is executing.
16 // Some of these things are in this module and some are in the Framework.
17 // Here is a list of these things:
18 //
19 // 1. There is a single mutex that is a data member of CondDBESSource.
20 // This is locked near the beginning of setIntervalFor and also
21 // near the beginning of ::DataProxy::prefetch so that these functions
22 // will never run concurrently. All the ::DataProxy objects have a
23 // pointer to this mutex stored in their ESSourceDataProxyTemplate
24 // base class.
25 //
26 // 2. CondDBESSource contains a single SerialTaskQueue. The tasks
27 // that run the prefetch function are placed in this SerialTaskQueue.
28 // This allows only one ::DataProxy::prefetch function to run at a
29 // time. All the ::DataProxy objects have a pointer to this SerialTaskQueue
30 // stored in their ESSourceDataProxyTemplate base class. Note that
31 // locking the mutex is inside the task that runs prefetch.
32 // Since these tasks are serialized by the SerialTaskQueue,
33 // the mutex will never be locked by another prefetch call
34 // when prefetch is called. The mutex is really only protecting
35 // setIntervalFor calls from each other and from prefetch calls.
36 //
37 // 3. An ESSource is not allowed to get data from the EventSetup
38 // while its DataProxy prefetch function runs, preventing deadlocks
39 // and ensuring the mutex does not need to be recursive.
40 //
41 // 4. The WaitingTaskList in ESSourceDataProxyBase (a base class of
42 // ::DataProxy) is used to notify other tasks waiting for prefetch
43 // to complete that the data is available (other tasks created and
44 // managed by the Framework).
45 //
46 // 5. There is an atomic<bool> in ESSourceDataProxyBase which
47 // prevents the prefetch function being run more than once for the
48 // same IOV and DataProxy.
49 //
50 // 6. The Framework ensures calls are sequenced such that a call to
51 // setIntervalFor is made and completes, then all related calls to
52 // DataProxy::initializeForNewIOV are made before another call to
53 // setIntervalFor is made. It is configurable how many
54 // IOVs can be running concurrently. The Framework will not call
55 // initializeForNewIOV or start running a new IOV unless the
56 // number of active IOVs is less than that configured number.
57 //
58 // 7. The Framework guarantees that after a call is made to
59 // DataProxy::initializeForNewIOV for a particular
60 // EventSetupRecordKey and iovIndex, all calls to DataProxy::make
61 // associated with that whose data is requested will be completed
62 // and processing of luminosity blocks associated with that will
63 // be completed before another call to DataProxy::initializeForNewIOV
64 // is made for that EventSetupRecordKey and iovIndex.
65 
66 // system include files
67 #include <string>
68 #include <map>
69 #include <memory>
70 #include <set>
71 #include <mutex>
72 // user include files
74 
78 
79 namespace edm {
80  class ParameterSet;
81 }
82 
83 namespace cond {
84  class DataProxyWrapperBase;
85 }
86 
88 public:
91  typedef std::shared_ptr<cond::DataProxyWrapperBase> ProxyP;
92  typedef std::multimap<std::string, ProxyP> ProxyMap;
93 
95 
96  explicit CondDBESSource(const edm::ParameterSet&);
97  ~CondDBESSource() override;
98 
99 protected:
101 
102  KeyedProxiesVector registerProxies(const EventSetupRecordKey&, unsigned int iovIndex) override;
103 
104  void initConcurrentIOVs(const EventSetupRecordKey& key, unsigned int nConcurrentIOVs) override;
105 
106  bool isConcurrentFinder() const override { return true; }
107 
108 private:
109  // ----------member data ---------------------------
110 
113 
114  // Container of DataProxy, implemented as multi-map keyed by records
116 
117  typedef std::map<std::string, cond::GTEntry_t> TagCollection;
118  // the collections of tag, record/label used in this ESSource
120  std::map<std::string, cond::Time_t> m_refreshTimeForRecord;
121  std::map<std::string, std::pair<cond::persistency::Session, std::string> > m_sessionPool;
122  std::map<std::string, std::pair<cond::persistency::Session, std::string> > m_sessionPoolForLumiConditions;
123  std::map<std::string, cond::Time_t> m_lastRecordRuns;
124 
127 
128  struct Stats {
129  int nData;
130  int nSet;
131  int nRun;
132  int nLumi;
133  int nRefresh;
137  };
138 
140 
141  unsigned int m_lastRun;
142  unsigned int m_lastLumi;
144 
145  bool m_doDump;
146 
147 private:
148  void fillList(const std::string& pfn,
149  std::vector<std::string>& pfnList,
150  const unsigned int listSize,
151  const std::string& type);
152 
154  const std::string& prefix,
155  const std::string& postfix,
156  const std::string& roottag,
157  std::set<cond::GTEntry_t>& tagcoll,
158  cond::GTMetadata_t& gtMetadata);
159 
160  void fillTagCollectionFromDB(const std::vector<std::string>& connectionStringList,
161  const std::vector<std::string>& prefixList,
162  const std::vector<std::string>& postfixList,
163  const std::vector<std::string>& roottagList,
164  std::map<std::string, cond::GTEntry_t>& replacement,
165  cond::GTMetadata_t& gtMetadata);
166 };
167 #endif
edm::eventsetup::DataProxyProvider
Definition: DataProxyProvider.h:64
CondDBESSource::REFRESH_EACH_RUN
Definition: CondDBESSource.h:94
CondDBESSource::fillList
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
Definition: CondDBESSource.cc:297
ConnectionPool.h
CondDBESSource::m_connection
cond::persistency::ConnectionPool m_connection
Definition: CondDBESSource.h:111
CondDBESSource::Stats::nActualReconnect
int nActualReconnect
Definition: CondDBESSource.h:136
CondDBESSource::isConcurrentFinder
bool isConcurrentFinder() const override
Definition: CondDBESSource.h:106
CondDBESSource::Stats::nRun
int nRun
Definition: CondDBESSource.h:131
cond::GTMetadata_t
Definition: Types.h:101
CondDBESSource::initConcurrentIOVs
void initConcurrentIOVs(const EventSetupRecordKey &key, unsigned int nConcurrentIOVs) override
Definition: CondDBESSource.cc:591
edm
HLT enums.
Definition: AlignableModifier.h:19
CondDBESSource::TagCollection
std::map< std::string, cond::GTEntry_t > TagCollection
Definition: CondDBESSource.h:117
CondDBESSource::m_lastRun
unsigned int m_lastRun
Definition: CondDBESSource.h:141
edm::ValidityInterval
Definition: ValidityInterval.h:28
CondDBESSource::m_connectionString
std::string m_connectionString
Definition: CondDBESSource.h:112
EventSetupRecordKey
CondDBESSource::m_proxies
ProxyMap m_proxies
Definition: CondDBESSource.h:115
CondDBESSource::REFRESH_ALWAYS
Definition: CondDBESSource.h:94
edm::eventsetup::DataKey
Definition: DataKey.h:29
edm::SerialTaskQueue
Definition: SerialTaskQueue.h:67
CondDBESSource::CondDBESSource
CondDBESSource(const edm::ParameterSet &)
Definition: CondDBESSource.cc:98
CondDBESSource::NOREFRESH
Definition: CondDBESSource.h:94
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
CondDBESSource::m_doDump
bool m_doDump
Definition: CondDBESSource.h:145
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
CondDBESSource::m_sessionPoolForLumiConditions
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPoolForLumiConditions
Definition: CondDBESSource.h:122
CondDBESSource::REFRESH_OPEN_IOVS
Definition: CondDBESSource.h:94
CondDBESSource::m_lastLumi
unsigned int m_lastLumi
Definition: CondDBESSource.h:142
CondDBESSource::fillTagCollectionFromDB
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 &gtMetadata)
Definition: CondDBESSource.cc:637
CondDBESSource::m_tagCollection
TagCollection m_tagCollection
Definition: CondDBESSource.h:119
CondDBESSource
Definition: CondDBESSource.h:87
CondDBESSource::Stats::nActualRefresh
int nActualRefresh
Definition: CondDBESSource.h:134
SerialTaskQueue.h
DataProxyProvider.h
CondDBESSource::m_stats
Stats m_stats
Definition: CondDBESSource.h:139
cond::persistency::ConnectionPool
Definition: ConnectionPool.h:35
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
CondDBESSource::m_policy
RefreshPolicy m_policy
Definition: CondDBESSource.h:143
EventSetupRecordIntervalFinder.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CondDBESSource::Stats::nRefresh
int nRefresh
Definition: CondDBESSource.h:133
cond
Definition: plugin.cc:23
edm::ParameterSet
Definition: ParameterSet.h:47
ParameterSet
Definition: Functions.h:16
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
CondDBESSource::RECONNECT_EACH_RUN
Definition: CondDBESSource.h:94
mutex
static std::mutex mutex
Definition: Proxy.cc:8
CondDBESSource::RefreshPolicy
RefreshPolicy
Definition: CondDBESSource.h:94
CondDBESSource::setIntervalFor
void setIntervalFor(const EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Definition: CondDBESSource.cc:341
CondDBESSource::Stats::nSet
int nSet
Definition: CondDBESSource.h:130
edm::eventsetup::DataProxyProvider::KeyedProxiesVector
std::vector< std::pair< DataKey, std::shared_ptr< DataProxy > >> KeyedProxiesVector
Definition: DataProxyProvider.h:196
CondDBESSource::registerProxies
KeyedProxiesVector registerProxies(const EventSetupRecordKey &, unsigned int iovIndex) override
Definition: CondDBESSource.cc:567
CondDBESSource::fillTagCollectionFromGT
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 &gtMetadata)
Definition: CondDBESSource.cc:603
CondDBESSource::m_mutex
std::mutex m_mutex
Definition: CondDBESSource.h:126
CondDBESSource::ProxyMap
std::multimap< std::string, ProxyP > ProxyMap
Definition: CondDBESSource.h:92
CondDBESSource::Stats::nReconnect
int nReconnect
Definition: CondDBESSource.h:135
CondDBESSource::Stats::nData
int nData
Definition: CondDBESSource.h:129
CondDBESSource::m_refreshTimeForRecord
std::map< std::string, cond::Time_t > m_refreshTimeForRecord
Definition: CondDBESSource.h:120
CondDBESSource::~CondDBESSource
~CondDBESSource() override
Definition: CondDBESSource.cc:315
CondDBESSource::ProxyP
std::shared_ptr< cond::DataProxyWrapperBase > ProxyP
Definition: CondDBESSource.h:91
CondDBESSource::m_lastRecordRuns
std::map< std::string, cond::Time_t > m_lastRecordRuns
Definition: CondDBESSource.h:123
l1RCTOmdsFedVectorProducer_cfi.connectionString
connectionString
Definition: l1RCTOmdsFedVectorProducer_cfi.py:4
CondDBESSource::Stats::nLumi
int nLumi
Definition: CondDBESSource.h:132
crabWrapper.key
key
Definition: crabWrapper.py:19
CondDBESSource::Stats
Definition: CondDBESSource.h:128
CondDBESSource::m_sessionPool
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
Definition: CondDBESSource.h:121
CondDBESSource::m_queue
edm::SerialTaskQueue m_queue
Definition: CondDBESSource.h:125
ZMuMuAnalysisNtupler_cff.prefix
prefix
Definition: ZMuMuAnalysisNtupler_cff.py:14