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 ::ProductResolver::prefetch so that these functions
22 // will never run concurrently. All the ::ProductResolver objects have a
23 // pointer to this mutex stored in their ESSourceProductResolverTemplate
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 ::ProductResolver::prefetch function to run at a
29 // time. All the ::ProductResolver objects have a pointer to this SerialTaskQueue
30 // stored in their ESSourceProductResolverTemplate 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 ProductResolver prefetch function runs, preventing deadlocks
39 // and ensuring the mutex does not need to be recursive.
40 //
41 // 4. The WaitingTaskList in ESSourceProductResolverBase (a base class of
42 // ::ProductResolver) 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 ESSourceProductResolverBase which
47 // prevents the prefetch function being run more than once for the
48 // same IOV and ProductResolver.
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 // ProductResolver::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 // ProductResolver::initializeForNewIOV for a particular
60 // EventSetupRecordKey and iovIndex, all calls to ProductResolver::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 ProductResolver::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 ProductResolverWrapperBase;
85 }
86 
88 public:
91  typedef std::shared_ptr<cond::ProductResolverWrapperBase> ResolverP;
92  typedef std::multimap<std::string, ResolverP> ResolverMap;
93 
95 
96  explicit CondDBESSource(const edm::ParameterSet&);
97  ~CondDBESSource() override;
98 
99 protected:
101 
102  KeyedResolversVector registerResolvers(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 
114 
115  // Container of ProductResolver, implemented as multi-map keyed by records
117 
118  typedef std::map<std::string, cond::GTEntry_t> TagCollection;
119  // the collections of tag, record/label used in this ESSource
121  std::map<std::string, std::pair<cond::Time_t, bool> > m_refreshTimeForRecord;
122  std::map<std::string, std::pair<cond::persistency::Session, std::string> > m_sessionPool;
123  std::map<std::string, std::pair<cond::persistency::Session, std::string> > m_sessionPoolForLumiConditions;
124  std::map<std::string, unsigned int> m_lastRecordRuns;
125 
128 
129  struct Stats {
130  int nData;
131  int nSet;
132  int nRun;
133  int nLumi;
134  int nRefresh;
138  };
139 
141 
142  unsigned int m_lastRun;
143  unsigned int m_lastLumi;
145 
146  bool m_doDump;
147 
148 private:
149  void fillList(const std::string& pfn,
150  std::vector<std::string>& pfnList,
151  const unsigned int listSize,
152  const std::string& type);
153 
155  const std::string& prefix,
156  const std::string& postfix,
157  const std::string& roottag,
158  std::set<cond::GTEntry_t>& tagcoll,
159  cond::GTMetadata_t& gtMetadata);
160 
161  void fillTagCollectionFromDB(const std::vector<std::string>& connectionStringList,
162  const std::vector<std::string>& prefixList,
163  const std::vector<std::string>& postfixList,
164  const std::vector<std::string>& roottagList,
165  std::map<std::string, cond::GTEntry_t>& replacement,
166  cond::GTMetadata_t& gtMetadata);
167 };
168 #endif
std::map< std::string, std::pair< cond::Time_t, bool > > m_refreshTimeForRecord
ResolverMap m_resolvers
std::mutex m_mutex
std::multimap< std::string, ResolverP > ResolverMap
std::map< std::string, cond::GTEntry_t > TagCollection
std::shared_ptr< cond::ProductResolverWrapperBase > ResolverP
static std::mutex mutex
Definition: Proxy.cc:8
void setIntervalFor(const EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
RefreshPolicy m_policy
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)
edm::SerialTaskQueue m_queue
cond::persistency::ConnectionPool m_connection
void initConcurrentIOVs(const EventSetupRecordKey &key, unsigned int nConcurrentIOVs) override
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPoolForLumiConditions
TagCollection m_tagCollection
~CondDBESSource() override
std::vector< std::pair< DataKey, std::shared_ptr< ESProductResolver > >> KeyedResolversVector
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)
std::string m_connectionString
Definition: plugin.cc:23
HLT enums.
unsigned int m_lastRun
std::string m_frontierKey
CondDBESSource(const edm::ParameterSet &)
bool isConcurrentFinder() const override
std::map< std::string, unsigned int > m_lastRecordRuns
KeyedResolversVector registerResolvers(const EventSetupRecordKey &, unsigned int iovIndex) override
unsigned int m_lastLumi