CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PopCon.h
Go to the documentation of this file.
1 
2 #ifndef POPCON_POPCON_H
3 #define POPCON_POPCON_H
4 //
5 // Author: Vincenzo Innocente
6 // Original Author: Marcin BOGUSZ
7 //
8 
9 
12 
16 
18 
20 
22 
23 
24 #include <boost/bind.hpp>
25 #include <algorithm>
26 #include <vector>
27 #include <string>
28 
29 
30 #include<iostream>
31 
32 namespace cond {
33  class Summary;
34 }
35 
36 
37 namespace popcon {
38 
39 
40  /* Populator of the Condition DB
41  *
42  */
43  class PopCon {
44  public:
47 
48  PopCon(const edm::ParameterSet& pset);
49 
50  virtual ~PopCon();
51 
52  template<typename Source>
53  void write(Source const & source);
54 
55  template<typename T>
56  void writeOne(T * payload, Time_t time);
57 
58 
59 
60 
61  private:
62  void initialize();
63  void finalize(Time_t lastTill);
64 
65 
66  private:
67 
69 
70  std::string m_record;
71 
72  std::string m_payload_name;
73 
75 
77 
78  std::string m_tag;
79 
81 
83 
84  bool m_close;
86 
87 
88  };
89 
90 
91  template<typename T>
92  void PopCon::writeOne(T * payload, Time_t time) {
93  m_dbService->writeOne(payload, time, m_record, m_LoggingOn);
94  }
95 
96 
97  template<typename Container>
99  typename Container::const_iterator it;
100  for (it = payloads.begin(); it != payloads.end(); it++)
101  edm::LogInfo ("PopCon")<< "Since " << (*it).time << std::endl;
102  }
103 
104 
105  template<typename Container>
106  const std::string displayIovHelper(Container const & payloads) {
107  if (payloads.empty()) return "Nothing to transfer;";
108  std::ostringstream s;
109  // when only 1 payload is transferred;
110  if ( payloads.size()==1)
111  s <<"Since " << (*payloads.begin()).time << "; " ;
112  else{
113  // when more than one payload are transferred;
114  s << "first payload Since " << (*payloads.begin()).time << ","
115  << "last payload Since " << (*payloads.rbegin()).time << ";" ;
116  }
117  return s.str();
118  }
119 
120 
121 
122 
123 
124  template<typename Source>
125  void PopCon::write(Source const & source) {
126  typedef typename Source::value_type value_type;
127  typedef typename Source::Container Container;
128 
129  initialize();
130  std::pair<Container const *, std::string const> ret = source(m_dbService->session(),
132  Container const & payloads = *ret.first;
133 
134  if(m_LoggingOn)
135  m_dbService->setLogHeaderForRecord(m_record,source.id(),"PopCon v4.0; " +
136  cond::userInfo() + displayIovHelper(payloads) + ret.second);
137 
138  displayHelper(payloads);
139 
140  std::for_each(payloads.begin(),payloads.end(),
141  boost::bind(&popcon::PopCon::writeOne<value_type>,this,
142  boost::bind(&Container::value_type::payload,_1),
143  boost::bind(&Container::value_type::time,_1)
144  )
145  );
146 
147 
148  finalize(payloads.empty() ? Time_t(0): payloads.back().time);
149  }
150 
151 }
152 
153 #endif // POPCON_POPCON_H
154 
155 
cond::LogDBEntry m_logDBEntry
Definition: PopCon.h:82
void finalize(Time_t lastTill)
Definition: PopCon.cc:60
EcalChannelStatus Container
Time_t m_lastTill
Definition: PopCon.h:85
bool m_close
Definition: PopCon.h:84
cond::Time_t Time_t
Definition: PopCon.h:45
std::string m_tag
Definition: PopCon.h:78
std::string m_record
Definition: PopCon.h:70
void write(Source const &source)
Definition: PopCon.h:125
unsigned long long Time_t
Definition: Time.h:16
void writeOne(T *payload, Time_t time)
Definition: PopCon.h:92
void displayHelper(Container const &payloads)
Definition: PopCon.h:98
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
Container::value_type value_type
PopCon(const edm::ParameterSet &pset)
Definition: PopCon.cc:9
void setLogHeaderForRecord(const std::string &recordName, const std::string &provenance, const std::string &usertext)
bool m_IsDestDbCheckedInQueryLog
Definition: PopCon.h:76
cond::Summary Summary
Definition: PopCon.h:46
void initialize()
Definition: PopCon.cc:28
cond::TagInfo m_tagInfo
Definition: PopCon.h:80
virtual ~PopCon()
Definition: PopCon.cc:25
std::string userInfo()
Definition: IOVInfo.cc:9
const std::string displayIovHelper(Container const &payloads)
Definition: PopCon.h:106
long double T
std::string m_payload_name
Definition: PopCon.h:72
edm::Service< cond::service::PoolDBOutputService > m_dbService
Definition: PopCon.h:68
bool m_LoggingOn
Definition: PopCon.h:74