CMS 3D CMS Logo

CondCachedIter.h

Go to the documentation of this file.
00001 #ifndef CondIter_CondCachedIter_h
00002 #define CondIter_CondCachedIter_h
00003 
00004 #include<vector>
00005 #include <string>
00006 #include <boost/program_options.hpp>
00007 #include <iterator>
00008 #include <iostream>
00009 
00010 #include "CondCore/Utilities/interface/CondIter.h"
00011 
00012 
00013 template <class T>
00014 class CondCachedIter{
00015     private:
00016         CondIter<T> * Iterator;
00017       
00018         std::vector<const T *> m_CondCachedIter;
00019  
00020         std::vector<const cond::TypedRef<T> *> m_TempCache;
00021                 
00022         std::vector<unsigned int> m_Run;
00023         std::vector<unsigned int> m_RunStop;
00024         std::vector<unsigned int> m_RunStart;
00025         
00026                 
00027         std::string NameDB;
00028         std::string File;
00029         std::string User;
00030         std::string Pass;
00031         std::string nameBlob;
00032                         
00033         unsigned int now;
00034         unsigned int howMany;
00035         
00036         unsigned int m_startTime;
00037         unsigned int m_stopTime;
00038 
00039         
00040     
00041     public:
00042 
00043         CondCachedIter();
00044         ~CondCachedIter();
00045  
00057         void create(const std::string & NameDB,
00058                     const std::string & File,
00059                     const std::string & User = "",
00060                     const std::string & Pass = "",
00061                     const std::string & nameBlob = ""
00062                    );
00063 
00069         T const * next();
00070         
00074         void rewind();
00075         
00079         void drop();
00080         
00084         void clear();
00085         
00086             
00091         void setMin(int min);
00092         
00096         void setMax(int max);
00097         
00101         void setRange(int min,int max); 
00102       
00106         unsigned int getTime();
00107         
00111         unsigned int getStartTime();
00112         
00116         unsigned int getStopTime();
00117 
00118 };
00119 
00120 
00121 
00122 template <class T> CondCachedIter<T>::CondCachedIter(){
00123     
00124     Iterator = 0;
00125     howMany = 0;
00126     now = 0;
00127     m_startTime = 0;
00128     m_stopTime = 0;
00129 
00130 }
00131 
00132 
00133 template <class T> CondCachedIter<T>::~CondCachedIter(){
00134 
00135     if (Iterator) {
00136         Iterator->free(); //now when I delete Iterator "ref" may survive
00137         delete Iterator;
00138     }
00139     
00140       
00141     
00142     while( ! m_TempCache.empty() )
00143     {
00144         if (m_TempCache.back()) {
00145             delete m_TempCache.back();
00146         }
00147         m_TempCache.pop_back();
00148     }
00149  
00150     while( ! m_CondCachedIter.empty() )
00151     {
00152         m_CondCachedIter.pop_back();
00153     }
00154     
00155     
00156     
00157     
00158 
00159     
00160 }
00161 
00162 
00163 
00164 
00165 
00166 template <class T> void CondCachedIter<T>::create(const std::string & NameDB_in,const std::string & File_in,const std::string & User_in,const std::string & Pass_in,const std::string & nameBlob_in){
00167 
00168     NameDB = NameDB_in;
00169     File = File_in;
00170     User = User_in;
00171     Pass = Pass_in;
00172     nameBlob = nameBlob_in;
00173     
00174     if (!Iterator) Iterator = new CondIter<T>;
00175 
00176     Iterator->create(NameDB,File,User,Pass,nameBlob);
00177          
00178 }
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 template <class T> void CondCachedIter<T>::rewind() {
00189  
00190     now = 0; //back at the beginning
00191     if (!Iterator) Iterator = new CondIter<T>;
00192     Iterator->create(NameDB,File,User,Pass,nameBlob);  
00193     Iterator->setRange(m_startTime,m_stopTime);
00194     m_CondCachedIter.reserve(m_stopTime-m_startTime+2);
00195     m_TempCache.reserve(m_stopTime-m_startTime+2);
00196 
00197 }
00198 
00199 
00200 
00201 template <class T> T const * CondCachedIter<T>::next(){
00202     //if it doesn't exist yet
00203     if (now==howMany){
00204         m_CondCachedIter.push_back(Iterator->next(0));//"0" thus not destroying the object (see Iter class)
00205         m_TempCache.push_back(Iterator->whatRef());
00206         m_Run.push_back(Iterator->getTime());
00207         m_RunStart.push_back(Iterator->getStartTime());
00208         m_RunStop.push_back(Iterator->getStopTime());        
00209         howMany++;
00210     }
00211     else Iterator->jump();
00212     
00213     now++; //increase the position
00214     return m_CondCachedIter.at(now-1);
00215 }
00216 
00217 
00218 template <class T> void CondCachedIter<T>::clear(){
00219 
00220     
00221     while( ! m_TempCache.empty() )
00222     {
00223         if (m_TempCache.back()) delete m_TempCache.back();
00224         m_TempCache.pop_back();
00225     }
00226     
00227     while( ! m_CondCachedIter.empty() )
00228     {
00229         m_CondCachedIter.pop_back();
00230     }
00231 
00232     m_Run.clear();
00233     m_RunStart.clear();
00234     m_RunStop.clear();
00235     
00236     now = 0;
00237     howMany = 0;
00238 
00239     rewind();
00240        
00241 }
00242 
00243 
00244 template <class T> void CondCachedIter<T>::drop(){
00245         
00246     if (now) {
00247         if (m_TempCache.at(now-1)) delete (m_TempCache.at(now-1));
00248         m_CondCachedIter.pop_back(); //it destroys the last datum inserted
00249         m_TempCache.pop_back();
00250         
00251         m_Run.pop_back();
00252         m_RunStop.pop_back();
00253         m_RunStart.pop_back();
00254         now--;
00255         howMany--;
00256         
00257     }  
00258 
00259 }
00260 
00261 
00262 template <class T> void CondCachedIter<T>::setRange(int min,int max){
00263     
00264     Iterator->setRange(min,max);
00265     Iterator->getRange(&m_startTime,&m_stopTime);
00266     std::cout << "\nMIN = " << m_startTime << "\tMAX = " << m_stopTime << std::endl;
00267     m_CondCachedIter.reserve(m_stopTime-m_startTime+2);
00268     m_TempCache.reserve(m_stopTime-m_startTime+2);
00269     
00270 }
00271  
00272 template <class T> void CondCachedIter<T>::setMin(int min){
00273     Iterator->setMin(min);
00274     m_startTime = Iterator->getMin();
00275     m_CondCachedIter.reserve(m_stopTime-m_startTime+2);
00276     m_TempCache.reserve(m_stopTime-m_startTime+2);
00277 
00278 }
00279  
00280 template <class T> void CondCachedIter<T>::setMax(int max){
00281     Iterator->setMax(max);
00282     m_stopTime = Iterator->getMax();
00283     m_CondCachedIter.reserve(m_stopTime-m_startTime+2);
00284     m_TempCache.reserve(m_stopTime-m_startTime+2);
00285 
00286 }
00287  
00288 
00289 template <class T> unsigned int CondCachedIter<T>::getTime(){
00290     if (now) return m_Run.at(now-1);
00291     else return 0;
00292 }
00293 
00294 
00295 template <class T> unsigned int CondCachedIter<T>::getStartTime(){
00296     if (now) return m_RunStart.at(now-1);
00297     else return 0;
00298 }
00299 
00300 
00301 template <class T> unsigned int CondCachedIter<T>::getStopTime(){
00302     if (now) return m_RunStop.at(now-1);
00303     else return 0;
00304 }
00305 
00306 
00307 
00308 
00309 
00310 
00311 
00312 
00313 
00314 
00315 
00316 
00317 
00318 
00319 
00320 #endif
00321 
00322 

Generated on Tue Jun 9 17:26:14 2009 for CMSSW by  doxygen 1.5.4