forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctpCCDBManager.cxx
More file actions
242 lines (239 loc) · 9.54 KB
/
ctpCCDBManager.cxx
File metadata and controls
242 lines (239 loc) · 9.54 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file ctpCCDBManager.cxx
/// \author Roman Lietava
#include "CTPWorkflowScalers/ctpCCDBManager.h"
#include "DataFormatsCTP/Configuration.h"
#include "CCDB/CcdbApi.h"
#include "CCDB/BasicCCDBManager.h"
#include <sstream>
#include <regex>
#include "CommonUtils/StringUtils.h"
#include <fairlogger/Logger.h>
using namespace o2::ctp;
std::string ctpCCDBManager::mCCDBHost = "http://o2-ccdb.internal";
std::string ctpCCDBManager::mQCDBHost = "http://ali-qcdb.cern.ch:8083";
// std::string ctpCCDBManager::mQCDBHost = "none";
//
int ctpCCDBManager::saveRunScalersToCCDB(CTPRunScalers& scalers, long timeStart, long timeStop)
{
// data base
if (mCCDBHost == "none") {
LOG(debug) << "Scalers not written to CCDB none";
return 0;
}
// CTPActiveRun* run = mActiveRuns[i];
using namespace std::chrono_literals;
std::chrono::seconds days3 = 259200s;
std::chrono::seconds min10 = 600s;
long time3days = std::chrono::duration_cast<std::chrono::milliseconds>(days3).count();
long time10min = std::chrono::duration_cast<std::chrono::milliseconds>(min10).count();
long tmin = timeStart - time10min;
long tmax = timeStop + time3days;
o2::ccdb::CcdbApi api;
std::map<std::string, std::string> metadata; // can be empty
metadata["runNumber"] = std::to_string(scalers.getRunNumber());
api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
// store abitrary user object in strongly typed manner
int ret = api.storeAsTFileAny(&(scalers), mCCDBPathCTPScalers, metadata, tmin, tmax);
if (ret == 0) {
LOG(info) << "CTP scalers saved in ccdb:" << mCCDBHost << " run:" << scalers.getRunNumber() << " tmin:" << tmin << " tmax:" << tmax;
} else {
LOG(fatal) << "Problem writing to database ret:" << ret;
}
return ret;
}
int ctpCCDBManager::saveRunScalersToQCDB(CTPRunScalers& scalers, long timeStart, long timeStop)
{
// data base
if (mQCDBHost == "none") {
LOG(debug) << "Scalers not written to QCDB none";
return 0;
}
// CTPActiveRun* run = mActiveRuns[i];q
using namespace std::chrono_literals;
std::chrono::seconds days3 = 259200s;
std::chrono::seconds min10 = 600s;
long time3days = std::chrono::duration_cast<std::chrono::milliseconds>(days3).count();
long time10min = std::chrono::duration_cast<std::chrono::milliseconds>(min10).count();
long tmin = timeStart - time10min;
long tmax = timeStop + time3days;
o2::ccdb::CcdbApi api;
std::map<std::string, std::string> metadata; // can be empty
metadata["runNumber"] = std::to_string(scalers.getRunNumber());
api.init(mQCDBHost.c_str()); // or http://localhost:8080 for a local installation
// store abitrary user object in strongly typed manner
int ret = api.storeAsTFileAny(&(scalers), mQCDBPathCTPScalers, metadata, tmin, tmax);
if (ret == 0) {
LOG(info) << "CTP scalers saved in qcdb:" << mQCDBHost << " run:" << scalers.getRunNumber() << " tmin:" << tmin << " tmax:" << tmax;
} else {
LOG(fatal) << "CTP scalers Problem writing to database qcdb ret:" << ret;
}
return ret;
}
int ctpCCDBManager::saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart)
{
// data base
if (mCCDBHost == "none") {
LOG(info) << "CTP config not written to CCDB none";
return 0;
}
using namespace std::chrono_literals;
std::chrono::seconds days3 = 259200s;
std::chrono::seconds min10 = 600s;
long time3days = std::chrono::duration_cast<std::chrono::milliseconds>(days3).count();
long time10min = std::chrono::duration_cast<std::chrono::milliseconds>(min10).count();
long tmin = timeStart - time10min;
long tmax = timeStart + time3days;
o2::ccdb::CcdbApi api;
std::map<std::string, std::string> metadata; // can be empty
metadata["runNumber"] = std::to_string(cfg->getRunNumber());
api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
// store abitrary user object in strongly typed manner
int ret = api.storeAsTFileAny(cfg, CCDBPathCTPConfig, metadata, tmin, tmax);
if (ret == 0) {
LOG(info) << "CTP config saved in ccdb:" << mCCDBHost << " run:" << cfg->getRunNumber() << " tmin:" << tmin << " tmax:" << tmax;
} else {
LOG(fatal) << "CTPConfig: Problem writing to database ret:" << ret;
}
return ret;
}
int ctpCCDBManager::saveSoxOrbit(uint32_t runNumber, uint32_t soxOrbit, long timestamp)
{
// data base
if (mCCDBHost == "none") {
LOG(info) << "SOX Orbit not written to CCDB none";
return 0;
}
std::vector<int64_t> vect;
if (timestamp == 0) {
auto now = std::chrono::system_clock::now();
timestamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
}
vect.push_back(timestamp);
vect.push_back((uint64_t)runNumber);
vect.push_back((uint64_t)soxOrbit);
long tmin = timestamp / 1000;
long tmax = tmin + 381928219;
o2::ccdb::CcdbApi api;
std::map<std::string, std::string> metadata; // can be empty
metadata["runNumber"] = std::to_string(runNumber);
api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
// store abitrary user object in strongly typed manner
int ret = api.storeAsTFileAny(&vect, mCCDBPathSoxOrbit, metadata, tmin, tmax);
if (ret == 0) {
LOG(info) << "SOX orbit saved in ccdb:" << mCCDBHost << " run:" << runNumber << " tmin:" << tmin << " tmax:" << tmax;
} else {
LOG(fatal) << "SOX orbit Problem writing to database ret:" << ret;
}
return 0;
}
int ctpCCDBManager::saveOrbitReset(long timeStamp)
{
// data base
if (mCCDBHost == "none") {
LOG(info) << "Orbit Reset not written to CCDB none";
return 0;
}
std::vector<int64_t> vect;
if (timeStamp == 0) {
auto now = std::chrono::system_clock::now();
timeStamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
LOG(warn) << "Received timestamp = 0 , using current time:" << timeStamp;
}
vect.push_back(timeStamp);
long tmin = timeStamp / 1000;
long tmax = tmin + 381928219;
o2::ccdb::CcdbApi api;
std::map<std::string, std::string> metadata; // can be empty
api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
// store abitrary user object in strongly typed manner
int ret = api.storeAsTFileAny(&vect, mCCDBPathOrbitReset, metadata, tmin, tmax);
if (ret == 0) {
LOG(info) << "Orbit reset saved in ccdb:" << mCCDBHost << " tmin:" << tmin << " tmax:" << tmax;
} else {
LOG(fatal) << "Orbit reset Problem writing to database ret:" << ret;
}
return 0;
}
int ctpCCDBManager::saveCtpCfg(uint32_t runNumber, long timeStart)
{
if (mCCDBHost == "none") {
LOG(info) << "CtpCfg not written to CCDB none";
return 0;
}
CtpCfg ctpcfg;
int ret = ctpcfg.readAndSave(mCtpCfgDir);
if (ret == 0) {
using namespace std::chrono_literals;
std::chrono::seconds days3 = 259200s;
std::chrono::seconds min10 = 600s;
long time3days = std::chrono::duration_cast<std::chrono::milliseconds>(days3).count();
long time10min = std::chrono::duration_cast<std::chrono::milliseconds>(min10).count();
long tmin = timeStart - time10min;
long tmax = timeStart + time3days;
o2::ccdb::CcdbApi api;
std::map<std::string, std::string> metadata; // can be empty
metadata["runNumber"] = std::to_string(runNumber);
api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
// store abitrary user object in strongly typed manner
ret = api.storeAsTFileAny(&ctpcfg, mCCDBPathCtpCfg, metadata, tmin, tmax);
if (ret == 0) {
LOG(info) << "CtpCfg saved in ccdb:" << mCCDBHost << " tmin:" << tmin << " tmax:" << tmax;
} else {
LOG(error) << "CtpCfg Problem writing to database ret:" << ret;
}
}
return ret;
}
CTPConfiguration ctpCCDBManager::getConfigFromCCDB(long timestamp, std::string run, bool& ok)
{
auto& mgr = o2::ccdb::BasicCCDBManager::instance();
mgr.setURL(mCCDBHost);
std::map<std::string, std::string> metadata; // can be empty
metadata["runNumber"] = run;
auto ctpconfigdb = mgr.getSpecific<CTPConfiguration>(CCDBPathCTPConfig, timestamp, metadata);
if (ctpconfigdb == nullptr) {
LOG(info) << "CTP config not in database, timestamp:" << timestamp;
ok = 0;
} else {
// ctpconfigdb->printStream(std::cout);
LOG(info) << "CTP config found. Run:" << run;
ok = 1;
}
return *ctpconfigdb;
}
CTPConfiguration ctpCCDBManager::getConfigFromCCDB(long timestamp, std::string run)
{
bool ok;
auto ctpconfig = getConfigFromCCDB(timestamp, run, ok);
if (ok == 0) {
LOG(error) << "CTP config not in CCDB";
return CTPConfiguration();
}
return ctpconfig;
}
CTPRunScalers ctpCCDBManager::getScalersFromCCDB(long timestamp, std::string run, bool& ok)
{
auto& mgr = o2::ccdb::BasicCCDBManager::instance();
mgr.setURL(mCCDBHost);
std::map<std::string, std::string> metadata; // can be empty
metadata["runNumber"] = run;
auto ctpscalers = mgr.getSpecific<CTPRunScalers>(mCCDBPathCTPScalers, timestamp, metadata);
if (ctpscalers == nullptr) {
LOG(info) << "CTPRunScalers not in database, timestamp:" << timestamp;
ok = 0;
} else {
// ctpscalers->printStream(std::cout);
ok = 1;
}
return *ctpscalers;
}