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 
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, Summary * summary, 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, Summary * summary, Time_t time) {
93  m_dbService->writeOne(payload, summary, time, m_record, m_LoggingOn);
94  }
95 
96 
97  template<typename Container>
98  void displayHelper(Container const & payloads) {
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 
135 
136  if(m_LoggingOn)
137  m_dbService->setLogHeaderForRecord(m_record,source.id(),"PopCon v4.0; " +
138  cond::userInfo() + displayIovHelper(payloads) + ret.second);
139 
140 
141  displayHelper(payloads);
142 
143  std::for_each(payloads.begin(),payloads.end(),
144  boost::bind(&popcon::PopCon::writeOne<value_type>,this,
145  boost::bind(&Container::value_type::payload,_1),
146  boost::bind(&Container::value_type::summary,_1),
147  boost::bind(&Container::value_type::time,_1)
148  )
149  );
150 
151 
152  finalize(payloads.empty() ? Time_t(0): payloads.back().time);
153  }
154 
155 }
156 
157 #endif // POPCON_POPCON_H
158 
159 
cond::LogDBEntry m_logDBEntry
Definition: PopCon.h:82
void finalize(Time_t lastTill)
Definition: PopCon.cc:56
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 writeOne(T *payload, Summary *summary, Time_t time)
Definition: PopCon.h:92
void write(Source const &source)
Definition: PopCon.h:125
unsigned long long Time_t
Definition: Time.h:16
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:10
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:29
cond::TagInfo m_tagInfo
Definition: PopCon.h:80
virtual ~PopCon()
Definition: PopCon.cc:26
std::string userInfo()
Definition: IOVInfo.cc:9
string s
Definition: asciidump.py:422
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