-
Notifications
You must be signed in to change notification settings - Fork 488
TOF DCS Processor #5047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TOF DCS Processor #5047
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| #include "DetectorsDCS/DataPointCreator.h" | ||
| #include "DetectorsDCS/DataPointCompositeObject.h" | ||
| #include "DetectorsDCS/StringUtils.h" | ||
| #include "Framework/Logger.h" | ||
| #include <fmt/format.h> | ||
| #include <random> | ||
| #include <utility> | ||
|
|
@@ -23,16 +24,27 @@ namespace | |
| { | ||
| std::pair<uint32_t, uint16_t> getDate(const std::string& refDate) | ||
| { | ||
|
|
||
| uint32_t seconds; | ||
| if (refDate.empty()) { | ||
| auto current = std::time(nullptr); | ||
| auto t = std::localtime(¤t); | ||
| uint32_t seconds = mktime(t); | ||
| seconds = mktime(t); | ||
| } else { | ||
| std::tm t{}; | ||
| std::istringstream ss(refDate); | ||
| ss >> std::get_time(&t, "%Y-%b-%d %H:%M:%S"); | ||
| seconds = mktime(&t); | ||
| if (ss.fail()) { // let's see if it was passed as a TDatime | ||
|
||
| std::tm tt{}; | ||
| std::istringstream sss(refDate); | ||
| sss >> std::get_time(&tt, "%a %b %d %H:%M:%S %Y"); | ||
| if (sss.fail()) { | ||
| LOG(ERROR) << "We cannot parse the date"; | ||
| } | ||
| seconds = mktime(&tt); | ||
| } else { | ||
| seconds = mktime(&t); | ||
| } | ||
| } | ||
| uint16_t msec = 5; | ||
| return std::make_pair(seconds, msec); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,11 @@ | |
| #include "Framework/DeviceSpec.h" | ||
| #include "Framework/Logger.h" | ||
| #include "Framework/Task.h" | ||
| #include <TDatime.h> | ||
| #include <random> | ||
| #include <variant> | ||
| #include <string> | ||
| #include <algorithm> | ||
|
|
||
| using namespace o2::framework; | ||
|
|
||
|
|
@@ -54,9 +56,18 @@ using HintType = std::variant<DataPointHint<double>, | |
| std::vector<int> generateIntegers(size_t size, int min, int max) | ||
| { | ||
| std::uniform_int_distribution<int> distribution(min, max); | ||
| std::mt19937 generator; | ||
| std::vector<int> data(size); | ||
| std::generate(data.begin(), data.end(), [&]() { return distribution(generator); }); | ||
| std::mt19937 generator(std::random_device{}()); | ||
|
||
| std::vector<int> data; | ||
|
||
| while (data.size() != size) { | ||
| data.emplace_back(distribution(generator)); | ||
| std::sort(begin(data), end(data)); | ||
| auto last = std::unique(begin(data), end(data)); // make sure we do not duplicate | ||
| data.erase(last, end(data)); | ||
| } | ||
| std::shuffle(begin(data), end(data), generator); | ||
| for (auto i = 0; i < data.size(); ++i) { | ||
| LOG(INFO) << "Generating randomly DP at index " << data[i]; | ||
| } | ||
| return data; | ||
| } | ||
|
|
||
|
|
@@ -68,12 +79,20 @@ std::vector<int> generateIntegers(size_t size, int min, int max) | |
| * @returns a vector of DataPointCompositeObjects | ||
| */ | ||
| std::vector<o2::dcs::DataPointCompositeObject> generate(const std::vector<HintType> hints, | ||
| float fraction = 1.0) | ||
| float fraction = 1.0, | ||
| uint64_t tfid = 0) | ||
| { | ||
| std::vector<o2::dcs::DataPointCompositeObject> dataPoints; | ||
|
|
||
| auto GenerateVisitor = [](const auto& t) { | ||
| return o2::dcs::generateRandomDataPoints({t.aliasPattern}, t.minValue, t.maxValue); | ||
| TDatime d; | ||
|
||
| auto dsec = d.Convert(); | ||
| dsec += tfid; | ||
| d.Set(dsec); | ||
|
|
||
| std::string refDate = d.AsString(); | ||
|
|
||
| auto GenerateVisitor = [refDate](const auto& t) { | ||
| return o2::dcs::generateRandomDataPoints({t.aliasPattern}, t.minValue, t.maxValue, refDate); | ||
chiarazampolli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| for (const auto& hint : hints) { | ||
|
|
@@ -84,7 +103,8 @@ std::vector<o2::dcs::DataPointCompositeObject> generate(const std::vector<HintTy | |
| } | ||
| if (fraction < 1.0) { | ||
| auto indices = generateIntegers(fraction * dataPoints.size(), 0, dataPoints.size() - 1); | ||
| auto tmp = dataPoints; | ||
| std::vector<o2::dcs::DataPointCompositeObject> tmp; | ||
| tmp.swap(dataPoints); | ||
| dataPoints.clear(); | ||
| for (auto i : indices) { | ||
| dataPoints.push_back(tmp[i]); | ||
|
|
@@ -114,11 +134,29 @@ class DCSRandomDataGenerator : public o2::framework::Task | |
| mMaxCyclesNoFullMap = ic.options().get<int64_t>("max-cycles-no-full-map"); | ||
|
|
||
| // create the list of DataPointHints to be used by the generator | ||
| mDataPointHints.emplace_back(DataPointHint<char>{"TestChar_0", 'A', 'z'}); | ||
| // each detector should create his own when running the tests | ||
|
|
||
| /*mDataPointHints.emplace_back(DataPointHint<char>{"TestChar_0", 'A', 'z'}); | ||
| mDataPointHints.emplace_back(DataPointHint<double>{"TestDouble_[0..3]", 0, 1700}); | ||
| mDataPointHints.emplace_back(DataPointHint<int32_t>{"TestInt_[0..50000{:d}]", 0, 1234}); | ||
| mDataPointHints.emplace_back(DataPointHint<bool>{"TestBool_[00..03]", 0, 1}); | ||
| mDataPointHints.emplace_back(DataPointHint<std::string>{"TestString_0", "ABC", "ABCDEF"}); | ||
| */ | ||
| // for TOF | ||
| // for test, we use less DPs that official ones | ||
| mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_vp_[00..02]", 0, 50.}); | ||
| mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_vn_[00..02]", 0, 50.}); | ||
| mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_ip_[00..02]", 0, 50.}); | ||
| mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_in_[00..02]", 0, 50.}); | ||
| mTOFDataPointHints.emplace_back(DataPointHint<int32_t>{"TOF_FEACSTATUS_[00..01]", 0, 255}); | ||
| mTOFDataPointHints.emplace_back(DataPointHint<int32_t>{"TOF_HVSTATUS_SM[00..01]MOD[0..1]", 0, 524287}); | ||
| // for TOF, official list | ||
| //mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_vp_[00..89]", 0, 50.}); | ||
| //mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_vn_[00..89]", 0, 50.}); | ||
| //mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_ip_[00..89]", 0, 50.}); | ||
| //mTOFDataPointHints.emplace_back(DataPointHint<double>{"tof_hv_in_[00..89]", 0, 50.}); | ||
| //mTOFDataPointHints.emplace_back(DataPointHint<int32_t>{"TOF_FEACSTATUS_[00..71]", 0, 255}); | ||
| //mTOFDataPointHints.emplace_back(DataPointHint<int32_t>{"TOF_HVSTATUS_SM[00..17]MOD[0..4]", 0, 524287}); | ||
| } | ||
|
|
||
| void run(o2::framework::ProcessingContext& pc) final | ||
|
|
@@ -135,12 +173,13 @@ class DCSRandomDataGenerator : public o2::framework::Task | |
| // fraction is one if we generate FBI (Full Buffer Image) | ||
| float fraction = (generateFBI ? 1.0 : mDeltaFraction); | ||
|
|
||
| auto dpcoms = generate(mDataPointHints, fraction); | ||
| TDatime d; | ||
| auto dpcoms = generate(mDataPointHints, fraction, tfid); | ||
| auto tofdpcoms = generate(mTOFDataPointHints, fraction, tfid); | ||
|
|
||
| // the output must always get both FBI and Delta, but one of them is empty. | ||
| std::vector<o2::dcs::DataPointCompositeObject> empty; | ||
| pc.outputs().snapshot(Output{"DCS", "DATAPOINTS", 0, Lifetime::Timeframe}, generateFBI ? dpcoms : empty); | ||
| pc.outputs().snapshot(Output{"DCS", "DATAPOINTSdelta", 0, Lifetime::Timeframe}, generateFBI ? empty : dpcoms); | ||
| LOG(INFO) << "***************** TF " << tfid << " has generated " << tofdpcoms.size() << " DPs for TOF"; | ||
|
||
| pc.outputs().snapshot(Output{"DCS", "DATAPOINTS", 0, Lifetime::Timeframe}, dpcoms); | ||
| pc.outputs().snapshot(Output{"DCS", "TOFDATAPOINTS", 0, Lifetime::Timeframe}, tofdpcoms); | ||
| mTFs++; | ||
| } | ||
|
|
||
|
|
@@ -150,6 +189,7 @@ class DCSRandomDataGenerator : public o2::framework::Task | |
| uint64_t mMaxCyclesNoFullMap; | ||
| float mDeltaFraction; | ||
| std::vector<HintType> mDataPointHints; | ||
| std::vector<HintType> mTOFDataPointHints; | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
@@ -159,7 +199,7 @@ DataProcessorSpec getDCSRandomDataGeneratorSpec() | |
| return DataProcessorSpec{ | ||
| "dcs-random-data-generator", | ||
| Inputs{}, | ||
| Outputs{{{"outputDCS"}, "DCS", "DATAPOINTS"}, {{"outputDCSdelta"}, "DCS", "DATAPOINTSdelta"}}, | ||
| Outputs{{{"outputDCS"}, "DCS", "DATAPOINTS"}, {{"outputDCSTOF"}, "DCS", "TOFDATAPOINTS"}}, | ||
| AlgorithmSpec{adaptFromTask<DCSRandomDataGenerator>()}, | ||
| Options{ | ||
| {"max-timeframes", VariantType::Int64, 99999999999ll, {"max TimeFrames to generate"}}, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright CERN and copyright holders of ALICE O2. This software is | ||
| // distributed under the terms of the GNU General Public License v3 (GPL | ||
| // Version 3), copied verbatim in the file "COPYING". | ||
| // | ||
| // See http://alice-o2.web.cern.ch/license for full licensing information. | ||
| // | ||
| // In applying this license CERN does not waive the privileges and immunities | ||
| // granted to it by virtue of its status as an Intergovernmental Organization | ||
| // or submit itself to any jurisdiction. | ||
|
|
||
| #include "DetectorsDCS/DataPointIdentifier.h" | ||
| #include "DetectorsDCS/DataPointValue.h" | ||
| #include "Framework/TypeTraits.h" | ||
| #include <unordered_map> | ||
| #include "Framework/DataProcessorSpec.h" | ||
| #include "DCSRandomDataGeneratorSpec.h" | ||
|
|
||
| using namespace o2::framework; | ||
|
|
||
| // we need to add workflow options before including Framework/runDataProcessing | ||
| void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions) | ||
| { | ||
| // option allowing to set parameters | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------ | ||
|
|
||
| #include "Framework/runDataProcessing.h" | ||
|
|
||
| WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) | ||
| { | ||
| WorkflowSpec specs; | ||
| specs.emplace_back(getDCSRandomDataGeneratorSpec()); | ||
| return specs; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aphecetche : this is the fix.