Project
Loading...
Searching...
No Matches
DCSAdaposParserSpec.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
13
15
16namespace o2
17{
18namespace its
19{
21// Default constructor
26
29{
30 LOGF(info, "ITSDCSAdaposParser init...", mSelfName);
31
32 this->mCcdbUrl = ic.options().get<std::string>("ccdb-out-url");
33
34 this->mVerboseOutput = ic.options().get<bool>("use-verbose-mode");
35
36 // Read alpide param object from ccdb: this is the first read, object will be refreshed in run()
37 this->mCcdbFetchUrl = ic.options().get<std::string>("ccdb-fetch-url");
38 mMgr.setURL(mCcdbFetchUrl);
39 getCurrentCcdbAlpideParam();
41
42 return;
43}
44
46// Main running function
47// Get Data from ADAPOS and prepare CCDB objects
49{
50
51 // Retrieve adapos data and process them
52 auto dps = pc.inputs().get<gsl::span<DPCOM>>("input");
53 process(dps);
54
55 if (doStrobeUpload && dps.size() > 0) {
56 // upload to ccdb
57 pushToCCDB(pc);
58 }
59
60 // refresh the local Alpide Param object in case another software/user uploaded an object in that path
61 // do the update every 10s
62 long int currentTs = o2::ccdb::getCurrentTimestamp();
63 if (currentTs - startTime > 10000) {
64 getCurrentCcdbAlpideParam();
65 startTime = currentTs;
66 }
67
68 // clear memory
69 mDPstrobe.clear();
70
71 return;
72}
73
75// Function to retrieve AlpideParam object from CCDB
76void ITSDCSAdaposParser::getCurrentCcdbAlpideParam()
77{
78 long int ts = o2::ccdb::getCurrentTimestamp();
79 LOG(info) << "Getting AlpideParam from CCDB url " << mCcdbFetchUrl << " with timestamp " << ts;
80 mMgr.setTimestamp(ts);
81 mCcdbAlpideParam = mMgr.get<o2::itsmft::DPLAlpideParam<o2::detectors::DetID::ITS>>("ITS/Config/AlpideParam");
82}
83
85// Function to process DPs
86void ITSDCSAdaposParser::process(const gsl::span<const DPCOM> dps)
87{
88
89 // first we check which DPs are missing - if some are, it means that
90 // the delta map was sent
91 if (mVerboseOutput) {
92 LOG(info) << "\n\n\nProcessing new TF\n-----------------";
93 }
94
95 // Process all DPs, one by one
96 for (const auto& it : dps) {
97 processDP(it);
98 }
99
100 /**************************************
101 decide whether to upload or not the object to ccdb. The logic for strobe length is:
102 - compare the value which arrived from ADAPOS with the one stored in CCDB
103 - if the values are different, store it and create a new object for ccdb
104 - refresh the local ccdb object (int run() method)
105 - the logic continue... memory is cleaned at the end of every run() cycle
106 ***************************************/
107 auto mapel = mDPstrobe.begin();
108 if (!mDPstrobe.size()) {
109 doStrobeUpload = false;
110 return;
111 }
112 if (mapel->second.payload_pt1 + 8 != mCcdbAlpideParam->roFrameLengthInBC) {
113 mStrobeToUpload = mapel->second.payload_pt1;
115 if (pushTime - lastPushTime > 30000) { // push to CCDB only if at least 30s passed from the last push
116 doStrobeUpload = true;
117 } else {
118 doStrobeUpload = false;
119 }
120 } else {
121 doStrobeUpload = false;
122 }
123
124 return;
125}
126
128// Process single DPs
129void ITSDCSAdaposParser::processDP(const DPCOM& dpcom)
130{
131 auto& dpid = dpcom.id;
132 const auto& type = dpid.get_type();
133 auto& val = dpcom.data;
134 auto flags = val.get_flags();
135
136 if (mVerboseOutput) {
137 LOG(info) << "Processing DP = " << dpcom << ", with value = " << o2::dcs::getValue<int>(dpcom);
138 }
139 auto value = o2::dcs::getValue<int>(dpcom);
140 if (value < 190) {
141 if (mVerboseOutput) {
142 LOG(info) << "Value is < 190 BCs, skipping it";
143 }
144 return;
145 }
146
147 if (value > 189) { // Discard strobe length lower than this: thr scan
148 mDPstrobe[dpid] = val;
149 }
150}
151
153void ITSDCSAdaposParser::pushToCCDB(ProcessingContext& pc)
154{
155 // Timestamps for CCDB entry
156 long tstart = 0, tend = 0;
157 // retireve run start/stop times from CCDB
159 api.init("http://alice-ccdb.cern.ch");
160 // Initialize empty metadata object for search
161 std::map<std::string, std::string> metadata;
162
164 tend = tstart + 365L * 2 * 24 * 3600 * 1000; // valid two years by default
165
166 // Create metadata for database object
167 metadata = {{"comment", "uploaded by flp199 (ADAPOS data)"}, {"StrobeLength", std::to_string(mStrobeToUpload + 8)}};
168
169 std::string path("ITS/Config/AlpideParam");
170
171 std::string filename = "o2-itsmft-DPLAlpideParam<0>_" + std::to_string(tstart) + ".root";
172 o2::ccdb::CcdbObjectInfo info(path, "dplalpideparam", filename, metadata, tstart, tend);
173 // Define the dpl alpide param and set the strobe length to ship
174 o2::conf::ConfigurableParam::setValue("ITSAlpideParam", "roFrameLengthInBC", (int)mStrobeToUpload + 8); // +8 is because the strobe length of ALPIDE (sent via ADAPOS) is 200ns shorter than the external trigger strobe length.
175 o2::conf::ConfigurableParam::setProvenance("ITSAlpideParam", "roFrameLengthInBC", o2::conf::ConfigurableParam::EParamProvenance::kCCDB); // to be able to update from CCDB
177 auto class_name = o2::utils::MemFileHelper::getClassName(dplAlpideParams);
178
179 auto image = o2::ccdb::CcdbApi::createObjectImage(&dplAlpideParams, &info);
180 info.setFileName(filename);
181
182 // Send to ccdb-populator wf or upload directly from here
183 if (mCcdbUrl.empty()) {
184 LOG(info) << "Class Name: " << class_name << " | File Name: " << filename
185 << "\nSending to ccdb-populator the object " << info.getPath() << "/" << info.getFileName()
186 << " of size " << image->size() << " bytes, valid for "
187 << info.getStartValidityTimestamp() << " : "
188 << info.getEndValidityTimestamp();
189
192
193 } else { // if url is specified, send object to ccdb from THIS wf
194
195 LOG(info) << "Sending object " << info.getFileName() << " to " << mCcdbUrl << "/browse/"
196 << info.getPath() << " from the ITS ADAPOS parser workflow";
198 mApi.init(mCcdbUrl);
200 &image->at(0), image->size(), info.getFileName(), info.getObjectType(), info.getPath(),
201 info.getMetaData(), info.getStartValidityTimestamp(), info.getEndValidityTimestamp());
202 }
203
204 // uptade lastPushTime
205 lastPushTime = o2::ccdb::getCurrentTimestamp();
206
207 return;
208}
209
212{
214 std::vector<InputSpec> inputs;
215 inputs.emplace_back("input", "DCS", "ITSDATAPOINTS");
216
217 std::vector<OutputSpec> outputs;
218 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "ITSALPIDEPARAM"}, Lifetime::Sporadic);
219 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "ITSALPIDEPARAM"}, Lifetime::Sporadic);
220
221 return DataProcessorSpec{
222 "its-adapos-parser",
223 inputs,
224 outputs,
225 AlgorithmSpec{adaptFromTask<o2::its::ITSDCSAdaposParser>()},
226 Options{
227 {"use-verbose-mode", VariantType::Bool, false, {"Use verbose output mode"}},
228 {"ccdb-out-url", VariantType::String, "", {"CCDB url, default is empty (i.e. send output to CCDB populator workflow)"}},
229 {"ccdb-fetch-url", VariantType::String, "", {"CCDB url from when to fetch the AlpideParam object, default is ccdb-test"}}}};
230}
231} // namespace its
232} // namespace o2
void setTimestamp(long t)
set timestamp cache for all queries
void setURL(const std::string &url)
set a URL to query from
T * get(std::string const &path)
retrieve an object of type T from CCDB as stored under path; will use the timestamp member
void init(std::string const &hosts)
Definition CcdbApi.cxx:165
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
int storeAsBinaryFile(const char *buffer, size_t size, const std::string &fileName, const std::string &objectType, const std::string &path, const std::map< std::string, std::string > &metadata, long startValidityTimestamp, long endValidityTimestamp, std::vector< char >::size_type maxSize=0) const
Definition CcdbApi.cxx:351
static void setProvenance(std::string const &mainkey, std::string const &subkey, EParamProvenance p)
static void setValue(std::string const &mainkey, std::string const &subkey, T x)
DeliveryType get_type() const noexcept
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
Definition InitContext.h:33
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
void run(ProcessingContext &pc) final
void init(InitContext &ic) final
static constexpr std::string_view getName()
GLeglImageOES image
Definition glcorearb.h:4021
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint GLfloat * val
Definition glcorearb.h:1582
GLbitfield flags
Definition glcorearb.h:1570
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
constexpr o2::header::DataOrigin gDataOriginITS
Definition DataHeader.h:570
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
std::vector< ConfigParamSpec > Options
o2::framework::DataProcessorSpec getITSDCSAdaposParserSpec()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
uint16_t get_flags() const noexcept
int roFrameLengthInBC
ROF length in BC for continuos mode.
static std::string getClassName(const T &obj)
get the class name of the object
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"