Skip to content

Commit 0fe332f

Browse files
chiarazampollishahor02
authored andcommitted
TOF DCS Processor
Adding processing of LV info (FEAC). Processing also HV Configuring DPs for TOF either from CCDB or by hand. Macro included to create CCDB entry Preparing CCDB update Writing to CCDB Some updates and improvements more in the README, for LHCphase, ChannelOffset, TimeSlewing formatting of README formatting of README clang-format clang again update README add macro makeCCDBEntryForDCS.C to tests including algorithm shuffle instead of random_shuffle fix for macro test (hopefully) Fix for test Now it should work! Making CI happy from PR review turning test into executable typo fixed clang again clang
1 parent 8e85101 commit 0fe332f

File tree

17 files changed

+1256
-17
lines changed

17 files changed

+1256
-17
lines changed

Detectors/DCS/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ o2_add_executable(
5959
PUBLIC_LINK_LIBRARIES O2::Framework
6060
O2::DetectorsDCS)
6161

62+
o2_add_executable(
63+
sim-workflow
64+
COMPONENT_NAME dcs
65+
SOURCES testWorkflow/dcs-sim-workflow.cxx
66+
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsDCS)
67+
6268
if(OpenMP_CXX_FOUND)
6369
target_compile_definitions(${targetName} PRIVATE WITH_OPENMP)
6470
target_link_libraries(${targetName} PRIVATE OpenMP::OpenMP_CXX)

Detectors/DCS/src/DataPointGenerator.cxx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "DetectorsDCS/DataPointCreator.h"
1414
#include "DetectorsDCS/DataPointCompositeObject.h"
1515
#include "DetectorsDCS/StringUtils.h"
16+
#include "Framework/Logger.h"
1617
#include <fmt/format.h>
1718
#include <random>
1819
#include <utility>
@@ -23,16 +24,27 @@ namespace
2324
{
2425
std::pair<uint32_t, uint16_t> getDate(const std::string& refDate)
2526
{
27+
2628
uint32_t seconds;
2729
if (refDate.empty()) {
2830
auto current = std::time(nullptr);
2931
auto t = std::localtime(&current);
30-
uint32_t seconds = mktime(t);
32+
seconds = mktime(t);
3133
} else {
3234
std::tm t{};
3335
std::istringstream ss(refDate);
3436
ss >> std::get_time(&t, "%Y-%b-%d %H:%M:%S");
35-
seconds = mktime(&t);
37+
if (ss.fail()) { // let's see if it was passed as a TDatime
38+
std::tm tt{};
39+
std::istringstream sss(refDate);
40+
sss >> std::get_time(&tt, "%a %b %d %H:%M:%S %Y");
41+
if (sss.fail()) {
42+
LOG(ERROR) << "We cannot parse the date";
43+
}
44+
seconds = mktime(&tt);
45+
} else {
46+
seconds = mktime(&t);
47+
}
3648
}
3749
uint16_t msec = 5;
3850
return std::make_pair(seconds, msec);

Detectors/DCS/src/DetectorsDCSLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
#pragma link C++ class std::unordered_map < o2::dcs::DataPointIdentifier, o2::dcs::DataPointValue> + ;
2222
#pragma link C++ function o2::dcs::expandAlias(const std::string&);
2323
#pragma link C++ function o2::dcs::expandAliases(const std::vector<std::string>&);
24+
#pragma link C++ class std::unordered_map < o2::dcs::DataPointIdentifier, std::string> + ;
2425

2526
#endif

Detectors/DCS/testWorkflow/DCSRandomDataGeneratorSpec.h

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
#include "Framework/DeviceSpec.h"
1919
#include "Framework/Logger.h"
2020
#include "Framework/Task.h"
21+
#include <TDatime.h>
2122
#include <random>
2223
#include <variant>
2324
#include <string>
25+
#include <algorithm>
2426

2527
using namespace o2::framework;
2628

@@ -54,9 +56,18 @@ using HintType = std::variant<DataPointHint<double>,
5456
std::vector<int> generateIntegers(size_t size, int min, int max)
5557
{
5658
std::uniform_int_distribution<int> distribution(min, max);
57-
std::mt19937 generator;
58-
std::vector<int> data(size);
59-
std::generate(data.begin(), data.end(), [&]() { return distribution(generator); });
59+
std::mt19937 generator(std::random_device{}());
60+
std::vector<int> data;
61+
while (data.size() != size) {
62+
data.emplace_back(distribution(generator));
63+
std::sort(begin(data), end(data));
64+
auto last = std::unique(begin(data), end(data)); // make sure we do not duplicate
65+
data.erase(last, end(data));
66+
}
67+
std::shuffle(begin(data), end(data), generator);
68+
for (auto i = 0; i < data.size(); ++i) {
69+
LOG(INFO) << "Generating randomly DP at index " << data[i];
70+
}
6071
return data;
6172
}
6273

@@ -68,12 +79,20 @@ std::vector<int> generateIntegers(size_t size, int min, int max)
6879
* @returns a vector of DataPointCompositeObjects
6980
*/
7081
std::vector<o2::dcs::DataPointCompositeObject> generate(const std::vector<HintType> hints,
71-
float fraction = 1.0)
82+
float fraction = 1.0,
83+
uint64_t tfid = 0)
7284
{
7385
std::vector<o2::dcs::DataPointCompositeObject> dataPoints;
7486

75-
auto GenerateVisitor = [](const auto& t) {
76-
return o2::dcs::generateRandomDataPoints({t.aliasPattern}, t.minValue, t.maxValue);
87+
TDatime d;
88+
auto dsec = d.Convert();
89+
dsec += tfid;
90+
d.Set(dsec);
91+
92+
std::string refDate = d.AsString();
93+
94+
auto GenerateVisitor = [refDate](const auto& t) {
95+
return o2::dcs::generateRandomDataPoints({t.aliasPattern}, t.minValue, t.maxValue, refDate);
7796
};
7897

7998
for (const auto& hint : hints) {
@@ -84,7 +103,8 @@ std::vector<o2::dcs::DataPointCompositeObject> generate(const std::vector<HintTy
84103
}
85104
if (fraction < 1.0) {
86105
auto indices = generateIntegers(fraction * dataPoints.size(), 0, dataPoints.size() - 1);
87-
auto tmp = dataPoints;
106+
std::vector<o2::dcs::DataPointCompositeObject> tmp;
107+
tmp.swap(dataPoints);
88108
dataPoints.clear();
89109
for (auto i : indices) {
90110
dataPoints.push_back(tmp[i]);
@@ -114,11 +134,29 @@ class DCSRandomDataGenerator : public o2::framework::Task
114134
mMaxCyclesNoFullMap = ic.options().get<int64_t>("max-cycles-no-full-map");
115135

116136
// create the list of DataPointHints to be used by the generator
117-
mDataPointHints.emplace_back(DataPointHint<char>{"TestChar_0", 'A', 'z'});
137+
// each detector should create his own when running the tests
138+
139+
/*mDataPointHints.emplace_back(DataPointHint<char>{"TestChar_0", 'A', 'z'});
118140
mDataPointHints.emplace_back(DataPointHint<double>{"TestDouble_[0..3]", 0, 1700});
119141
mDataPointHints.emplace_back(DataPointHint<int32_t>{"TestInt_[0..50000{:d}]", 0, 1234});
120142
mDataPointHints.emplace_back(DataPointHint<bool>{"TestBool_[00..03]", 0, 1});
121143
mDataPointHints.emplace_back(DataPointHint<std::string>{"TestString_0", "ABC", "ABCDEF"});
144+
*/
145+
// for TOF
146+
// for test, we use less DPs that official ones
147+
mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_vp_[00..02]", 0, 50.});
148+
mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_vn_[00..02]", 0, 50.});
149+
mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_ip_[00..02]", 0, 50.});
150+
mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_in_[00..02]", 0, 50.});
151+
mTOFDataPointHints.emplace_back(DataPointHint<int32_t>{"TOF_FEACSTATUS_[00..01]", 0, 255});
152+
mTOFDataPointHints.emplace_back(DataPointHint<int32_t>{"TOF_HVSTATUS_SM[00..01]MOD[0..1]", 0, 524287});
153+
// for TOF, official list
154+
//mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_vp_[00..89]", 0, 50.});
155+
//mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_vn_[00..89]", 0, 50.});
156+
//mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_ip_[00..89]", 0, 50.});
157+
//mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_in_[00..89]", 0, 50.});
158+
//mTOFDataPointHints.emplace_back(DataPointHint<int32_t>{"TOF_FEACSTATUS_[00..71]", 0, 255});
159+
//mTOFDataPointHints.emplace_back(DataPointHint<int32_t>{"TOF_HVSTATUS_SM[00..17]MOD[0..4]", 0, 524287});
122160
}
123161

124162
void run(o2::framework::ProcessingContext& pc) final
@@ -135,12 +173,13 @@ class DCSRandomDataGenerator : public o2::framework::Task
135173
// fraction is one if we generate FBI (Full Buffer Image)
136174
float fraction = (generateFBI ? 1.0 : mDeltaFraction);
137175

138-
auto dpcoms = generate(mDataPointHints, fraction);
176+
TDatime d;
177+
auto dpcoms = generate(mDataPointHints, fraction, tfid);
178+
auto tofdpcoms = generate(mTOFDataPointHints, fraction, tfid);
139179

140-
// the output must always get both FBI and Delta, but one of them is empty.
141-
std::vector<o2::dcs::DataPointCompositeObject> empty;
142-
pc.outputs().snapshot(Output{"DCS", "DATAPOINTS", 0, Lifetime::Timeframe}, generateFBI ? dpcoms : empty);
143-
pc.outputs().snapshot(Output{"DCS", "DATAPOINTSdelta", 0, Lifetime::Timeframe}, generateFBI ? empty : dpcoms);
180+
LOG(INFO) << "***************** TF " << tfid << " has generated " << tofdpcoms.size() << " DPs for TOF";
181+
pc.outputs().snapshot(Output{"DCS", "DATAPOINTS", 0, Lifetime::Timeframe}, dpcoms);
182+
pc.outputs().snapshot(Output{"DCS", "TOFDATAPOINTS", 0, Lifetime::Timeframe}, tofdpcoms);
144183
mTFs++;
145184
}
146185

@@ -150,6 +189,7 @@ class DCSRandomDataGenerator : public o2::framework::Task
150189
uint64_t mMaxCyclesNoFullMap;
151190
float mDeltaFraction;
152191
std::vector<HintType> mDataPointHints;
192+
std::vector<HintType> mTOFDataPointHints;
153193
};
154194

155195
} // namespace
@@ -159,7 +199,7 @@ DataProcessorSpec getDCSRandomDataGeneratorSpec()
159199
return DataProcessorSpec{
160200
"dcs-random-data-generator",
161201
Inputs{},
162-
Outputs{{{"outputDCS"}, "DCS", "DATAPOINTS"}, {{"outputDCSdelta"}, "DCS", "DATAPOINTSdelta"}},
202+
Outputs{{{"outputDCS"}, "DCS", "DATAPOINTS"}, {{"outputDCSTOF"}, "DCS", "TOFDATAPOINTS"}},
163203
AlgorithmSpec{adaptFromTask<DCSRandomDataGenerator>()},
164204
Options{
165205
{"max-timeframes", VariantType::Int64, 99999999999ll, {"max TimeFrames to generate"}},
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include "DetectorsDCS/DataPointIdentifier.h"
12+
#include "DetectorsDCS/DataPointValue.h"
13+
#include "Framework/TypeTraits.h"
14+
#include <unordered_map>
15+
#include "Framework/DataProcessorSpec.h"
16+
#include "DCSRandomDataGeneratorSpec.h"
17+
18+
using namespace o2::framework;
19+
20+
// we need to add workflow options before including Framework/runDataProcessing
21+
void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
22+
{
23+
// option allowing to set parameters
24+
}
25+
26+
// ------------------------------------------------------------------
27+
28+
#include "Framework/runDataProcessing.h"
29+
30+
WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
31+
{
32+
WorkflowSpec specs;
33+
specs.emplace_back(getDCSRandomDataGeneratorSpec());
34+
return specs;
35+
}

Detectors/TOF/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ add_subdirectory(reconstruction)
1515
add_subdirectory(compression)
1616
if(BUILD_TESTING)
1717
add_subdirectory(prototyping)
18+
add_subdirectory(calibration/macros)
1819
endif()
1920
add_subdirectory(workflow)

Detectors/TOF/base/include/TOFBase/Geo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Geo
4343
static void getPos(Int_t* det, Float_t* pos);
4444
static void getVolumePath(const Int_t* ind, Char_t* path);
4545
static Int_t getStripNumberPerSM(Int_t iplate, Int_t istrip);
46+
static void getStripAndModule(Int_t iStripPerSM, Int_t& iplate, Int_t& istrip); // Return the module and strip per module corresponding to the strip number per SM
4647

4748
static Float_t getAngles(Int_t iplate, Int_t istrip) { return ANGLES[iplate][istrip]; }
4849
static Float_t getHeights(Int_t iplate, Int_t istrip) { return HEIGHTS[iplate][istrip]; }

Detectors/TOF/base/src/Geo.cxx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,32 @@ Int_t Geo::getIndexFromEquipment(Int_t icrate, Int_t islot, Int_t ichain, Int_t
723723
{
724724
return 0; // to be implemented
725725
}
726+
727+
void Geo::getStripAndModule(Int_t iStripPerSM, Int_t& iplate, Int_t& istrip)
728+
{
729+
//
730+
// Convert the serial number of the TOF strip number iStripPerSM [0,90]
731+
// in module number iplate [0,4] and strip number istrip [0,14/18].
732+
// Copied from AliRoot TOF::AliTOFGeometry
733+
//
734+
735+
if (iStripPerSM < 0 || iStripPerSM >= NSTRIPC + NSTRIPB + NSTRIPA + NSTRIPB + NSTRIPC) {
736+
iplate = -1;
737+
istrip = -1;
738+
} else if (iStripPerSM < NSTRIPC) {
739+
iplate = 0;
740+
istrip = iStripPerSM;
741+
} else if (iStripPerSM >= NSTRIPC && iStripPerSM < NSTRIPC + NSTRIPB) {
742+
iplate = 1;
743+
istrip = iStripPerSM - NSTRIPC;
744+
} else if (iStripPerSM >= NSTRIPC + NSTRIPB && iStripPerSM < NSTRIPC + NSTRIPB + NSTRIPA) {
745+
iplate = 2;
746+
istrip = iStripPerSM - NSTRIPC - NSTRIPB;
747+
} else if (iStripPerSM >= NSTRIPC + NSTRIPB + NSTRIPA && iStripPerSM < NSTRIPC + NSTRIPB + NSTRIPA + NSTRIPB) {
748+
iplate = 3;
749+
istrip = iStripPerSM - NSTRIPC - NSTRIPB - NSTRIPA;
750+
} else if (iStripPerSM >= NSTRIPC + NSTRIPB + NSTRIPA + NSTRIPB && iStripPerSM < NSTRIPC + NSTRIPB + NSTRIPA + NSTRIPB + NSTRIPC) {
751+
iplate = 4;
752+
istrip = iStripPerSM - NSTRIPC - NSTRIPB - NSTRIPA - NSTRIPB;
753+
}
754+
}

Detectors/TOF/calibration/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ o2_add_library(TOFCalibration
1515
src/LHCClockCalibrator.cxx
1616
src/TOFChannelCalibrator.cxx
1717
src/TOFCalibCollector.cxx
18+
src/TOFDCSProcessor.cxx
1819
PUBLIC_LINK_LIBRARIES O2::DataFormatsTOF O2::TOFBase
1920
O2::CCDB
2021
O2::DetectorsCalibration
22+
O2::DetectorsDCS
2123
ROOT::Minuit
2224
ms_gsl::ms_gsl)
2325

@@ -28,7 +30,8 @@ o2_target_root_dictionary(TOFCalibration
2830
include/TOFCalibration/LHCClockCalibrator.h
2931
include/TOFCalibration/TOFChannelCalibrator.h
3032
include/TOFCalibration/TOFCalibCollector.h
31-
include/TOFCalibration/CollectCalibInfoTOF.h)
33+
include/TOFCalibration/CollectCalibInfoTOF.h
34+
include/TOFCalibration/TOFDCSProcessor.h)
3235

3336

3437
o2_add_executable(data-generator-workflow
@@ -73,3 +76,10 @@ o2_add_executable(tof-collect-calib-workflow
7376
PUBLIC_LINK_LIBRARIES O2::Framework
7477
O2::TOFCalibration
7578
O2::DetectorsCalibration)
79+
80+
o2_add_executable(tof-dcs-workflow
81+
COMPONENT_NAME calibration
82+
SOURCES testWorkflow/tof-dcs-data-workflow.cxx
83+
PUBLIC_LINK_LIBRARIES O2::Framework
84+
O2::TOFCalibration
85+
O2::DetectorsDCS)

0 commit comments

Comments
 (0)