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 <string>
11 #include <map>
12 
13 // many many clients do not include explicitely!
14 #ifndef COND_EXCEPTION_H
16 // #warning please include "CondCore/DBCommon/interface/Exception.h" explicitely
17 // #define COND_EXP_WARNING
18 #endif
19 
20 //
21 // Package: DBOutputService
22 // Class : PoolDBOutputService
23 //
27 //
28 // Author: Zhen Xie
29 // Fixes and other changes: Giacomo Govi
30 //
31 namespace edm{
32  class Event;
33  class EventSetup;
34  class ParameterSet;
35 }
36 namespace cond{
37 
38  inline std::string classNameForTypeId( const std::type_info& typeInfo ){
39  edm::TypeID type( typeInfo );
40  return type.className();
41  }
42 
43  namespace service {
44 
52  struct GetToken {
53  virtual std::string operator()(cond::DbSession&) const =0;
54  };
55 
56  struct GetTrivialToken : public GetToken {
57 
59  m_token(token){}
60  virtual ~GetTrivialToken(){}
62  return m_token;
63  }
65  };
66 
67  template<typename T>
68  struct GetTokenFromPointer : public GetToken {
69 
70  static
72  if(!pointer) return classNameForTypeId( typeid(T) );
73  return classNameForTypeId( typeid(*pointer) );
74  }
75 
76  explicit GetTokenFromPointer(T * p) :
77  m_p(p){}
78 
79  virtual std::string operator()(cond::DbSession& pooldb) const {
81  boost::shared_ptr<T> sptr( m_p );
82  return pooldb.storeObject(m_p,className);
83  }
84  T* m_p;
85  };
86 
87 
89  public:
90  PoolDBOutputService( const edm::ParameterSet & iConfig,
91  edm::ActivityRegistry & iAR );
92  //use these to control connections
93  //void postBeginJob();
94  void postEndJob();
95  //
96  //use these to control transaction interval
97  //
98  void preEventProcessing( const edm::EventID & evtID,
99  const edm::Timestamp & iTime );
100  void preModule(const edm::ModuleDescription& desc);
101  void postModule(const edm::ModuleDescription& desc);
103  const edm::Timestamp& );
104  //
105  // return the database session in use
106  //
107  cond::DbSession session() const;
108  //
110  bool isNewTagRequest( const std::string& recordName );
111  const cond::Logger& queryLog() const;
112 
113  //
114  template<typename T>
115  void writeOne( T * payload, Time_t time, const std::string& recordName, bool withlogging=false ) {
116  if (isNewTagRequest(recordName) ){
117  createNewIOV<T>(payload, time, endOfTime(), recordName, withlogging);
118  }else{
119  appendSinceTime<T>(payload, time, recordName, withlogging);
120  }
121  }
122 
123  // close the IOVSequence setting lastTill
124  void closeIOV(Time_t lastTill, const std::string& recordName,
125  bool withlogging=false);
126 
127  //
128  template<typename T>
129  void createNewIOV( T* firstPayloadObj,
130  cond::Time_t firstSinceTime,
131  cond::Time_t firstTillTime,
132  const std::string& recordName,
133  bool withlogging=false){
134  createNewIOV( GetTokenFromPointer<T>(firstPayloadObj),
135  firstSinceTime,
136  firstTillTime,
137  recordName,
138  withlogging);
139  }
140 
141  void createNewIOV( const std::string& firstPayloadToken,
142  cond::Time_t firstSinceTime,
143  cond::Time_t firstTillTime,
144  const std::string& recordName,
145  bool withlogging=false) {
146  createNewIOV( GetTrivialToken(firstPayloadToken),
147  firstSinceTime,
148  firstTillTime,
149  recordName,
150  withlogging);
151  }
152 
153 
154  //
155  template<typename T> void appendSinceTime( T* payloadObj,
156  cond::Time_t sinceTime,
157  const std::string& recordName,
158  bool withlogging=false){
159  add( GetTokenFromPointer<T>(payloadObj),
160  sinceTime,
161  recordName,
162  withlogging);
163  }
164 
165  // Append the payload and its valid sinceTime into the database
166  // Note: user looses the ownership of the pointer to the payloadObj
167  // Note: the iov index appended to MUST pre-existing and the existing
168  // conditions data are retrieved from the DB
169  //
170  void appendSinceTime( const std::string& payloadToken,
171  cond::Time_t sinceTime,
172  const std::string& recordName,
173  bool withlogging=false) {
174  add(GetTrivialToken(payloadToken),
175  sinceTime,
176  recordName,
177  withlogging);
178  }
179 
180  // set last till so that the iov sequence is "closed"
181  // void closeSequence(cond::Time_t tillTime,
182  // const std::string& recordName,
183  // bool withlogging=false);
184 
185 
186  //
187  // Service time utility method
188  // return the infinity value according to the given timetype
189  //
190  cond::Time_t endOfTime() const;
191  //
192  // Service time utility method
193  // return beginning of time value according to the given timetype
194  //
195  cond::Time_t beginOfTime() const;
196  //
197  // Service time utility method
198  // return the time value of the current edm::Event according to the
199  // given timetype
200  //
201  cond::Time_t currentTime() const;
202 
203  // optional. User can inject additional information into the log associated with a given record
204  void setLogHeaderForRecord(const std::string& recordName,
205  const std::string& provenance,
206  const std::string& usertext);
207  //
208  // Retrieve tag information of the data
209  //
210  void tagInfo(const std::string& recordName,
212 
213  virtual ~PoolDBOutputService();
214 
215  private:
216 
217  struct Record{
218  Record(): m_tag(),
219  m_isNewTag(false),
220  m_idName(),
221  m_iovtoken(),
222  m_timetype(cond::runnumber),
223  m_closeIOV(false),
225  {}
226 
235  };
236 
237 
238 
239  void fillRecord( edm::ParameterSet & pset);
240 
241  void createNewIOV( GetToken const & token,
242  cond::Time_t firstSinceTime,
243  cond::Time_t firstTillTime,
244  const std::string& recordName,
245  bool withlogging=false);
246 
247  void add( GetToken const & token,
249  const std::string& recordName,
250  bool withlogging=false);
251 
252  void connect();
253  void disconnect();
254  void initDB( bool forReading=true );
255  unsigned int appendIOV(cond::DbSession&,
256  Record& record,
257  const std::string& payloadToken,
258  cond::Time_t sinceTime);
259 
261  unsigned int
262  insertIOV(cond::DbSession& pooldb,
263  Record& record,
264  const std::string& payloadToken,
265  cond::Time_t tillTime);
266 
267  Record & lookUpRecord(const std::string& recordName);
268  cond::UserLogInfo& lookUpUserLogInfo(const std::string& recordName);
269 
270  private:
274 
278  std::auto_ptr<cond::Logger> m_logdb;
280 
281  std::map<std::string, Record> m_callbacks;
282  std::vector< std::pair<std::string,std::string> > m_newtags;
285  std::map<std::string, cond::UserLogInfo> m_logheaders;
286 
287  };//PoolDBOutputService
288  }//ns service
289 }//ns cond
290 #endif
std::vector< std::pair< std::string, std::string > > m_newtags
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
type
Definition: HCALResponse.h:21
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)
JetCorrectorParameters::Record record
Definition: classes.h:13
virtual std::string operator()(cond::DbSession &pooldb) const
void fillRecord(edm::ParameterSet &pset)
std::map< std::string, cond::UserLogInfo > m_logheaders
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)
tuple result
Definition: query.py:137
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
virtual std::string operator()(cond::DbSession &) const
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 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:131
void tagInfo(const std::string &recordName, cond::TagInfo &result)
void postModule(const edm::ModuleDescription &desc)
void preModule(const edm::ModuleDescription &desc)
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::string const & className() const
Definition: TypeID.cc:40
std::map< std::string, Record > m_callbacks
char const * className(const std::type_info &t)
Definition: ClassID.cc:8
void preEventProcessing(const edm::EventID &evtID, const edm::Timestamp &iTime)
long double T
cond::UserLogInfo & lookUpUserLogInfo(const std::string &recordName)
const cond::Logger & queryLog() const
PoolDBOutputService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)
std::auto_ptr< cond::Logger > m_logdb
unsigned int appendIOV(cond::DbSession &, Record &record, const std::string &payloadToken, cond::Time_t sinceTime)
virtual std::string operator()(cond::DbSession &) const =0