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)
bool isValid (const std::string &iovToken, cond::Time_t currenttime)
IOVEditornewIOVEditor (const std::string &token="")
std::string payloadContainerName (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 10 of file IOVService.h.


Constructor & Destructor Documentation

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

Definition at line 14 of file IOVService.cc.

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

Definition at line 17 of file IOVService.cc.

{}

Member Function Documentation

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

Definition at line 96 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->wrapperToken();
        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

maybe no longer required...

Definition at line 146 of file IOVService.cc.

References prof2calltree::back, cond::IOVNames::container(), Exception, cond::IOVSequence::find(), cond::IOVSequence::firstSince(), cond::DbSession::getTypedObject(), cond::DbSession::importObject(), o2o::iov, cond::IOVSequence::iovs(), cond::IOVSequence::lastTill(), max(), cond::IOVSequence::metadataToken(), cond::DbSession::storeObject(), cond::IOVSequence::timeType(), cond::DbSession::updateObject(), and cond::userInfo().

                                              {
  
  
  //loadDicts(iovToken);
   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.metadataToken()));
    dToken = destDB.storeObject( newiovref.get(),cond::IOVNames::container());
  } else {
    newiovref = destDB.getTypedObject<cond::IOVSequence>(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");
    destDB.updateObject( newiovref.get(),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->wrapperToken());
    newiovref->add(lsince, newPtoken);
  }
  newiovref->stamp(cond::userInfo(),false);
  destDB.updateObject( newiovref.get(),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 118 of file IOVService.cc.

References cond::IOVNames::container(), cond::DbSession::importObject(), o2o::iov, cond::IOVSequence::iovs(), cond::IOVSequence::lastTill(), cond::IOVSequence::metadataToken(), cond::DbSession::storeObject(), and cond::IOVSequence::timeType().

                                                                  {
  cond::IOVSequence const & iov=iovSeq(iovToken);
  
  boost::shared_ptr<cond::IOVSequence> newiov(new cond::IOVSequence(iov.timeType(), iov.lastTill(),iov.metadataToken()));
  
  for( IOVSequence::const_iterator it=iov.iovs().begin();
       it!=iov.iovs().end(); ++it){
    std::string newPToken = destDB.importObject( m_dbSess, it->wrapperToken());
    newiov->add(it->sinceTime(),newPToken);
  }
  return destDB.storeObject(newiov.get(), cond::IOVNames::container());
}
cond::IOVSequence const & cond::IOVService::iovSeq ( const std::string &  iovToken) [private]

Definition at line 27 of file IOVService.cc.

                                                                        {
  if (m_token!=iovToken) {
    m_iov = m_dbSess.getTypedObject<cond::IOVSequence>( iovToken );
    m_token=iovToken;
  }
  return *m_iov;
}
bool cond::IOVService::isValid ( const std::string &  iovToken,
cond::Time_t  currenttime 
)

Definition at line 54 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 20 of file IOVService.cc.

                                                    {
  return new cond::IOVEditor( m_dbSess,token);
}
std::string cond::IOVService::payloadContainerName ( const std::string &  iovtoken)

Definition at line 83 of file IOVService.cc.

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

                                                               {
  cond::IOVSequence const & iov=iovSeq(iovToken);
  
  // FIXME move to metadata
  std::string payloadtokstr=iov.iovs().front().wrapperToken();
  std::pair<std::string,int> oidData = parseToken( payloadtokstr );
  return oidData.first;
}
std::string cond::IOVService::payloadToken ( const std::string &  iovToken,
cond::Time_t  currenttime 
)

Definition at line 38 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->wrapperToken();
  }
}
cond::TimeType cond::IOVService::timeType ( const std::string &  iovToken)

Definition at line 49 of file IOVService.cc.

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

                                                                 {
  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 63 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 62 of file IOVService.h.

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

Definition at line 64 of file IOVService.h.

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

Definition at line 63 of file IOVService.h.