-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
PopCon.h
154 lines (97 loc) · 3.52 KB
/
PopCon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef POPCON_POPCON_H
#define POPCON_POPCON_H
//
// Author: Vincenzo Innocente
// Original Author: Marcin BOGUSZ
//
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
#include "CondCore/CondDB/interface/Time.h"
#include <boost/bind.hpp>
#include <algorithm>
#include <vector>
#include <string>
#include<iostream>
namespace popcon {
/* Populator of the Condition DB
*
*/
class PopCon {
public:
typedef cond::Time_t Time_t;
//typedef cond::Summary Summary;
PopCon(const edm::ParameterSet& pset);
virtual ~PopCon();
template<typename Source>
void write(Source const & source);
template<typename T>
void writeOne(T * payload, Time_t time);
private:
cond::persistency::Session initialize();
void finalize(Time_t lastTill);
private:
edm::Service<cond::service::PoolDBOutputService> m_dbService;
cond::persistency::Session m_targetSession;
std::string m_targetConnectionString;
std::string m_authPath;
int m_authSys;
std::string m_record;
std::string m_payload_name;
bool m_LoggingOn;
std::string m_tag;
cond::TagInfo_t m_tagInfo;
cond::LogDBEntry_t m_logDBEntry;
bool m_close;
Time_t m_lastTill;
static constexpr const char* const s_version = "5.0";
};
template<typename T>
void PopCon::writeOne(T * payload, Time_t time) {
m_dbService->writeOne(payload, time, m_record, m_LoggingOn);
}
template<typename Container>
void displayHelper(Container const & payloads) {
typename Container::const_iterator it;
for (it = payloads.begin(); it != payloads.end(); it++)
edm::LogInfo ("PopCon")<< "Since " << (*it).time << std::endl;
}
template<typename Container>
const std::string displayIovHelper(Container const & payloads) {
if (payloads.empty()) return std::string("Nothing to transfer;");
std::ostringstream s;
// when only 1 payload is transferred;
if ( payloads.size()==1)
s << "Since " << (*payloads.begin()).time << "; " ;
else{
// when more than one payload are transferred;
s << "first payload Since " << (*payloads.begin()).time << ", "
<< "last payload Since " << (*payloads.rbegin()).time << "; " ;
}
return s.str();
}
template<typename Source>
void PopCon::write(Source const & source) {
typedef typename Source::value_type value_type;
typedef typename Source::Container Container;
std::pair<Container const *, std::string const> ret = source(initialize(),
m_tagInfo,m_logDBEntry);
Container const & payloads = *ret.first;
if(m_LoggingOn) {
std::ostringstream s;
s << "PopCon v" << s_version << "; " << displayIovHelper(payloads) << ret.second;
//s << "PopCon v" << s_version << "; " << cond::userInfo() << displayIovHelper(payloads) << ret.second;
m_dbService->setLogHeaderForRecord(m_record,source.id(),s.str());
}
displayHelper(payloads);
std::for_each(payloads.begin(),payloads.end(),
boost::bind(&popcon::PopCon::writeOne<value_type>,this,
boost::bind(&Container::value_type::payload,_1),
boost::bind(&Container::value_type::time,_1)
)
);
finalize(payloads.empty() ? Time_t(0): payloads.back().time);
}
}
#endif // POPCON_POPCON_H