Project
Loading...
Searching...
No Matches
PHOSL1phaseCalibDevice.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
15#include "CCDB/CcdbApi.h"
16#include "CCDB/CcdbObjectInfo.h"
19
20#include "FairLogger.h"
21
22using namespace o2::phos;
23
25{
27 mCalibrator.reset(new PHOSL1phaseCalibrator());
28 mCalibrator->setUpdateAtTheEndOfRunOnly();
29}
30
32{
33
35 auto crTime = pc.services().get<o2::framework::TimingInfo>().creation;
36 if (mRunStartTime == 0 || crTime < mRunStartTime) {
37 mRunStartTime = crTime;
38 }
39 auto tfcounter = o2::header::get<o2::header::DataHeader*>(pc.inputs().get("cells").header)->tfCounter;
40 auto cells = pc.inputs().get<gsl::span<Cell>>("cells");
41 auto cellTR = pc.inputs().get<gsl::span<TriggerRecord>>("cellTR");
42 LOG(detail) << "Processing TF with " << cells.size() << " cells and " << cellTR.size() << " TrigRecords";
43 mCalibrator->process(tfcounter, cells, cellTR);
44
45 ++mNprocessed;
46 // If sufficient statistics was collected, try to calculate L1phases
47 // If statistics reached N*thresholds try to re-calculate L1phases
48 // if they changed wrt previous, replace ccdb object, otherwise do nothing
49 if (mNprocessed % minStatisticsForCalib == 0) {
50 minStatisticsForCalib *= 2;
51 mCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
52 mCalibrator->endOfStream();
53 if (mPrevCalibration != mCalibrator->getCalibration()) {
54 mPrevCalibration = mCalibrator->getCalibration();
55 // send this version of calibration to replace old one
56 sendCCDB(pc.outputs());
57 }
58 }
59}
60
62{
63 mCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
64 mCalibrator->endOfStream();
65
66 // try to re-calculate L1phases. If they was not calculated yet, or
67 // they changed wrt previous, replace ccdb object, otherwise do nothing
68
69 if (mRunStartTime == 0 || mCalibrator->getCalibration() == 0) { // run not started || calibration was not produced
70 return; // do not create CCDB object
71 }
72 // already uploaded, no need to repeat
73 if (mPrevCalibration == mCalibrator->getCalibration()) {
74 return;
75 }
76 mPrevCalibration = mCalibrator->getCalibration();
77 sendCCDB(ec.outputs());
78}
80{
81
82 std::vector<int> l1phase{mPrevCalibration};
83 LOG(info) << "Sending L1phase to CCDB";
84 // prepare all info to be sent to CCDB
85 auto flName = o2::ccdb::CcdbApi::generateFileName("L1phase");
86 std::map<std::string, std::string> md;
87 o2::ccdb::CcdbObjectInfo info("PHS/Calib/L1phase", "L1phase", flName, md, mRunStartTime - o2::ccdb::CcdbObjectInfo::MINUTE,
88 mRunStartTime + o2::ccdb::CcdbObjectInfo::DAY);
89 info.setMetaData(md);
90 auto image = o2::ccdb::CcdbApi::createObjectImage(&l1phase, &info);
91
92 LOG(info) << "Sending object " << info.getPath() << "/" << info.getFileName()
93 << " of size " << image->size()
94 << " bytes, valid for " << info.getStartValidityTimestamp()
95 << " : " << info.getEndValidityTimestamp();
96
97 outputs.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, "PHOS_L1phase", 0}, *image.get());
98 outputs.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "PHOS_L1phase", 0}, info);
99 // Send summary to QC
100 LOG(info) << "Sending histos to QC ";
101 outputs.snapshot(o2::framework::Output{"PHS", "L1PHASEHISTO", 0}, mCalibrator->getQcHistos());
102}
103
105{
106
107 std::vector<OutputSpec> outputs;
108 outputs.emplace_back(o2::calibration::Utils::gDataOriginCDBPayload, "PHOS_L1phase", 0, Lifetime::Sporadic);
109 outputs.emplace_back(o2::calibration::Utils::gDataOriginCDBWrapper, "PHOS_L1phase", 0, Lifetime::Sporadic);
110 outputs.emplace_back(o2::header::gDataOriginPHS, "L1PHASEHISTO", 0, o2::framework::Lifetime::Sporadic);
111
112 std::vector<InputSpec> inputs;
113 inputs.emplace_back("cells", "PHS", "CELLS");
114 inputs.emplace_back("cellTR", "PHS", "CELLTRIGREC");
115 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
116 true, // GRPECS=true
117 false, // GRPLHCIF
118 false, // GRPMagField
119 false, // askMatLUT
121 inputs);
122 return DataProcessorSpec{
123 "calib-phos-l1phase",
124 inputs,
125 outputs,
126 AlgorithmSpec{adaptFromTask<PHOSL1phaseCalibDevice>(ccdbRequest)},
127 Options{}};
128}
Utils and constants for calibration and related workflows.
Device to calculate PHOS time shift (L1phase)
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
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
long getEndValidityTimestamp() const
const std::string & getPath() const
static constexpr long DAY
void setMetaData(const std::map< std::string, std::string > &md)
long getStartValidityTimestamp() const
const std::string & getFileName() const
static constexpr long MINUTE
void snapshot(const Output &spec, T const &object)
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.
ServiceRegistryRef services()
The services registry associated with this processing context.
void endOfStream(o2::framework::EndOfStreamContext &ec)
void sendCCDB(DataAllocator &outputs)
void init(o2::framework::InitContext &ic)
void run(o2::framework::ProcessingContext &pc)
GLeglImageOES image
Definition glcorearb.h:4021
constexpr o2::header::DataOrigin gDataOriginPHS
Definition DataHeader.h:574
constexpr TFType INFINITE_TF
Definition TimeSlot.h:30
std::vector< ConfigParamSpec > Options
o2::framework::DataProcessorSpec getPHOSL1phaseCalibDeviceSpec()
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cell > cells