CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

cond::IOVService Class Reference

#include <IOVService.h>

List of all members.

Public Member Functions

void deleteAll (bool withPayload=false)
std::string exportIOVRangeWithPayload (cond::DbSession &destDB, const std::string &iovToken, const std::string &destToken, cond::Time_t since, cond::Time_t till, bool outOfOrder)
std::string exportIOVWithPayload (cond::DbSession &destDB, const std::string &iovToken)
 IOVService (cond::DbSession &dbSess)
int iovSize (const std::string &iovtoken)
bool isValid (const std::string &iovToken, cond::Time_t currenttime)
IOVEditornewIOVEditor (const std::string &token="")
std::set< std::string > payloadClasses (const std::string &iovtoken)
std::string payloadToken (const std::string &iovToken, cond::Time_t currenttime)
cond::TimeType timeType (const std::string &iovToken)
std::pair< cond::Time_t,
cond::Time_t
validity (const std::string &iovToken, cond::Time_t currenttime)
virtual ~IOVService ()

Private Member Functions

cond::IOVSequence const & iovSeq (const std::string &iovToken)

Private Attributes

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

Detailed Description

Definition at line 11 of file IOVService.h.


Constructor & Destructor Documentation

cond::IOVService::IOVService ( cond::DbSession dbSess)

Definition at line 54 of file IOVService.cc.

                                               :
  m_dbSess(dbSess) {}
cond::IOVService::~IOVService ( ) [virtual]

Definition at line 57 of file IOVService.cc.

{}

Member Function Documentation

void cond::IOVService::deleteAll ( bool  withPayload = false)

Definition at line 128 of file IOVService.cc.

References cont, cond::IOVNames::container(), ora::Database::containerHandle(), EcalCondDB::db, ora::Container::erase(), ora::Container::flush(), ora::ContainerIterator::get(), o2o::iov, cond::IOVSequence::iovs(), ora::ContainerIterator::itemId(), ora::Container::iterator(), and ora::ContainerIterator::next().

                                         {
  ora::Database& db = m_dbSess.storage();
  ora::Container cont = db.containerHandle( cond::IOVNames::container() );
  ora::ContainerIterator it = cont.iterator();
  while ( it.next() ) {
    if(withPayload){
      std::string tokenStr;
      IOVSequence::const_iterator payloadIt;
      boost::shared_ptr<cond::IOVSequence> iov = it.get<cond::IOVSequence>();
      IOVSequence::const_iterator payloadItBegin=iov->iovs().begin();
      IOVSequence::const_iterator payloadItEnd=iov->iovs().end();
      for(payloadIt=payloadItBegin;payloadIt!=payloadItEnd;++payloadIt){
        tokenStr=payloadIt->token();
        m_dbSess.deleteObject( tokenStr );
      }
    }
    cont.erase( it.itemId() );
  }
  cont.flush();
}
std::string cond::IOVService::exportIOVRangeWithPayload ( cond::DbSession destDB,
const std::string &  iovToken,
const std::string &  destToken,
cond::Time_t  since,
cond::Time_t  till,
bool  outOfOrder 
)

export IOV selected by token within selected range and associated payload to another database return new iov token string

Definition at line 168 of file IOVService.cc.

References prof2calltree::back, ora::Container::className(), cont, ora::Database::containerHandle(), ora::OId::containerId(), Exception, cond::IOVSequence::find(), cond::IOVSequence::firstSince(), ora::OId::fromString(), cond::DbSession::importObject(), cond::insertIOV(), o2o::iov, cond::IOVSequence::iovs(), cond::IOVSequence::lastTill(), cond::loadIOV(), max(), cond::IOVSequence::metadata(), cond::DbSession::storage(), cond::IOVSequence::timeType(), cond::updateIOV(), and cond::userInfo().

                                                              {
  cond::IOVSequence const & iov=iovSeq(iovToken);
  since = std::max(since, iov.firstSince());
  IOVSequence::const_iterator ifirstTill=iov.find(since);
  IOVSequence::const_iterator isecondTill=iov.find(till);
  if( isecondTill!=iov.iovs().end() ) isecondTill++;
  
  if (ifirstTill==isecondTill) 
    throw cond::Exception("IOVServiceImpl::exportIOVRangeWithPayload Error: empty input range");
  
  // since > ifirstTill->sinceTime() used to overwrite the actual time
  //since = ifirstTill->sinceTime();
  
  boost::shared_ptr<cond::IOVSequence> newiovref;
  //FIXME more option and eventually ability to resume (roll back is difficult)
  std::string dToken = destToken;
  if (dToken.empty()) {
    // create a new one
   newiovref.reset( new cond::IOVSequence(iov.timeType(), iov.lastTill(),iov.metadata()));
    dToken = insertIOV( destDB, newiovref );
  } else {
    newiovref = loadIOV( destDB, destToken);
    if (newiovref->iovs().empty()) ; // do not waist time
    else if (outOfOrder) {
      for( IOVSequence::const_iterator it=ifirstTill;
           it!=isecondTill; ++it)
        if (newiovref->exist(it->sinceTime()))
          throw cond::Exception("IOVServiceImpl::exportIOVRangeWithPayload Error: since time already exists");
    } else if (since <= newiovref->iovs().back().sinceTime())
      throw cond::Exception("IOVServiceImpl::exportIOVRangeWithPayload Error: since time out of range, below last since");
   updateIOV( destDB, newiovref, destToken );
  }

  cond::Time_t lsince = since;
  for(  IOVSequence::const_iterator it=ifirstTill;
        it!=isecondTill; ++it, lsince=it->sinceTime()){
    // first since overwritten by global since...
    
    std::string newPtoken = destDB.importObject( m_dbSess,it->token());
    ora::OId poid;
    poid.fromString( newPtoken );
    ora::Container cont = destDB.storage().containerHandle( poid.containerId() );
    newiovref->add(lsince, newPtoken,cont.className());
  }
  newiovref->stamp(cond::userInfo(),false);
  updateIOV( destDB, newiovref, dToken );
  return dToken;
}
std::string cond::IOVService::exportIOVWithPayload ( cond::DbSession destDB,
const std::string &  iovToken 
)

export IOV selected by token and associated payload to another database return new iov token string

Definition at line 150 of file IOVService.cc.

References ora::Container::className(), cont, ora::Database::containerHandle(), ora::OId::containerId(), ora::OId::fromString(), cond::DbSession::importObject(), cond::insertIOV(), o2o::iov, cond::IOVSequence::iovs(), cond::IOVSequence::lastTill(), cond::IOVSequence::metadata(), cond::DbSession::storage(), and cond::IOVSequence::timeType().

                                                                  {
  cond::IOVSequence const & iov=iovSeq(iovToken);
  
  boost::shared_ptr<cond::IOVSequence> newiov(new cond::IOVSequence(iov.timeType(), iov.lastTill(),iov.metadata()));
  
  for( IOVSequence::const_iterator it=iov.iovs().begin();
       it!=iov.iovs().end(); ++it){
    std::string newPToken = destDB.importObject( m_dbSess, it->token());
    ora::OId poid;
    poid.fromString( newPToken );
    ora::Container cont = destDB.storage().containerHandle( poid.containerId() );
    newiov->add(it->sinceTime(),newPToken, cont.className());
  }
  return insertIOV( destDB, newiov, true );
}
cond::IOVSequence const & cond::IOVService::iovSeq ( const std::string &  iovToken) [private]

Definition at line 64 of file IOVService.cc.

References cond::loadIOV().

                                                                        {
  if (m_token!=iovToken) {
    m_iov = loadIOV( m_dbSess, iovToken );
    m_token=iovToken;
  }
  return *m_iov;
}
int cond::IOVService::iovSize ( const std::string &  iovtoken)

Definition at line 122 of file IOVService.cc.

References o2o::iov, and cond::IOVSequence::iovs().

                                                      {
  cond::IOVSequence const & iov=iovSeq(iovtoken);
  return iov.iovs().size();
}
bool cond::IOVService::isValid ( const std::string &  iovToken,
cond::Time_t  currenttime 
)

Definition at line 89 of file IOVService.cc.

References cond::IOVSequence::firstSince(), o2o::iov, and cond::IOVSequence::lastTill().

                                                        {  
  cond::IOVSequence const & iov=iovSeq(iovToken);
  return (  currenttime >= iov.firstSince() && 
            currenttime <= iov.lastTill() );
}
cond::IOVEditor * cond::IOVService::newIOVEditor ( const std::string &  token = "")

create an editor to the iov selected by the token user aquires the ownership of the pointer. Need explicit delete after usage

Definition at line 60 of file IOVService.cc.

                                                    {
  return new cond::IOVEditor( m_dbSess,token);
}
std::set< std::string > cond::IOVService::payloadClasses ( const std::string &  iovtoken)

Definition at line 117 of file IOVService.cc.

References o2o::iov, and cond::IOVSequence::payloadClasses().

                                                         {
  cond::IOVSequence const & iov=iovSeq(iovToken);
  return iov.payloadClasses();
}
std::string cond::IOVService::payloadToken ( const std::string &  iovToken,
cond::Time_t  currenttime 
)

Definition at line 73 of file IOVService.cc.

References cond::IOVSequence::find(), o2o::iov, and cond::IOVSequence::iovs().

Referenced by l1t::DataWriter::payloadToken().

                                                        {
  cond::IOVSequence const & iov=iovSeq(iovToken);
  cond::IOVSequence::const_iterator iEnd=iov.find(currenttime);
  if( iEnd==iov.iovs().end() ){
    return "";
  }else{
    return iEnd->token();
  }
}
cond::TimeType cond::IOVService::timeType ( const std::string &  iovToken)

Definition at line 84 of file IOVService.cc.

References o2o::iov, and cond::IOVSequence::timeType().

Referenced by cond::AlignSplitIOV::execute().

                                                                 {
  cond::IOVSequence const & iov=iovSeq(iovToken);
  return iov.timeType();
}
std::pair< cond::Time_t, cond::Time_t > cond::IOVService::validity ( const std::string &  iovToken,
cond::Time_t  currenttime 
)

Definition at line 97 of file IOVService.cc.

References cond::IOVSequence::find(), cond::IOVSequence::firstSince(), o2o::iov, cond::IOVSequence::iovs(), and cond::IOVSequence::lastTill().

                                                                           {
  
  cond::IOVSequence const & iov=iovSeq(iovToken);
  
  cond::Time_t since=iov.firstSince();
  cond::Time_t till=iov.lastTill();
  IOVSequence::const_iterator iter=iov.find(currenttime);
  if (iter!=iov.iovs().end())  {
    since=iter->sinceTime();
    iter++;
    if (iter!=iov.iovs().end()) 
      till = iter->sinceTime()-1;
  }
  else {
    since=iov.lastTill();
  }
  return std::pair<cond::Time_t, cond::Time_t>(since,till);
}

Member Data Documentation

Definition at line 65 of file IOVService.h.

boost::shared_ptr<cond::IOVSequence> cond::IOVService::m_iov [private]

Definition at line 67 of file IOVService.h.

std::string cond::IOVService::m_token [private]

Definition at line 66 of file IOVService.h.