CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

cond::IOVEditor Class Reference

#include <IOVEditor.h>

List of all members.

Public Member Functions

unsigned int append (cond::Time_t sinceTime, const std::string &payloadToken)
 Append a payload with known since time. The previous last payload's till time will be adjusted to the new payload since time. Returns the payload index in the iov sequence.
void bulkAppend (std::vector< std::pair< cond::Time_t, std::string > > &values)
 Bulk append of iov chunck.
void bulkAppend (std::vector< cond::IOVElement > &values)
void create (cond::TimeType timetype, cond::Time_t lastTill)
void create (cond::TimeType timetype)
void deleteEntries (bool withPayload=false)
Time_t firstSince () const
unsigned int freeInsert (cond::Time_t sinceTime, const std::string &payloadToken)
 insert a payload with known since in any position
void import (const std::string &sourceIOVtoken)
unsigned int insert (cond::Time_t tillTime, const std::string &payloadToken)
 Assign a payload with till time. Returns the payload index in the iov sequence.
IOVSequenceiov ()
 IOVEditor (cond::DbSession &dbSess, const std::string &token)
 IOVEditor (cond::DbSession &dbSess)
Time_t lastTill () const
void stamp (std::string const &icomment, bool append=false)
TimeType timetype () const
std::string const & token () const
 Returns the token of the iov sequence associated with this editor.
unsigned int truncate (bool withPayload=false)
void updateClosure (cond::Time_t newtillTime)
 Update the closure of the iov sequence.
 ~IOVEditor ()
 Destructor.

Private Member Functions

void debugInfo (std::ostream &co) const
void init ()
void reportError (std::string message) const
void reportError (std::string message, cond::Time_t time) const
bool validTime (cond::Time_t time, cond::TimeType timetype) const
bool validTime (cond::Time_t time) const

Private Attributes

cond::DbSession m_dbSess
boost::shared_ptr
< cond::IOVSequence
m_iov
bool m_isActive
std::string m_token

Detailed Description

Definition at line 25 of file IOVEditor.h.


Constructor & Destructor Documentation

IOVEditor::IOVEditor ( cond::DbSession dbSess) [explicit]

Definition at line 14 of file IOVEditor.cc.

                                            :m_dbSess(dbSess),
                                                 m_isActive(false){
  }
IOVEditor::IOVEditor ( cond::DbSession dbSess,
const std::string &  token 
)

Definition at line 18 of file IOVEditor.cc.

                         :m_dbSess(dbSess),m_token(token),
                          m_isActive(false){
  }
IOVEditor::~IOVEditor ( )

Destructor.

Definition at line 12 of file IOVEditor.cc.

{}

Member Function Documentation

unsigned int IOVEditor::append ( cond::Time_t  sinceTime,
const std::string &  payloadToken 
)

Append a payload with known since time. The previous last payload's till time will be adjusted to the new payload since time. Returns the payload index in the iov sequence.

Definition at line 212 of file IOVEditor.cc.

References init(), lastTill(), m_dbSess, m_iov, m_isActive, m_token, reportError(), runTheMatrix::ret, timetype(), cond::timeTypeSpecs, updateClosure(), cond::DbSession::updateObject(), and validTime().

Referenced by cond::service::PoolDBOutputService::appendIOV(), cond::service::PoolDBOutputService::createNewIOV(), and cond::AlignSplitIOV::execute().

                      {
    if( m_token.empty() ) {
      reportError("cond::IOVEditor::appendIOV cannot append to non-existing IOV index");
    }
    
    if(!m_isActive) {
      this->init();
    }

    if(!validTime(sinceTime))
      reportError("cond::IOVEditor::append time not in global range",sinceTime);
    
    
    if(  !m_iov->iovs().empty() ){
      //range check in case 
      cond::Time_t lastValidSince=m_iov->iovs().back().sinceTime();
      if( sinceTime<= lastValidSince){
        reportError("IOVEditor::append Error: since time out of range: below last since",sinceTime);
      }
    }

    // does it make sense? (in case of mixed till and since insertions...)
    if (lastTill()<=sinceTime) updateClosure(timeTypeSpecs[timetype()].endValue);
    unsigned int ret = m_iov->add(sinceTime,payloadToken);
    m_dbSess.updateObject( m_iov.get(), m_token );
    return ret;
  }
void IOVEditor::bulkAppend ( std::vector< cond::IOVElement > &  values)

Definition at line 176 of file IOVEditor.cc.

References firstTime, init(), lastTill(), m_dbSess, m_iov, m_isActive, m_token, reportError(), cond::DbSession::updateObject(), and validTime().

                                                          {
    if (values.empty()) return;
    if(!m_isActive) this->init();
    cond::Time_t firstTime = values.front().sinceTime();
    cond::Time_t   lastTime = values.back().sinceTime();
    if(!validTime(firstTime))
      reportError("cond::IOVEditor::bulkInsert first time not in global range",firstTime);

    if(!validTime(lastTime))
      reportError("cond::IOVEditor::bulkInsert last time not in global range",lastTime);

   if(lastTime>=lastTill() ||
      ( !m_iov->iovs().empty() && firstTime<=m_iov->iovs().back().sinceTime()) 
      )    reportError("cond::IOVEditor::bulkInsert IOV not in range",firstTime);

   m_dbSess.updateObject( m_iov.get(), m_token );
 }
void IOVEditor::bulkAppend ( std::vector< std::pair< cond::Time_t, std::string > > &  values)

Bulk append of iov chunck.

Definition at line 152 of file IOVEditor.cc.

References firstTime, init(), lastTill(), m_dbSess, m_iov, m_isActive, m_token, reportError(), cond::DbSession::updateObject(), validTime(), and makeHLTPrescaleTable::values.

                                                                         {
    if (values.empty()) return;
    if(!m_isActive) this->init();
    cond::Time_t firstTime = values.front().first;
    cond::Time_t  lastTime = values.back().first;
    if(!validTime(firstTime))
      reportError("cond::IOVEditor::bulkInsert first time not in global range",firstTime);

    if(!validTime(lastTime))
      reportError("cond::IOVEditor::bulkInsert last time not in global range",lastTime);

   if(lastTime>=lastTill() ||
      ( !m_iov->iovs().empty() && firstTime<=m_iov->iovs().back().sinceTime()) 
       )    
     reportError("cond::IOVEditor::bulkInsert IOV not in range",firstTime);

   for(std::vector< std::pair<cond::Time_t,std::string> >::const_iterator it=values.begin(); it!=values.end(); ++it){
     //     m_iov->iov.insert(m_iov->iov.end(), values.begin(), values.end());
     m_iov->add(it->first,it->second);
   }
   m_dbSess.updateObject( m_iov.get(), m_token );
  }
void IOVEditor::create ( cond::TimeType  timetype)

Definition at line 67 of file IOVEditor.cc.

References cond::IOVNames::container(), m_dbSess, m_iov, m_isActive, m_token, reportError(), and cond::DbSession::storeObject().

Referenced by cond::service::PoolDBOutputService::createNewIOV(), and cond::AlignSplitIOV::execute().

                                              {
    if(!m_token.empty()){
      // problem??
      reportError("cond::IOVEditor::create cannot create a IOV using an initialized Editor");
    }

    m_iov.reset( new cond::IOVSequence(timetype) );
    m_token = m_dbSess.storeObject( m_iov.get(), cond::IOVNames::container());
    m_isActive=true;

  }
void IOVEditor::create ( cond::TimeType  timetype,
cond::Time_t  lastTill 
)

Definition at line 79 of file IOVEditor.cc.

References cond::IOVNames::container(), m_dbSess, m_iov, m_isActive, m_token, reportError(), cond::DbSession::storeObject(), and validTime().

                                                                  {
    if(!m_token.empty()){
      // problem??
      reportError("cond::IOVEditor::create cannot create a IOV using an initialized Editor");
    }
    
    if(!validTime(lastTill, timetype))
      reportError("cond::IOVEditor::create time not in global range",lastTill);
    
    m_iov.reset( new cond::IOVSequence((int)timetype,lastTill," ") );
    m_token = m_dbSess.storeObject( m_iov.get(),cond::IOVNames::container());
    m_isActive=true;
  }
void IOVEditor::debugInfo ( std::ostream &  co) const [private]

Definition at line 27 of file IOVEditor.cc.

References cond::DbSession::connectionString(), m_dbSess, m_iov, m_token, cond::TimeTypeSpecs::name, and cond::timeTypeSpecs.

Referenced by reportError().

                                                 {
    co << "IOVEditor: ";
    co << "db " << m_dbSess.connectionString();
    if(m_token.empty()) {
      co << " no token"; return;
    }
    if (!m_iov.get() )  {
      co << " no iov for token " << m_token;
      return;
    }
    co << " iov token " << m_token;
    co << "\nStamp: " <<  m_iov->comment()
       << "; time " <<  m_iov->timestamp()
       << "; revision " <<  m_iov->revision();
    co <<". TimeType " << cond::timeTypeSpecs[ m_iov->timeType()].name;
    if(  m_iov->iovs().empty() ) 
      co << ". empty";
    else
      co << ". size " <<  m_iov->iovs().size() 
         << "; last since " << m_iov->iovs().back().sinceTime();
  }
void IOVEditor::deleteEntries ( bool  withPayload = false)

Definition at line 296 of file IOVEditor.cc.

References cond::DbSession::deleteObject(), init(), m_dbSess, m_iov, m_isActive, m_token, and reportError().

                                          {
    if( m_token.empty() ) reportError("cond::IOVEditor::deleteEntries cannot delete to non-existing IOV sequence");
    if(!m_isActive) this->init();
    if(withPayload){
      std::string tokenStr;
      IOVSequence::const_iterator payloadIt;
      IOVSequence::const_iterator payloadItEnd=m_iov->piovs().end();
      for(payloadIt=m_iov->piovs().begin();payloadIt!=payloadItEnd;++payloadIt){
        tokenStr=payloadIt->wrapperToken();
        m_dbSess.deleteObject( tokenStr );
      }
    }
    m_dbSess.deleteObject( m_token );
    m_iov->piovs().clear();
  }
Time_t IOVEditor::firstSince ( ) const

Definition at line 105 of file IOVEditor.cc.

References m_iov.

                                     {
    return m_iov->firstSince();
  }
unsigned int IOVEditor::freeInsert ( cond::Time_t  sinceTime,
const std::string &  payloadToken 
)

insert a payload with known since in any position

Definition at line 244 of file IOVEditor.cc.

References cond::TimeTypeSpecs::endValue, init(), lastTill(), m_dbSess, m_iov, m_isActive, m_token, reportError(), runTheMatrix::ret, timetype(), cond::timeTypeSpecs, updateClosure(), cond::DbSession::updateObject(), and validTime().

Referenced by cond::service::PoolDBOutputService::appendIOV().

                         {
    // reportError("cond::IOVEditor::freeInsert not supported yet");
    
    if( m_token.empty() ) {
      reportError("cond::IOVEditor::freeInsert cannot append to non-existing IOV index");
    }
    
    if(!m_isActive) {
      this->init();
    }
    
    //   if( m_iov->iov.empty() ) reportError("cond::IOVEditor::freeInsert cannot insert  to empty IOV index");
    

   if(!validTime(sinceTime))
     reportError("cond::IOVEditor::freeInsert time not in global range",sinceTime);

   
   // we do not support multiple iov with identical since...
   if (m_iov->exist(sinceTime))
     reportError("cond::IOVEditor::freeInsert sinceTime already existing",sinceTime);



     // does it make sense? (in case of mixed till and since insertions...)
   if (lastTill()<sinceTime) updateClosure(timeTypeSpecs[timetype()].endValue);
   unsigned int ret = m_iov->add(sinceTime,payloadToken);
   
   m_dbSess.updateObject( m_iov.get(), m_token );
   return ret;
  }
void IOVEditor::import ( const std::string &  sourceIOVtoken)

Definition at line 313 of file IOVEditor.cc.

References cond::DbSession::getTypedObject(), m_dbSess, m_iov, m_token, and reportError().

                                                    {
    if( !m_token.empty() ) reportError("cond::IOVEditor::import IOV sequence already exists, cannot import");
    m_iov = m_dbSess.getTypedObject<cond::IOVSequence>(sourceIOVtoken);
    //m_token=m_iov.toString();
    m_token=sourceIOVtoken;
  }
void IOVEditor::init ( void  ) [private]

Definition at line 93 of file IOVEditor.cc.

References cond::DbSession::getTypedObject(), m_dbSess, m_iov, m_isActive, m_token, and reportError().

Referenced by append(), bulkAppend(), deleteEntries(), freeInsert(), insert(), stamp(), truncate(), and updateClosure().

                      {
    if(m_token.empty()){
      // problem?
      reportError("cond::IOVEditor::init cannot init w/o token change");
    }
    
    m_iov = m_dbSess.getTypedObject<cond::IOVSequence>(m_token);
    m_isActive=true;
    
  }
unsigned int IOVEditor::insert ( cond::Time_t  tillTime,
const std::string &  payloadToken 
)

Assign a payload with till time. Returns the payload index in the iov sequence.

Definition at line 130 of file IOVEditor.cc.

References init(), lastTill(), m_dbSess, m_iov, m_isActive, m_token, reportError(), runTheMatrix::ret, updateClosure(), cond::DbSession::updateObject(), and validTime().

                      {
    if(!m_isActive) this->init();
    
    if( m_iov->iovs().empty() ) 
      reportError("cond::IOVEditor::insert cannot inser into empty IOV sequence",tillTime);
    
    if(!validTime(tillTime))
      reportError("cond::IOVEditor::insert time not in global range",tillTime);
    
    if(tillTime<=lastTill() )
      reportError("cond::IOVEditor::insert IOV not in range",tillTime);
    
    cond::Time_t newSince=lastTill()+1;
    unsigned int ret = m_iov->add(newSince, payloadToken);
    updateClosure(tillTime);
    m_dbSess.updateObject( m_iov.get(), m_token );
    return ret;
  }
IOVSequence & IOVEditor::iov ( )

Definition at line 24 of file IOVEditor.cc.

References m_iov.

{ return *m_iov;}
Time_t IOVEditor::lastTill ( ) const

Definition at line 109 of file IOVEditor.cc.

References m_iov.

Referenced by append(), bulkAppend(), freeInsert(), and insert().

                                   {
    return m_iov->lastTill();
  }
void IOVEditor::reportError ( std::string  message,
cond::Time_t  time 
) const [private]

Definition at line 57 of file IOVEditor.cc.

References debugInfo(), Exception, dbtoconf::out, and cond::rpcobgas::time.

                                                                      {
    std::ostringstream out;
    out << "Error in";
    debugInfo(out);
    out << "\n" <<  message << " for time:  " << time;
    throw cond::Exception(out.str());
  }
void IOVEditor::reportError ( std::string  message) const [private]

Definition at line 49 of file IOVEditor.cc.

References debugInfo(), Exception, argparse::message, and dbtoconf::out.

Referenced by append(), bulkAppend(), create(), deleteEntries(), freeInsert(), import(), init(), insert(), truncate(), and updateClosure().

                                                     {
    std::ostringstream out;
    out << "Error in ";
    debugInfo(out);
    out  << "\n" << message;
    throw cond::Exception(out.str());
  }
void IOVEditor::stamp ( std::string const &  icomment,
bool  append = false 
)
TimeType IOVEditor::timetype ( ) const

Definition at line 113 of file IOVEditor.cc.

References m_iov.

Referenced by append(), freeInsert(), and validTime().

                                     {
    return m_iov->timeType();
  }
std::string const& cond::IOVEditor::token ( ) const [inline]

Returns the token of the iov sequence associated with this editor.

Definition at line 81 of file IOVEditor.h.

References m_token.

Referenced by cond::service::PoolDBOutputService::createNewIOV(), and cond::AlignSplitIOV::execute().

{ return m_token;}
unsigned int IOVEditor::truncate ( bool  withPayload = false)

Definition at line 280 of file IOVEditor.cc.

References cond::DbSession::deleteObject(), init(), m_dbSess, m_iov, m_isActive, m_token, reportError(), runTheMatrix::ret, and cond::DbSession::updateObject().

                                                   {
    if( m_token.empty() ) reportError("cond::IOVEditor::truncate cannot delete to non-existing IOV sequence");
    if(!m_isActive) this->init();
    if (m_iov->piovs().empty()) return 0;
    if(withPayload){
      std::string tokenStr = m_iov->piovs().back().wrapperToken();
      m_dbSess.deleteObject( tokenStr );
    }
    unsigned int ret = m_iov->truncate();
    m_dbSess.updateObject( m_iov.get(), m_token );
    return ret;
    
  }
void IOVEditor::updateClosure ( cond::Time_t  newtillTime)

Update the closure of the iov sequence.

Definition at line 204 of file IOVEditor.cc.

References init(), m_dbSess, m_iov, m_isActive, m_token, reportError(), and cond::DbSession::updateObject().

Referenced by append(), cond::service::PoolDBOutputService::appendIOV(), cond::service::PoolDBOutputService::closeIOV(), freeInsert(), and insert().

                                                  {
    if( m_token.empty() ) reportError("cond::IOVEditor::updateClosure cannot change non-existing IOV index");
    if(!m_isActive) this->init();
    m_iov->updateLastTill(newtillTime);
    m_dbSess.updateObject( m_iov.get(), m_token );
  }
bool IOVEditor::validTime ( cond::Time_t  time,
cond::TimeType  timetype 
) const [private]
bool IOVEditor::validTime ( cond::Time_t  time) const [private]

Definition at line 123 of file IOVEditor.cc.

References timetype(), and validTime().

                                                 {
    return validTime(time,timetype());
  }

Member Data Documentation

boost::shared_ptr<cond::IOVSequence> cond::IOVEditor::m_iov [private]
std::string cond::IOVEditor::m_token [private]