Project
Loading...
Searching...
No Matches
DCSGeneratorSpec.cxx
Go to the documentation of this file.
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
19#include "Framework/Logger.h"
20#include "Framework/Task.h"
21#include <TDatime.h>
22#include <random>
23#include <variant>
24#include <string>
25#include <algorithm>
26
27using namespace o2::its;
28
29namespace
30{
31std::vector<o2::dcs::DataPointCompositeObject> generate(std::vector<std::string> aliases, int val)
32{
33 std::vector<o2::dcs::DataPointCompositeObject> dataPoints;
34
35 for (auto alias : aliases) {
36 dataPoints.emplace_back(o2::dcs::createDataPointCompositeObject(alias, val, 1, 0));
37 }
38
39 return dataPoints;
40}
41
42//______________________________________________________________________________________________________________
43// class ITSDCSDataGenerator
44class ITSDCSDataGenerator : public o2::framework::Task
45{
46 public:
47 ITSDCSDataGenerator(o2::header::DataDescription description);
48
49 void init(o2::framework::InitContext& ic) final;
50
52
53 void fillAliasesStrobeDuration();
54
55 private:
56 uint64_t mMaxTF = 1e6;
57 uint64_t mTFs = 0;
58 uint64_t mMaxCyclesNoFullMap;
59 uint64_t changeAfterTF = 0;
60 int valueA = 190;
61 int valueB = 190;
62 bool isStrobeDurationData = false;
63 std::vector<std::string> mAliases;
64 std::vector<o2::dcs::test::HintType> mDataPointHints;
65 o2::header::DataDescription mDataDescription;
66};
67
68ITSDCSDataGenerator::ITSDCSDataGenerator(o2::header::DataDescription description) : mDataDescription(description) {}
69
70void ITSDCSDataGenerator::fillAliasesStrobeDuration()
71{
72
73 // Aliases in this case are in the format: ITS_L0_00_STROBE
74 // Here we fill them for every stave in mAliases
75 int nStaves[] = {12, 16, 20, 24, 30, 42, 48};
76 for (int iL = 0; iL < 7; iL++) {
77 for (int iS = 0; iS < nStaves[iL]; iS++) {
78 std::string stv = iS > 9 ? std::to_string(iS) : std::string(1, '0').append(std::to_string(iS));
79 mAliases.push_back("ITS_L" + std::to_string(iL) + "_" + stv + "_STROBE");
80 }
81 }
82}
83
84void ITSDCSDataGenerator::init(o2::framework::InitContext& ic)
85{
86 mMaxTF = ic.options().get<int64_t>("max-timeframes");
87 mMaxCyclesNoFullMap = ic.options().get<int64_t>("max-cycles-no-full-map");
88 isStrobeDurationData = ic.options().get<bool>("generate-strobe-duration-data");
89 changeAfterTF = ic.options().get<int64_t>("change-after-n-timeframes");
90 valueA = ic.options().get<int>("value-a");
91 valueB = ic.options().get<int>("value-b");
92
93 if (isStrobeDurationData) {
94 fillAliasesStrobeDuration();
95 }
96}
97
98void ITSDCSDataGenerator::run(o2::framework::ProcessingContext& pc)
99{
100 auto input = pc.inputs().begin();
101 uint64_t tfid = o2::header::get<o2::framework::DataProcessingHeader*>((*input).header)->startTime;
102 if (tfid >= mMaxTF) {
103 LOG(info) << "ITS DCS Data generator reached TF " << tfid << ", stopping";
104 pc.services().get<o2::framework::ControlService>().endOfStream();
106 }
107
108 // generate data simulating ADAPOS
109 bool doGen = mTFs % mMaxCyclesNoFullMap == 0;
110 std::vector<o2::dcs::DataPointCompositeObject> dpcoms;
111 if (doGen) {
112 dpcoms = generate(mAliases, mTFs > changeAfterTF ? valueB : valueA);
113 }
114
115 LOG(info) << "TF " << tfid << " has generated " << dpcoms.size() << " DPs";
116 auto& timingInfo = pc.services().get<o2::framework::TimingInfo>();
117 auto timeNow = std::chrono::system_clock::now();
118 timingInfo.creation = std::chrono::duration_cast<std::chrono::milliseconds>(timeNow.time_since_epoch()).count(); // in ms
119
120 pc.outputs().snapshot(Output{"ITS", mDataDescription, 0}, dpcoms);
121 mTFs++;
122}
123} // namespace
124
125namespace o2::its
126{
128{
129 std::string desc{detName};
130 desc += "DATAPOINTS";
131
133
134 dd.runtimeInit(desc);
135
136 return DataProcessorSpec{
137 "its-dcs-data-generator",
138 Inputs{},
139 Outputs{{{"outputDCS"}, "ITS", dd}},
140 AlgorithmSpec{adaptFromTask<ITSDCSDataGenerator>(dd)},
141 Options{
142 {"change-after-n-timeframes", VariantType::Int64, 99999999999ll, {"change value generated after n timeframes: do not change val by default"}},
143 {"value-a", VariantType::Int, 0, {"First value to be generated, will change to value-b after nTF = change-after-n-timeframes"}},
144 {"value-b", VariantType::Int, 1, {"Second value to be generated, will be after value-a once nTF = change-after-n-timeframes has been reached"}},
145 {"max-timeframes", VariantType::Int64, 99999999999ll, {"max TimeFrames to generate"}},
146 {"max-cycles-no-full-map", VariantType::Int64, 6000ll, {"max num of cycles between the sending of 2 full maps"}},
147 {"generate-strobe-duration-data", VariantType::Bool, false, {"enable generation of DCS data containing the strobe duration in BCs"}}}};
148}
149} // namespace o2::its
header::DataDescription description
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
Definition InitContext.h:33
const_iterator begin() const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
virtual void init(InitContext &context)
Definition Task.h:37
virtual void run(ProcessingContext &context)=0
GLsizei const GLchar *const * string
Definition glcorearb.h:809
GLuint GLfloat * val
Definition glcorearb.h:1582
o2::dcs::DataPointCompositeObject createDataPointCompositeObject(const std::string &alias, T val, uint32_t seconds, uint16_t msec, uint16_t flags=0)
@ Me
Only quit this data processor.
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
o2::framework::DataProcessorSpec getITSDCSDataGeneratorSpec(const char *detName="ITS")
std::vector< std::string > aliases(std::vector< MeasurementType > types={ MeasurementType::HV_V, MeasurementType::HV_I, MeasurementType::LV_V_FEE_ANALOG, MeasurementType::LV_V_FEE_DIGITAL, MeasurementType::LV_V_SOLAR})
void append(const char *msg, std::string &to)
TLorentzVector generate(Vec3D &vtx, std::vector< o2::track::TrackParCov > &vctr, float bz, TGenPhaseSpace &genPHS, double parMass, const std::vector< double > &dtMass, std::vector< int > forceQ)
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
void runtimeInit(std::string_view string)
Definition DataHeader.h:260
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"