Project
Loading...
Searching...
No Matches
ctpCCDBManager.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16#include "CCDB/CcdbApi.h"
18#include <sstream>
19#include <regex>
21#include <fairlogger/Logger.h>
22using namespace o2::ctp;
23std::string ctpCCDBManager::mCCDBHost = "http://o2-ccdb.internal";
24std::string ctpCCDBManager::mQCDBHost = "http://ali-qcdb.cern.ch:8083";
25// std::string ctpCCDBManager::mQCDBHost = "none";
26//
27int ctpCCDBManager::saveRunScalersToCCDB(CTPRunScalers& scalers, long timeStart, long timeStop)
28{
29 // data base
30 if (mCCDBHost == "none") {
31 LOG(debug) << "Scalers not written to CCDB none";
32 return 0;
33 }
34 // CTPActiveRun* run = mActiveRuns[i];
35 using namespace std::chrono_literals;
36 std::chrono::seconds days3 = 259200s;
37 std::chrono::seconds min10 = 600s;
38 long time3days = std::chrono::duration_cast<std::chrono::milliseconds>(days3).count();
39 long time10min = std::chrono::duration_cast<std::chrono::milliseconds>(min10).count();
40 long tmin = timeStart - time10min;
41 long tmax = timeStop + time3days;
43 std::map<std::string, std::string> metadata; // can be empty
44 metadata["runNumber"] = std::to_string(scalers.getRunNumber());
45 api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
46 // store abitrary user object in strongly typed manner
47 int ret = api.storeAsTFileAny(&(scalers), mCCDBPathCTPScalers, metadata, tmin, tmax);
48 if (ret == 0) {
49 LOG(info) << "CTP scalers saved in ccdb:" << mCCDBHost << " run:" << scalers.getRunNumber() << " tmin:" << tmin << " tmax:" << tmax;
50 } else {
51 LOG(fatal) << "Problem writing to database ret:" << ret;
52 }
53 return ret;
54}
55int ctpCCDBManager::saveRunScalersToQCDB(CTPRunScalers& scalers, long timeStart, long timeStop)
56{
57 // data base
58 if (mQCDBHost == "none") {
59 LOG(debug) << "Scalers not written to QCDB none";
60 return 0;
61 }
62 // CTPActiveRun* run = mActiveRuns[i];q
63 using namespace std::chrono_literals;
64 std::chrono::seconds days3 = 259200s;
65 std::chrono::seconds min10 = 600s;
66 long time3days = std::chrono::duration_cast<std::chrono::milliseconds>(days3).count();
67 long time10min = std::chrono::duration_cast<std::chrono::milliseconds>(min10).count();
68 long tmin = timeStart - time10min;
69 long tmax = timeStop + time3days;
71 std::map<std::string, std::string> metadata; // can be empty
72 metadata["runNumber"] = std::to_string(scalers.getRunNumber());
73 api.init(mQCDBHost.c_str()); // or http://localhost:8080 for a local installation
74 // store abitrary user object in strongly typed manner
75 int ret = api.storeAsTFileAny(&(scalers), mQCDBPathCTPScalers, metadata, tmin, tmax);
76 if (ret == 0) {
77 LOG(info) << "CTP scalers saved in qcdb:" << mQCDBHost << " run:" << scalers.getRunNumber() << " tmin:" << tmin << " tmax:" << tmax;
78 } else {
79 LOG(fatal) << "CTP scalers Problem writing to database qcdb ret:" << ret;
80 }
81 return ret;
82}
84{
85 // data base
86 if (mCCDBHost == "none") {
87 LOG(info) << "CTP config not written to CCDB none";
88 return 0;
89 }
90 using namespace std::chrono_literals;
91 std::chrono::seconds days3 = 259200s;
92 std::chrono::seconds min10 = 600s;
93 long time3days = std::chrono::duration_cast<std::chrono::milliseconds>(days3).count();
94 long time10min = std::chrono::duration_cast<std::chrono::milliseconds>(min10).count();
95 long tmin = timeStart - time10min;
96 long tmax = timeStart + time3days;
98 std::map<std::string, std::string> metadata; // can be empty
99 metadata["runNumber"] = std::to_string(cfg->getRunNumber());
100 api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
101 // store abitrary user object in strongly typed manner
102 int ret = api.storeAsTFileAny(cfg, CCDBPathCTPConfig, metadata, tmin, tmax);
103 if (ret == 0) {
104 LOG(info) << "CTP config saved in ccdb:" << mCCDBHost << " run:" << cfg->getRunNumber() << " tmin:" << tmin << " tmax:" << tmax;
105 } else {
106 LOG(fatal) << "CTPConfig: Problem writing to database ret:" << ret;
107 }
108 return ret;
109}
110int ctpCCDBManager::saveSoxOrbit(uint32_t runNumber, uint32_t soxOrbit, long timestamp)
111{
112 // data base
113 if (mCCDBHost == "none") {
114 LOG(info) << "SOX Orbit not written to CCDB none";
115 return 0;
116 }
117 std::vector<int64_t> vect;
118 if (timestamp == 0) {
119 auto now = std::chrono::system_clock::now();
120 timestamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
121 }
122 vect.push_back(timestamp);
123 vect.push_back((uint64_t)runNumber);
124 vect.push_back((uint64_t)soxOrbit);
125 long tmin = timestamp / 1000;
126 long tmax = tmin + 381928219;
128 std::map<std::string, std::string> metadata; // can be empty
129 metadata["runNumber"] = std::to_string(runNumber);
130 api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
131
132 // store abitrary user object in strongly typed manner
133 int ret = api.storeAsTFileAny(&vect, mCCDBPathSoxOrbit, metadata, tmin, tmax);
134 if (ret == 0) {
135 LOG(info) << "SOX orbit saved in ccdb:" << mCCDBHost << " run:" << runNumber << " tmin:" << tmin << " tmax:" << tmax;
136 } else {
137 LOG(fatal) << "SOX orbit Problem writing to database ret:" << ret;
138 }
139 return 0;
140}
142{
143 // data base
144 if (mCCDBHost == "none") {
145 LOG(info) << "Orbit Reset not written to CCDB none";
146 return 0;
147 }
148 std::vector<int64_t> vect;
149 if (timeStamp == 0) {
150 auto now = std::chrono::system_clock::now();
151 timeStamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
152 LOG(warn) << "Received timestamp = 0 , using current time:" << timeStamp;
153 }
154 vect.push_back(timeStamp);
155 long tmin = timeStamp / 1000;
156 long tmax = tmin + 381928219;
158 std::map<std::string, std::string> metadata; // can be empty
159 api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
160 // int ret = api.storeAsTFileAny(&vect, mCCDBPathOrbitReset, metadata, tmin, tmax);
161 std::cout << "Storing:" << mCCDBPathOrbitReset << " tmin:" << tmin << " tmax:" << tmax << " ts:" << timeStamp << std::endl;
162 std::string filename = "orbitReset.root";
163 auto classname = "std::vector<int64_t>";
164 metadata["adjustableEOV"] = "true";
165 int ret = api.storeAsTFileAny(&(vect), mCCDBPathOrbitReset, metadata, tmin, tmax);
166 o2::ccdb::CcdbObjectInfo oi(mCCDBPathOrbitReset, classname, filename, metadata, tmin, tmax);
167 adjustOverriddenEOV(api, oi);
168 if (ret == 0) {
169 LOG(info) << "Orbit reset saved in ccdb:" << mCCDBHost << " tmin:" << tmin << " tmax:" << tmax;
170 } else {
171 LOG(fatal) << "Orbit reset Problem writing to database ret:" << ret;
172 }
173 return 0;
174}
175int ctpCCDBManager::saveCtpCfg(uint32_t runNumber, long timeStart)
176{
177 if (mCCDBHost == "none") {
178 LOG(info) << "CtpCfg not written to CCDB none";
179 return 0;
180 }
181 CtpCfg ctpcfg;
182 int ret = ctpcfg.readAndSave(mCtpCfgDir);
183 if (ret == 0) {
184 using namespace std::chrono_literals;
185 std::chrono::seconds days3 = 259200s;
186 std::chrono::seconds min10 = 600s;
187 long time3days = std::chrono::duration_cast<std::chrono::milliseconds>(days3).count();
188 long time10min = std::chrono::duration_cast<std::chrono::milliseconds>(min10).count();
189 long tmin = timeStart - time10min;
190 long tmax = timeStart + time3days;
192 std::map<std::string, std::string> metadata; // can be empty
193 metadata["runNumber"] = std::to_string(runNumber);
194 api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
195 // store abitrary user object in strongly typed manner
196 ret = api.storeAsTFileAny(&ctpcfg, mCCDBPathCtpCfg, metadata, tmin, tmax);
197 if (ret == 0) {
198 LOG(info) << "CtpCfg saved in ccdb:" << mCCDBHost << " tmin:" << tmin << " tmax:" << tmax;
199 } else {
200 LOG(error) << "CtpCfg Problem writing to database ret:" << ret;
201 }
202 }
203 return ret;
204}
205CTPConfiguration ctpCCDBManager::getConfigFromCCDB(long timestamp, std::string run, bool& ok)
206{
207
209 mgr.setURL(mCCDBHost);
210 std::map<std::string, std::string> metadata; // can be empty
211 metadata["runNumber"] = run;
212 if (timestamp == 0) {
213 // Timestamp
214 auto soreor = mgr.getRunDuration(std::stoi(run));
215 timestamp = (soreor.second - soreor.first) / 2 + soreor.first;
216 }
217 auto ctpconfigdb = mgr.getSpecific<CTPConfiguration>(CCDBPathCTPConfig, timestamp, metadata);
218 if (ctpconfigdb == nullptr) {
219 LOG(info) << "CTP config not in database, timestamp:" << timestamp;
220 ok = 0;
221 } else {
222 // ctpconfigdb->printStream(std::cout);
223 LOG(info) << "CTP config found. Run:" << run;
224 ok = 1;
225 }
226 return *ctpconfigdb;
227}
229{
230 bool ok;
231 auto ctpconfig = getConfigFromCCDB(timestamp, run, ok);
232 if (ok == 0) {
233 LOG(error) << "CTP config not in CCDB";
234 return CTPConfiguration();
235 }
236 return ctpconfig;
237}
238CTPRunScalers ctpCCDBManager::getScalersFromCCDB(long timestamp, std::string run, bool& ok)
239{
241 mgr.setURL(mCCDBHost);
242 std::map<std::string, std::string> metadata; // can be empty
243 metadata["runNumber"] = run;
244 auto ctpscalers = mgr.getSpecific<CTPRunScalers>(mCCDBPathCTPScalers, timestamp, metadata);
245 if (ctpscalers == nullptr) {
246 LOG(info) << "CTPRunScalers not in database, timestamp:" << timestamp;
247 ok = 0;
248 } else {
249 // ctpscalers->printStream(std::cout);
250 ok = 1;
251 }
252 return *ctpscalers;
253}
254CTPRunScalers ctpCCDBManager::getScalersFromCCDB(long timestamp, std::string run, std::string path, bool& ok)
255{
257 mgr.setURL(mCCDBHost);
258 std::map<std::string, std::string> metadata; // can be empty
259 metadata["runNumber"] = run;
260 if (timestamp == 0) {
261 // Timestamp
262 auto soreor = mgr.getRunDuration(std::stoi(run));
263 timestamp = (soreor.second - soreor.first) / 2 + soreor.first;
264 }
265 auto ctpscalers = mgr.getSpecific<CTPRunScalers>(path, timestamp, metadata);
266 if (ctpscalers == nullptr) {
267 LOG(info) << "CTPRunScalers not in database, timestamp:" << timestamp;
268 ok = 0;
269 } else {
270 // ctpscalers->printStream(std::cout);
271 ok = 1;
272 }
273 return *ctpscalers;
274}
definition of CTPConfiguration and related CTP structures
std::ostringstream debug
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
char error[CURL_ERROR_SIZE]
static BasicCCDBManager & instance()
int storeAsTFileAny(const T *obj, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const
Definition CcdbApi.h:163
void init(std::string const &hosts)
Definition CcdbApi.cxx:240
uint32_t getRunNumber()
Definition Scalers.h:104
const std::string mCCDBPathOrbitReset
static std::string mCCDBHost
Database constants.
const std::string mQCDBPathCTPScalers
int saveRunScalersToQCDB(CTPRunScalers &scalers, long timeStart, long timeStop)
static std::string mQCDBHost
int saveSoxOrbit(uint32_t runNumber, uint32_t soxOrbit, long timeStart)
CTPRunScalers getScalersFromCCDB(long timestamp, std::string run, bool &ok)
int saveRunScalersToCCDB(CTPRunScalers &scalers, long timeStart, long timeStop)
int saveRunConfigToCCDB(CTPConfiguration *cfg, long timeStart)
int saveCtpCfg(uint32_t runNumber, long timeStamp)
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run, bool &ok)
const std::string mCCDBPathCtpCfg
const std::string mCCDBPathCTPScalers
int saveOrbitReset(long timeStamp)
const std::string mCCDBPathSoxOrbit
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
const std::string CCDBPathCTPConfig
Database constants.
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
int readAndSave(std::string &path)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"