Project
Loading...
Searching...
No Matches
ResidualAggregator.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
15
16#ifndef O2_TPC_RESIDUALAGGREGATOR_H
17#define O2_TPC_RESIDUALAGGREGATOR_H
18
22#include "DataFormatsTPC/Defs.h"
26#include <vector>
27#include <array>
28#include <string>
29
30#include "TFile.h"
31#include "TTree.h"
32
33namespace o2
34{
35namespace tpc
36{
37
39
41
42 ResidualsContainer() = default;
44 ResidualsContainer(const ResidualsContainer&); // no copying allowed, this will yield an error message
47
48 void init(const TrackResiduals* residualsEngine, std::string outputDir, bool wFile, bool wBinnedResid, bool wUnbinnedResid, bool wTrackData, int autosave, int compression, long orbitResetTime);
50 uint64_t getNEntries() const { return nResidualsTotal; }
51
52 void fill(const o2::dataformats::TFIDInfo& ti, const gsl::span<const UnbinnedResid> resid, const gsl::span<const DetInfoResid> detInfoRes, const gsl::span<const o2::tpc::TrackDataCompact> trkRefsIn, const gsl::span<const o2::tpc::TrackData>* trkDataIn, const o2::ctp::LumiInfo* lumiInput);
53 void merge(ResidualsContainer* prev);
54 void print();
55 void writeToFile(bool closeFileAfterwards);
56
58 std::array<std::vector<TrackResiduals::LocalResid>, SECTORSPERSIDE * SIDES> residuals{};
59 std::array<std::vector<TrackResiduals::LocalResid>*, SECTORSPERSIDE * SIDES> residualsPtr{};
60 std::array<std::vector<TrackResiduals::VoxStats>, SECTORSPERSIDE * SIDES> stats{};
61 std::array<std::vector<TrackResiduals::VoxStats>*, SECTORSPERSIDE * SIDES> statsPtr{};
62 std::vector<uint32_t> tfOrbits, *tfOrbitsPtr{&tfOrbits};
65 std::vector<o2::ctp::LumiInfo> lumi, *lumiPtr{&lumi};
66 std::vector<UnbinnedResid> unbinnedRes, *unbinnedResPtr{&unbinnedRes};
67 std::vector<DetInfoResid> detInfoUnbRes, *detInfoUnbResPtr{&detInfoUnbRes};
68 std::vector<TrackData> trkData, *trkDataPtr{&trkData};
69 std::vector<TrackDataCompact> trackInfo, *trackInfoPtr{&trackInfo};
71 uint64_t timeMS;
72
73 std::string fileName{"o2tpc_residuals"};
74 std::unique_ptr<TFile> fileOut{nullptr};
75 std::unique_ptr<TTree> treeOutResidualsUnbinned{nullptr};
76 std::unique_ptr<TTree> treeOutTrackData{nullptr};
77 std::unique_ptr<TTree> treeOutResiduals{nullptr};
78 std::unique_ptr<TTree> treeOutStats{nullptr};
79 std::unique_ptr<TTree> treeOutRecords{nullptr};
80
81 // settings
82 bool writeToRootFile{true};
83 bool writeBinnedResid{false};
85 bool writeTrackData{false};
87
88 // additional info
89 long orbitReset{0};
90 uint32_t firstTForbit{0};
93 uint64_t nResidualsTotal{0};
94 float TPCVDriftRef{-1.};
96
98};
99
100class ResidualAggregator final : public o2::calibration::TimeSlotCalibration<ResidualsContainer>
101{
103
104 public:
105 ResidualAggregator(size_t nMin = 1000) : mMinEntries(nMin) { mTrackResiduals.init(); }
106 ~ResidualAggregator() final;
107
108 void setDataTakingContext(o2::framework::DataTakingContext& dtc) { mDataTakingContext = dtc; }
109 void setOrbitResetTime(long t) { mOrbitResetTime = t; }
111 void setOutputDir(std::string dir)
112 {
113 mOutputDir = dir;
114 mWriteOutput = true;
115 }
116 void setMetaFileOutputDir(std::string dir)
117 {
118 mMetaOutputDir = dir;
119 mStoreMetaData = true;
120 }
121 void setLHCPeriod(std::string period) { mLHCPeriod = period; }
122 void setWriteBinnedResiduals(bool f) { mWriteBinnedResiduals = f; }
123 void setWriteUnbinnedResiduals(bool f) { mWriteUnbinnedResiduals = f; }
124 void setWriteTrackData(bool f) { mWriteTrackData = f; }
125 void setAutosaveInterval(int n) { mAutosaveInterval = n; }
126 void setCompression(int c) { mCompressionSetting = c; }
127
128 bool hasEnoughData(const Slot& slot) const final;
129 void initOutput() final;
130 void finalizeSlot(Slot& slot) final;
131 Slot& emplaceNewSlot(bool front, TFType tStart, TFType tEnd) final;
132
133 private:
134 o2::framework::DataTakingContext mDataTakingContext{};
135 TrackResiduals mTrackResiduals;
136 std::string mOutputDir{"./"};
137 std::string mMetaOutputDir{"none"};
138 std::string mLHCPeriod{""};
139 bool mStoreMetaData{false};
140 bool mWriteOutput{false};
141 bool mWriteBinnedResiduals{false};
142 bool mWriteUnbinnedResiduals{false};
143 bool mWriteTrackData{false};
144 int mAutosaveInterval{0};
145 int mCompressionSetting{101};
146 size_t mMinEntries;
147 long mOrbitResetTime;
148 float mTPCVDriftRef = -1.;
149 float mTPCDriftTimeOffsetRef = 0.;
150
151 ClassDefOverride(ResidualAggregator, 4);
152};
153
154} // namespace tpc
155} // namespace o2
156
157#endif // O2_TPC_RESIDUALAGGREGATOR_H
uint64_t TFType
uint32_t c
Definition RawData.h:2
Definition of the TrackResiduals class.
Slot & emplaceNewSlot(bool front, TFType tStart, TFType tEnd) final
bool hasEnoughData(const Slot &slot) const final
void setOutputDir(std::string dir)
void setLHCPeriod(std::string period)
void setTPCVDrift(const o2::tpc::VDriftCorrFact &v)
void finalizeSlot(Slot &slot) final
void setDataTakingContext(o2::framework::DataTakingContext &dtc)
void setMetaFileOutputDir(std::string dir)
void init(bool doBinning=true)
GLdouble n
Definition glcorearb.h:1982
GLenum src
Definition glcorearb.h:1767
const GLdouble * v
Definition glcorearb.h:832
GLdouble f
Definition glcorearb.h:310
uint32_t TFType
Definition TimeSlot.h:29
constexpr TFType INFINITE_TF
Definition TimeSlot.h:30
constexpr unsigned char SECTORSPERSIDE
Definition Defs.h:40
constexpr unsigned char SIDES
Definition Defs.h:41
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::unique_ptr< TTree > treeOutResidualsUnbinned
std::vector< TrackDataCompact > * trackInfoPtr
allows to obtain track type for each unbinned residual downstream
long orbitReset
current orbit reset time in ms
std::array< std::vector< TrackResiduals::VoxStats > *, SECTORSPERSIDE *SIDES > statsPtr
std::vector< TrackData > * trkDataPtr
track data and cluster ranges
std::unique_ptr< TTree > treeOutRecords
float TPCVDriftRef
TPC nominal drift speed in cm/microseconds.
std::vector< uint32_t > sumBinnedResid
void init(const TrackResiduals *residualsEngine, std::string outputDir, bool wFile, bool wBinnedResid, bool wUnbinnedResid, bool wTrackData, int autosave, int compression, long orbitResetTime)
TFType lastSeenTF
the last TF which was added to this container
uint64_t timeMS
for each processed TF we store its absolute time in ms in the tree of unbinned residuals
std::vector< DetInfoResid > * detInfoUnbResPtr
detector info associated to unbinned residuals which are sent to the aggregator
o2::calibration::TFType TFType
std::vector< UnbinnedResid > * unbinnedResPtr
unbinned residuals which are sent to the aggregator
std::vector< uint32_t > tfOrbits
ResidualsContainer & operator=(const ResidualsContainer &src)=delete
std::vector< uint32_t > * sumBinnedResidPtr
sum of binned residuals for each TF
uint32_t firstTForbit
stored for the first seen TF to allow conversion to time stamp
std::vector< o2::ctp::LumiInfo > * lumiPtr
luminosity information from CTP per TF
std::array< std::vector< TrackResiduals::LocalResid > *, SECTORSPERSIDE *SIDES > residualsPtr
bool writeBinnedResid
flag, whether binned residuals should be written out
std::vector< o2::ctp::LumiInfo > lumi
bool writeTrackData
flag, whether full seeding track information should be written out
std::vector< TrackDataCompact > trackInfo
std::vector< uint32_t > * tfOrbitsPtr
first TF orbit
bool writeUnbinnedResiduals
flag, whether unbinned residuals should be written out
void writeToFile(bool closeFileAfterwards)
o2::ctp::LumiInfo lumiTF
for each processed TF we store the lumi information in the tree of unbinned residuals
std::array< std::vector< TrackResiduals::LocalResid >, SECTORSPERSIDE *SIDES > residuals
local (binned) residuals per sector
void merge(ResidualsContainer *prev)
std::vector< UnbinnedResid > unbinnedRes
float TPCDriftTimeOffsetRef
TPC nominal (e.g. at the start of run) drift time bias in cm/mus.
void fill(const o2::dataformats::TFIDInfo &ti, const gsl::span< const UnbinnedResid > resid, const gsl::span< const DetInfoResid > detInfoRes, const gsl::span< const o2::tpc::TrackDataCompact > trkRefsIn, const gsl::span< const o2::tpc::TrackData > *trkDataIn, const o2::ctp::LumiInfo *lumiInput)
std::unique_ptr< TFile > fileOut
std::vector< uint32_t > sumUnbinnedResid
std::array< std::vector< TrackResiduals::VoxStats >, SECTORSPERSIDE *SIDES > stats
voxel statistics per sector
std::unique_ptr< TTree > treeOutStats
const TrackResiduals * trackResiduals
TFType firstSeenTF
the first TF which was added to this container
uint64_t nResidualsTotal
the total number of residuals for this container
std::vector< uint32_t > * sumUnbinnedResidPtr
sum of unbinned residuals for each TF
std::unique_ptr< TTree > treeOutResiduals
ClassDefNV(ResidualsContainer, 5)
int autosaveInterval
if > 0, then the output written to file for every n-th TF
std::vector< DetInfoResid > detInfoUnbRes
std::unique_ptr< TTree > treeOutTrackData
std::vector< TrackData > trkData
bool writeToRootFile
set to false to avoid that any output file is produced