Project
Loading...
Searching...
No Matches
CPVPedestalCalibDevice.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#include "CCDB/CcdbApi.h"
14#include "CCDB/CcdbObjectInfo.h"
15#include <string>
16#include <fairlogger/Logger.h>
24#include "CCDB/CcdbObjectInfo.h"
29#include "CPVBase/Geometry.h"
30
31using namespace o2::cpv;
32
34{
35
36 // Create histograms for mean and RMS
38 mMean = std::unique_ptr<TH2F>(new TH2F("Mean", "Mean", n, 0.5, n + 0.5, 500, 0., 500.));
39}
40
42{
43
44 //
45 for (const auto& rawData : framework::InputRecordWalker(ctx.inputs())) {
46
47 o2::cpv::RawReaderMemory rawreader(o2::framework::DataRefUtils::as<const char>(rawData));
48 // loop over all the DMA pages
49 while (rawreader.hasNext()) {
50 try {
51 rawreader.next();
52 } catch (RawErrorType_t e) {
53 LOG(error) << "Raw decoding error " << (int)e;
54 // if problem in header, abandon this page
56 break;
57 }
58 // if problem in payload, try to continue
59 continue;
60 }
61 // auto& header = rawreader.getRawHeader();
62 // auto triggerBC = o2::raw::RDHUtils::getTriggerBC(header);
63 // auto triggerOrbit = o2::raw::RDHUtils::getTriggerOrbit(header);
64 // use the decoder to decode the raw data, and extract signals
65 o2::cpv::RawDecoder decoder(rawreader);
66 RawErrorType_t err = decoder.decode();
67 if (err != kOK) {
68 // TODO handle severe errors
69 continue;
70 }
71 // Loop over all the channels
72 for (auto adch : decoder.getDigits()) {
73 AddressCharge ac = {adch};
74 unsigned short absId = ac.Address;
75 mMean->Fill(absId, ac.Charge);
76 }
77 } // RawReader::hasNext
78 }
79}
80
82{
83
84 LOG(info) << "[CPVPedestalCalibDevice - endOfStream]";
85 // calculate stuff here
88 sendOutput(ec.outputs());
89}
90
92{
93 // extract CCDB infos and calibration objects, convert it to TMemFile and send them to the output
94 // TODO in principle, this routine is generic, can be moved to Utils.h
95 // using clbUtils = o2::calibration::Utils;
96 if (mUpdateCCDB || mForceUpdate) {
97 // prepare all info to be sent to CCDB
99 auto image = o2::ccdb::CcdbApi::createObjectImage(mPedestals.get(), &info);
100
101 auto flName = o2::ccdb::CcdbApi::generateFileName("Pedestals");
102 info.setPath("CPV/Calib/Pedestals");
103 info.setObjectType("Pedestals");
104 info.setFileName(flName);
105 // TODO: should be changed to time of the run
106 const auto now = std::chrono::system_clock::now();
107 long timeStart = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
108 info.setStartValidityTimestamp(timeStart);
110 std::map<std::string, std::string> md;
111 info.setMetaData(md);
112
113 LOG(info) << "Sending object CPV/Calib/Pedestals";
114
116 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "CPV_PEDESTALS", subSpec}, *image.get());
117 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "CPV_PEDESTALS", subSpec}, info);
118 }
119 // Anyway send change to QC
120 LOG(info) << "[CPVPedestalCalibDevice - run] Writing ";
121 output.snapshot(o2::framework::Output{"CPV", "PEDDIFF", 0}, mPedDiff);
122
123 // Write pedestal distributions to calculate bad map
124 std::string filename = mPath + "CPVPedestals.root";
125 TFile f(filename.data(), "RECREATE");
126 mMean->Write();
127 f.Close();
128}
129
131{
132
133 mPedestals.reset(new Pedestals());
134
135 // Calculate mean of pedestal distributions
136 for (unsigned short i = mMean->GetNbinsX(); i > 0; i--) {
137 TH1D* pr = mMean->ProjectionY(Form("proj%d", i), i, i);
138 short pedMean = std::min(255, int(pr->GetMean()));
139 pr->Delete();
140 mPedestals->setPedestal(i - 1, pedMean);
141 }
142}
143
145{
146 // Compare pedestals to current ones stored in CCDB
147 // and send difference to QC to check
148 if (!mUseCCDB) {
149 mUpdateCCDB = true;
150 return;
151 }
152 // //TODO:
153 // //Get current map
154 // int nChanged=0;
155 // for(short i=o2::cpv::Geometry::kNCHANNELS; --i;){
156 // short dp=mPedestals.getPedestal(i)-oldPed.getPedestal(i);
157 // mPedDiff[i]=dp ;
158 // if(abs(dp)>1){ //not a fluctuation
159 // nChanged++;
160 // }
161 // }
162 // if(nChanged>kMinorChange){ //serious change, do not update CCDB automatically, use "force" option to overwrite
163 // mUpdateCCDB=false;
164 // }
165 // else{
166 // mUpdateCCDB=true;
167 // }
168}
169
170o2::framework::DataProcessorSpec o2::cpv::getPedestalCalibSpec(bool useCCDB, bool forceUpdate, std::string path)
171{
172
173 std::vector<o2::framework::OutputSpec> outputs;
174 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "CPV_PEDESTALS"}, o2::framework::Lifetime::Sporadic);
175 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "CPV_PEDESTALS"}, o2::framework::Lifetime::Sporadic);
176
177 outputs.emplace_back("CPV", "PEDDIFF", 0, o2::framework::Lifetime::Sporadic);
178
179 return o2::framework::DataProcessorSpec{"PedestalCalibSpec",
180 o2::framework::select("A:CPV/RAWDATA"),
181 outputs,
182 o2::framework::adaptFromTask<CPVPedestalCalibDevice>(useCCDB, forceUpdate, path),
184}
Utils and constants for calibration and related workflows.
int32_t i
A helper class to iteratate over all parts of all input routes.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
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
void setStartValidityTimestamp(long start)
void setFileName(const std::string &nm)
void setPath(const std::string &path)
void setEndValidityTimestamp(long end)
void setObjectType(const std::string &tp)
void setMetaData(const std::map< std::string, std::string > &md)
static constexpr long INFINITE_TIMESTAMP
void init(o2::framework::InitContext &ic) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void run(o2::framework::ProcessingContext &pc) final
void sendOutput(DataAllocator &output)
static constexpr short kNumberOfCPVPadsPhi
Definition Geometry.h:28
static constexpr short kNumberOfCPVPadsZ
Definition Geometry.h:29
Decoder of the ALTRO data in the raw page.
Definition RawDecoder.h:68
const std::vector< uint32_t > & getDigits() const
Get the reference to the digits container.
Definition RawDecoder.h:89
RawErrorType_t decode()
Decode the raw cpv payload stream.
Reader for raw data produced by the Readout application in in-memory format.
RawErrorType_t next()
Read next payload from the stream.
bool hasNext() const
check if more pages are available in the raw file
A helper class to iteratate over all parts of all input routes.
InputRecord & inputs()
The inputs associated with this processing context.
GLdouble n
Definition glcorearb.h:1982
GLeglImageOES image
Definition glcorearb.h:4021
GLdouble f
Definition glcorearb.h:310
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
o2::framework::DataProcessorSpec getPedestalCalibSpec(bool useCCDB, bool forceUpdate, std::string path)
@ kOK
NoError.
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > select(char const *matcher="")
std::string filename()
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
uint32_t SubSpecificationType
Definition DataHeader.h:620
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
uint32_t Charge
Bits 18 - 32 : charge.
Definition RawDecoder.h:44
uint32_t Address
Bits 0 - 17 : Address.
Definition RawDecoder.h:43