CMS 3D CMS Logo

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