Skip to content

Commit ec2f0b2

Browse files
committed
Utility for detector run status check in DCS processing
1 parent edb3944 commit ec2f0b2

4 files changed

Lines changed: 155 additions & 1 deletion

File tree

Detectors/DCS/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ o2_add_library(
2424
src/GenericFunctions.cxx
2525
src/StringUtils.cxx
2626
src/Clock.cxx
27+
src/RunStatusChecker.cxx
2728
PUBLIC_LINK_LIBRARIES O2::Headers O2::CommonUtils O2::CCDB
2829
O2::DetectorsCalibration Microsoft.GSL::GSL)
2930

3031
o2_target_root_dictionary(
3132
DetectorsDCS
3233
HEADERS include/DetectorsDCS/DataPointCompositeObject.h
3334
include/DetectorsDCS/DataPointIdentifier.h
34-
include/DetectorsDCS/DataPointValue.h)
35+
include/DetectorsDCS/DataPointValue.h
36+
include/DetectorsDCS/RunStatusChecker.h)
3537

3638
if(OpenMP_CXX_FOUND)
3739
target_compile_definitions(${targetName} PRIVATE WITH_OPENMP)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
12+
#ifndef O2_RUN_STATUS_CHECKER_H
13+
#define O2_RUN_STATUS_CHECKER_H
14+
15+
/// @author ruben.shahoyan@cern.ch
16+
17+
#include "DataFormatsParameters/GRPECSObject.h"
18+
#include "DetectorsCommonDataFormats/DetID.h"
19+
20+
/*
21+
Utility class to check the status of the run with particular detectors participating
22+
Usage: first create an instance for the mask of detectors which must be in the run, e.g.
23+
24+
RunStatusChecker runChecker{ o2::detectors::DetID::getMask("EMC,PHS") };
25+
const o2::parameters::GRPECSObject* myGRPECS = nullptr;
26+
27+
Then, periodically check:
28+
29+
myGRPECS = runChecker.check();
30+
31+
The check will set the status of the run with selected detectors (can be inspected by getRunStatus() method).
32+
33+
if (check.getRunStatus() == o2::dcs::RunStatusChecker::RunStatus::NONE) {
34+
LOGP(info, "No run with {} is ongoing or finished", o2::detectors::DetID::getNames(checker->getDetectorsMask()) );
35+
}
36+
else if (check.getRunStatus() == o2::dcs::RunStatusChecker::RunStatus::START) { // saw new run with wanted detectors
37+
LOGP(info, "Run {} with {} has started", checker.getFollowedRun(), o2::detectors::DetID::getNames(checker->getDetectorsMask()) );
38+
}
39+
else if (check.getRunStatus() == o2::dcs::RunStatusChecker::RunStatus::ONGOING) { // run which was already seen is still ongoing
40+
LOGP(info, "Run {} with {} is still ongoing", checker.getFollowedRun(), o2::detectors::DetID::getNames(checker->getDetectorsMask()) );
41+
}
42+
else if (check.getRunStatus() == o2::dcs::RunStatusChecker::RunStatus::STOP) { // run which was already seen was stopped (EOR seen)
43+
LOGP(info, "Run {} with {} was stopped", checker.getFollowedRun(), o2::detectors::DetID::getNames(checker->getDetectorsMask()) );
44+
}
45+
46+
In all cases except RunStatusChecker::NONE a const non-null pointer on the GRP of the followed run will be returned.
47+
48+
By default the check will be done for the current timestamp, for test purposes one can call it with arbitrary increasing timestamps
49+
*/
50+
51+
namespace o2::dcs
52+
{
53+
54+
class RunStatusChecker
55+
{
56+
public:
57+
enum class RunStatus { NONE, // check did not find onging run with current detector
58+
START, // check found a new run started
59+
ONGOING, // check found ongoing run which was already checked
60+
STOP // check found that previously ongoing run was stopped
61+
};
62+
63+
RunStatusChecker() = delete;
64+
RunStatusChecker(o2::detectors::DetID::mask_t detmask) : mDetMask(detmask) {}
65+
66+
RunStatus getRunStatus() const { return mRunStatus; }
67+
int getFollowedRun() const { return mRunFollowed; }
68+
o2::detectors::DetID::mask_t getDetectorsMask() const { return mDetMask; }
69+
const o2::parameters::GRPECSObject* check(long ts = -1);
70+
71+
private:
72+
RunStatus mRunStatus = RunStatus::NONE;
73+
o2::detectors::DetID::mask_t mDetMask{};
74+
int mRunFollowed = -1; // particular run followed, assumption is that at the given moment there might be only run with particular detector
75+
long mLastTimeStampChecked = -1;
76+
77+
ClassDefNV(RunStatusChecker, 0);
78+
};
79+
80+
} // namespace o2::dcs
81+
82+
#endif

Detectors/DCS/src/DetectorsDCSLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#pragma link off all classes;
1515
#pragma link off all functions;
1616

17+
#pragma link C++ class o2::dcs::RunStatusChecker;
1718
#pragma link C++ struct o2::dcs::DataPointCompositeObject + ;
1819
#pragma link C++ class o2::dcs::DataPointIdentifier + ;
1920
#pragma link C++ struct o2::dcs::DataPointValue + ;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
12+
#include "DetectorsDCS/RunStatusChecker.h"
13+
#include "CCDB/BasicCCDBManager.h"
14+
#include "CCDB/CCDBTimeStampUtils.h"
15+
16+
using namespace o2::dcs;
17+
18+
const o2::parameters::GRPECSObject* RunStatusChecker::check(long ts)
19+
{
20+
if (ts < 0) {
21+
ts = o2::ccdb::getCurrentTimestamp();
22+
}
23+
if (ts <= mLastTimeStampChecked) {
24+
LOGP(alarm, "RunStatusChecker::check was called with decreasing timestamp {}, previous was {}", ts, mLastTimeStampChecked);
25+
return nullptr;
26+
}
27+
mLastTimeStampChecked = ts;
28+
29+
auto& mgr = o2::ccdb::BasicCCDBManager::instance();
30+
bool fatalOn = mgr.getFatalWhenNull();
31+
mgr.setFatalWhenNull(false);
32+
if (mRunStatus == RunStatus::STOP) { // the STOP was detected at previous check
33+
mRunFollowed = -1;
34+
mRunStatus = RunStatus::NONE;
35+
}
36+
std::map<std::string, std::string> md;
37+
if (mRunFollowed > 0) { // run start was seen
38+
md["runNumber"] = std::to_string(mRunFollowed);
39+
}
40+
const auto* grp = mgr.getSpecific<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", ts, md);
41+
if (grp) { // some object was returned
42+
if (mRunFollowed > 0) {
43+
if ((ts > grp->getTimeEnd()) && (grp->getTimeEnd() > grp->getTimeStart())) { // this means that the EOR was registered
44+
mRunStatus = RunStatus::STOP;
45+
} else { // run still continues
46+
mRunStatus = RunStatus::ONGOING;
47+
}
48+
} else { // we were not following detector run, check if the current one has asked detectors
49+
if ((grp->getDetsReadOut() & mDetMask) == mDetMask) { // we start following this run
50+
if (grp->getTimeEnd() > grp->getTimeStart()) {
51+
if (ts < grp->getTimeEnd()) { // only in tests with ad hoc ts the ts_EOR can be seen > ts
52+
mRunStatus = RunStatus::START;
53+
mRunFollowed = grp->getRun();
54+
}
55+
} else {
56+
mRunStatus = RunStatus::START;
57+
mRunFollowed = grp->getRun();
58+
}
59+
}
60+
}
61+
} else { // query did not return any GRP -> we are certainly not in the wanted detectors run
62+
if (mRunFollowed > 0) { // normally this should not happen
63+
LOGP(warning, "We were following {} run {} but the query at {} did not return any GRP, problem with EOR?", o2::detectors::DetID::getNames(mDetMask), mRunFollowed, ts);
64+
mRunStatus = RunStatus::STOP;
65+
}
66+
}
67+
mgr.setFatalWhenNull(fatalOn);
68+
return mRunStatus == RunStatus::NONE ? nullptr : grp;
69+
}

0 commit comments

Comments
 (0)