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