Skip to content

Commit 0a85418

Browse files
committed
dev: finishing orbitsox and orbitreset via zmq
1 parent 75153a0 commit 0a85418

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

Detectors/CTP/workflowScalers/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ o2_add_library(CTPWorkflowScalers
1313
SOURCES src/RunManager.cxx
1414
PUBLIC_LINK_LIBRARIES O2::Framework
1515
O2::DataFormatsCTP
16-
AliceO2::BookkeepingApi)
16+
AliceO2::BookkeepingApi
17+
AliceO2::InfoLogger)
1718
o2_target_root_dictionary(CTPWorkflowScalers HEADERS
1819
include/CTPWorkflowScalers/ctpCCDBManager.h)
1920
o2_add_executable(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include "DataFormatsCTP/Configuration.h"
1919
#include "BookkeepingApi/BkpClientFactory.h"
2020
#include "BookkeepingApi/BkpClient.h"
21+
#include <InfoLogger/InfoLogger.hxx>
22+
23+
2124
using namespace o2::bkp::api;
2225
namespace o2
2326
{
@@ -71,6 +74,7 @@ class CTPRunManager : public ctpCCDBManager
7174
int mEOX = 0; // redundancy check
7275
int mNew = 1; // 1 - no CCDB: used for QC
7376
int mQCWritePeriod = 3; // Time in 10secs between two writes to QCCD
77+
AliceO2::InfoLogger::InfoLogger mInfoLogger;
7478
ClassDefNV(CTPRunManager, 7);
7579
};
7680
} // namespace ctp

Detectors/CTP/workflowScalers/src/RunManager.cxx

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <regex>
1919
#include "CommonUtils/StringUtils.h"
2020
#include <fairlogger/Logger.h>
21+
2122
using namespace o2::ctp;
2223
///
2324
/// Active run to keep cfg and saclers of active runs
@@ -232,10 +233,53 @@ int CTPRunManager::processMessage(std::string& topic, const std::string& message
232233
return 0;
233234
}
234235
if (topic.find("soxorbit") != std::string::npos) {
235-
return 0;
236+
std::vector<std::string> tokens = o2::utils::Str::tokenize(message, ' ');
237+
int ret = 0;
238+
if(tokens.size() == 3) {
239+
long timestamp = std::stol(tokens[0]);
240+
uint32_t runnumber = std::stoul(tokens[1]);
241+
uint32_t orbit = std::stoul(tokens[2]);
242+
ret = saveSoxOrbit(timestamp,runnumber,orbit);
243+
LOG(info) << "soxorbit: " << timestamp << " " << runnumber << " " << orbit;
244+
std::string logmessage;
245+
if(ret) {
246+
logmessage = "Failed to update CCDB with SOX orbit.";
247+
} else {
248+
logmessage = "CCDB updated with SOX orbit.";
249+
}
250+
int rlog = mInfoLogger.log(logmessage.c_str());
251+
if(rlog) {
252+
LOG(warn) << "Writing to infologger failed.";
253+
}
254+
} else {
255+
LOG(error) << "Topic soxorbit dize !=3: " << message << " token size:" << tokens.size();
256+
ret = 1;
257+
}
258+
return ret;
236259
}
237260
if (topic.find("orbitreset") != std::string::npos) {
238-
return 0;
261+
std::vector<std::string> tokens = o2::utils::Str::tokenize(message, ' ');
262+
int ret = 0;
263+
if(tokens.size() == 1) {
264+
long timestamp = std::stol(tokens[0]);
265+
ret = saveOrbitReset(timestamp);
266+
LOG(info) << "orbitreset: " << timestamp;
267+
std::string logmessage;
268+
if(ret) {
269+
logmessage = "Failed to update CCDB with orbitreset.";
270+
return 1;
271+
} else {
272+
logmessage = "CCDB updated with orbitreset.";
273+
}
274+
int rlog = mInfoLogger.log(logmessage.c_str());
275+
if(rlog) {
276+
LOG(warn) << "Writing to infologger failed.";
277+
}
278+
} else {
279+
LOG(error) << "Topic orbit reset != 2: " << message << " token size:" << tokens.size();
280+
ret = 1;
281+
}
282+
return ret;
239283
}
240284
static int nerror = 0;
241285
if (topic.find("sox") != std::string::npos) {

Detectors/CTP/workflowScalers/src/ctpCCDBManager.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ int ctpCCDBManager::saveSoxOrbit(uint32_t runNumber, uint32_t soxOrbit, long tim
122122
vect.push_back(timestamp);
123123
vect.push_back((uint64_t)runNumber);
124124
vect.push_back((uint64_t)soxOrbit);
125-
long tmin = timestamp;
125+
long tmin = timestamp/1000;
126126
long tmax = tmin + 381928219;
127127
o2::ccdb::CcdbApi api;
128128
map<string, string> metadata; // can be empty
@@ -149,9 +149,10 @@ int ctpCCDBManager::saveOrbitReset(long timeStamp)
149149
if (timeStamp == 0) {
150150
auto now = std::chrono::system_clock::now();
151151
timeStamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
152+
LOG(warn) << "Received timestamp = 0 , using current time:" << timeStamp;
152153
}
153154
vect.push_back(timeStamp);
154-
long tmin = timeStamp;
155+
long tmin = timeStamp/1000;
155156
long tmax = tmin + 381928219;
156157
o2::ccdb::CcdbApi api;
157158
map<string, string> metadata; // can be empty

0 commit comments

Comments
 (0)