CMS 3D CMS Logo

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