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