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 namespace popcon {
20 
29  template <class T>
31  public:
32  typedef T value_type;
33  typedef PopConSourceHandler<T> self;
36 
37  struct Triplet {
41  };
42 
43  typedef std::vector<Triplet> Container;
44 
45  typedef std::vector<std::pair<T*, cond::Time_t> > OldContainer;
46 
47  class Ref {
48  public:
49  Ref() : m_dbsession() {}
50  Ref(cond::persistency::Session& dbsession, const std::string& hash) : m_dbsession(dbsession) {
52  }
53  ~Ref() {}
54 
55  Ref(const Ref& ref) : m_dbsession(ref.m_dbsession), m_d(ref.m_d) {}
56 
57  Ref& operator=(const Ref& ref) {
59  m_d = ref.m_d;
60  return *this;
61  }
62 
63  T const* ptr() const { return m_d.get(); }
64 
65  T const* operator->() const { return ptr(); }
66  // dereference operator
67  T const& operator*() const { return *ptr(); }
68 
69  private:
71  std::shared_ptr<T> m_d;
72  };
73 
74  PopConSourceHandler() : m_tagInfo(nullptr), m_logDBEntry(nullptr) {}
75 
76  virtual ~PopConSourceHandler() {}
77 
78  cond::TagInfo_t const& tagInfo() const { return *m_tagInfo; }
79 
80  // return last paylod of the tag
81  Ref lastPayload() const { return Ref(m_session, tagInfo().lastInterval.payloadId); }
82 
83  // return last successful log entry for the tag in question
84  cond::LogDBEntry_t const& logDBEntry() const { return *m_logDBEntry; }
85 
86  // FIX ME
88  cond::TagInfo_t const& tagInfo,
91  m_tagInfo = &tagInfo;
93  }
94 
95  // this is the only mandatory interface
96  std::pair<Container const*, std::string const> operator()(const cond::persistency::Session& session,
97  cond::TagInfo_t const& tagInfo,
98  cond::LogDBEntry_t const& logDBEntry) const {
99  const_cast<self*>(this)->initialize(session, tagInfo, logDBEntry);
100  return std::pair<Container const*, std::string const>(&(const_cast<self*>(this)->returnData()), userTextLog());
101  }
102 
104  getNewObjects();
105  if (!m_to_transfer.empty())
106  convertFromOld();
107  sort();
108  return m_triplets;
109  }
110 
111  std::string const& userTextLog() const { return m_userTextLog; }
112 
113  //Implement to fill m_to_transfer vector and m_userTextLog
114  //use getOfflineInfo to get the contents of offline DB
115  virtual void getNewObjects() = 0;
116 
117  // return a string identifing the source
118  virtual std::string id() const = 0;
119 
120  void sort() {
121  std::sort(m_triplets.begin(),
122  m_triplets.end(),
123  boost::bind(std::less<cond::Time_t>(),
124  boost::bind(&Container::value_type::time, _1),
125  boost::bind(&Container::value_type::time, _2)));
126  }
127 
128  // make sure to create a new one each time...
130  return new cond::GenericSummary("not supplied");
131  }
132 
133  void convertFromOld() {
134  std::for_each(m_to_transfer.begin(),
135  m_to_transfer.end(),
136  boost::bind(&self::add,
137  this,
138  boost::bind(&OldContainer::value_type::first, _1),
139  boost::bind(&self::dummySummary, this, _1),
140  boost::bind(&OldContainer::value_type::second, _1)));
141  }
142 
143  protected:
145 
147  Triplet t = {payload, summary, time};
148  m_triplets.push_back(t);
149  return m_triplets.size();
150  }
151 
152  private:
154 
156 
158 
159  protected:
160  //vector of payload objects and iovinfo to be transferred
161  //class looses ownership of payload object
163 
164  private:
166 
167  protected:
169  };
170 } // namespace popcon
171 #endif
popcon::PopConSourceHandler::m_logDBEntry
cond::LogDBEntry_t const * m_logDBEntry
Definition: PopConSourceHandler.h:157
popcon::PopConSourceHandler::Triplet
Definition: PopConSourceHandler.h:37
popcon::PopConSourceHandler::Ref::~Ref
~Ref()
Definition: PopConSourceHandler.h:53
popcon::PopConSourceHandler::m_to_transfer
OldContainer m_to_transfer
Definition: PopConSourceHandler.h:162
popcon::PopConSourceHandler::operator()
std::pair< Container const *, std::string const > operator()(const cond::persistency::Session &session, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry) const
Definition: PopConSourceHandler.h:96
popcon::PopConSourceHandler::getNewObjects
virtual void getNewObjects()=0
popcon::PopConSourceHandler::dbSession
cond::persistency::Session & dbSession() const
Definition: PopConSourceHandler.h:144
cond::hash
Definition: Time.h:19
popcon::PopConSourceHandler::Ref::ptr
T const * ptr() const
Definition: PopConSourceHandler.h:63
popcon::PopConSourceHandler::Time_t
cond::Time_t Time_t
Definition: PopConSourceHandler.h:34
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
popcon::PopConSourceHandler::Triplet::payload
value_type * payload
Definition: PopConSourceHandler.h:38
popcon::PopConSourceHandler::id
virtual std::string id() const =0
popcon::PopConSourceHandler::OldContainer
std::vector< std::pair< T *, cond::Time_t > > OldContainer
Definition: PopConSourceHandler.h:45
dqmdumpme.first
first
Definition: dqmdumpme.py:55
popcon::PopConSourceHandler::~PopConSourceHandler
virtual ~PopConSourceHandler()
Definition: PopConSourceHandler.h:76
cond::persistency::Session::fetchPayload
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
popcon::PopConSourceHandler::Ref
Definition: PopConSourceHandler.h:47
popcon::PopConSourceHandler::Triplet::time
Time_t time
Definition: PopConSourceHandler.h:40
popcon::PopConSourceHandler::Container
std::vector< Triplet > Container
Definition: PopConSourceHandler.h:43
popcon::PopConSourceHandler::Ref::operator*
T const & operator*() const
Definition: PopConSourceHandler.h:67
jets_cff.payload
payload
Definition: jets_cff.py:34
popcon::PopConSourceHandler::returnData
Container const & returnData()
Definition: PopConSourceHandler.h:103
popcon::PopConSourceHandler::m_tagInfo
cond::TagInfo_t const * m_tagInfo
Definition: PopConSourceHandler.h:155
OrderedSet.t
t
Definition: OrderedSet.py:90
popcon::PopConSourceHandler::Ref::operator=
Ref & operator=(const Ref &ref)
Definition: PopConSourceHandler.h:57
popcon::PopConSourceHandler::Ref::m_d
std::shared_ptr< T > m_d
Definition: PopConSourceHandler.h:71
CastorPedestals
Definition: CastorPedestals.h:18
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond
Definition: plugin.cc:23
Time.h
popcon::PopConSourceHandler::tagInfo
cond::TagInfo_t const & tagInfo() const
Definition: PopConSourceHandler.h:78
GenericSummary.h
popcon::PopConSourceHandler::Ref::operator->
T const * operator->() const
Definition: PopConSourceHandler.h:65
cond::persistency::Session
Definition: Session.h:63
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
popcon::PopConSourceHandler::value_type
T value_type
Definition: PopConSourceHandler.h:32
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
popcon::PopConSourceHandler::Ref::Ref
Ref()
Definition: PopConSourceHandler.h:49
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
popcon::PopConSourceHandler::Ref::Ref
Ref(cond::persistency::Session &dbsession, const std::string &hash)
Definition: PopConSourceHandler.h:50
popcon::PopConSourceHandler
Definition: PopConSourceHandler.h:30
popcon::PopConSourceHandler::convertFromOld
void convertFromOld()
Definition: PopConSourceHandler.h:133
popcon::PopConSourceHandler::Triplet::summary
Summary * summary
Definition: PopConSourceHandler.h:39
popcon::PopConSourceHandler::Ref::m_dbsession
cond::persistency::Session m_dbsession
Definition: PopConSourceHandler.h:70
popcon
Definition: Exception.h:6
popcon::PopConSourceHandler::Summary
cond::Summary Summary
Definition: PopConSourceHandler.h:35
popcon::PopConSourceHandler::add
int add(value_type *payload, Summary *summary, Time_t time)
Definition: PopConSourceHandler.h:146
T
long double T
Definition: Basic3DVectorLD.h:48
reco::JetExtendedAssociation::Ref
edm::Ref< Container > Ref
Definition: JetExtendedAssociation.h:32
popcon::PopConSourceHandler::lastPayload
Ref lastPayload() const
Definition: PopConSourceHandler.h:81
popcon::PopConSourceHandler::initialize
void initialize(const cond::persistency::Session &dbSession, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry)
Definition: PopConSourceHandler.h:87
popcon::PopConSourceHandler::m_session
cond::persistency::Session m_session
Definition: PopConSourceHandler.h:153
cond::Summary
Definition: Summary.h:13
popcon::PopConSourceHandler::dummySummary
Summary * dummySummary(typename OldContainer::value_type const &) const
Definition: PopConSourceHandler.h:129
EcalCondDBWriter_cfi.Summary
Summary
Definition: EcalCondDBWriter_cfi.py:155
cond::LogDBEntry_t
Definition: Types.h:86
cond::GenericSummary
Definition: GenericSummary.h:12
popcon::PopConSourceHandler::Ref::Ref
Ref(const Ref &ref)
Definition: PopConSourceHandler.h:55
cond::TagInfo_t
Definition: Types.h:69
ntuplemaker.time
time
Definition: ntuplemaker.py:310
Session.h
popcon::PopConSourceHandler::m_userTextLog
std::string m_userTextLog
Definition: PopConSourceHandler.h:168
popcon::PopConSourceHandler::logDBEntry
cond::LogDBEntry_t const & logDBEntry() const
Definition: PopConSourceHandler.h:84
popcon::PopConSourceHandler::sort
void sort()
Definition: PopConSourceHandler.h:120
popcon::PopConSourceHandler::PopConSourceHandler
PopConSourceHandler()
Definition: PopConSourceHandler.h:74
popcon::PopConSourceHandler::userTextLog
std::string const & userTextLog() const
Definition: PopConSourceHandler.h:111
popcon::PopConSourceHandler::m_triplets
Container m_triplets
Definition: PopConSourceHandler.h:165