CMS 3D CMS Logo

Classes | Public Member Functions | Private Member Functions | Private Attributes

cond::service::PoolDBOutputService Class Reference

#include <PoolDBOutputService.h>

List of all members.

Classes

struct  Record

Public Member Functions

template<typename T >
void appendSinceTime (T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
void appendSinceTime (const std::string &payloadToken, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
cond::Time_t beginOfTime () const
void closeIOV (Time_t lastTill, const std::string &recordName, bool withlogging=false)
template<typename T >
void createNewIOV (T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
void createNewIOV (const std::string &firstPayloadToken, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
cond::Time_t currentTime () const
cond::Time_t endOfTime () const
bool isNewTagRequest (const std::string &recordName)
 PoolDBOutputService (const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)
void postEndJob ()
void postModule (const edm::ModuleDescription &desc)
void preBeginLumi (const edm::LuminosityBlockID &, const edm::Timestamp &)
void preEventProcessing (const edm::EventID &evtID, const edm::Timestamp &iTime)
void preModule (const edm::ModuleDescription &desc)
const cond::LoggerqueryLog () const
cond::DbSession session () const
void setLogHeaderForRecord (const std::string &recordName, const std::string &provenance, const std::string &usertext)
std::string tag (const std::string &recordName)
void tagInfo (const std::string &recordName, cond::TagInfo &result)
template<typename T >
void writeOne (T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
virtual ~PoolDBOutputService ()

Private Member Functions

void add (GetToken const &token, cond::Time_t time, const std::string &recordName, bool withlogging=false)
unsigned int appendIOV (cond::DbSession &, Record &record, const std::string &payloadToken, cond::Time_t sinceTime)
void connect ()
void createNewIOV (GetToken const &token, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
void disconnect ()
void fillRecord (edm::ParameterSet &pset)
void initDB (bool forReading=true)
unsigned int insertIOV (cond::DbSession &pooldb, Record &record, const std::string &payloadToken, cond::Time_t tillTime)
 Returns payload location index.
RecordlookUpRecord (const std::string &recordName)
cond::UserLogInfolookUpUserLogInfo (const std::string &recordName)

Private Attributes

std::map< std::string, Recordm_callbacks
bool m_closeIOV
std::string m_connectionString
cond::Time_t m_currentTime
bool m_dbstarted
bool m_freeInsert
std::string m_logConnectionString
std::auto_ptr< cond::Loggerm_logdb
std::map< std::string,
cond::UserLogInfo
m_logheaders
std::vector< std::pair
< std::string, std::string > > 
m_newtags
cond::DbSession m_session
cond::TimeType m_timetype
std::string m_timetypestr

Detailed Description

Definition at line 88 of file PoolDBOutputService.h.


Constructor & Destructor Documentation

PoolDBOutputService::PoolDBOutputService ( const edm::ParameterSet iConfig,
edm::ActivityRegistry iAR 
)

Definition at line 44 of file PoolDBOutputService.cc.

References cond::Auth::COND_WRITER_ROLE, cond::DbConnection::configuration(), edm::ParameterSet::exists(), fillRecord(), cond::findSpecs(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), m_closeIOV, m_connectionString, m_freeInsert, m_logConnectionString, m_logdb, m_session, m_timetype, m_timetypestr, cond::DbSession::open(), postEndJob(), postModule(), preBeginLumi(), preEventProcessing(), preModule(), cond::DbConnectionConfiguration::setParameters(), AlCaHLTBitMon_QueryRunRegistry::string, convertXMLtoSQLite_cfg::toPut, cond::TimeTypeSpecs::type, edm::ActivityRegistry::watchPostEndJob(), edm::ActivityRegistry::watchPostModule(), edm::ActivityRegistry::watchPreBeginLumi(), edm::ActivityRegistry::watchPreModule(), and edm::ActivityRegistry::watchPreProcessEvent().

                                                                                                             : 
  m_timetypestr(""),
  m_currentTime( 0 ),
  m_connectionString(""),
  m_session(),
  m_logConnectionString(""),
  m_logdb(),
  m_dbstarted( false ),
  m_callbacks(),
  m_newtags(),
  m_closeIOV(false),
  m_freeInsert(false),
  m_logheaders()
{
  m_closeIOV=iConfig.getUntrackedParameter<bool>("closeIOV",m_closeIOV);

  if( iConfig.exists("outOfOrder") ){
     m_freeInsert=iConfig.getUntrackedParameter<bool>("outOfOrder");
  }  

  m_timetypestr=iConfig.getUntrackedParameter< std::string >("timetype","runnumber");
  m_timetype=cond::findSpecs( m_timetypestr).type;

  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>("DBParameters");
  cond::DbConnection connection;
  connection.configuration().setParameters( connectionPset );
  connection.configure();

  m_connectionString = iConfig.getParameter<std::string>("connect");
  m_session = connection.createSession();
  m_session.open( m_connectionString, Auth::COND_WRITER_ROLE );  
  
  if( iConfig.exists("logconnect") ){
    m_logConnectionString = iConfig.getUntrackedParameter<std::string>("logconnect");
    cond::DbSession logSession = connection.createSession();
    m_logdb.reset( new cond::Logger( logSession ) );
  }  
  
  typedef std::vector< edm::ParameterSet > Parameters;
  Parameters toPut=iConfig.getParameter<Parameters>("toPut");
  for(Parameters::iterator itToPut = toPut.begin(); itToPut != toPut.end(); ++itToPut)
    fillRecord( *itToPut);


  iAR.watchPreProcessEvent(this,&cond::service::PoolDBOutputService::preEventProcessing);
  iAR.watchPostEndJob(this,&cond::service::PoolDBOutputService::postEndJob);
  iAR.watchPreModule(this,&cond::service::PoolDBOutputService::preModule);
  iAR.watchPostModule(this,&cond::service::PoolDBOutputService::postModule);
  iAR.watchPreBeginLumi(this,&cond::service::PoolDBOutputService::preBeginLumi);
}
PoolDBOutputService::~PoolDBOutputService ( ) [virtual]

Definition at line 168 of file PoolDBOutputService.cc.

                                                    {
}

Member Function Documentation

void PoolDBOutputService::add ( GetToken const &  token,
cond::Time_t  time,
const std::string &  recordName,
bool  withlogging = false 
) [private]

Definition at line 243 of file PoolDBOutputService.cc.

References a, exception, Exception, AlCaHLTBitMon_QueryRunRegistry::string, and cond::rpcobgas::time.

Referenced by appendSinceTime().

                                                           {
  DbOpenTransaction trans( m_session.transaction() );
  Record& myrecord=this->lookUpRecord(recordName);
  if(withlogging){
    if( m_logConnectionString.empty() ) {
       throw cond::Exception("Log db was not set from PoolDBOutputService::add");
    }
  }

  std::string objToken;
  std::string objClass;
  unsigned int payloadIdx=0;

  try{
    objToken = payloadToken(m_session);
    objClass = m_session.classNameForItem( objToken );
    payloadIdx= appendIOV(m_session,myrecord,objToken,time);
    if(withlogging){
      std::string destconnect=m_session.connectionString();
      cond::UserLogInfo a=this->lookUpUserLogInfo(recordName);
      m_logdb->logOperationNow(a,destconnect,objClass,objToken,myrecord.m_tag,myrecord.timetypestr(),payloadIdx,time);
    }
  }catch(const std::exception& er){
    if(withlogging){
      std::string destconnect=m_session.connectionString();
      cond::UserLogInfo a=this->lookUpUserLogInfo(recordName);
      m_logdb->logFailedOperationNow(a,destconnect,objClass,objToken,myrecord.m_tag,myrecord.timetypestr(),payloadIdx,time,std::string(er.what()));
    }
    throw cond::Exception(std::string(er.what()) + " from PoolDBOutputService::add ");
  }
  trans.ok();
}
unsigned int PoolDBOutputService::appendIOV ( cond::DbSession pooldb,
Record record,
const std::string &  payloadToken,
cond::Time_t  sinceTime 
) [private]

Definition at line 307 of file PoolDBOutputService.cc.

References cond::IOVEditor::append(), idDealer::editor, Exception, cond::IOVEditor::freeInsert(), cond::service::PoolDBOutputService::Record::m_closeIOV, cond::service::PoolDBOutputService::Record::m_freeInsert, cond::service::PoolDBOutputService::Record::m_iovtoken, cond::service::PoolDBOutputService::Record::m_isNewTag, cond::service::PoolDBOutputService::Record::m_tag, cond::IOVEditor::stamp(), AlCaHLTBitMon_QueryRunRegistry::string, cond::IOVEditor::updateClosure(), and cond::userInfo().

                                                                        {
  DbOpenTransaction trans( m_session.transaction() );
  if( record.m_isNewTag ) {
    throw cond::Exception(std::string("Cannot append to non-existing tag ") + record.m_tag + std::string(" from PoolDBOutputService::appendIOV"));  
  }

  cond::IOVEditor editor(pooldb,record.m_iovtoken);
  
  unsigned int payloadIdx =  record.m_freeInsert ? 
    editor.freeInsert(sinceTime,payloadToken) :
    editor.append(sinceTime,payloadToken);
  if (record.m_closeIOV) editor.updateClosure(sinceTime);
  editor.stamp(cond::userInfo(),false);
  trans.ok();
  return payloadIdx;
}
template<typename T >
void cond::service::PoolDBOutputService::appendSinceTime ( T payloadObj,
cond::Time_t  sinceTime,
const std::string &  recordName,
bool  withlogging = false 
) [inline]

Definition at line 155 of file PoolDBOutputService.h.

References add().

Referenced by HLTPrescaleRecorder::endRun().

                                                                        {
        add( GetTokenFromPointer<T>(payloadObj),
             sinceTime,
             recordName,
             withlogging);
      }
void cond::service::PoolDBOutputService::appendSinceTime ( const std::string &  payloadToken,
cond::Time_t  sinceTime,
const std::string &  recordName,
bool  withlogging = false 
) [inline]

Definition at line 170 of file PoolDBOutputService.h.

References add().

                                                    {
        add(GetTrivialToken(payloadToken),
            sinceTime,
            recordName,
            withlogging);
      }
cond::Time_t PoolDBOutputService::beginOfTime ( ) const

Definition at line 178 of file PoolDBOutputService.cc.

References cond::TimeTypeSpecs::beginValue, and cond::timeTypeSpecs.

Referenced by HLTPrescaleRecorder::endRun().

                                                 {
  return timeTypeSpecs[m_timetype].beginValue;
}
void PoolDBOutputService::closeIOV ( Time_t  lastTill,
const std::string &  recordName,
bool  withlogging = false 
)

Definition at line 328 of file PoolDBOutputService.cc.

References idDealer::editor, Exception, cond::service::PoolDBOutputService::Record::m_iovtoken, cond::service::PoolDBOutputService::Record::m_isNewTag, cond::service::PoolDBOutputService::Record::m_tag, record, cond::IOVEditor::stamp(), AlCaHLTBitMon_QueryRunRegistry::string, cond::IOVEditor::updateClosure(), and cond::userInfo().

                                                               {
  // not fully working.. not be used for now...
  Record & record  = lookUpRecord(recordName);
  DbOpenTransaction trans( m_session.transaction() );

  if( record.m_isNewTag ) {
    throw cond::Exception(std::string("Cannot close non-existing tag ") + record.m_tag + std::string(" from PoolDBOutputService::closeIOV"));
  }
  cond::IOVEditor editor(m_session,record.m_iovtoken);
  editor.updateClosure(lastTill);
  editor.stamp(cond::userInfo(),false);
  trans.ok();
}
void cond::service::PoolDBOutputService::connect ( ) [private]
void PoolDBOutputService::createNewIOV ( GetToken const &  token,
cond::Time_t  firstSinceTime,
cond::Time_t  firstTillTime,
const std::string &  recordName,
bool  withlogging = false 
) [private]

Definition at line 188 of file PoolDBOutputService.cc.

References a, cond::MetaData::addMapping(), cond::IOVEditor::append(), cond::IOVEditor::create(), idDealer::editor, exception, Exception, cond::IOVEditor::setScope(), cond::IOVEditor::stamp(), AlCaHLTBitMon_QueryRunRegistry::string, cond::IOVSequence::Tag, cond::IOVEditor::token(), and cond::userInfo().

                                                                   {
  DbOpenTransaction trans( m_session.transaction() );
  Record& myrecord=this->lookUpRecord(recordName);
  if(!myrecord.m_isNewTag) {
    throw cond::Exception(myrecord.m_tag + " is not a new tag from PoolDBOutputService::createNewIOV");
  }
  std::string iovToken;
  if(withlogging){
    if( m_logConnectionString.empty() ) {
       throw cond::Exception("Log db was not set from PoolDBOutputService::createNewIOV");
    }
  }
 
  std::string objToken;
  std::string objClass;
  unsigned int payloadIdx=0;
  try{
    cond::IOVEditor editor(m_session);
    editor.create(myrecord.m_timetype, firstTillTime);
    objToken = payloadToken(m_session);
    objClass = m_session.classNameForItem( objToken );
    unsigned int payloadIdx=editor.append(firstSinceTime, objToken);
    iovToken=editor.token();
    editor.stamp(cond::userInfo(),false);
    editor.setScope( cond::IOVSequence::Tag );
    
    cond::MetaData metadata(m_session);

    metadata.addMapping(myrecord.m_tag,iovToken,myrecord.m_timetype);

    m_newtags.push_back( std::pair<std::string,std::string>(myrecord.m_tag,iovToken) );
    myrecord.m_iovtoken=iovToken;
    myrecord.m_isNewTag=false;
    if(withlogging){
      std::string destconnect=m_session.connectionString();
      cond::UserLogInfo a=this->lookUpUserLogInfo(recordName);
      m_logdb->logOperationNow(a,destconnect,objClass,objToken,myrecord.m_tag,myrecord.timetypestr(),payloadIdx,firstSinceTime);
    }
  }catch(const std::exception& er){ 
    if(withlogging){
      std::string destconnect=m_session.connectionString();
      cond::UserLogInfo a=this->lookUpUserLogInfo(recordName);
      m_logdb->logFailedOperationNow(a,destconnect,objClass,objToken,myrecord.m_tag,myrecord.timetypestr(),payloadIdx,firstSinceTime,std::string(er.what()));
    }
    throw cond::Exception(std::string(er.what()) + " from PoolDBOutputService::createNewIOV ");
  }
  trans.ok();
}
void cond::service::PoolDBOutputService::createNewIOV ( const std::string &  firstPayloadToken,
cond::Time_t  firstSinceTime,
cond::Time_t  firstTillTime,
const std::string &  recordName,
bool  withlogging = false 
) [inline]

Definition at line 141 of file PoolDBOutputService.h.

References createNewIOV().

                                                 {
        createNewIOV( GetTrivialToken(firstPayloadToken),
                      firstSinceTime,
                      firstTillTime,
                      recordName,
                      withlogging);
      }
template<typename T >
void cond::service::PoolDBOutputService::createNewIOV ( T firstPayloadObj,
cond::Time_t  firstSinceTime,
cond::Time_t  firstTillTime,
const std::string &  recordName,
bool  withlogging = false 
) [inline]

Definition at line 129 of file PoolDBOutputService.h.

Referenced by createNewIOV(), and HLTPrescaleRecorder::endRun().

                                                {
        createNewIOV( GetTokenFromPointer<T>(firstPayloadObj),
                      firstSinceTime,
                      firstTillTime,
                      recordName,
                      withlogging);     
      }
cond::Time_t PoolDBOutputService::currentTime ( ) const

Definition at line 183 of file PoolDBOutputService.cc.

                                                 {
  return m_currentTime;
}
void cond::service::PoolDBOutputService::disconnect ( ) [private]
cond::Time_t PoolDBOutputService::endOfTime ( ) const

Definition at line 173 of file PoolDBOutputService.cc.

References cond::TimeTypeSpecs::endValue, and cond::timeTypeSpecs.

Referenced by HLTPrescaleRecorder::endRun(), and writeOne().

                                               {
  return timeTypeSpecs[m_timetype].endValue;
}
void PoolDBOutputService::fillRecord ( edm::ParameterSet pset) [private]
void PoolDBOutputService::initDB ( bool  forReading = true) [private]

Definition at line 112 of file PoolDBOutputService.cc.

References cond::IOVNames::container(), cond::IOVSchemaUtility::createIOVContainer(), exception, Exception, and AlCaHLTBitMon_QueryRunRegistry::string.

{
  m_session.transaction().start(false);
  DbOpenTransaction trans( m_session.transaction() );
  try{ 
    if(!forReading) {
      cond::IOVSchemaUtility schemaUtil( m_session );
      schemaUtil.createIOVContainer();
      m_session.storage().lockContainer( IOVNames::container() );
    }
    //init logdb if required
    if(!m_logConnectionString.empty()){
      m_logdb->connect( m_logConnectionString );
      m_logdb->createLogDBIfNonExist();
    }
  } catch( const std::exception& er ){
    throw cond::Exception( std::string(er.what()) + " from PoolDBOutputService::initDB" );
  }
  trans.ok();
  m_dbstarted=true;
}
unsigned int cond::service::PoolDBOutputService::insertIOV ( cond::DbSession pooldb,
Record record,
const std::string &  payloadToken,
cond::Time_t  tillTime 
) [private]

Returns payload location index.

bool PoolDBOutputService::isNewTagRequest ( const std::string &  recordName)

Definition at line 106 of file PoolDBOutputService.cc.

References cond::service::PoolDBOutputService::Record::m_isNewTag.

Referenced by HLTPrescaleRecorder::endRun(), and writeOne().

                                                                            {
  Record& myrecord=this->lookUpRecord(recordName);
  return myrecord.m_isNewTag; 
}
cond::service::PoolDBOutputService::Record & PoolDBOutputService::lookUpRecord ( const std::string &  recordName) [private]

Definition at line 280 of file PoolDBOutputService.cc.

References cond::MetaData::getToken(), and cond::MetaData::hasTag().

                                                                       {
  if (!m_dbstarted) this->initDB( false );
  DbOpenTransaction trans( m_session.transaction() );
  std::map<std::string,Record>::iterator it=m_callbacks.find(recordName);
  if(it==m_callbacks.end()) {
    throw cond::UnregisteredRecordException(recordName + " from PoolDBOutputService::lookUpRecord");
  }
  cond::MetaData metadata(m_session);
  if( !metadata.hasTag(it->second.m_tag) ){
    it->second.m_iovtoken="";
    it->second.m_isNewTag=true;
  }else{
    it->second.m_iovtoken=metadata.getToken(it->second.m_tag);
    it->second.m_isNewTag=false;
  }
  trans.ok();
  return it->second;
}
cond::UserLogInfo & PoolDBOutputService::lookUpUserLogInfo ( const std::string &  recordName) [private]

Definition at line 299 of file PoolDBOutputService.cc.

                                                                            {
  std::map<std::string,cond::UserLogInfo>::iterator it=m_logheaders.find(recordName);
  if(it==m_logheaders.end()) throw cond::Exception("Log db was not set for record " + recordName + " from PoolDBOutputService::lookUpUserLogInfo");
  return it->second;
}
void PoolDBOutputService::postEndJob ( )

Definition at line 135 of file PoolDBOutputService.cc.

Referenced by PoolDBOutputService().

{
  if( m_dbstarted) {
    m_session.transaction().commit();
    m_dbstarted = false;
  }
}
void PoolDBOutputService::postModule ( const edm::ModuleDescription desc)

Definition at line 165 of file PoolDBOutputService.cc.

Referenced by PoolDBOutputService().

                                                                          {
}
void PoolDBOutputService::preBeginLumi ( const edm::LuminosityBlockID iLumiid,
const edm::Timestamp iTime 
)

Definition at line 158 of file PoolDBOutputService.cc.

References cond::lumiid, and edm::LuminosityBlockID::value().

Referenced by PoolDBOutputService().

                                                                                                            {
  if( m_timetype == cond::lumiid ){
    m_currentTime=iLumiid.value();
  }
}
void PoolDBOutputService::preEventProcessing ( const edm::EventID evtID,
const edm::Timestamp iTime 
)

Definition at line 144 of file PoolDBOutputService.cc.

References edm::EventID::run(), cond::runnumber, cond::timestamp, and edm::Timestamp::value().

Referenced by PoolDBOutputService().

{
  if( m_timetype == cond::runnumber ){//runnumber
    m_currentTime=iEvtid.run();
  }else if( m_timetype == cond::timestamp ){ //timestamp
    m_currentTime=iTime.value();
  }
}
void PoolDBOutputService::preModule ( const edm::ModuleDescription desc)

Definition at line 154 of file PoolDBOutputService.cc.

Referenced by PoolDBOutputService().

                                                                         {
}
const cond::Logger & PoolDBOutputService::queryLog ( ) const

Definition at line 355 of file PoolDBOutputService.cc.

                                             {
  if( !m_logdb.get() ) throw cond::Exception("Log database is not set from PoolDBOutputService::queryLog");
  return *m_logdb;
}
cond::DbSession PoolDBOutputService::session ( ) const

Definition at line 96 of file PoolDBOutputService.cc.

                                             {
  return m_session;
}
void PoolDBOutputService::setLogHeaderForRecord ( const std::string &  recordName,
const std::string &  provenance,
const std::string &  usertext 
)

Definition at line 346 of file PoolDBOutputService.cc.

References cond::UserLogInfo::provenance, and cond::UserLogInfo::usertext.

{
  cond::UserLogInfo& myloginfo=this->lookUpUserLogInfo(recordName);
  myloginfo.provenance=dataprovenance;
  myloginfo.usertext=usertext;
}
std::string PoolDBOutputService::tag ( const std::string &  recordName)

Definition at line 101 of file PoolDBOutputService.cc.

                                                                {
  return this->lookUpRecord(recordName).m_tag;
}
void PoolDBOutputService::tagInfo ( const std::string &  recordName,
cond::TagInfo result 
)
template<typename T >
void cond::service::PoolDBOutputService::writeOne ( T payload,
Time_t  time,
const std::string &  recordName,
bool  withlogging = false 
) [inline]

Definition at line 115 of file PoolDBOutputService.h.

References endOfTime(), isNewTagRequest(), ecalTPGAnalyzer_cfg::recordName, and cond::rpcobgas::time.

                                                                                                     {
        if (isNewTagRequest(recordName) ){
          createNewIOV<T>(payload, time, endOfTime(), recordName, withlogging);
        }else{
          appendSinceTime<T>(payload, time, recordName, withlogging);
        }       
      }

Member Data Documentation

std::map<std::string, Record> cond::service::PoolDBOutputService::m_callbacks [private]

Definition at line 281 of file PoolDBOutputService.h.

Referenced by fillRecord().

Definition at line 283 of file PoolDBOutputService.h.

Referenced by fillRecord(), and PoolDBOutputService().

Definition at line 275 of file PoolDBOutputService.h.

Referenced by PoolDBOutputService().

Definition at line 273 of file PoolDBOutputService.h.

Definition at line 279 of file PoolDBOutputService.h.

Definition at line 284 of file PoolDBOutputService.h.

Referenced by fillRecord(), and PoolDBOutputService().

Definition at line 277 of file PoolDBOutputService.h.

Referenced by fillRecord(), and PoolDBOutputService().

Definition at line 278 of file PoolDBOutputService.h.

Referenced by PoolDBOutputService().

Definition at line 285 of file PoolDBOutputService.h.

Referenced by fillRecord().

std::vector< std::pair<std::string,std::string> > cond::service::PoolDBOutputService::m_newtags [private]

Definition at line 282 of file PoolDBOutputService.h.

Definition at line 276 of file PoolDBOutputService.h.

Referenced by PoolDBOutputService().

Definition at line 271 of file PoolDBOutputService.h.

Referenced by PoolDBOutputService().

Definition at line 272 of file PoolDBOutputService.h.

Referenced by fillRecord(), and PoolDBOutputService().