00001 #ifndef CondIter_CondIter_h
00002 #define CondIter_CondIter_h
00003
00004
00005 #include "CondCore/Utilities/interface/CondBasicIter.h"
00006
00007
00008
00009 #include "CondCore/DBCommon/interface/TypedRef.h"
00010
00011 #include "CondCore/IOVService/interface/IOVIterator.h"
00012 #include "CondCore/DBCommon/interface/CoralTransaction.h"
00013 #include "CondCore/DBCommon/interface/PoolTransaction.h"
00014 #include "CondCore/DBCommon/interface/AuthenticationMethod.h"
00015 #include "CondCore/DBCommon/interface/SessionConfiguration.h"
00016 #include "CondCore/DBCommon/interface/ConnectionConfiguration.h"
00017 #include "CondCore/DBCommon/interface/MessageLevel.h"
00018 #include "CondCore/DBCommon/interface/DBSession.h"
00019 #include "CondCore/DBCommon/interface/Exception.h"
00020 #include "CondCore/MetaDataService/interface/MetaData.h"
00021 #include "CondCore/IOVService/interface/IOVService.h"
00022
00023 #include <boost/program_options.hpp>
00024 #include <iterator>
00025 #include <iostream>
00026 #include<vector>
00027 #include <string>
00028
00029
00030 template <class T>
00031 class CondIter{
00032 private:
00033
00034
00035 const T* Reference;
00036 cond::TypedRef<T> *ref;
00037 CondBasicIter bIter;
00038
00039 public:
00040
00041 bool NumberOfTimes;
00042
00043
00044 CondIter();
00045 ~CondIter();
00046
00047
00048 template <class A> friend class CondCachedIter;
00049
00050
00051
00064 void create(const std::string & NameDB,
00065 const std::string & File,
00066 const std::string & User = "",
00067 const std::string & Pass = "",
00068 const std::string & nameBlob = ""
00069 );
00070
00077 T const * next(int test = 1);
00078
00083 void setRange(unsigned int min,unsigned int max);
00084 void setRange(int min,int max);
00085
00089 void setMin(unsigned int min);
00090 void setMin(int min);
00091
00096 void setMax(unsigned int max);
00097 void setMax(int max);
00098
00102 unsigned int getTime();
00103
00107 unsigned int getStartTime();
00108
00112 unsigned int getStopTime();
00113
00114
00119 void jump();
00120
00124 void free();
00125
00130 cond::TypedRef<T> const * whatRef();
00131
00136 unsigned int getMin();
00137
00141 unsigned int getMax();
00142
00143
00147 void getRange(unsigned int*,unsigned int*);
00148
00149
00150 };
00151
00152
00153 template <class T> CondIter<T>::CondIter(){
00154
00155 Reference = 0;
00156 ref = 0;
00157 }
00158
00159
00160 template <class T> CondIter<T>::~CondIter(){
00161
00162 if (ref) delete ref;
00163 }
00164
00165
00166 template <class T> void CondIter<T>::create(const std::string & NameDB,const std::string & File,const std::string & User,const std::string & Pass,const std::string & nameBlob){
00167
00168 bIter.create(NameDB,File,User,Pass,nameBlob);
00169 NumberOfTimes = true;
00170 ref = 0;
00171 Reference = 0;
00172
00173 }
00174
00175
00176
00177
00178
00179
00180 template <class T> T const * CondIter<T>::next(int test) {
00181
00182 if ((bIter.iter_Min)==0 && (bIter.iter_Max)==0){
00183
00184
00185 if( (bIter.ioviterator)->next() ){
00186
00187 std::cout<<"PayloadContainerName "<<bIter.payloadContainer<<"\n";
00188 std::cout<<"since \t till \t payloadToken"<<std::endl;
00189 std::cout<< (bIter.ioviterator)->validity().first<<" \t "<< (bIter.ioviterator)->validity().second<<" \t "<<(bIter.ioviterator)->payloadToken()<<std::endl;
00190 if (test && ref) {
00191
00192 delete ref;
00193 }
00194 ref = new cond::TypedRef<T> (*(bIter.pooldb),(bIter.ioviterator)->payloadToken());
00195 Reference = (const T*) ref->ptr();
00196 bIter.setStartTime((bIter.ioviterator)->validity().first);
00197 bIter.setStopTime((bIter.ioviterator)->validity().second);
00198
00199 long long int temp = (long long int) (( bIter.getStartTime()+ bIter.getStopTime()) / 2.);
00200 if (temp<0) temp = - temp;
00201 bIter.setTime((unsigned int) temp);
00202 return Reference;
00203 }
00204 else {
00205 std::cout << "No more data ! " << std::endl;
00206 Reference = 0;
00207 ref = 0;
00208 return Reference;
00209
00210 }
00211 }
00212 else{
00213
00214 if (NumberOfTimes){
00215 unsigned int minTemp = bIter.getMin();
00216 for (unsigned int i=0; i< minTemp; i++){
00217
00218 if (!((bIter.ioviterator)->next())) {
00219 std::cout << "No data. Minimum too high." << std::endl;
00220 Reference = 0;
00221 ref = 0;
00222 return Reference;
00223
00224 }
00225 if (((bIter.ioviterator)->validity().second)>=minTemp) i = minTemp;
00226 }
00227 NumberOfTimes = false;
00228 }
00229 if( (bIter.ioviterator)->next() ){
00230 if (((bIter.ioviterator)->validity().first)>=(bIter.getMax())){
00231 std::cout << "No more data in the range" << std::endl;
00232 Reference = 0;
00233 ref = 0;
00234 return Reference;
00235
00236 }
00237 else {
00238 std::cout<<"PayloadContainerName "<<bIter.payloadContainer<<"\n";
00239 std::cout<<"since \t till \t payloadToken"<<std::endl;
00240 std::cout<< (bIter.ioviterator)->validity().first<<" \t "<< (bIter.ioviterator)->validity().second<<" \t "<<(bIter.ioviterator)->payloadToken()<<std::endl;
00241
00242
00243 if (test && ref) {
00244
00245 delete ref;
00246 }
00247 ref = new cond::TypedRef<T> (*(bIter.pooldb),(bIter.ioviterator)->payloadToken());
00248 Reference = (const T*) ref->ptr();
00249 bIter.setStartTime((bIter.ioviterator)->validity().first);
00250 bIter.setStopTime((bIter.ioviterator)->validity().second);
00251
00252 long long int temp = (long long int) (( bIter.getStartTime()+ bIter.getStopTime()) / 2.);
00253 if (temp<0) temp = - temp;
00254 bIter.setTime((unsigned int) temp);
00255 return Reference;
00256 }
00257 }
00258
00259 else {
00260 std::cout << "No more data ! " << std::endl;
00261 Reference = 0;
00262 ref = 0;
00263 return Reference;
00264
00265 }
00266 }
00267
00268 }
00269
00270
00271
00272
00273
00274
00275 template <class T> void CondIter<T>::jump() {
00276
00277 if (NumberOfTimes){
00278 unsigned int minTemp = bIter.getMin();
00279
00280 for (unsigned int i=0; i< minTemp; i++){
00281
00282 if (!((bIter.ioviterator)->next())) {
00283 std::cout << "No data. Minimum too high." << std::endl;
00284
00285 }
00286 if (((bIter.ioviterator)->validity().second)>=minTemp) i = minTemp;
00287 }
00288 NumberOfTimes = false;
00289 }
00290 else (bIter.ioviterator)->next();
00291 }
00292
00293
00294 template <class T> void CondIter<T>::free(){
00295 Reference = 0;
00296 ref = 0;
00297 }
00298
00299
00300
00301
00302 template <class T> cond::TypedRef<T> const * CondIter<T>::whatRef() {
00303
00304 return ref;
00305
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315 template <class T> void CondIter<T>::setRange(unsigned int min,unsigned int max){
00316 bIter.setRange(min,max);
00317 }
00318
00319 template <class T> void CondIter<T>::setMin(unsigned int min){
00320 bIter.setMin(min);
00321 }
00322
00323 template <class T> void CondIter<T>::setMax(unsigned int max){
00324 bIter.setMax(max);
00325 }
00326
00327 template <class T> void CondIter<T>::setRange(int min,int max){
00328 bIter.setRange(min,max);
00329 }
00330
00331 template <class T> void CondIter<T>::setMin(int min){
00332 bIter.setMin(min);
00333 }
00334
00335 template <class T> void CondIter<T>::setMax(int max){
00336 bIter.setMax(max);
00337 }
00338
00339
00340 template <class T> unsigned int CondIter<T>::getMin(){return bIter.getMin();}
00341
00342 template <class T> unsigned int CondIter<T>::getMax(){return bIter.getMax();}
00343
00344 template <class T> void CondIter<T>::getRange(unsigned int * Min_out,unsigned int * Max_out){
00345 *Min_out = bIter.getMin();
00346 *Max_out = bIter.getMax();
00347 }
00348
00349
00350 template <class T> unsigned int CondIter<T>::getTime(){return bIter.getTime();}
00351
00352 template <class T> unsigned int CondIter<T>::getStartTime(){return bIter.getStartTime();}
00353
00354 template <class T> unsigned int CondIter<T>::getStopTime(){return bIter.getStopTime();}
00355
00356 #endif
00357