CMS 3D CMS Logo

PopConSourceHandler.h
Go to the documentation of this file.
1 #ifndef PopConSourceHandler_H
2 #define PopConSourceHandler_H
3 
6 
7 #include <boost/bind.hpp>
8 #include <algorithm>
9 #include <memory>
10 #include <vector>
11 #include <string>
12 
13 namespace cond {
14  class Summary;
15 }
16 
18 
19 
20 
21 namespace popcon {
22 
31  template <class T>
33  public:
34  typedef T value_type;
35  typedef PopConSourceHandler<T> self;
38 
39  struct Triplet {
40  value_type * payload;
41  Summary * summary;
42  Time_t time;
43  };
44 
45  typedef std::vector<Triplet> Container;
46 
47  typedef std::vector<std::pair<T*, cond::Time_t> > OldContainer;
48 
49 
50  class Ref {
51  public:
52  Ref() : m_dbsession(){}
54  m_dbsession(dbsession){
55  m_d = m_dbsession.fetchPayload<T>( hash );
56  }
57  ~Ref() {
58  }
59 
60  Ref(const Ref & ref) :
61  m_dbsession(ref.m_dbsession), m_d(ref.m_d) {
62  }
63 
64  Ref & operator=(const Ref & ref) {
65  m_dbsession = ref.m_dbsession;
66  m_d = ref.m_d;
67  return *this;
68  }
69 
70  T const * ptr() const {
71  return m_d.get();
72  }
73 
74  T const * operator->() const {
75  return ptr();
76  }
77  // dereference operator
78  T const & operator*() const {
79  return *ptr();
80  }
81 
82 
83  private:
84 
86  std::shared_ptr<T> m_d;
87  };
88 
89 
91  m_tagInfo(0),
92  m_logDBEntry(0)
93  {}
94 
96  }
97 
98 
99  cond::TagInfo_t const & tagInfo() const { return *m_tagInfo; }
100 
101  // return last paylod of the tag
102  Ref lastPayload() const {
103  return Ref(m_session,tagInfo().lastPayloadToken);
104  }
105 
106  // return last successful log entry for the tag in question
107  cond::LogDBEntry_t const & logDBEntry() const { return *m_logDBEntry; }
108 
109  // FIX ME
110  void initialize (const cond::persistency::Session& dbSession,
111  cond::TagInfo_t const & tagInfo, cond::LogDBEntry_t const & logDBEntry) {
112  m_session = dbSession;
113  m_tagInfo = &tagInfo;
114  m_logDBEntry = &logDBEntry;
115  }
116 
117  // this is the only mandatory interface
118  std::pair<Container const *, std::string const> operator()(const cond::persistency::Session& session,
119  cond::TagInfo_t const & tagInfo,
120  cond::LogDBEntry_t const & logDBEntry) const {
121  const_cast<self*>(this)->initialize(session, tagInfo, logDBEntry);
122  return std::pair<Container const *, std::string const>(&(const_cast<self*>(this)->returnData()), userTextLog());
123  }
124 
125  Container const & returnData() {
126  getNewObjects();
127  if (!m_to_transfer.empty()) convertFromOld();
128  sort();
129  return m_triplets;
130  }
131 
132  std::string const & userTextLog() const { return m_userTextLog; }
133 
134  //Implement to fill m_to_transfer vector and m_userTextLog
135  //use getOfflineInfo to get the contents of offline DB
136  virtual void getNewObjects()=0;
137 
138  // return a string identifing the source
139  virtual std::string id() const=0;
140 
141  void sort() {
142  std::sort(m_triplets.begin(),m_triplets.end(),
143  boost::bind(std::less<cond::Time_t>(),
144  boost::bind(&Container::value_type::time,_1),
145  boost::bind(&Container::value_type::time,_2)
146  )
147  );
148  }
149 
150 
151  // make sure to create a new one each time...
152  Summary * dummySummary(typename OldContainer::value_type const &) const {
153  return new cond::GenericSummary("not supplied");
154  }
155 
156  void convertFromOld() {
157  std::for_each( m_to_transfer.begin(), m_to_transfer.end(),
158  boost::bind(&self::add, this,
159  boost::bind(&OldContainer::value_type::first,_1),
160  boost::bind(&self::dummySummary, this, _1),
161  boost::bind(&OldContainer::value_type::second,_1)
162  ));
163  }
164 
165  protected:
166 
168  return m_session;
169  }
170 
171  int add(value_type * payload, Summary * summary, Time_t time) {
172  Triplet t = {payload,summary,time};
173  m_triplets.push_back(t);
174  return m_triplets.size();
175  }
176 
177  private:
178 
180 
182 
184 
185 
186  protected:
187 
188  //vector of payload objects and iovinfo to be transferred
189  //class looses ownership of payload object
190  OldContainer m_to_transfer;
191 
192  private:
193  Container m_triplets;
194 
195  protected:
197 
198 
199  };
200 }
201 #endif
cond::persistency::Session & dbSession() const
static AlgebraicMatrix initialize()
cond::persistency::Session m_dbsession
std::string const & userTextLog() const
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
cond::LogDBEntry_t const * m_logDBEntry
std::vector< Triplet > Container
U second(std::pair< T, U > const &p)
payload
payload postfix for testing
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_t const &logDBEntry) const
cond::LogDBEntry_t const & logDBEntry() const
void initialize(const cond::persistency::Session &dbSession, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry)
Summary * dummySummary(typename OldContainer::value_type const &) const
dbsession
create,insert
Definition: lumiNorm.py:82
Definition: plugin.cc:24
Ref(cond::persistency::Session &dbsession, const std::string &hash)
cond::TagInfo_t const * m_tagInfo
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