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.
17 
18 #include <vector>
19 #include<memory>
20 
21 void
23  Record thisrecord;
24 
25  thisrecord.m_idName = pset.getParameter<std::string>("record");
26  thisrecord.m_tag = pset.getParameter<std::string>("tag");
27 
28  thisrecord.m_closeIOV =
29  pset.getUntrackedParameter<bool>("closeIOV", m_closeIOV);
30 
31  thisrecord.m_freeInsert =
32  pset.getUntrackedParameter<bool>("outOfOrder",m_freeInsert);
33 
35 
36  m_callbacks.insert(std::make_pair(thisrecord.m_idName,thisrecord));
37 
38  if( !m_logConnectionString.empty() ){
39  cond::UserLogInfo userloginfo;
40  m_logheaders.insert(std::make_pair(thisrecord.m_idName,userloginfo));
41  }
42 }
43 
45  m_timetypestr(""),
46  m_currentTime( 0 ),
47  m_connectionString(""),
48  m_session(),
49  m_logConnectionString(""),
50  m_logdb(),
51  m_dbstarted( false ),
52  m_callbacks(),
53  m_newtags(),
54  m_closeIOV(false),
55  m_freeInsert(false),
56  m_logheaders()
57 {
58  m_closeIOV=iConfig.getUntrackedParameter<bool>("closeIOV",m_closeIOV);
59 
60  if( iConfig.exists("outOfOrder") ){
61  m_freeInsert=iConfig.getUntrackedParameter<bool>("outOfOrder");
62  }
63 
64  m_timetypestr=iConfig.getUntrackedParameter< std::string >("timetype","runnumber");
66 
67  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>("DBParameters");
68  cond::DbConnection connection;
69  connection.configuration().setParameters( connectionPset );
70  connection.configure();
71 
72  m_connectionString = iConfig.getParameter<std::string>("connect");
73  m_session = connection.createSession();
75 
76  if( iConfig.exists("logconnect") ){
78  cond::DbSession logSession = connection.createSession();
79  m_logdb.reset( new cond::Logger( logSession ) );
80  }
81 
82  typedef std::vector< edm::ParameterSet > Parameters;
83  Parameters toPut=iConfig.getParameter<Parameters>("toPut");
84  for(Parameters::iterator itToPut = toPut.begin(); itToPut != toPut.end(); ++itToPut)
85  fillRecord( *itToPut);
86 
87 
93 }
94 
97  return m_session;
98 }
99 
102  return this->lookUpRecord(recordName).m_tag;
103 }
104 
105 bool
107  Record& myrecord=this->lookUpRecord(recordName);
108  return myrecord.m_isNewTag;
109 }
110 
111 void
113 {
114  m_session.transaction().start(false);
115  DbOpenTransaction trans( m_session.transaction() );
116  try{
117  if(!forReading) {
118  cond::IOVSchemaUtility schemaUtil( m_session );
119  schemaUtil.createIOVContainer();
120  m_session.storage().lockContainer( IOVNames::container() );
121  }
122  //init logdb if required
123  if(!m_logConnectionString.empty()){
124  m_logdb->connect( m_logConnectionString );
125  m_logdb->createLogDBIfNonExist();
126  }
127  } catch( const std::exception& er ){
128  throw cond::Exception( std::string(er.what()) + " from PoolDBOutputService::initDB" );
129  }
130  trans.ok();
131  m_dbstarted=true;
132 }
133 
134 void
136 {
137  if( m_dbstarted) {
138  m_session.transaction().commit();
139  m_dbstarted = false;
140  }
141 }
142 
143 void
145 {
146  if( m_timetype == cond::runnumber ){//runnumber
147  m_currentTime=iEvtid.run();
148  }else if( m_timetype == cond::timestamp ){ //timestamp
149  m_currentTime=iTime.value();
150  }
151 }
152 
153 void
155 }
156 
157 void
159  if( m_timetype == cond::lumiid ){
160  m_currentTime=iLumiid.value();
161  }
162 }
163 
164 void
166 }
167 
169 }
170 
171 
174  return timeTypeSpecs[m_timetype].endValue;
175 }
176 
179  return timeTypeSpecs[m_timetype].beginValue;
180 }
181 
184  return m_currentTime;
185 }
186 
187 void
189  cond::Time_t firstSinceTime,
190  cond::Time_t firstTillTime,
191  const std::string& recordName,
192  bool withlogging){
193  DbOpenTransaction trans( m_session.transaction() );
194  Record& myrecord=this->lookUpRecord(recordName);
195  if(!myrecord.m_isNewTag) {
196  throw cond::Exception(myrecord.m_tag + " is not a new tag from PoolDBOutputService::createNewIOV");
197  }
198  std::string iovToken;
199  if(withlogging){
200  if( m_logConnectionString.empty() ) {
201  throw cond::Exception("Log db was not set from PoolDBOutputService::createNewIOV");
202  }
203  }
204 
205  std::string objToken;
206  std::string objClass;
207  unsigned int payloadIdx=0;
208  try{
209  cond::IOVEditor editor(m_session);
210  editor.create(myrecord.m_timetype, firstTillTime);
211  objToken = payloadToken(m_session);
212  objClass = m_session.classNameForItem( objToken );
213  unsigned int payloadIdx=editor.append(firstSinceTime, objToken);
214  iovToken=editor.token();
215  editor.stamp(cond::userInfo(),false);
217 
218  cond::MetaData metadata(m_session);
219 
220  metadata.addMapping(myrecord.m_tag,iovToken,myrecord.m_timetype);
221 
222  m_newtags.push_back( std::pair<std::string,std::string>(myrecord.m_tag,iovToken) );
223  myrecord.m_iovtoken=iovToken;
224  myrecord.m_isNewTag=false;
225  if(withlogging){
226  std::string destconnect=m_session.connectionString();
227  cond::UserLogInfo a=this->lookUpUserLogInfo(recordName);
228  m_logdb->logOperationNow(a,destconnect,objClass,objToken,myrecord.m_tag,myrecord.timetypestr(),payloadIdx,firstSinceTime);
229  }
230  }catch(const std::exception& er){
231  if(withlogging){
232  std::string destconnect=m_session.connectionString();
233  cond::UserLogInfo a=this->lookUpUserLogInfo(recordName);
234  m_logdb->logFailedOperationNow(a,destconnect,objClass,objToken,myrecord.m_tag,myrecord.timetypestr(),payloadIdx,firstSinceTime,std::string(er.what()));
235  }
236  throw cond::Exception(std::string(er.what()) + " from PoolDBOutputService::createNewIOV ");
237  }
238  trans.ok();
239 }
240 
241 
242 void
245  const std::string& recordName,
246  bool withlogging) {
247  DbOpenTransaction trans( m_session.transaction() );
248  Record& myrecord=this->lookUpRecord(recordName);
249  if(withlogging){
250  if( m_logConnectionString.empty() ) {
251  throw cond::Exception("Log db was not set from PoolDBOutputService::add");
252  }
253  }
254 
255  std::string objToken;
256  std::string objClass;
257  unsigned int payloadIdx=0;
258 
259  try{
260  objToken = payloadToken(m_session);
261  objClass = m_session.classNameForItem( objToken );
262  payloadIdx= appendIOV(m_session,myrecord,objToken,time);
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  }
274  throw cond::Exception(std::string(er.what()) + " from PoolDBOutputService::add ");
275  }
276  trans.ok();
277 }
278 
281  if (!m_dbstarted) this->initDB( false );
282  DbOpenTransaction trans( m_session.transaction() );
283  std::map<std::string,Record>::iterator it=m_callbacks.find(recordName);
284  if(it==m_callbacks.end()) {
285  throw cond::UnregisteredRecordException(recordName + " from PoolDBOutputService::lookUpRecord");
286  }
287  cond::MetaData metadata(m_session);
288  if( !metadata.hasTag(it->second.m_tag) ){
289  it->second.m_iovtoken="";
290  it->second.m_isNewTag=true;
291  }else{
292  it->second.m_iovtoken=metadata.getToken(it->second.m_tag);
293  it->second.m_isNewTag=false;
294  }
295  trans.ok();
296  return it->second;
297 }
300  std::map<std::string,cond::UserLogInfo>::iterator it=m_logheaders.find(recordName);
301  if(it==m_logheaders.end()) throw cond::Exception("Log db was not set for record " + recordName + " from PoolDBOutputService::lookUpUserLogInfo");
302  return it->second;
303 }
304 
305 
306 unsigned int
308  Record& record,
309  const std::string& payloadToken,
310  cond::Time_t sinceTime){
311  DbOpenTransaction trans( m_session.transaction() );
312  if( record.m_isNewTag ) {
313  throw cond::Exception(std::string("Cannot append to non-existing tag ") + record.m_tag + std::string(" from PoolDBOutputService::appendIOV"));
314  }
315 
316  cond::IOVEditor editor(pooldb,record.m_iovtoken);
317 
318  unsigned int payloadIdx = record.m_freeInsert ?
319  editor.freeInsert(sinceTime,payloadToken) :
320  editor.append(sinceTime,payloadToken);
321  if (record.m_closeIOV) editor.updateClosure(sinceTime);
322  editor.stamp(cond::userInfo(),false);
323  trans.ok();
324  return payloadIdx;
325 }
326 
327 void
329  bool withlogging) {
330  // not fully working.. not be used for now...
331  Record & record = lookUpRecord(recordName);
332  DbOpenTransaction trans( m_session.transaction() );
333 
334  if( record.m_isNewTag ) {
335  throw cond::Exception(std::string("Cannot close non-existing tag ") + record.m_tag + std::string(" from PoolDBOutputService::closeIOV"));
336  }
337  cond::IOVEditor editor(m_session,record.m_iovtoken);
338  editor.updateClosure(lastTill);
339  editor.stamp(cond::userInfo(),false);
340  trans.ok();
341 }
342 
343 
344 
345 void
347 {
348  cond::UserLogInfo& myloginfo=this->lookUpUserLogInfo(recordName);
349  myloginfo.provenance=dataprovenance;
350  myloginfo.usertext=usertext;
351 }
352 
353 
354 const cond::Logger&
356  if( !m_logdb.get() ) throw cond::Exception("Log database is not set from PoolDBOutputService::queryLog");
357  return *m_logdb;
358 }
359 
360 
361 void
363  //
364  Record& record = lookUpRecord(recordName);
365  result.name=record.m_tag;
366  result.token=record.m_iovtoken;
367  //use iovproxy to find out.
368  cond::IOVProxy iov(m_session, record.m_iovtoken);
369  result.size=iov.size();
370  if (result.size>0) {
371  // get last object
372  cond::IOVElementProxy last = *(--iov.end());
373  result.lastInterval = cond::ValidityInterval(last.since(), last.till());
374  result.lastPayloadToken=last.token();
375  }
376 }
RunNumber_t run() const
Definition: EventID.h:42
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
T getParameter(std::string const &) const
std::string usertext
Definition: LogDBEntry.h:9
T getUntrackedParameter(std::string const &, T const &) const
std::string create(cond::TimeType timetype)
Definition: IOVEditor.cc:244
void closeIOV(Time_t lastTill, const std::string &recordName, bool withlogging=false)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
Time_t beginValue
Definition: Time.h:45
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:144
JetCorrectorParameters::Record record
Definition: classes.h:13
void fillRecord(edm::ParameterSet &pset)
std::map< std::string, cond::UserLogInfo > m_logheaders
void watchPostModule(PostModule::slot_type const &iSlot)
void watchPreProcessEvent(PreProcessEvent::slot_type const &iSlot)
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:89
boost::uint64_t value() const
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string const & token() const
Definition: IOVEditor.cc:526
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
void add(GetToken const &token, cond::Time_t time, const std::string &recordName, bool withlogging=false)
const std::string getToken(const std::string &tagname) const
Definition: MetaData.cc:53
cond::Time_t till() const
Definition: IOVProxy.h:71
void preBeginLumi(const edm::LuminosityBlockID &, const edm::Timestamp &)
const_iterator end() const
Definition: IOVProxy.h:193
void setScope(cond::IOVSequence::ScopeType scope)
set the scope
Definition: IOVEditor.cc:379
std::string lastPayloadToken
Definition: TagInfo.h:12
unsigned int freeInsert(cond::Time_t sinceTime, const std::string &payloadToken)
insert a payload with known since in any position
Definition: IOVEditor.cc:435
void watchPreModule(PreModule::slot_type const &iSlot)
void setParameters(const edm::ParameterSet &connectionPset)
std::string tag(const std::string &recordName)
std::string name
Definition: TagInfo.h:9
unsigned long long Time_t
Definition: Time.h:16
vector< ParameterSet > Parameters
bool addMapping(const std::string &name, const std::string &token, cond::TimeType timetype=cond::runnumber)
Definition: MetaData.cc:36
tuple iov
Definition: o2o.py:307
bool isNewTagRequest(const std::string &recordName)
Record & lookUpRecord(const std::string &recordName)
std::string const & token() const
Definition: IOVProxy.h:75
bool hasTag(const std::string &name) const
Definition: MetaData.cc:70
TimeType type
Definition: Time.h:41
tuple result
Definition: query.py:137
static const std::string COND_WRITER_ROLE
Definition: Auth.h:18
std::string provenance
Definition: LogDBEntry.h:8
size_t size
Definition: TagInfo.h:13
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 tagInfo(const std::string &recordName, cond::TagInfo &result)
TimeValue_t value() const
Definition: Timestamp.cc:72
void postModule(const edm::ModuleDescription &desc)
int size() const
Definition: IOVProxy.cc:272
std::string token
Definition: TagInfo.h:10
tuple editor
Definition: idDealer.py:73
void updateClosure(cond::Time_t newtillTime)
Update the closure of the iov sequence.
Definition: IOVEditor.cc:389
unsigned int append(cond::Time_t sinceTime, const std::string &payloadToken)
Definition: IOVEditor.cc:400
void preModule(const edm::ModuleDescription &desc)
cond::Time_t since() const
Definition: IOVProxy.h:67
static std::string container()
Definition: IOVNames.h:7
cond::ValidityInterval lastInterval
Definition: TagInfo.h:11
double a
Definition: hdecay.h:121
void stamp(std::string const &icomment, bool append=false)
Definition: IOVEditor.cc:359
void watchPreBeginLumi(PreBeginLumi::slot_type const &iSlot)
std::string userInfo()
Definition: IOVInfo.cc:9
const TimeTypeSpecs & findSpecs(std::string const &name)
Definition: Time.cc:33
std::map< std::string, Record > m_callbacks
bool createIOVContainer()
create iov tables
Time_t endValue
Definition: Time.h:46
void preEventProcessing(const edm::EventID &evtID, const edm::Timestamp &iTime)
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)