CMS 3D CMS Logo

PoolDBOutputService.h
Go to the documentation of this file.
1 #ifndef CondCore_PoolDBOutputService_h
2 #define CondCore_PoolDBOutputService_h
6 #include <string>
7 #include <map>
8 #include <mutex>
9 
10 //
11 // Package: DBOutputService
12 // Class : PoolDBOutputService
13 //
17 //
18 // Author: Zhen Xie
19 // Fixes and other changes: Giacomo Govi
20 //
21 
22 namespace edm {
23  class Event;
24  class EventSetup;
25  class ParameterSet;
26 } // namespace edm
27 namespace cond {
28 
29  inline std::string classNameForTypeId(const std::type_info& typeInfo) {
30  edm::TypeID type(typeInfo);
31  return type.className();
32  }
33 
34  namespace service {
35 
37  public:
39  //use these to control connections
40  //void postBeginJob();
41  void postEndJob();
42 
43  //
44  // return the database session in use ( GG: not sure this is still useful... )
45  //
46  cond::persistency::Session session() const;
47  //
49  bool isNewTagRequest(const std::string& recordName);
50 
51  //
52  template <typename T>
53  void writeOne(T* payload, Time_t time, const std::string& recordName, bool withlogging = false) {
54  if (!payload)
55  throwException("Provided payload pointer is invalid.", "PoolDBOutputService::writeOne");
56  std::lock_guard<std::recursive_mutex> lock(m_mutex);
57  if (!m_dbstarted)
58  this->initDB();
59  Hash payloadId = m_session.storePayload(*payload);
60  std::string payloadType = cond::demangledName(typeid(T));
61  if (isNewTagRequest(recordName)) {
62  createNewIOV(payloadId, payloadType, time, endOfTime(), recordName, withlogging);
63  } else {
64  appendSinceTime(payloadId, time, recordName, withlogging);
65  }
66  }
67 
68  // close the IOVSequence setting lastTill
69  void closeIOV(Time_t lastTill, const std::string& recordName, bool withlogging = false);
70 
71  //
72  template <typename T>
73  void createNewIOV(T* firstPayloadObj,
74  cond::Time_t firstSinceTime,
75  cond::Time_t firstTillTime,
76  const std::string& recordName,
77  bool withlogging = false) {
78  if (!firstPayloadObj)
79  throwException("Provided payload pointer is invalid.", "PoolDBOutputService::createNewIOV");
80  std::lock_guard<std::recursive_mutex> lock(m_mutex);
81  if (!m_dbstarted)
82  this->initDB();
83  createNewIOV(m_session.storePayload(*firstPayloadObj),
84  cond::demangledName(typeid(T)),
85  firstSinceTime,
86  firstTillTime,
87  recordName,
88  withlogging);
89  }
90 
91  void createNewIOV(const std::string& firstPayloadId,
93  cond::Time_t firstSinceTime,
94  cond::Time_t firstTillTime,
95  const std::string& recordName,
96  bool withlogging = false);
97 
98  // this one we need to avoid to adapt client code around... to be removed in the long term!
99  void createNewIOV(const std::string& firstPayloadId,
100  cond::Time_t firstSinceTime,
101  cond::Time_t firstTillTime,
102  const std::string& recordName,
103  bool withlogging = false);
104 
105  //
106  template <typename T>
107  void appendSinceTime(T* payloadObj,
108  cond::Time_t sinceTime,
109  const std::string& recordName,
110  bool withlogging = false) {
111  if (!payloadObj)
112  throwException("Provided payload pointer is invalid.", "PoolDBOutputService::appendSinceTime");
113  appendSinceTime(m_session.storePayload(*payloadObj), sinceTime, recordName, withlogging);
114  }
115 
116  // Append the payload and its valid sinceTime into the database
117  // Note: the iov index appended to MUST pre-existing and the existing
118  // conditions data are retrieved from the DB
119  //
120  void appendSinceTime(const std::string& payloadId,
121  cond::Time_t sinceTime,
122  const std::string& recordName,
123  bool withlogging = false);
124 
125  //
126  // Service time utility method
127  // return the infinity value according to the given timetype
128  //
129  cond::Time_t endOfTime() const;
130  //
131  // Service time utility method
132  // return beginning of time value according to the given timetype
133  //
134  cond::Time_t beginOfTime() const;
135  //
136  // Service time utility method
137  // return the time value of the current edm::Event according to the
138  // given timetype
139  //
140  cond::Time_t currentTime() const;
141 
142  // optional. User can inject additional information into the log associated with a given record
143  void setLogHeaderForRecord(const std::string& recordName,
144  const std::string& provenance,
145  const std::string& usertext);
146 
147  //
148  // Retrieve tag information of the data
149  //
150  void tagInfo(const std::string& recordName, cond::TagInfo_t& result);
151 
152  virtual ~PoolDBOutputService();
153 
154  void forceInit();
155 
156  private:
157  //
158  //use these to control transaction interval
159  //
160  void preEventProcessing(edm::StreamContext const&);
161  void preGlobalBeginLumi(edm::GlobalContext const&);
162  void preGlobalBeginRun(edm::GlobalContext const&);
163  void preModuleEvent(edm::StreamContext const&, edm::ModuleCallingContext const&);
164  void postModuleEvent(edm::StreamContext const&, edm::ModuleCallingContext const&);
165 
166  struct Record {
167  Record() : m_tag(), m_isNewTag(false), m_idName(), m_timetype(cond::runnumber), m_closeIOV(false) {}
168 
169  std::string timetypestr() const { return cond::timeTypeSpecs[m_timetype].name; }
175  };
176 
177  void fillRecord(edm::ParameterSet& pset);
178 
179  void connect();
180  void disconnect();
181  void initDB(bool dummy = false);
182 
183  Record& lookUpRecord(const std::string& recordName);
184  cond::UserLogInfo& lookUpUserLogInfo(const std::string& recordName);
185 
186  private:
187  std::recursive_mutex m_mutex;
190  std::vector<cond::Time_t> m_currentTimes;
191 
194 
195  std::map<std::string, Record> m_callbacks;
196  std::vector<std::pair<std::string, std::string> > m_newtags;
198  std::map<std::string, cond::UserLogInfo> m_logheaders;
199 
200  }; //PoolDBOutputService
201  } // namespace service
202 } // namespace cond
203 #endif
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
type
Definition: HCALResponse.h:21
std::map< std::string, cond::UserLogInfo > m_logheaders
std::vector< cond::Time_t > m_currentTimes
TimeType
Definition: Time.h:19
std::string classNameForTypeId(const std::type_info &typeInfo)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
unsigned long long Time_t
Definition: Time.h:14
std::string Hash
Definition: Types.h:43
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
cond::persistency::Session m_session
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
std::vector< std::pair< std::string, std::string > > m_newtags
std::string name
Definition: Time.h:39
Definition: plugin.cc:23
HLT enums.
std::string const & className() const
Definition: TypeID.cc:43
std::map< std::string, Record > m_callbacks
long double T
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12