CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CondCore/IOVService/src/IOVProxy.cc

Go to the documentation of this file.
00001 #include "CondCore/IOVService/interface/IOVProxy.h"
00002 #include "CondFormats/Common/interface/TimeConversions.h"
00003 
00004 void cond::IOVProxyData::refresh(){
00005   data = dbSession.getTypedObject<cond::IOVSequence>( token );
00006   // loading the lazy-loading Queryable vector...
00007   data->loadAll();
00008   //**** temporary for the schema transition
00009   if( dbSession.isOldSchema() ){
00010     PoolTokenParser parser(  dbSession.storage() ); 
00011     data->swapTokens( parser );
00012   }
00013 }
00014 
00015 void cond::IOVProxyData::refresh( cond::DbSession& newSession ){
00016   dbSession = newSession;
00017   refresh();
00018 }
00019 
00020 std::pair<int,int> cond::IOVProxyData::range( cond::Time_t since, 
00021                                               cond::Time_t  till ){
00022   int low = -1;
00023   int high = -1;
00024   if( data->iovs().size() ){
00025     cond::Time_t firstSince = data->iovs().front().sinceTime();
00026     if( till >= firstSince ){
00027       low = (since < firstSince) ? 0 :
00028         data->find(since)-data->iovs().begin();
00029       high = data->find(till) - data->iovs().begin();
00030       high = std::min( high+1,(int)data->iovs().size())-1;
00031     }
00032   }
00033   return std::make_pair( low, high );
00034 }
00035 
00036 void cond::IOVElementProxy::set(IOVSequence const & v, int ii) {
00037   if (ii>=(int)v.iovs().size() || ii<0) {
00038     set(cond::invalidTime, cond::invalidTime,"");
00039     return;
00040   }
00041   size_t i =ii;
00042   m_token = v.iovs()[i].token();
00043   m_since =  v.iovs()[i].sinceTime();
00044   if(i+1==v.iovs().size()) {
00045     m_till = v.lastTill();
00046     return;
00047   }
00048   cond::UnpackedTime unpackedTime;
00049   cond::Time_t totalNanoseconds;
00050   cond::Time_t totalSecondsInNanoseconds;
00051   switch (v.timeType()) {
00052   case timestamp:
00053     //unpacking
00054     unpackedTime = cond::time::unpack(v.iovs()[i+1].sinceTime());
00055     //number of seconds in nanoseconds (avoid multiply and divide by 1e09)
00056     totalSecondsInNanoseconds = ((cond::Time_t)unpackedTime.first)*1000000000;
00057     //total number of nanoseconds
00058     totalNanoseconds = totalSecondsInNanoseconds + ((cond::Time_t)(unpackedTime.second));
00059     //now decrementing of 1 nanosecond
00060     totalNanoseconds--;
00061     //now repacking (just change the value of the previous pair)
00062     unpackedTime.first = (unsigned int) (totalNanoseconds/1000000000);
00063     unpackedTime.second = (unsigned int)(totalNanoseconds - (cond::Time_t)unpackedTime.first*1000000000);
00064     m_till = cond::time::pack(unpackedTime);
00065     break;
00066   default:
00067     m_till = v.iovs()[i+1].sinceTime()-1;
00068   }
00069 }
00070 
00071 cond::IterHelp::IterHelp(IOVProxyData& impl) :
00072   lowBound(0),
00073   iov(&(*impl.data)), 
00074   elem(){
00075 }
00076 cond::IterHelp::IterHelp(IOVProxyData& impl, cond::Time_t lb) :
00077   lowBound(lb),
00078   iov(&(*impl.data)), 
00079   elem(){
00080 }
00081 
00082 cond::IOVRange::IOVRange():
00083   m_iov(),
00084   m_low(-1),
00085   m_high(-1),
00086   m_lowBound(0){
00087 }
00088     
00089 cond::IOVRange::IOVRange( const boost::shared_ptr<IOVProxyData>& iov, 
00090                           cond::Time_t since, 
00091                           cond::Time_t till,
00092                           int selection ):
00093   m_iov( iov ),
00094   m_low( -1 ),
00095   m_high( -1 ),
00096   m_lowBound(0){
00097   std::pair<int,int> rg = m_iov->range( since, till );
00098   m_low = rg.first;
00099   m_high = rg.second;
00100   if( selection > 0 ){
00101     m_low = rg.first;
00102     m_high = std::min( rg.first-selection-1, rg.second );
00103   } else if( selection < 0 ){
00104     m_low = std::max( rg.second-selection+1,rg.first);
00105     m_high = rg.second;
00106   }
00107   cond::Time_t tlow = m_iov->data->iovs()[m_low].sinceTime();
00108   if( since < tlow ) since = tlow;
00109   m_lowBound = since;
00110 }
00111 
00112 cond::IOVRange::IOVRange( const boost::shared_ptr<IOVProxyData>& iov, 
00113                           int selection ):
00114   m_iov(iov),
00115   m_low(-1),
00116   m_high(-1),
00117   m_lowBound(0){
00118   int sz  =  iov->data->iovs().size();
00119   m_low = 0;
00120   m_high = sz-1;
00121   if( selection > 0 ){
00122     m_high = std::min( selection, sz-1 );
00123   } else if( selection < 0 ){
00124     m_low = sz+selection;
00125     if(m_low < 0) m_low = 0;
00126   }
00127 }
00128 
00129 cond::IOVRange::IOVRange( const IOVRange& rhs ):
00130   m_iov( rhs.m_iov ),
00131   m_low( rhs.m_low ),
00132   m_high( rhs.m_high ),
00133   m_lowBound( rhs.m_lowBound){
00134 }
00135     
00136 cond::IOVRange& cond::IOVRange::operator=( const IOVRange& rhs ){
00137   m_iov = rhs.m_iov;
00138   m_low = rhs.m_low;
00139   m_high = rhs.m_high;
00140   m_lowBound = rhs.m_lowBound;
00141   return *this;
00142 }
00143 
00144 cond::IOVRange::const_iterator cond::IOVRange::find(cond::Time_t time) const {
00145   int n = m_iov->data->find(time)-m_iov->data->iovs().begin();
00146   return (n<m_low || m_high<n ) ? 
00147     end() :  
00148     boost::make_transform_iterator(boost::counting_iterator<int>(n),
00149                                    IterHelp(*m_iov, m_lowBound));
00150 }
00151 
00152 cond::IOVElementProxy cond::IOVRange::front() const {
00153   IterHelp helper(*m_iov, m_lowBound);
00154   return helper( m_low );
00155 }
00156 
00157 cond::IOVElementProxy cond::IOVRange::back() const {
00158   IterHelp helper(*m_iov, m_lowBound);
00159   return helper( m_high );
00160 }
00161 
00162 size_t cond::IOVRange::size() const {
00163   size_t sz = 0;
00164   if( m_high>=0 && m_low>=0 ) sz = m_high-m_low+1;
00165   return sz;
00166 }
00167 
00168 cond::IOVProxy::IOVProxy() : 
00169   m_iov(){
00170 }
00171  
00172 cond::IOVProxy::~IOVProxy() {
00173 }
00174 
00175 cond::IOVProxy::IOVProxy(cond::DbSession& dbSession):
00176   m_iov(new IOVProxyData(dbSession)){
00177 }
00178 
00179 cond::IOVProxy::IOVProxy(cond::DbSession& dbSession,
00180                          const std::string & token):
00181   m_iov(new IOVProxyData(dbSession,token)){
00182 }
00183 
00184 cond::IOVProxy::IOVProxy( boost::shared_ptr<IOVProxyData>& data ):
00185   m_iov( data ){
00186 }
00187 
00188 cond::IOVProxy::IOVProxy( const IOVProxy& rhs ):
00189   m_iov( rhs.m_iov ){
00190 }
00191 
00192 cond::IOVProxy& cond::IOVProxy::operator=( const IOVProxy& rhs ){
00193   m_iov = rhs.m_iov;
00194   return *this;
00195 }
00196 
00197 void cond::IOVProxy::load( const std::string & token){
00198   m_iov->token = token;
00199   m_iov->refresh();
00200 }
00201 
00202 bool cond::IOVProxy::refresh(){
00203   int oldsize = size();
00204   m_iov->refresh();
00205   return oldsize<size();
00206 }
00207 
00208 bool cond::IOVProxy::refresh( cond::DbSession& newSession ){
00209   int oldsize = size();
00210   m_iov->refresh( newSession );
00211   return oldsize<size();
00212 }
00213 
00214 const std::string& cond::IOVProxy::token(){
00215   return m_iov->token;
00216 }
00217 
00218 bool cond::IOVProxy::isValid( cond::Time_t currenttime ){
00219   return (  currenttime >= iov().firstSince() && 
00220             currenttime <= iov().lastTill() );
00221 }
00222 
00223 std::pair<cond::Time_t, cond::Time_t> cond::IOVProxy::validity( cond::Time_t currenttime ){  
00224   cond::Time_t since=iov().firstSince();
00225   cond::Time_t till=iov().lastTill();
00226   IOVSequence::const_iterator iter=iov().find(currenttime);
00227   if (iter!=iov().iovs().end())  {
00228     since=iter->sinceTime();
00229     iter++;
00230     if (iter!=iov().iovs().end()) 
00231       till = iter->sinceTime()-1;
00232   }
00233   else {
00234     since=iov().lastTill();
00235   }
00236   return std::pair<cond::Time_t, cond::Time_t>(since,till);
00237 }
00238 
00239 cond::IOVRange cond::IOVProxy::range(cond::Time_t since, 
00240                                      cond::Time_t  till) const {
00241   return IOVRange( m_iov, since, till );
00242 }
00243 
00244 cond::IOVRange cond::IOVProxy::rangeHead(cond::Time_t since, 
00245                                          cond::Time_t  till, 
00246                                          int n) const {
00247   return IOVRange( m_iov, since, till, n );
00248 }
00249 
00250 cond::IOVRange cond::IOVProxy::rangeTail(cond::Time_t since, 
00251                                          cond::Time_t  till, 
00252                                          int n) const {
00253   return IOVRange( m_iov, since, till, -n );
00254 }
00255 
00256 cond::IOVRange cond::IOVProxy::head(int n) const {
00257   return IOVRange( m_iov, n );
00258 }
00259 
00260 cond::IOVRange cond::IOVProxy::tail(int n) const {
00261   return IOVRange( m_iov, -n );
00262 }
00263 
00264 cond::IOVProxy::const_iterator cond::IOVProxy::find(cond::Time_t time) const {
00265   int n = iov().find(time)-iov().iovs().begin();
00266   return ( n<0 || n>size() ) ? 
00267     end() :  
00268     boost::make_transform_iterator(boost::counting_iterator<int>(n),
00269                                    IterHelp(*m_iov));
00270 }
00271 
00272 int cond::IOVProxy::size() const {
00273   return iov().iovs().size();
00274 }
00275 
00276 cond::IOVSequence const & cond::IOVProxy::iov() const {
00277   return *(m_iov->data);
00278 }
00279 
00280 cond::TimeType cond::IOVProxy::timetype() const {
00281   return iov().timeType();     
00282 }
00283 
00284 cond::Time_t cond::IOVProxy::firstSince() const {
00285   return iov().firstSince();
00286 }
00287 
00288 cond::Time_t cond::IOVProxy::lastTill() const {
00289   return iov().lastTill();
00290 }
00291  
00292 std::set<std::string> const& 
00293 cond::IOVProxy::payloadClasses() const{
00294   return iov().payloadClasses();
00295 }
00296   
00297 std::string 
00298 cond::IOVProxy::comment() const{
00299   return iov().comment();
00300 }
00301 
00302 int 
00303 cond::IOVProxy::revision() const{
00304   return iov().revision();
00305 }
00306 
00307 cond::Time_t cond::IOVProxy::timestamp() const {
00308   return iov().timestamp();
00309 }
00310 
00311 cond::DbSession& cond::IOVProxy::db() const {
00312   return m_iov->dbSession;
00313 }
00314 
00315 
00316