Skip to content

Commit 8acfb61

Browse files
wiechuladavidrohr
authored andcommitted
DCS: Add possibility to play back data from DARMA export
* data exported from DARMA can be directly played back via DPL and allows running the standard detector DCS workflow * improve debugging information in DataPointCompositeObject
1 parent ce6e6c6 commit 8acfb61

6 files changed

Lines changed: 194 additions & 17 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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_DCS_TEST_WORKFLOW_DATAPOINTHINT_H
13+
#define O2_DCS_TEST_WORKFLOW_DATAPOINTHINT_H
14+
15+
#include <variant>
16+
#include <string>
17+
#include <vector>
18+
#include <cstdint>
19+
20+
namespace o2::dcs::test
21+
{
22+
/*
23+
* A compact representation a group of alias to be generated
24+
*/
25+
template <typename T>
26+
struct DataPointHint {
27+
std::string aliasPattern; // alias pattern e.g. DET/HV/Crate[0..2]/Channel[000..012]/vMon
28+
T minValue; // minimum value to generate
29+
T maxValue; // maximum value to generate
30+
};
31+
32+
using HintType = std::variant<DataPointHint<double>,
33+
DataPointHint<float>,
34+
DataPointHint<uint32_t>,
35+
DataPointHint<int32_t>,
36+
DataPointHint<char>,
37+
DataPointHint<bool>,
38+
DataPointHint<std::string>>;
39+
40+
} // namespace o2::dcs::test
41+
42+
#endif

Detectors/DCS/src/DataPointCompositeObject.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// or submit itself to any jurisdiction.
1111

1212
#include "DetectorsDCS/DataPointCompositeObject.h"
13+
#include "DetectorsDCS/GenericFunctions.h"
1314

1415
using namespace o2::dcs;
1516

@@ -25,7 +26,7 @@ T getValueImpl(const DataPointCompositeObject& dpcom)
2526
T t_value;
2627
};
2728
if (dpcom.id.get_type() != dt) {
28-
throw std::runtime_error("DPCOM is of unexpected type " + o2::dcs::show(dt));
29+
throw std::runtime_error("DPCOM is of unexpected type " + o2::dcs::show(dpcom.id.get_type()) + " instead of the requested " + o2::dcs::show(dt));
2930
}
3031
Converter converter;
3132
converter.raw_data = dpcom.data.payload_pt1;

Detectors/DCS/testWorkflow/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
o2_add_library(
33
DCStestWorkflow
44
SOURCES src/DCSRandomDataGeneratorSpec.cxx
5+
src/DCSDataReplaySpec.cxx
56
PUBLIC_LINK_LIBRARIES O2::DetectorsDCS O2::Framework)
67

78
o2_add_executable(
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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_DCS_TEST_WORKFLOW_DATA_REPLAY_SPEC_H
13+
#define O2_DCS_TEST_WORKFLOW_DATA_REPLAY_SPEC_H
14+
15+
#include "DetectorsDCS/DCSDataPointHint.h"
16+
#include "Framework/DataProcessorSpec.h"
17+
#include <variant>
18+
#include <string>
19+
#include <vector>
20+
#include <cstdint>
21+
22+
namespace o2::dcs::test
23+
{
24+
25+
o2::framework::DataProcessorSpec getDCSDataReplaySpec(std::vector<HintType> hints = {},
26+
const char* detName = "TPC");
27+
28+
} // namespace o2::dcs::test
29+
30+
#endif

Detectors/DCS/testWorkflow/include/DCStestWorkflow/DCSRandomDataGeneratorSpec.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef O2_DCS_TEST_WORKFLOW_RANDOM_DATA_GENERATOR_SPEC_H
1313
#define O2_DCS_TEST_WORKFLOW_RANDOM_DATA_GENERATOR_SPEC_H
1414

15+
#include "DetectorsDCS/DCSDataPointHint.h"
1516
#include "Framework/DataProcessorSpec.h"
1617
#include <variant>
1718
#include <string>
@@ -20,22 +21,6 @@
2021

2122
namespace o2::dcs::test
2223
{
23-
/*
24-
* A compact representation a group of alias to be generated
25-
*/
26-
template <typename T>
27-
struct DataPointHint {
28-
std::string aliasPattern; // alias pattern e.g. DET/HV/Crate[0..2]/Channel[000..012]/vMon
29-
T minValue; // minimum value to generate
30-
T maxValue; // maximum value to generate
31-
};
32-
33-
using HintType = std::variant<DataPointHint<double>,
34-
DataPointHint<uint32_t>,
35-
DataPointHint<int32_t>,
36-
DataPointHint<char>,
37-
DataPointHint<bool>,
38-
DataPointHint<std::string>>;
3924

4025
o2::framework::DataProcessorSpec getDCSRandomDataGeneratorSpec(std::vector<HintType> hints = {},
4126
const char* detName = "TOF");
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 "DCStestWorkflow/DCSDataReplaySpec.h"
13+
#include "DetectorsDCS/DataPointCompositeObject.h"
14+
#include "DetectorsDCS/DataPointGenerator.h"
15+
#include "DetectorsDCS/DataPointCreator.h"
16+
#include "Framework/ConfigParamRegistry.h"
17+
#include "Framework/ControlService.h"
18+
#include "Framework/DeviceSpec.h"
19+
#include "Framework/Logger.h"
20+
#include "Framework/Task.h"
21+
#include "TTree.h"
22+
#include <cmath>
23+
#include <variant>
24+
#include <string>
25+
#include <algorithm>
26+
#include <vector>
27+
28+
using namespace o2::framework;
29+
30+
namespace
31+
{
32+
33+
class DCSDataReplayer : public o2::framework::Task
34+
{
35+
public:
36+
DCSDataReplayer(std::vector<o2::dcs::test::HintType> hints, o2::header::DataDescription description);
37+
38+
void init(o2::framework::InitContext& ic) final;
39+
40+
void run(o2::framework::ProcessingContext& pc) final;
41+
42+
private:
43+
std::string mInputFileName{};
44+
double mTime{};
45+
double mValue{};
46+
char mAlias[50];
47+
uint64_t mMaxTF;
48+
uint64_t mTFs = 0;
49+
TTree mInputData;
50+
std::vector<o2::dcs::test::HintType> mDataPointHints;
51+
o2::header::DataDescription mDataDescription;
52+
};
53+
54+
DCSDataReplayer::DCSDataReplayer(std::vector<o2::dcs::test::HintType> hints,
55+
o2::header::DataDescription description) : mDataPointHints(hints),
56+
mDataDescription(description) {}
57+
58+
void DCSDataReplayer::init(o2::framework::InitContext& ic)
59+
{
60+
mMaxTF = ic.options().get<int64_t>("max-timeframes");
61+
mInputFileName = ic.options().get<std::string>("input-file");
62+
mInputData.ReadFile(mInputFileName.data(), "time/D:alias/C:value/D", ';');
63+
mInputData.SetBranchAddress("time", &mTime);
64+
mInputData.SetBranchAddress("value", &mValue);
65+
mInputData.SetBranchAddress("alias", mAlias);
66+
}
67+
68+
void DCSDataReplayer::run(o2::framework::ProcessingContext& pc)
69+
{
70+
auto input = pc.inputs().begin();
71+
uint64_t tfid = o2::header::get<o2::framework::DataProcessingHeader*>((*input).header)->startTime;
72+
if (tfid >= mMaxTF) {
73+
LOG(info) << "Data generator reached TF " << tfid << ", stopping";
74+
pc.services().get<o2::framework::ControlService>().endOfStream();
75+
pc.services().get<o2::framework::ControlService>().readyToQuit(o2::framework::QuitRequest::Me);
76+
}
77+
78+
std::vector<o2::dcs::DataPointCompositeObject> dpcoms;
79+
for (Long64_t iEntry = 0; iEntry < mInputData.GetEntries(); ++iEntry) {
80+
mInputData.GetEntry(iEntry);
81+
const auto ultime = uint64_t(std::round(mTime * 1000));
82+
const auto seconds = uint32_t(ultime / 1000);
83+
const auto msec = uint16_t(ultime % 1000);
84+
85+
dpcoms.emplace_back(o2::dcs::createDataPointCompositeObject(mAlias, float(mValue), seconds, msec));
86+
}
87+
// auto dpcoms = generate(mDataPointHints, fraction, tfid);
88+
89+
LOG(info)
90+
<< "***************** TF " << tfid << " has generated " << dpcoms.size() << " DPs";
91+
pc.outputs().snapshot(Output{"DCS", mDataDescription, 0, Lifetime::Timeframe}, dpcoms);
92+
mTFs++;
93+
}
94+
} // namespace
95+
96+
namespace o2::dcs::test
97+
{
98+
o2::framework::DataProcessorSpec getDCSDataReplaySpec(std::vector<o2::dcs::test::HintType> hints,
99+
const char* detName)
100+
{
101+
std::string desc{detName};
102+
desc += "DATAPOINTS";
103+
104+
o2::header::DataDescription dd;
105+
106+
dd.runtimeInit(desc.c_str(), desc.size());
107+
108+
return DataProcessorSpec{
109+
"dcs-random-data-generator",
110+
Inputs{},
111+
Outputs{{{"outputDCS"}, "DCS", dd}},
112+
AlgorithmSpec{adaptFromTask<DCSDataReplayer>(hints, dd)},
113+
Options{
114+
{"max-timeframes", VariantType::Int64, 99999999999ll, {"max TimeFrames to generate"}},
115+
{"delta-fraction", VariantType::Float, 0.05f, {"fraction of data points to put in the delta"}},
116+
{"input-file", VariantType::String, "", {"Input file with data to play back"}}}};
117+
}
118+
} // namespace o2::dcs::test

0 commit comments

Comments
 (0)