CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PoolDBOutputService.cc
Go to the documentation of this file.
3 //#include "CondCore/DBCommon/interface/TagInfo.h"
4 //#include "CondCore/DBCommon/interface/IOVInfo.h"
10 //
11 #include <vector>
12 #include<memory>
13 
14 void
16  Record thisrecord;
17 
18  thisrecord.m_idName = pset.getParameter<std::string>("record");
19  thisrecord.m_tag = pset.getParameter<std::string>("tag");
20 
21  thisrecord.m_closeIOV =
22  pset.getUntrackedParameter<bool>("closeIOV", m_closeIOV);
23 
24  //thisrecord.m_timetype=cond::findSpecs(pset.getUntrackedParameter< std::string >("timetype",m_timetypestr)).type;
26 
27  m_callbacks.insert(std::make_pair(thisrecord.m_idName,thisrecord));
28 
29  // *** THE LOGGING has still to be defined and implemented.
30  //if( !m_logConnectionString.empty() ){
31  // cond::UserLogInfo userloginfo;
32  // m_logheaders.insert(std::make_pair(thisrecord.m_idName,userloginfo));
33  //}
34 }
35 
37  m_timetypestr(""),
38  m_currentTime( 0 ),
39  m_session(),
40  //m_logConnectionString(""),
41  //m_logdb(),
42  m_dbstarted( false ),
43  m_callbacks(),
44  //m_newtags(),
45  m_closeIOV(false)//,
46  //m_logheaders()
47 {
48  m_closeIOV=iConfig.getUntrackedParameter<bool>("closeIOV",m_closeIOV);
49 
50  m_timetypestr=iConfig.getUntrackedParameter< std::string >("timetype","runnumber");
51  m_timetype = cond::time::timeTypeFromName( m_timetypestr );
52 
53  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>("DBParameters");
55  connection.setParameters( connectionPset );
56  connection.configure();
57  std::string connectionString = iConfig.getParameter<std::string>("connect");
58  BackendType backType = (BackendType) iConfig.getUntrackedParameter<int>("dbFormat", DEFAULT_DB );
59  if( backType == UNKNOWN_DB ) backType = DEFAULT_DB;
60  m_session = connection.createSession( connectionString, true, backType );
61 
62  //if( iConfig.exists("logconnect") ){
63  // m_logConnectionString = iConfig.getUntrackedParameter<std::string>("logconnect");
64  // cond::DbSession logSession = connection.createSession();
65  // m_logdb.reset( new cond::Logger( logSession ) );
66  //}
67 
68  typedef std::vector< edm::ParameterSet > Parameters;
69  Parameters toPut=iConfig.getParameter<Parameters>("toPut");
70  for(Parameters::iterator itToPut = toPut.begin(); itToPut != toPut.end(); ++itToPut)
71  fillRecord( *itToPut);
72 
73 
79 }
80 
83  return m_session;
84 }
85 
88  return this->lookUpRecord(recordName).m_tag;
89 }
90 
91 bool
93  Record& myrecord=this->lookUpRecord(recordName);
94  return myrecord.m_isNewTag;
95 }
96 
97 void
99 {
100  m_session.transaction().start(false);
101  cond::persistency::TransactionScope scope( m_session.transaction() );
102  try{
103  if(!forReading) {
104  if( !m_session.existsDatabase() ) m_session.createDatabase();
105  }
106  //init logdb if required
107  //if(!m_logConnectionString.empty()){
108  // m_logdb->connect( m_logConnectionString );
109  // m_logdb->createLogDBIfNonExist();
110  //}
111  } catch( const std::exception& er ){
112  cond::throwException( std::string(er.what()),"PoolDBOutputService::initDB" );
113  }
114  scope.close();
115  m_dbstarted=true;
116 }
117 
118 void
120 {
121  if( m_dbstarted) {
122  m_session.transaction().commit();
123  m_dbstarted = false;
124  }
125 }
126 
127 void
129 {
130  if( m_timetype == cond::runnumber ){//runnumber
131  m_currentTime=iEvtid.run();
132  }else if( m_timetype == cond::timestamp ){ //timestamp
133  m_currentTime=iTime.value();
134  }
135 }
136 
137 void
139 }
140 
141 void
143  if( m_timetype == cond::lumiid ){
144  m_currentTime=iLumiid.value();
145  }
146 }
147 
148 void
150 }
151 
153 }
154 
155 
158  return timeTypeSpecs[m_timetype].endValue;
159 }
160 
163  return timeTypeSpecs[m_timetype].beginValue;
164 }
165 
168  return m_currentTime;
169 }
170 
171 void
173  const std::string payloadType,
174  cond::Time_t firstSinceTime,
175  cond::Time_t firstTillTime,
176  const std::string& recordName,
177  bool withlogging){
178  cond::persistency::TransactionScope scope( m_session.transaction() );
179  Record& myrecord=this->lookUpRecord(recordName);
180  if(!myrecord.m_isNewTag) {
181  cond::throwException( myrecord.m_tag + " is not a new tag", "PoolDBOutputService::createNewIOV");
182  }
183  std::string iovToken;
184  //if(withlogging){
185  // if( m_logConnectionString.empty() ) {
186  // throw cond::db::Exception("Log db was not set from PoolDBOutputService::createNewIOV",
187  // "PoolDBOutputService::createNewIOV");
188  // }
189  //}
190 
191  try{
192  // FIX ME: synchronization type and description have to be passed as the other parameters?
193  cond::persistency::IOVEditor editor = m_session.createIov( payloadType, myrecord.m_tag, myrecord.m_timetype, cond::OFFLINE );
194  editor.setDescription( "New Tag" );
195  editor.insert( firstSinceTime, firstPayloadId );
196  editor.flush();
197  myrecord.m_isNewTag=false;
198  //if(withlogging){
199  // std::string destconnect=m_session.connectionString();
200  // cond::UserLogInfo a=this->lookUpUserLogInfo(recordName);
201  // m_logdb->logOperationNow(a,destconnect,objClass,objToken,myrecord.m_tag,myrecord.timetypestr(),payloadIdx,firstSinceTime);
202  //}
203  }catch(const std::exception& er){
204  //if(withlogging){
205  // std::string destconnect=m_session.connectionString();
206  // cond::UserLogInfo a=this->lookUpUserLogInfo(recordName);
207  // m_logdb->logFailedOperationNow(a,destconnect,objClass,objToken,myrecord.m_tag,myrecord.timetypestr(),payloadIdx,firstSinceTime,std::string(er.what()));
208  //}
209  cond::throwException(std::string(er.what()) + " from PoolDBOutputService::createNewIOV ",
210  "PoolDBOutputService::createNewIOV");
211  }
212  scope.close();
213 }
214 
215 void
217  cond::Time_t firstSinceTime,
218  cond::Time_t firstTillTime,
219  const std::string& recordName,
220  bool withlogging){
221  cond::persistency::TransactionScope scope( m_session.transaction() );
222  Record& myrecord=this->lookUpRecord(recordName);
223  if(!myrecord.m_isNewTag) {
224  cond::throwException( myrecord.m_tag + " is not a new tag", "PoolDBOutputService::createNewIOV");
225  }
226  std::string iovToken;
227  try{
228  // FIX ME: synchronization type and description have to be passed as the other parameters?
229  cond::persistency::IOVEditor editor = m_session.createIovForPayload( firstPayloadId, myrecord.m_tag, myrecord.m_timetype, cond::OFFLINE );
230  editor.setDescription( "New Tag" );
231  editor.insert( firstSinceTime, firstPayloadId );
232  editor.flush();
233  myrecord.m_isNewTag=false;
234  }catch(const std::exception& er){
235  cond::throwException(std::string(er.what()) + " from PoolDBOutputService::createNewIOV ",
236  "PoolDBOutputService::createNewIOV");
237  }
238  scope.close();
239 }
240 
241 void
244  const std::string& recordName,
245  bool withlogging) {
246  cond::persistency::TransactionScope scope( m_session.transaction() );
247  Record& myrecord=this->lookUpRecord(recordName);
248  if( myrecord.m_isNewTag ) {
249  cond::throwException(std::string("Cannot append to non-existing tag ") + myrecord.m_tag,
250  "PoolDBOutputService::appendSinceTime");
251  }
252  //if(withlogging){
253  // if( m_logConnectionString.empty() ) {
254  // throw cond::Exception("Log db was not set from PoolDBOutputService::add");
255  // }
256  //}
257 
258  try{
259  cond::persistency::IOVEditor editor = m_session.editIov( myrecord.m_tag );
260  editor.insert( time, payloadId );
261  editor.flush();
262 
263  //if(withlogging){
264  // std::string destconnect=m_session.connectionString();
265  // cond::UserLogInfo a=this->lookUpUserLogInfo(recordName);
266  // m_logdb->logOperationNow(a,destconnect,objClass,objToken,myrecord.m_tag,myrecord.timetypestr(),payloadIdx,time);
267  //}
268  }catch(const std::exception& er){
269  //if(withlogging){
270  // std::string destconnect=m_session.connectionString();
271  // cond::UserLogInfo a=this->lookUpUserLogInfo(recordName);
272  // m_logdb->logFailedOperationNow(a,destconnect,objClass,objToken,myrecord.m_tag,myrecord.timetypestr(),payloadIdx,time,std::string(er.what()));
273  //}
275  "PoolDBOutputService::appendSinceTime");
276  }
277  scope.close();
278 }
279 
282  if (!m_dbstarted) this->initDB( false );
283  cond::persistency::TransactionScope scope( m_session.transaction() );
284  std::map<std::string,Record>::iterator it=m_callbacks.find(recordName);
285  if(it==m_callbacks.end()) {
286  cond::throwException("The record \""+recordName +"\" has not been registered.","PoolDBOutputService::lookUpRecord");
287  }
288  if( !m_session.existsIov( it->second.m_tag) ){
289  it->second.m_isNewTag=true;
290  } else {
291  it->second.m_isNewTag=false;
292  }
293  scope.close();
294  return it->second;
295 }
296 
297 //cond::UserLogInfo&
298 //cond::service::PoolDBOutputService::lookUpUserLogInfo(const std::string& recordName){
299 // std::map<std::string,cond::UserLogInfo>::iterator it=m_logheaders.find(recordName);
300 // if(it==m_logheaders.end()) throw cond::Exception("Log db was not set for record " + recordName + " from PoolDBOutputService::lookUpUserLogInfo");
301 // return it->second;
302 //}
303 
304 void
306  bool withlogging) {
307  // not fully working.. not be used for now...
308  Record & myrecord = lookUpRecord(recordName);
309  cond::persistency::TransactionScope scope( m_session.transaction() );
310 
311  if( myrecord.m_isNewTag ) {
312  cond::throwException(std::string("Cannot close non-existing tag ") + myrecord.m_tag,
313  "PoolDBOutputService::closeIOV");
314  }
315  cond::persistency::IOVEditor editor = m_session.editIov( myrecord.m_tag );
316  editor.setEndOfValidity( lastTill );
317  editor.flush();
318  scope.close();
319 }
320 
321 
322 void
324 {
325  //cond::UserLogInfo& myloginfo=this->lookUpUserLogInfo(recordName);
326  //myloginfo.provenance=dataprovenance;
327  //myloginfo.usertext=usertext;
328 }
329 
330 //
331 //const cond::Logger&
332 //cond::service::PoolDBOutputService::queryLog()const{
333 // if( !m_logdb.get() ) throw cond::Exception("Log database is not set from PoolDBOutputService::queryLog");
334 // return *m_logdb;
335 //}
336 
337 // Still required.
338 void
340  //
341  Record& record = lookUpRecord(recordName);
342  result.name=record.m_tag;
343  //use iovproxy to find out.
344  cond::persistency::IOVProxy iov = m_session.readIov( record.m_tag );
345  result.size=iov.sequenceSize();
346  if (result.size>0) {
347  cond::Iov_t last = iov.getLast();
348  result.lastInterval = cond::ValidityInterval( last.since, last.till );
349  result.lastPayloadToken = last.payloadId;
350  }
351 }
RunNumber_t run() const
Definition: EventID.h:42
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void closeIOV(Time_t lastTill, const std::string &recordName, bool withlogging=false)
void initDB(bool forReading=true)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
Time_t beginValue
Definition: Time.h:45
void fillRecord(edm::ParameterSet &pset)
cond::persistency::Session session() const
void watchPostModule(PostModule::slot_type const &iSlot)
void watchPreProcessEvent(PreProcessEvent::slot_type const &iSlot)
Time_t since
Definition: Types.h:46
boost::uint64_t value() const
size_t size
Definition: Types.h:67
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
void setDescription(const std::string &description)
Definition: IOVEditor.cc:111
void preBeginLumi(const edm::LuminosityBlockID &, const edm::Timestamp &)
void watchPreModule(PreModule::slot_type const &iSlot)
void setParameters(const edm::ParameterSet &connectionPset)
std::string tag(const std::string &recordName)
std::string name
Definition: Types.h:63
cond::ValidityInterval lastInterval
Definition: Types.h:65
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
unsigned long long Time_t
Definition: Time.h:16
vector< ParameterSet > Parameters
TimeType timeTypeFromName(const std::string &name)
Definition: Time.cc:24
tuple iov
Definition: o2o.py:307
bool isNewTagRequest(const std::string &recordName)
Record & lookUpRecord(const std::string &recordName)
tuple result
Definition: query.py:137
Hash payloadId
Definition: Types.h:48
cond::persistency::Session m_session
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
BackendType
Definition: Types.h:23
void setLogHeaderForRecord(const std::string &recordName, const std::string &provenance, const std::string &usertext)
void postModule(const edm::ModuleDescription &desc)
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
Definition: IOVEditor.cc:129
void throwException(std::string const &message, std::string const &methodName)
Definition: Exception.cc:17
tuple editor
Definition: idDealer.py:73
void preModule(const edm::ModuleDescription &desc)
void tagInfo(const std::string &recordName, cond::TagInfo_t &result)
std::string lastPayloadToken
Definition: Types.h:66
static constexpr BackendType DEFAULT_DB
Definition: Types.h:24
void watchPreBeginLumi(PreBeginLumi::slot_type const &iSlot)
void setEndOfValidity(cond::Time_t validity)
Definition: IOVEditor.cc:100
std::map< std::string, Record > m_callbacks
volatile std::atomic< bool > shutdown_flag false
Time_t endValue
Definition: Time.h:46
void preEventProcessing(const edm::EventID &evtID, const edm::Timestamp &iTime)
TimeValue_t value() const
Definition: Timestamp.h:56
PoolDBOutputService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)
Time_t till
Definition: Types.h:47