CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PopConSourceHandler.h
Go to the documentation of this file.
1 #ifndef PopConSourceHandler_H
2 #define PopConSourceHandler_H
3 
4 //#include "CondCore/DBCommon/interface/DbSession.h"
5 //#include "CondCore/DBCommon/interface/DbTransaction.h"
6 
9 //#include "CondCore/DBCommon/interface/TagInfo.h"
11 
12 #include <boost/bind.hpp>
13 #include <algorithm>
14 #include <vector>
15 #include <string>
16 
17 namespace cond {
18  class Summary;
19 }
20 
22 
23 
24 
25 namespace popcon {
26 
35  template <class T>
37  public:
38  typedef T value_type;
39  typedef PopConSourceHandler<T> self;
42 
43  struct Triplet {
47  };
48 
49  typedef std::vector<Triplet> Container;
50 
51  typedef std::vector<std::pair<T*, cond::Time_t> > OldContainer;
52 
53 
54  class Ref {
55  public:
56  Ref() : m_dbsession(){}
58  m_dbsession(dbsession){
60  }
61  ~Ref() {
62  }
63 
64  Ref(const Ref & ref) :
65  m_dbsession(ref.m_dbsession), m_d(ref.m_d) {
66  }
67 
68  Ref & operator=(const Ref & ref) {
70  m_d = ref.m_d;
71  return *this;
72  }
73 
74  T const * ptr() const {
75  return m_d.get();
76  }
77 
78  T const * operator->() const {
79  return ptr();
80  }
81  // dereference operator
82  T const & operator*() const {
83  return *ptr();
84  }
85 
86 
87  private:
88 
90  boost::shared_ptr<T> m_d;
91  };
92 
93 
95  m_tagInfo(0),
96  m_logDBEntry(0)
97  {}
98 
100  }
101 
102 
103  cond::TagInfo_t const & tagInfo() const { return *m_tagInfo; }
104 
105  // return last paylod of the tag
106  Ref lastPayload() const {
107  return Ref(m_session,tagInfo().lastPayloadToken);
108  }
109 
110  // return last successful log entry for the tag in question
111  cond::LogDBEntry const & logDBEntry() const { return *m_logDBEntry; }
112 
113  // FIX ME
114  void initialize (const cond::persistency::Session& dbSession,
116  m_session = dbSession;
117  m_tagInfo = &tagInfo;
119  }
120 
121  // this is the only mandatory interface
122  std::pair<Container const *, std::string const> operator()(const cond::persistency::Session& session,
123  cond::TagInfo_t const & tagInfo,
124  cond::LogDBEntry const & logDBEntry) const {
125  const_cast<self*>(this)->initialize(session, tagInfo, logDBEntry);
126  return std::pair<Container const *, std::string const>(&(const_cast<self*>(this)->returnData()), userTextLog());
127  }
128 
129  Container const & returnData() {
130  getNewObjects();
131  if (!m_to_transfer.empty()) convertFromOld();
132  sort();
133  return m_triplets;
134  }
135 
136  std::string const & userTextLog() const { return m_userTextLog; }
137 
138  //Implement to fill m_to_transfer vector and m_userTextLog
139  //use getOfflineInfo to get the contents of offline DB
140  virtual void getNewObjects()=0;
141 
142  // return a string identifing the source
143  virtual std::string id() const=0;
144 
145  void sort() {
146  std::sort(m_triplets.begin(),m_triplets.end(),
147  boost::bind(std::less<cond::Time_t>(),
148  boost::bind(&Container::value_type::time,_1),
149  boost::bind(&Container::value_type::time,_2)
150  )
151  );
152  }
153 
154 
155  // make sure to create a new one each time...
156  Summary * dummySummary(typename OldContainer::value_type const &) const {
157  return new cond::GenericSummary("not supplied");
158  }
159 
160  void convertFromOld() {
161  std::for_each( m_to_transfer.begin(), m_to_transfer.end(),
162  boost::bind(&self::add, this,
163  boost::bind(&OldContainer::value_type::first,_1),
164  boost::bind(&self::dummySummary, this, _1),
165  boost::bind(&OldContainer::value_type::second,_1)
166  ));
167  }
168 
169  protected:
170 
171 
172  int add(value_type * payload, Summary * summary, Time_t time) {
173  Triplet t = {payload,summary,time};
174  m_triplets.push_back(t);
175  return m_triplets.size();
176  }
177 
178  private:
179 
181 
183 
185 
186 
187  protected:
188 
189  //vector of payload objects and iovinfo to be transferred
190  //class looses ownership of payload object
192 
193  private:
195 
196  protected:
198 
199 
200  };
201 }
202 #endif
tuple dbsession
create,insert
Definition: lumiNorm.py:82
cond::persistency::Session m_dbsession
std::string const & userTextLog() const
virtual void getNewObjects()=0
boost::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:215
std::vector< Triplet > Container
Definition: Triplet.h:9
cond::LogDBEntry const * m_logDBEntry
U second(std::pair< T, U > const &p)
cond::LogDBEntry const & logDBEntry() const
unsigned long long Time_t
Definition: Time.h:16
std::pair< Container const *, std::string const > operator()(const cond::persistency::Session &session, cond::TagInfo_t const &tagInfo, cond::LogDBEntry const &logDBEntry) const
Summary * dummySummary(typename OldContainer::value_type const &) const
Container::value_type value_type
Ref(cond::persistency::Session &dbsession, const std::string &hash)
cond::TagInfo_t const * m_tagInfo
virtual std::string id() const =0
void initialize(const cond::persistency::Session &dbSession, cond::TagInfo_t const &tagInfo, cond::LogDBEntry const &logDBEntry)
cond::persistency::Session m_session
long double T
std::vector< std::pair< T *, cond::Time_t > > OldContainer
int add(value_type *payload, Summary *summary, Time_t time)
cond::TagInfo_t const & tagInfo() const