test
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 
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 {
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){
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) {
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,
112  m_session = dbSession;
113  m_tagInfo = &tagInfo;
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 
167 
168  int add(value_type * payload, Summary * summary, Time_t time) {
169  Triplet t = {payload,summary,time};
170  m_triplets.push_back(t);
171  return m_triplets.size();
172  }
173 
174  private:
175 
177 
179 
181 
182 
183  protected:
184 
185  //vector of payload objects and iovinfo to be transferred
186  //class looses ownership of payload object
188 
189  private:
191 
192  protected:
194 
195 
196  };
197 }
198 #endif
tuple dbsession
create,insert
Definition: lumiNorm.py:82
cond::persistency::Session m_dbsession
std::string const & userTextLog() const
virtual void getNewObjects()=0
tuple session
Definition: dataDML.py:2333
cond::LogDBEntry_t const * m_logDBEntry
std::vector< Triplet > Container
U second(std::pair< T, U > const &p)
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
Ref(cond::persistency::Session &dbsession, const std::string &hash)
cond::TagInfo_t const * m_tagInfo
virtual std::string id() const =0
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
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:187