Skip to content

Commit 2b06259

Browse files
committed
dev: ctp config to BK and first orbit and orbit reset via zmq
1 parent 699feec commit 2b06259

File tree

4 files changed

+92
-17
lines changed

4 files changed

+92
-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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,63 @@ 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+
// data base
112+
if (mCCDBHost == "none") {
113+
LOG(info) << "SOX Orbit not written to CCDB none";
114+
return 0;
115+
}
116+
std::vector<int64_t> vect;
117+
if (timestamp == 0) {
118+
auto now = std::chrono::system_clock::now();
119+
timestamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
120+
}
121+
vect.push_back(timestamp);
122+
vect.push_back((uint64_t) runNumber);
123+
vect.push_back((uint64_t) soxOrbit);
124+
long tmin = timestamp;
125+
long tmax = tmin + 381928219;
126+
o2::ccdb::CcdbApi api;
127+
map<string, string> metadata; // can be empty
128+
metadata["runNumber"] = std::to_string(runNumber);
129+
api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
130+
131+
// store abitrary user object in strongly typed manner
132+
int ret = api.storeAsTFileAny(&vect, mCCDBPathSoxOrbit, metadata, tmin, tmax);
133+
if (ret == 0) {
134+
LOG(info) << "SOX orbit saved in ccdb:" << mCCDBHost << " run:" << runNumber << " tmin:" << tmin << " tmax:" << tmax;
135+
} else {
136+
LOG(fatal) << "SOX orbit Problem writing to database ret:" << ret;
137+
}
138+
return 0;
139+
}
140+
int ctpCCDBManager::saveOrbitReset(long timeStamp) {
141+
// data base
142+
if (mCCDBHost == "none") {
143+
LOG(info) << "Orbit Reset not written to CCDB none";
144+
return 0;
145+
}
146+
std::vector<int64_t> vect;
147+
if (timeStamp == 0) {
148+
auto now = std::chrono::system_clock::now();
149+
timeStamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
150+
}
151+
vect.push_back(timeStamp);
152+
long tmin = timeStamp;
153+
long tmax = tmin + 381928219;
154+
o2::ccdb::CcdbApi api;
155+
map<string, string> metadata; // can be empty
156+
api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
157+
158+
// store abitrary user object in strongly typed manner
159+
int ret = api.storeAsTFileAny(&vect, mCCDBPathOrbitReset, metadata, tmin, tmax);
160+
if (ret == 0) {
161+
LOG(info) << "Orbit reset saved in ccdb:" << mCCDBHost << " tmin:" << tmin << " tmax:" << tmax;
162+
} else {
163+
LOG(fatal) << "Orbit reset Problem writing to database ret:" << ret;
164+
}
165+
return 0;
166+
}
110167
CTPConfiguration ctpCCDBManager::getConfigFromCCDB(long timestamp, std::string run, bool& ok)
111168
{
112169
auto& mgr = o2::ccdb::BasicCCDBManager::instance();

0 commit comments

Comments
 (0)