Project
Loading...
Searching...
No Matches
TOFDCSConfigProcessorSpec.h
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
12#ifndef O2_TOF_DCSCONFIGPROCESSOR_H
13#define O2_TOF_DCSCONFIGPROCESSOR_H
14
17
21#include "CCDB/CcdbObjectInfo.h"
22#include "CCDB/CcdbApi.h"
23
28#include "Framework/Task.h"
29#include "Framework/Logger.h"
30
31using namespace o2::framework;
32using TFType = uint64_t;
33
34namespace o2
35{
36namespace tof
37{
38
40{
41 public:
43 {
44 mVerbose = ic.options().get<bool>("use-verbose-mode");
45 LOG(info) << " ************************* Verbose?" << mVerbose;
46 }
47
48 //---------------------------------------------------------
49
51 {
52 auto configBuff = pc.inputs().get<gsl::span<char>>("inputConfig");
53 auto configFileName = pc.inputs().get<std::string>("inputConfigFileName");
54 LOG(info) << "got input file " << configFileName << " of size " << configBuff.size();
55 mTOFFEElightReader.loadFEElightConfig(configBuff);
56 mTOFFEElightReader.parseFEElightConfig(mVerbose);
57 sendOutput(pc.outputs(), configFileName);
58 }
59
60 //---------------------------------------------------------
61
65
66 private:
67 void sendOutput(DataAllocator& output, std::string fileName)
68 {
69 // sending output to CCDB
70
72 const auto& payload = mTOFFEElightReader.getTOFFEElightInfo();
73 auto clName = o2::utils::MemFileHelper::getClassName(payload);
74 auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
75 std::map<std::string, std::string> md;
76 md.emplace("created_by", "dpl");
77
78 // finding start of validity and run number in filename
79 int n = fileName.length();
80 char fileName_char[n + 1];
81 strcpy(fileName_char, fileName.c_str());
82 std::vector<std::string> tokens;
83 const char* delimiters = ".";
84 const char* token = strtok(fileName_char, delimiters);
85 std::string startOfValidityStr = "";
86 std::string runNumberStr = "";
87 bool foundSOV = false;
88 bool foundRUN = false;
89 std::string timeStampLabel = "sov";
90 std::string runNumberLabel = "run";
91 while (token) {
92 LOG(debug) << "token = " << token;
93 std::string stoken(token);
94 auto idxInStringSOV = stoken.find(timeStampLabel);
95 auto idxInStringRUN = stoken.find(runNumberLabel);
96 if (idxInStringSOV != std::string::npos) {
97 foundSOV = true;
98 stoken.erase(idxInStringSOV, timeStampLabel.length());
99 startOfValidityStr = stoken;
100 }
101 if (idxInStringRUN != std::string::npos) {
102 foundRUN = true;
103 stoken.erase(idxInStringRUN, runNumberLabel.length());
104 runNumberStr = stoken;
105 }
106 token = std::strtok(nullptr, delimiters);
107 }
108 if (!foundSOV) {
109 LOG(fatal) << "SOV not found but needed!";
110 } else {
111 }
112 if (!foundRUN) {
113 LOG(warning) << "RUN not found, will be left empty!";
114 }
115 LOG(debug) << "startOfValidityStr = " << startOfValidityStr << ", run = " << runNumberStr;
116 long tf = std::stol(startOfValidityStr) * 1E3; // in ms
117 md.emplace("runNumberFromTOF", runNumberStr);
118
119 // creating CCDB object to be shipped
120 o2::ccdb::CcdbObjectInfo info("TOF/Calib/FEELIGHT", clName, flName, md, tf, tf + o2::ccdb::CcdbObjectInfo::MONTH);
121 auto image = o2::ccdb::CcdbApi::createObjectImage(&payload, &info);
122 LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName() << " of size " << image->size()
123 << " bytes, valid for " << info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp();
124 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "TOF_FEELIGHT", 0}, *image.get()); // vector<char>
125 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "TOF_FEELIGHT", 0}, info); // root-serialized
126 }
127 //________________________________________________________________
128
129 TOFFEElightReader mTOFFEElightReader; // reader for configuration
130 bool mVerbose = false; // to enable verbose mode
131
132}; // end class
133} // namespace tof
134
135namespace framework
136{
137
138DataProcessorSpec getTOFDCSConfigProcessorSpec()
139{
140
141 std::vector<OutputSpec> outputs;
142 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TOF_FEELIGHT"}, Lifetime::Sporadic);
143 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TOF_FEELIGHT"}, Lifetime::Sporadic);
144
145 return DataProcessorSpec{
146 "tof-dcs-config-processor",
147 Inputs{{"inputConfig", o2::header::gDataOriginTOF, "DCS_CONFIG_FILE", Lifetime::Sporadic},
148 {"inputConfigFileName", o2::header::gDataOriginTOF, "DCS_CONFIG_NAME", Lifetime::Sporadic}},
149 outputs,
150 AlgorithmSpec{adaptFromTask<o2::tof::TOFDCSConfigProcessor>()},
151 Options{{"use-verbose-mode", VariantType::Bool, false, {"Use verbose mode"}}}};
152}
153
154} // namespace framework
155} // namespace o2
156
157#endif
Utils and constants for calibration and related workflows.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
uint64_t TFType
std::ostringstream debug
static std::string generateFileName(const std::string &inp)
Definition CcdbApi.cxx:798
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
static constexpr long MONTH
void run(o2::framework::ProcessingContext &pc) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void init(o2::framework::InitContext &ic) final
TOFFEElightInfo & getTOFFEElightInfo()
void loadFEElightConfig(const char *fileName)
int parseFEElightConfig(bool verbose=false)
GLdouble n
Definition glcorearb.h:1982
GLeglImageOES image
Definition glcorearb.h:4021
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< InputSpec > Inputs
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::unique_ptr< GPUReconstructionTimeframe > tf
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
static std::string getClassName(const T &obj)
get the class name of the object
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"