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){
59  m_d = m_dbsession.getTypedObject<T>(token);
60  }
61  ~Ref() {
62  if(m_dbsession.isOpen())
64  }
65 
66  Ref(const Ref & ref) :
67  m_dbsession(ref.m_dbsession), m_d(ref.m_d) {
68  //ref.m_dbsession=0; // avoid commit;
69  }
70 
71  Ref & operator=(const Ref & ref) {
73  m_d = ref.m_d;
74  //ref.m_dbsession=0; // avoid commit;
75  return *this;
76  }
77 
78  T const * ptr() const {
79  return m_d.get();
80  }
81 
82  T const * operator->() const {
83  return ptr();
84  }
85  // dereference operator
86  T const & operator*() const {
87  return *ptr();
88  }
89 
90 
91  private:
92 
94  boost::shared_ptr<T> m_d;
95  };
96 
97 
99 
101  }
102 
103 
104  cond::TagInfo const & tagInfo() const { return *m_tagInfo; }
105 
106  // return last paylod of the tag
107  Ref lastPayload() const {
108  return Ref(m_session,tagInfo().lastPayloadToken);
109  }
110 
111  // return last successful log entry for the tag in question
112  cond::LogDBEntry const & logDBEntry() const { return *m_logDBEntry; }
113 
114 
115  void initialize (cond::DbSession dbSession,
116  cond::TagInfo const & tagInfo, cond::LogDBEntry const & logDBEntry) {
117  m_session = dbSession;
118  m_tagInfo = &tagInfo;
120  }
121 
122  // this is the only mandatory interface
123  std::pair<Container const *, std::string const> operator()(cond::DbSession session,
124  cond::TagInfo const & tagInfo,
125  cond::LogDBEntry const & logDBEntry) const {
126  const_cast<self*>(this)->initialize(session, tagInfo, logDBEntry);
127  return std::pair<Container const *, std::string const>(&(const_cast<self*>(this)->returnData()), userTextLog());
128  }
129 
130  Container const & returnData() {
131  getNewObjects();
132  if (!m_to_transfer.empty()) convertFromOld();
133  sort();
134  return m_triplets;
135  }
136 
137  std::string const & userTextLog() const { return m_userTextLog; }
138 
139  //Implement to fill m_to_transfer vector and m_userTextLog
140  //use getOfflineInfo to get the contents of offline DB
141  virtual void getNewObjects()=0;
142 
143  // return a string identifing the source
144  virtual std::string id() const=0;
145 
146  void sort() {
147  std::sort(m_triplets.begin(),m_triplets.end(),
148  boost::bind(std::less<cond::Time_t>(),
149  boost::bind(&Container::value_type::time,_1),
150  boost::bind(&Container::value_type::time,_2)
151  )
152  );
153  }
154 
155 
156  // make sure to create a new one each time...
157  Summary * dummySummary(typename OldContainer::value_type const &) const {
158  return new cond::GenericSummary("not supplied");
159  }
160 
161  void convertFromOld() {
162  std::for_each( m_to_transfer.begin(), m_to_transfer.end(),
163  boost::bind(&self::add, this,
164  boost::bind(&OldContainer::value_type::first,_1),
165  boost::bind(&self::dummySummary, this, _1),
166  boost::bind(&OldContainer::value_type::second,_1)
167  ));
168  }
169 
170  protected:
171 
172 
173  int add(value_type * payload, Summary * summary, Time_t time) {
174  Triplet t = {payload,summary,time};
175  m_triplets.push_back(t);
176  return m_triplets.size();
177  }
178 
179  private:
180 
182 
184 
186 
187 
188  protected:
189 
190  //vector of payload objects and iovinfo to be transferred
191  //class looses ownership of payload object
193 
194  private:
196 
197  protected:
198  std::string m_userTextLog;
199 
200 
201  };
202 }
203 #endif
std::string const & userTextLog() const
virtual void getNewObjects()=0
DbTransaction & transaction()
Definition: DbSession.cc:153
int commit()
commit transaction.
Container::value_type value_type
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
int start(bool readOnly=false)
start transaction
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:79
Ref(cond::DbSession &dbsession, std::string token)
virtual std::string id() const =0
bool isOpen() const
Definition: DbSession.cc:129
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:98
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)