Project
Loading...
Searching...
No Matches
SACDecoder.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 ALICEO2_SACDECODER_H
17#define ALICEO2_SACDECODER_H
18
19#include <algorithm>
20#include <array>
21#include <deque>
22#include <unordered_map>
23#include <vector>
24#include <bitset>
25#include <gsl/span>
26
29
30#include "DataFormatsTPC/Defs.h"
31#include "DataFormatsTPC/SAC.h"
32
33using o2::constants::lhc::LHCBunchSpacingMUS;
34
35namespace o2::tpc::sac
36{
37
38constexpr float ADCtoNanoAmp = 125000.f / 8388608.f;
39constexpr uint32_t ChannelsPerFE = 8;
40constexpr size_t Instances = 2;
41constexpr size_t NumberFEs = FEsPerInstance * Instances;
42
46 std::array<int32_t, 8> currents{};
47
49 {
50 std::fill(currents.begin(), currents.end(), 0);
51 }
52
53 void reset()
54 {
55 timeStamp = 0;
57 }
58};
59
60struct DataPoint {
62 int32_t currents[GEMSTACKS]{};
63
64 void reset()
65 {
66 time = 0;
67 std::fill(&currents[0], &currents[GEMSTACKS], 0);
68 }
69
71};
72
74 double referenceTime{-1.};
75 std::vector<DataPoint> data;
76 std::vector<std::bitset<NumberFEs>> fes;
77
78 void resize(size_t newSize)
79 {
80 data.resize(newSize);
81 fes.resize(newSize);
82 }
83
85 size_t getNGoodEntries() const
86 {
87 size_t posGood = 0;
88 while (posGood < fes.size()) {
89 if (!fes[posGood].all()) {
90 break;
91 }
92 ++posGood;
93 }
94 return posGood;
95 }
96
98 gsl::span<const DataPoint> getGoodData() const
99 {
100 return gsl::span<const DataPoint>(data.data(), data.data() + getNGoodEntries());
101 }
102
105 {
106 const auto pos = getNGoodEntries();
107 data.erase(data.begin(), data.begin() + pos);
108 fes.erase(fes.begin(), fes.begin() + pos);
109 }
110
112 void clear()
113 {
114 data.clear();
115 fes.clear();
116 }
117
119 void insertFront(const size_t entries)
120 {
121 data.insert(data.begin(), entries, DataPoint());
122 fes.insert(fes.begin(), entries, std::bitset<NumberFEs>());
123 }
124
126 void setData(const size_t pos, uint32_t time, const DecodedDataFE& decdata, const int feid);
127
129};
130
132{
133 public:
134 static constexpr std::string_view AllowedAdditionalStreams{"MRLIX"};
135 static constexpr uint32_t SampleDistance = 16;
136 static constexpr double SampleTimeMS = LHCBunchSpacingMUS * 2.5;
138
139 enum class DebugFlags {
140 PacketInfo = 0x01,
141 TimingInfo = 0x02,
142 ProcessingInfo = 0x04,
143 DumpFullStream = 0x10,
144 StreamSingleFE = 0x100,
145 StreamFinalData = 0x200,
146 };
147
148 enum class ReAlignType {
149 None = 0,
150 AlignOnly = 1,
153 };
154
155 bool process(const char* data, size_t size);
156
157 void runDecoding();
158
159 void finalize();
160
162 {
163 mDecodedData.referenceTime = time;
164 }
165
166 double getReferenceTime() const
167 {
168 return mDecodedData.referenceTime;
169 }
170
180 void setDecodeAdditional(std::string_view additional)
181 {
182 mDecodeAdditional.clear();
183 for (const auto c : additional) {
184 if (AllowedAdditionalStreams.find(c) != std::string_view::npos) {
185 mDecodeAdditional += c;
186 }
187 }
188 }
189
191 {
192 if (!mDebugStream) {
193 mDebugStream = std::make_unique<o2::utils::TreeStreamRedirector>(mDebugOutputName.data(), "recreate");
194 }
195 }
196
205
206 void clearDecodedData();
207 void streamDecodedData(bool streamAll = false);
208
209 const DecodedData& getDecodedData() const { return mDecodedData; }
210
212 ReAlignType getReAlignType() const { return mReAlignType; }
213
216 static void setNThreads(const int nThreads) { sNThreads = nThreads; }
217
219 static int getNThreads() { return sNThreads; }
220
221 private:
222 inline static int sNThreads{1};
223 size_t mCollectedDataPackets{};
224 std::array<uint32_t, Instances> mPktCountInstance{};
225 std::array<uint32_t, NumberFEs> mPktCountFEs{};
226 std::array<std::pair<uint32_t, uint32_t>, NumberFEs> mTSCountFEs;
227 std::array<std::string, NumberFEs> mDataStrings;
228 DecodedData mDecodedData;
229 std::unique_ptr<o2::utils::TreeStreamRedirector> mDebugStream;
230 std::string mDecodeAdditional;
231 std::string mDebugOutputName{"SAC_debug.root"};
232 ReAlignType mReAlignType{ReAlignType::None};
233
234 uint32_t mDebugLevel{0};
235
236 uint32_t decodeTimeStamp(const char* data);
237
239 int decodeChannels(DecodedDataFE& sacs, size_t& carry, int feid);
240 void decode(int feid);
241
242 void printPacketInfo(const sac::packet& sac);
243
244 void dumpStreams();
245
246 ClassDefNV(Decoder, 0);
247};
248
249} // namespace o2::tpc::sac
250#endif
int16_t time
Definition RawEventData.h:4
std::vector< long > entries
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to process
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
Header to collect LHC related constants.
uint16_t pos
Definition RawData.h:3
uint32_t c
Definition RawData.h:2
Sampled Analogue Currents (SACs) data format definitions.
static int getNThreads()
Definition SACDecoder.h:219
static void setNThreads(const int nThreads)
Definition SACDecoder.h:216
@ DumpFullStream
Dump the data character streams.
@ StreamSingleFE
Stream debug output for each single FE.
@ ProcessingInfo
Print some processing info.
@ PacketInfo
Print packe information.
@ StreamFinalData
Stream debug output for each single FE.
void setDebugLevel(uint32_t level=(uint32_t) DebugFlags::PacketInfo)
set a debug level, see DebugFlags
Definition SACDecoder.h:198
double getReferenceTime() const
Definition SACDecoder.h:166
static constexpr double SampleTimeMS
Internal timer sampling time in milli seconds (downsampled from LHC clock x 2500)
Definition SACDecoder.h:136
const DecodedData & getDecodedData() const
Definition SACDecoder.h:209
void setReAlignType(ReAlignType type=ReAlignType::AlignOnly)
Definition SACDecoder.h:211
void setDecodeAdditional(std::string_view additional)
Definition SACDecoder.h:180
ReAlignType getReAlignType() const
Definition SACDecoder.h:212
static constexpr uint32_t SampleDistance
Number of samples between time data stamps.
Definition SACDecoder.h:135
void streamDecodedData(bool streamAll=false)
static constexpr double SampleDistanceTimeMS
Time distance in MS between samples.
Definition SACDecoder.h:137
void setReferenceTime(double time)
Definition SACDecoder.h:161
static constexpr std::string_view AllowedAdditionalStreams
Allowed additional data streams that can be decoded with debug stream enabled.
Definition SACDecoder.h:134
@ MaxType
Largest type number.
@ None
Print packe information.
@ AlignAndFillMissing
Try re-alignment and fill missing packets with 0s.
GLsizeiptr size
Definition glcorearb.h:659
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLint level
Definition glcorearb.h:275
constexpr size_t NumberFEs
Total number of frontends to process.
Definition SACDecoder.h:41
constexpr uint32_t ChannelsPerFE
Channels per front-end card. One channel is one stack.
Definition SACDecoder.h:39
constexpr float ADCtoNanoAmp
125000 nA / std::pow(2,23) bits
Definition SACDecoder.h:38
constexpr size_t Instances
Number of instances to process.
Definition SACDecoder.h:40
Marks an empty item in the context.
int32_t currents[GEMSTACKS]
Current in signed ADC values, use SACDecoder::ADCtoNanoAmp, to convert to nA.
Definition SACDecoder.h:62
uint32_t time
Reference time since epoch in ms.
Definition SACDecoder.h:61
ClassDefNV(DataPoint, 2)
Decoded data of one FE.
Definition SACDecoder.h:44
std::array< int32_t, 8 > currents
Definition SACDecoder.h:46
void insertFront(const size_t entries)
insert entries at the front
Definition SACDecoder.h:119
double referenceTime
reference time when sampling clock was started
Definition SACDecoder.h:74
void setData(const size_t pos, uint32_t time, const DecodedDataFE &decdata, const int feid)
copy decoded data from single FE and mark FE as received
size_t getNGoodEntries() const
Number of good entries, for which all FEs were decoded.
Definition SACDecoder.h:85
std::vector< std::bitset< NumberFEs > > fes
bitmask of decoded FEs
Definition SACDecoder.h:76
void clearGoodData()
clear entries where all FEs were already decoded
Definition SACDecoder.h:104
gsl::span< const DataPoint > getGoodData() const
span of good entries for which all FEs were already decoded
Definition SACDecoder.h:98
ClassDefNV(DecodedData, 1)
void clear()
clear all data
Definition SACDecoder.h:112
void resize(size_t newSize)
Definition SACDecoder.h:78
std::vector< DataPoint > data
decoded data
Definition SACDecoder.h:75