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