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
5 //#include "CondCore/DBCommon/interface/Logger.h"
6 //#include "CondCore/DBCommon/interface/LogDBEntry.h"
7 //#include "CondCore/DBCommon/interface/TagInfo.h"
9 #include <string>
10 #include <map>
11 
12 //
13 // Package: DBOutputService
14 // Class : PoolDBOutputService
15 //
19 //
20 // Author: Zhen Xie
21 // Fixes and other changes: Giacomo Govi
22 //
23 
24 namespace edm{
25  class Event;
26  class EventSetup;
27  class ParameterSet;
28 }
29 namespace cond{
30 
31  inline std::string classNameForTypeId( const std::type_info& typeInfo ){
32  edm::TypeID type( typeInfo );
33  return type.className();
34  }
35 
36  namespace service {
37 
39  public:
40  PoolDBOutputService( const edm::ParameterSet & iConfig,
41  edm::ActivityRegistry & iAR );
42  //use these to control connections
43  //void postBeginJob();
44  void postEndJob();
45  //
46  //use these to control transaction interval
47  //
48  void preEventProcessing( const edm::EventID & evtID,
49  const edm::Timestamp & iTime );
50  void preModule(const edm::ModuleDescription& desc);
51  void postModule(const edm::ModuleDescription& desc);
53  const edm::Timestamp& );
54  //
55  // return the database session in use ( GG: not sure this is still useful... )
56  //
58  //
60  bool isNewTagRequest( const std::string& recordName );
61  //const cond::Logger& queryLog() const;
62 
63  //
64  template<typename T>
65  void writeOne( T * payload, Time_t time, const std::string& recordName, bool withlogging=false ) {
66  if( !payload ) throwException( "Provided payload pointer is invalid.","PoolDBOutputService::writeOne");
67  if (!m_dbstarted) this->initDB( false );
68  Hash payloadId = m_session.storePayload( *payload );
69  std::string payloadType = cond::demangledName(typeid(T));
70  if (isNewTagRequest(recordName) ){
71  createNewIOV(payloadId, payloadType, time, endOfTime(), recordName, withlogging);
72  } else {
73  appendSinceTime(payloadId, time, recordName, withlogging);
74  }
75  }
76 
77  // close the IOVSequence setting lastTill
78  void closeIOV(Time_t lastTill, const std::string& recordName,
79  bool withlogging=false);
80 
81  //
82  template<typename T>
83  void createNewIOV( T* firstPayloadObj,
84  cond::Time_t firstSinceTime,
85  cond::Time_t firstTillTime,
86  const std::string& recordName,
87  bool withlogging=false){
88  if( !firstPayloadObj ) throwException( "Provided payload pointer is invalid.","PoolDBOutputService::createNewIOV");
89  createNewIOV( m_session.storePayload( *firstPayloadObj ),
90  cond::demangledName(typeid(T)),
91  firstSinceTime,
92  firstTillTime,
93  recordName,
94  withlogging);
95  }
96 
97  void createNewIOV( const std::string& firstPayloadId,
98  const std::string payloadType,
99  cond::Time_t firstSinceTime,
100  cond::Time_t firstTillTime,
101  const std::string& recordName,
102  bool withlogging=false);
103 
104  // this one we need to avoid to adapt client code around... to be removed in the long term!
105  void createNewIOV( const std::string& firstPayloadId,
106  cond::Time_t firstSinceTime,
107  cond::Time_t firstTillTime,
108  const std::string& recordName,
109  bool withlogging=false);
110 
111  //
112  template<typename T> void appendSinceTime( T* payloadObj,
113  cond::Time_t sinceTime,
114  const std::string& recordName,
115  bool withlogging=false){
116  if( !payloadObj ) throwException( "Provided payload pointer is invalid.","PoolDBOutputService::appendSinceTime");
117  appendSinceTime( m_session.storePayload( *payloadObj ),
118  sinceTime,
119  recordName,
120  withlogging);
121  }
122 
123  // Append the payload and its valid sinceTime into the database
124  // Note: the iov index appended to MUST pre-existing and the existing
125  // conditions data are retrieved from the DB
126  //
127  void appendSinceTime( const std::string& payloadId,
128  cond::Time_t sinceTime,
129  const std::string& recordName,
130  bool withlogging=false);
131 
132  //
133  // Service time utility method
134  // return the infinity value according to the given timetype
135  //
136  cond::Time_t endOfTime() const;
137  //
138  // Service time utility method
139  // return beginning of time value according to the given timetype
140  //
141  cond::Time_t beginOfTime() const;
142  //
143  // Service time utility method
144  // return the time value of the current edm::Event according to the
145  // given timetype
146  //
147  cond::Time_t currentTime() const;
148 
149  // optional. User can inject additional information into the log associated with a given record
150  void setLogHeaderForRecord(const std::string& recordName,
151  const std::string& provenance,
152  const std::string& usertext);
153  //
154  // Retrieve tag information of the data
155  //
156  void tagInfo(const std::string& recordName,
158 
159  virtual ~PoolDBOutputService();
160 
161  private:
162 
163  struct Record{
164  Record(): m_tag(),
165  m_isNewTag(false),
166  m_idName(),
167  m_timetype(cond::runnumber),
169  {}
170 
177  };
178 
179 
180 
181  void fillRecord( edm::ParameterSet & pset);
182 
183  void connect();
184  void disconnect();
185  void initDB( bool forReading=true );
186 
187  Record & lookUpRecord(const std::string& recordName);
188  //cond::UserLogInfo& lookUpUserLogInfo(const std::string& recordName);
189 
190  private:
194 
196  //std::string m_logConnectionString;
197  //std::auto_ptr<cond::Logger> m_logdb;
199 
200  std::map<std::string, Record> m_callbacks;
201  //std::vector< std::pair<std::string,std::string> > m_newtags;
203  //std::map<std::string, cond::UserLogInfo> m_logheaders;
204 
205  };//PoolDBOutputService
206  }//ns service
207 }//ns cond
208 #endif
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
type
Definition: HCALResponse.h:21
void closeIOV(Time_t lastTill, const std::string &recordName, bool withlogging=false)
void initDB(bool forReading=true)
void fillRecord(edm::ParameterSet &pset)
cond::persistency::Session session() const
void preBeginLumi(const edm::LuminosityBlockID &, const edm::Timestamp &)
TimeType
Definition: Time.h:21
std::string tag(const std::string &recordName)
std::string demangledName(const std::type_info &typeInfo)
Definition: ClassUtils.cc:82
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:16
bool isNewTagRequest(const std::string &recordName)
Record & lookUpRecord(const std::string &recordName)
tuple result
Definition: query.py:137
std::string Hash
Definition: Types.h:38
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)
void setLogHeaderForRecord(const std::string &recordName, const std::string &provenance, const std::string &usertext)
void postModule(const edm::ModuleDescription &desc)
void throwException(std::string const &message, std::string const &methodName)
Definition: Exception.cc:17
void preModule(const edm::ModuleDescription &desc)
void tagInfo(const std::string &recordName, cond::TagInfo_t &result)
std::string name
Definition: Time.h:43
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:155
std::string const & className() const
Definition: TypeID.cc:39
std::map< std::string, Record > m_callbacks
volatile std::atomic< bool > shutdown_flag false
void preEventProcessing(const edm::EventID &evtID, const edm::Timestamp &iTime)
long double T
PoolDBOutputService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)