test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CondIter.h
Go to the documentation of this file.
1 #ifndef CondIter_CondIter_h
2 #define CondIter_CondIter_h
3 
4 
6 
8 
9 #include <vector>
10 
11 
12 template <class DataT>
13 class CondIter : public CondBasicIter{
14 
15 protected:
16  virtual bool load(cond::DbSession& sess, std::string const & itoken) {
17  if (useCache)
18  if (n>=cache.size()) {
19  cache.resize(n+1);
20  return cache.back().load(sess,itoken);
21  } else return true;
22  else return data.load(sess,itoken);
23  }
24 
25 private:
27  bool useCache;
29  std::vector<cond::PayloadRef<DataT> > cache;
30  size_t n;
31 
32 public:
33 
34 
35  CondIter(bool cacheIt=false) : initialized(false), useCache(cacheIt),n(0){}
36  virtual ~CondIter(){}
37 
38 
39  void reset() { initialized=false; data.clear();}
40 
41  void rewind() { reset();}
42 
43  virtual void clear() {
44  reset();
45  cache.clear();
46  }
47 
48 
52  DataT const * next() {
53  bool ok=false;
54  if (!initialized) {
55  n=0;
56  ok =init();
57  initialized=true;
58  }
59  else {
60  ++n;
61  ok = forward();
62  }
63  if (!ok) return 0;
64  ok = make();
65  if (!ok) return 0;
66  return useCache ? &(*cache[n]) : &(*data);
67 
68  }
69 
70 };
71 
72 
73 
74 
75 #endif
76 
cond::PayloadRef< DataT > data
Definition: CondIter.h:28
virtual bool load(cond::DbSession &sess, std::string const &itoken)
Definition: CondIter.h:16
bool initialized
Definition: CondIter.h:26
void reset()
Definition: CondIter.h:39
size_t n
Definition: CondIter.h:30
std::vector< cond::PayloadRef< DataT > > cache
Definition: CondIter.h:29
void rewind()
Definition: CondIter.h:41
bool useCache
Definition: CondIter.h:27
CondIter(bool cacheIt=false)
Definition: CondIter.h:35
virtual ~CondIter()
Definition: CondIter.h:36
volatile std::atomic< bool > shutdown_flag false
DataT const * next()
Definition: CondIter.h:52
virtual void clear()
Definition: CondIter.h:43