CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PoolDBOutputService.h
Go to the documentation of this file.
1 #ifndef CondCore_PoolDBOutputService_h
2 #define CondCore_PoolDBOutputService_h
10 #include "Reflex/Type.h"
11 #include <string>
12 #include <map>
13 
14 // many many clients do not include explicitely!
15 #ifndef COND_EXCEPTION_H
17 // #warning please include "CondCore/DBCommon/interface/Exception.h" explicitely
18 // #define COND_EXP_WARNING
19 #endif
20 
21 //#include <iostream>
22 //
23 // Package: DBOutputService
24 // Class : PoolDBOutputService
25 //
29 //
30 // Author: Zhen Xie
31 //
32 namespace edm{
33  class Event;
34  class EventSetup;
35  class ParameterSet;
36 }
37 namespace cond{
38 
39  inline std::string classNameForTypeId( const std::type_info& typeInfo ){
40  Reflex::Type reflexType = Reflex::Type::ByTypeInfo( typeInfo );
41  //FIXME: should become Reflex::SCOPED?
42  return reflexType.Name();
43  }
44  //FIXME
45  class Summary;
46 
47  namespace service {
48 
59  struct GetToken {
60  virtual std::string operator()(cond::DbSession&, bool) const =0;
61  static unsigned int sizeDSW();
62  };
63 
64  struct GetTrivialToken : public GetToken {
65 
66  GetTrivialToken(std::string token) :
67  m_token(token){}
68  virtual ~GetTrivialToken(){}
69  virtual std::string operator()(cond::DbSession&, bool) const {
70  return m_token;
71  }
72  std::string m_token;
73  };
74 
75  template<typename T>
76  struct GetTokenFromPointer : public GetToken {
77 
79  m_p(p), m_s(s){}
80 
81  static std::string classNameForPointer( T* pointer ){
82  if(!pointer) return classNameForTypeId( typeid(T) );
83  return classNameForTypeId( typeid(*pointer) );
84  }
85  virtual std::string operator()(cond::DbSession& pooldb, bool /* withWrapper */) const {
86  std::string className = classNameForPointer( m_p );
87  boost::shared_ptr<T> sptr( m_p );
88  return pooldb.storeObject(m_p,className);
89  }
90  T* m_p;
92  //const std::string& m_recordName;
93  };
94 
95 
96 
97 
99  public:
100  PoolDBOutputService( const edm::ParameterSet & iConfig,
101  edm::ActivityRegistry & iAR );
102  //use these to control connections
103  //void postBeginJob();
104  void postEndJob();
105  //
106  //use these to control transaction interval
107  //
108  void preEventProcessing( const edm::EventID & evtID,
109  const edm::Timestamp & iTime );
110  void preModule(const edm::ModuleDescription& desc);
111  void postModule(const edm::ModuleDescription& desc);
113  const edm::Timestamp& );
114  //
115  // return the database session in use
116  //
117  cond::DbSession session() const;
118  //
119  std::string tag( const std::string& recordName );
120  bool isNewTagRequest( const std::string& recordName );
121  const cond::Logger& queryLog() const;
122 
123  // BW-compatible signature
124  template<typename T>
125  void writeOne(T * payload,
126  Time_t time, const std::string& recordName,
127  bool withlogging=false) {
128  this->writeOne<T>(payload, 0, time, recordName, withlogging);
129  }
130 
131  /* write one (either create or append)
132  * The ONE and ONLY interface supported in future!
133  */
134  template<typename T>
135  void writeOne(T * payload, Summary * summary,
136  Time_t time, const std::string& recordName,
137  bool withlogging=false) {
138  if (isNewTagRequest(recordName) ){
139  createNewIOV<T>(payload, summary,
140  time, endOfTime(), recordName, withlogging);
141  }else{
142  appendSinceTime<T>(payload, summary, time, recordName, withlogging);
143  }
144  }
145 
146  // close the IOVSequence setting lastTill
147  void closeIOV(Time_t lastTill, const std::string& recordName,
148  bool withlogging=false);
149 
150  // BW-compatible signature
151  template<typename T>
152  void createNewIOV( T* firstPayloadObj,
153  cond::Time_t firstSinceTime,
154  cond::Time_t firstTillTime,
155  const std::string& recordName,
156  bool withlogging=false){
157  this->createNewIOV(firstPayloadObj, 0, firstSinceTime, firstTillTime, recordName,withlogging);
158  }
159 
160  //
161  // insert the payload and its valid since time into the database
162  // Note: user looses the ownership of the pointer to the payloadObj
163  // The payload object will be stored as well
164  //
165  template<typename T> void createNewIOV( T* firstPayloadObj, Summary * summary,
166  cond::Time_t firstSinceTime,
167  cond::Time_t firstTillTime,
168  const std::string& recordName,
169  bool withlogging=false){
170  createNewIOV( GetTokenFromPointer<T>(firstPayloadObj, summary),
171  firstSinceTime,
172  firstTillTime,
173  recordName,
174  withlogging);
175  }
176 
177  void createNewIOV( const std::string& firstPayloadToken,
178  cond::Time_t firstSinceTime,
179  cond::Time_t firstTillTime,
180  const std::string& recordName,
181  bool withlogging=false) {
182  createNewIOV( GetTrivialToken(firstPayloadToken),
183  firstSinceTime,
184  firstTillTime,
185  recordName,
186  withlogging);
187  }
188 
189 
190  // BW-compatible signature
191  template<typename T> void appendSinceTime( T* payloadObj,
192  cond::Time_t sinceTime,
193  const std::string& recordName,
194  bool withlogging=false){
195  this->appendSinceTime<T>(payloadObj, 0, sinceTime, recordName, withlogging);
196  }
197 
198  template<typename T>
199  void appendSinceTime( T* payloadObj, Summary * summary,
200  cond::Time_t sinceTime,
201  const std::string& recordName,
202  bool withlogging=false){
203  add( GetTokenFromPointer<T>(payloadObj,summary),
204  sinceTime,
205  recordName,
206  withlogging);
207  }
208 
209  // Append the payload and its valid sinceTime into the database
210  // Note: user looses the ownership of the pointer to the payloadObj
211  // Note: the iov index appended to MUST pre-existing and the existing
212  // conditions data are retrieved from the DB
213  //
214  void appendSinceTime( const std::string& payloadToken,
215  cond::Time_t sinceTime,
216  const std::string& recordName,
217  bool withlogging=false) {
218  add(GetTrivialToken(payloadToken),
219  sinceTime,
220  recordName,
221  withlogging);
222  }
223 
224  // set last till so that the iov sequence is "closed"
225  // void closeSequence(cond::Time_t tillTime,
226  // const std::string& recordName,
227  // bool withlogging=false);
228 
229 
230  //
231  // Service time utility method
232  // return the infinity value according to the given timetype
233  //
234  cond::Time_t endOfTime() const;
235  //
236  // Service time utility method
237  // return beginning of time value according to the given timetype
238  //
239  cond::Time_t beginOfTime() const;
240  //
241  // Service time utility method
242  // return the time value of the current edm::Event according to the
243  // given timetype
244  //
245  cond::Time_t currentTime() const;
246 
247  // optional. User can inject additional information into the log associated with a given record
248  void setLogHeaderForRecord(const std::string& recordName,
249  const std::string& provenance,
250  const std::string& usertext);
251  //
252  // Retrieve tag information of the data
253  //
254  void tagInfo(const std::string& recordName,
256 
257  virtual ~PoolDBOutputService();
258 
259  private:
260 
261  struct Record{
263  m_idName(),
264  m_iovtoken(),
265  m_closeIOV(false),
268  {}
269 
270  std::string timetypestr() const { return cond::timeTypeSpecs[m_timetype].name;}
271  std::string m_tag;
273  std::string m_idName;
274  std::string m_iovtoken;
279  };
280 
281 
282 
284 
285  void createNewIOV( GetToken const & token,
286  cond::Time_t firstSinceTime,
287  cond::Time_t firstTillTime,
288  const std::string& recordName,
289  bool withlogging=false);
290 
291  void add( GetToken const & token,
293  const std::string& recordName,
294  bool withlogging=false);
295 
296 
297  void connect();
298  void disconnect();
299  void initDB();
300  unsigned int appendIOV(cond::DbSession&,
301  Record& record,
302  const std::string& payloadToken,
303  cond::Time_t sinceTime);
304 
306  unsigned int
307  insertIOV(cond::DbSession& pooldb,
308  Record& record,
309  const std::string& payloadToken,
310  cond::Time_t tillTime);
311  // const std::string& recordName);
312 
313  Record & lookUpRecord(const std::string& recordName);
314  cond::UserLogInfo& lookUpUserLogInfo(const std::string& recordName);
315 
316  private:
318  std::string m_timetypestr;
323  std::map<std::string, Record> m_callbacks;
324  std::vector< std::pair<std::string,std::string> > m_newtags;
327  bool m_logdbOn;
328 
330 
332 
334 
335  std::map<std::string, cond::UserLogInfo> m_logheaders;
336 
337  };//PoolDBOutputService
338  }//ns service
339 }//ns cond
340 #endif
std::vector< std::pair< std::string, std::string > > m_newtags
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
unsigned int insertIOV(cond::DbSession &pooldb, Record &record, const std::string &payloadToken, cond::Time_t tillTime)
Returns payload location index.
void closeIOV(Time_t lastTill, const std::string &recordName, bool withlogging=false)
virtual std::string operator()(cond::DbSession &, bool) const
JetCorrectorParameters::Record record
Definition: classes.h:11
void fillRecord(edm::ParameterSet &pset)
virtual std::string operator()(cond::DbSession &, bool) const =0
std::map< std::string, cond::UserLogInfo > m_logheaders
static unsigned int sizeDSW()
void add(GetToken const &token, cond::Time_t time, const std::string &recordName, bool withlogging=false)
void preBeginLumi(const edm::LuminosityBlockID &, const edm::Timestamp &)
TimeType
Definition: Time.h:21
std::string tag(const std::string &recordName)
std::string classNameForTypeId(const std::type_info &typeInfo)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
static std::string classNameForPointer(T *pointer)
unsigned long long Time_t
Definition: Time.h:16
bool isNewTagRequest(const std::string &recordName)
Record & lookUpRecord(const std::string &recordName)
virtual std::string operator()(cond::DbSession &pooldb, bool) const
tuple result
Definition: query.py:137
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
tuple pset
Definition: CrabTask.py:85
void writeOne(T *payload, Summary *summary, Time_t time, const std::string &recordName, bool withlogging=false)
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
void createNewIOV(const std::string &firstPayloadToken, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
void appendSinceTime(T *payloadObj, Summary *summary, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
void setLogHeaderForRecord(const std::string &recordName, const std::string &provenance, const std::string &usertext)
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:104
void tagInfo(const std::string &recordName, cond::TagInfo &result)
void postModule(const edm::ModuleDescription &desc)
void preModule(const edm::ModuleDescription &desc)
void createNewIOV(T *firstPayloadObj, Summary *summary, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
void appendSinceTime(const std::string &payloadToken, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
std::string name
Definition: Time.h:43
std::map< std::string, Record > m_callbacks
char const * className(const std::type_info &t)
Definition: ClassID.cc:8
string s
Definition: asciidump.py:422
void preEventProcessing(const edm::EventID &evtID, const edm::Timestamp &iTime)
cond::UserLogInfo & lookUpUserLogInfo(const std::string &recordName)
const cond::Logger & queryLog() const
PoolDBOutputService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)
unsigned int appendIOV(cond::DbSession &, Record &record, const std::string &payloadToken, cond::Time_t sinceTime)