CMS 3D CMS Logo

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