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