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
2527using namespace o2 ::framework;
2628
@@ -54,9 +56,18 @@ using HintType = std::variant<DataPointHint<double>,
5456std::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 */
7081std::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" }},
0 commit comments