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
9 #include "Reflex/Type.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  Reflex::Type reflexType = Reflex::Type::ByTypeInfo( typeInfo );
40  //FIXME: should become Reflex::SCOPED?
41  return reflexType.Name();
42  }
43 
44  namespace service {
45 
53  struct GetToken {
54  virtual std::string operator()(cond::DbSession&) const =0;
55  };
56 
57  struct GetTrivialToken : public GetToken {
58 
59  GetTrivialToken(std::string token) :
60  m_token(token){}
61  virtual ~GetTrivialToken(){}
62  virtual std::string operator()(cond::DbSession&) const {
63  return m_token;
64  }
65  std::string m_token;
66  };
67 
68  template<typename T>
69  struct GetTokenFromPointer : public GetToken {
70 
71  static
72  std::string classNameForPointer( T* pointer ){
73  if(!pointer) return classNameForTypeId( typeid(T) );
74  return classNameForTypeId( typeid(*pointer) );
75  }
76 
77  explicit GetTokenFromPointer(T * p) :
78  m_p(p){}
79 
80  virtual std::string operator()(cond::DbSession& pooldb) const {
81  std::string className = classNameForPointer( m_p );
82  boost::shared_ptr<T> sptr( m_p );
83  return pooldb.storeObject(m_p,className);
84  }
85  T* m_p;
86  };
87 
88 
90  public:
91  PoolDBOutputService( const edm::ParameterSet & iConfig,
92  edm::ActivityRegistry & iAR );
93  //use these to control connections
94  //void postBeginJob();
95  void postEndJob();
96  //
97  //use these to control transaction interval
98  //
99  void preEventProcessing( const edm::EventID & evtID,
100  const edm::Timestamp & iTime );
101  void preModule(const edm::ModuleDescription& desc);
102  void postModule(const edm::ModuleDescription& desc);
104  const edm::Timestamp& );
105  //
106  // return the database session in use
107  //
108  cond::DbSession session() const;
109  //
110  std::string tag( const std::string& recordName );
111  bool isNewTagRequest( const std::string& recordName );
112  const cond::Logger& queryLog() const;
113 
114  //
115  template<typename T>
116  void writeOne( T * payload, Time_t time, const std::string& recordName, bool withlogging=false ) {
117  if (isNewTagRequest(recordName) ){
118  createNewIOV<T>(payload, time, endOfTime(), recordName, withlogging);
119  }else{
120  appendSinceTime<T>(payload, time, recordName, withlogging);
121  }
122  }
123 
124  // close the IOVSequence setting lastTill
125  void closeIOV(Time_t lastTill, const std::string& recordName,
126  bool withlogging=false);
127 
128  //
129  template<typename T>
130  void createNewIOV( T* firstPayloadObj,
131  cond::Time_t firstSinceTime,
132  cond::Time_t firstTillTime,
133  const std::string& recordName,
134  bool withlogging=false){
135  createNewIOV( GetTokenFromPointer<T>(firstPayloadObj),
136  firstSinceTime,
137  firstTillTime,
138  recordName,
139  withlogging);
140  }
141 
142  void createNewIOV( const std::string& firstPayloadToken,
143  cond::Time_t firstSinceTime,
144  cond::Time_t firstTillTime,
145  const std::string& recordName,
146  bool withlogging=false) {
147  createNewIOV( GetTrivialToken(firstPayloadToken),
148  firstSinceTime,
149  firstTillTime,
150  recordName,
151  withlogging);
152  }
153 
154 
155  //
156  template<typename T> void appendSinceTime( T* payloadObj,
157  cond::Time_t sinceTime,
158  const std::string& recordName,
159  bool withlogging=false){
160  add( GetTokenFromPointer<T>(payloadObj),
161  sinceTime,
162  recordName,
163  withlogging);
164  }
165 
166  // Append the payload and its valid sinceTime into the database
167  // Note: user looses the ownership of the pointer to the payloadObj
168  // Note: the iov index appended to MUST pre-existing and the existing
169  // conditions data are retrieved from the DB
170  //
171  void appendSinceTime( const std::string& payloadToken,
172  cond::Time_t sinceTime,
173  const std::string& recordName,
174  bool withlogging=false) {
175  add(GetTrivialToken(payloadToken),
176  sinceTime,
177  recordName,
178  withlogging);
179  }
180 
181  // set last till so that the iov sequence is "closed"
182  // void closeSequence(cond::Time_t tillTime,
183  // const std::string& recordName,
184  // bool withlogging=false);
185 
186 
187  //
188  // Service time utility method
189  // return the infinity value according to the given timetype
190  //
191  cond::Time_t endOfTime() const;
192  //
193  // Service time utility method
194  // return beginning of time value according to the given timetype
195  //
196  cond::Time_t beginOfTime() const;
197  //
198  // Service time utility method
199  // return the time value of the current edm::Event according to the
200  // given timetype
201  //
202  cond::Time_t currentTime() const;
203 
204  // optional. User can inject additional information into the log associated with a given record
205  void setLogHeaderForRecord(const std::string& recordName,
206  const std::string& provenance,
207  const std::string& usertext);
208  //
209  // Retrieve tag information of the data
210  //
211  void tagInfo(const std::string& recordName,
213 
214  virtual ~PoolDBOutputService();
215 
216  private:
217 
218  struct Record{
219  Record(): m_tag(),
220  m_isNewTag(false),
221  m_idName(),
222  m_iovtoken(),
223  m_timetype(cond::runnumber),
224  m_closeIOV(false),
226  {}
227 
228  std::string timetypestr() const { return cond::timeTypeSpecs[m_timetype].name;}
229  std::string m_tag;
231  std::string m_idName;
232  std::string m_iovtoken;
236  };
237 
238 
239 
240  void fillRecord( edm::ParameterSet & pset);
241 
242  void createNewIOV( GetToken const & token,
243  cond::Time_t firstSinceTime,
244  cond::Time_t firstTillTime,
245  const std::string& recordName,
246  bool withlogging=false);
247 
248  void add( GetToken const & token,
250  const std::string& recordName,
251  bool withlogging=false);
252 
253  void connect();
254  void disconnect();
255  void initDB( bool forReading=true );
256  unsigned int appendIOV(cond::DbSession&,
257  Record& record,
258  const std::string& payloadToken,
259  cond::Time_t sinceTime);
260 
262  unsigned int
263  insertIOV(cond::DbSession& pooldb,
264  Record& record,
265  const std::string& payloadToken,
266  cond::Time_t tillTime);
267 
268  Record & lookUpRecord(const std::string& recordName);
269  cond::UserLogInfo& lookUpUserLogInfo(const std::string& recordName);
270 
271  private:
273  std::string m_timetypestr;
275 
276  std::string m_connectionString;
279  std::auto_ptr<cond::Logger> m_logdb;
281 
282  std::map<std::string, Record> m_callbacks;
283  std::vector< std::pair<std::string,std::string> > m_newtags;
286  std::map<std::string, cond::UserLogInfo> m_logheaders;
287 
288  };//PoolDBOutputService
289  }//ns service
290 }//ns cond
291 #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)
JetCorrectorParameters::Record record
Definition: classes.h:11
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::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