Skip to content

Commit 2dbd7f8

Browse files
authored
Ctpdev (#14037)
* dev: ctp config to BK and first orbit and orbit reset via zmq * clang
1 parent 8b6b16c commit 2dbd7f8

File tree

4 files changed

+94
-17
lines changed

4 files changed

+94
-17
lines changed

Detectors/CTP/workflowScalers/include/CTPWorkflowScalers/RunManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CTPRunManager : public ctpCCDBManager
4747
CTPRunManager() = default;
4848
void init();
4949
int loadRun(const std::string& cfg);
50-
int startRun(const std::string& cfg);
50+
int setRunConfigBK(uint32_t runNumber, const std::string& cfg);
5151
int stopRun(uint32_t irun, long timeStamp);
5252
int addScalers(uint32_t irun, std::time_t time, bool start = 0);
5353
int processMessage(std::string& topic, const std::string& message);

Detectors/CTP/workflowScalers/include/CTPWorkflowScalers/ctpCCDBManager.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ class ctpCCDBManager
2727
int saveRunScalersToCCDB(CTPRunScalers& scalers, long timeStart, long timeStop);
2828
int saveRunScalersToQCDB(CTPRunScalers& scalers, long timeStart, long timeStop);
2929
int saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart);
30+
int saveSoxOrbit(uint32_t runNumber, uint32_t soxOrbit, long timeStart);
31+
int saveOrbitReset(long timeStamp);
3032
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run, bool& ok);
3133
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run);
3234
CTPRunScalers getScalersFromCCDB(long timestamp, std::string, bool& ok);
33-
void setCCDBPathConfig(std::string path) { mCCDBPathCTPConfig = path; };
34-
void setCCDBPathScalers(std::string path) { mCCDBPathCTPScalers = path; };
35-
void setQCDBPathScalers(std::string path) { mQCDBPathCTPScalers = path; };
3635
static void setCCDBHost(std::string host) { mCCDBHost = host; };
3736
static void setQCDBHost(std::string host) { mQCDBHost = host; };
3837

@@ -42,9 +41,11 @@ class ctpCCDBManager
4241
// std::string mQCDBHost = "http://ali-qcdb.cern.ch:8083";
4342
static std::string mCCDBHost;
4443
static std::string mQCDBHost;
45-
std::string mCCDBPathCTPScalers = "CTP/Calib/Scalers";
46-
std::string mCCDBPathCTPConfig = "CTP/Config/Config";
47-
std::string mQCDBPathCTPScalers = "qc/CTP/Scalers";
44+
const std::string mCCDBPathCTPScalers = "CTP/Calib/Scalers";
45+
// std::string mCCDBPathCTPConfig = "CTP/Config/Config"; - in Configuration.h
46+
const std::string mQCDBPathCTPScalers = "qc/CTP/Scalers";
47+
const std::string mCCDBPathSoxOrbit = "CTP/Calib/FirstRunOrbit";
48+
const std::string mCCDBPathOrbitReset = "CTP/Calib/OrbitReset";
4849
ClassDefNV(ctpCCDBManager, 1);
4950
};
5051
} // namespace ctp

Detectors/CTP/workflowScalers/src/RunManager.cxx

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int CTPActiveRun::send2BK(std::unique_ptr<BkpClient>& BKClient, size_t ts, bool
5757
std::string clsname = cfg.getClassNameFromHWIndex(cls.first);
5858
// clsname = std::to_string(runOri) + "_" + clsname;
5959
try {
60-
BKClient->triggerCounters()->createOrUpdateForRun(runNumber, clsname, ts, cntsbk[0], cntsbk[1], cntsbk[2], cntsbk[3], cntsbk[4], cntsbk[5]);
60+
BKClient->ctpTriggerCounters()->createOrUpdateForRun(runNumber, clsname, ts, cntsbk[0], cntsbk[1], cntsbk[2], cntsbk[3], cntsbk[4], cntsbk[5]);
6161
} catch (std::runtime_error& error) {
6262
std::cerr << "An error occurred: " << error.what() << std::endl;
6363
return 1;
@@ -124,8 +124,19 @@ int CTPRunManager::loadRun(const std::string& cfg)
124124

125125
return 0;
126126
}
127-
int CTPRunManager::startRun(const std::string& cfg)
127+
int CTPRunManager::setRunConfigBK(uint32_t runNumber, const std::string& cfg)
128128
{
129+
std::cout << "Printing cfg:" << cfg << std::endl;
130+
if (mBKClient) {
131+
try {
132+
uint32_t runNumber = 1;
133+
mBKClient->run()->setRawCtpTriggerConfiguration(runNumber, cfg);
134+
} catch (std::runtime_error& error) {
135+
std::cerr << "An error occurred: " << error.what() << std::endl;
136+
return 1;
137+
}
138+
LOG(info) << "Run BK:" << runNumber << " CFG:" << cfg;
139+
}
129140
return 0;
130141
}
131142
int CTPRunManager::stopRun(uint32_t irun, long timeStamp)
@@ -221,6 +232,13 @@ int CTPRunManager::processMessage(std::string& topic, const std::string& message
221232
loadRun(message);
222233
return 0;
223234
}
235+
if (topic.find("soxorbit") != std::string::npos) {
236+
return 0;
237+
}
238+
if (topic.find("orbitreset") != std::string::npos) {
239+
return 0;
240+
}
241+
static int nerror = 0;
224242
if (topic.find("sox") != std::string::npos) {
225243
// get config
226244
size_t irun = message.find("run");
@@ -230,17 +248,15 @@ int CTPRunManager::processMessage(std::string& topic, const std::string& message
230248
}
231249
LOG(info) << "SOX received, Run keyword position:" << irun;
232250
std::string cfg = message.substr(irun, message.size() - irun);
233-
startRun(cfg);
234251
firstcounters = message.substr(0, irun);
235-
}
236-
if (topic.find("eox") != std::string::npos) {
252+
} else if (topic.find("eox") != std::string::npos) {
237253
LOG(info) << "EOX received";
238254
mEOX = 1;
239-
}
240-
static int nerror = 0;
241-
if (topic == "rocnts") {
242-
if (nerror < 1) {
243-
LOG(warning) << "Skipping topic rocnts";
255+
} else if (topic.find("cnts") != std::string::npos) {
256+
// just continue
257+
} else {
258+
if (nerror < 10) {
259+
LOG(warning) << "Skipping topic:" << topic;
244260
nerror++;
245261
}
246262
return 0;
@@ -293,6 +309,7 @@ int CTPRunManager::processMessage(std::string& topic, const std::string& message
293309
mActiveRunNumbers[i] = mCounters[i];
294310
mActiveRuns[i] = run->second;
295311
mRunsLoaded.erase(run);
312+
setRunConfigBK(mActiveRuns[i]->cfg.getRunNumber(), mActiveRuns[i]->cfg.getConfigString());
296313
addScalers(i, tt, 1);
297314
saveRunScalersToQCDB(mActiveRuns[i]->scalers, tt * 1000, tt * 1000);
298315
} else {

Detectors/CTP/workflowScalers/src/ctpCCDBManager.cxx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,65 @@ int ctpCCDBManager::saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart)
107107
}
108108
return ret;
109109
}
110+
int 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;
126+
long tmax = tmin + 381928219;
127+
o2::ccdb::CcdbApi api;
128+
map<string, 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+
}
141+
int ctpCCDBManager::saveOrbitReset(long timeStamp)
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+
}
153+
vect.push_back(timeStamp);
154+
long tmin = timeStamp;
155+
long tmax = tmin + 381928219;
156+
o2::ccdb::CcdbApi api;
157+
map<string, string> metadata; // can be empty
158+
api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
159+
160+
// store abitrary user object in strongly typed manner
161+
int ret = api.storeAsTFileAny(&vect, mCCDBPathOrbitReset, metadata, tmin, tmax);
162+
if (ret == 0) {
163+
LOG(info) << "Orbit reset saved in ccdb:" << mCCDBHost << " tmin:" << tmin << " tmax:" << tmax;
164+
} else {
165+
LOG(fatal) << "Orbit reset Problem writing to database ret:" << ret;
166+
}
167+
return 0;
168+
}
110169
CTPConfiguration ctpCCDBManager::getConfigFromCCDB(long timestamp, std::string run, bool& ok)
111170
{
112171
auto& mgr = o2::ccdb::BasicCCDBManager::instance();

0 commit comments

Comments
 (0)