16#ifndef _ALICEO2_CTFCODER_BASE_H_
17#define _ALICEO2_CTFCODER_BASE_H_
43class ProcessingContext;
70 template <
typename SPAN>
77 template <
typename CTF>
80 template <
typename CTF>
86 LOG_IF(warning, renormedHistogram.empty()) << fmt::format(
"Empty dictionary provided for slot {}, {} will assume literal symbols only", slot, (
op ==
OpType::Encoder ?
"encoding" :
"decoding"));
107 throw std::runtime_error(
"unsupported ANS version");
126 template <
typename T>
127 static bool readFromTree(TTree&
tree,
const std::string brname, T& dest,
int ev = 0);
130 template <
typename CTF>
133 template <
typename CTF,
typename BUF>
136 template <
typename CTF>
172 return diff < 0 ? true : diff >= shift;
176 template <
typename source_IT>
179 template <
typename source_T>
182 template <
typename source_T>
188 template <
typename CTF>
214 auto* br =
tree.GetBranch(brname.c_str());
215 if (br && br->GetEntries() > ev) {
217 br->SetAddress(&
ptr);
226template <
typename CTF>
229 auto buff = readDictionaryFromFile<CTF>(dictPath, mayFail);
234 throw std::runtime_error(
"Failed to create CTF dictionaty");
240template <
typename CTF>
243 std::vector<char> bufVec;
252template <
typename CTF>
255 std::vector<char> bufVec;
256 std::unique_ptr<TFile> fileDict;
257 if (std::filesystem::exists(dictPath)) {
258 fileDict.reset(TFile::Open(dictPath.c_str()));
260 if (!fileDict || fileDict->IsZombie()) {
261 std::string errstr = fmt::format(
"CTF dictionary file {} for detector {} is absent", dictPath,
mDet.
getName());
263 LOGP(info,
"{}, will assume dictionary stored in CTF", errstr);
265 throw std::runtime_error(errstr);
269 std::unique_ptr<TTree>
tree;
270 std::unique_ptr<std::vector<char>> bv((std::vector<char>*)fileDict->GetObjectChecked(
o2::base::NameConf::CCDBOBJECT.data(),
"std::vector<char>"));
276 auto v = loadDictionaryFromTree<CTF>(
tree.get());
282 if (dictHeader.det !=
mDet) {
284 LOGP(
error,
"{} contains dictionary vector for {}, expected {}", dictPath, dictHeader.det.getName(),
mDet.
getName());
293 LOGP(info,
"{}, will assume dictionary stored in CTF",
mDet.
getName());
295 LOGP(fatal,
"CTF dictionary file for detector {} is empty",
mDet.
getName());
302template <
typename CTF>
317 bool ansVersionProvided =
false;
320 const std::string ansVersionString = ic.
options().
get<std::string>(
"ans-version");
321 if (!ansVersionString.empty()) {
323 LOGP(info,
"parsing ansVersionString {} into {}", ansVersionString,
static_cast<std::string
>(
mANSVersion));
325 throw std::invalid_argument(fmt::format(
"Invalid ANS Version {}", ansVersionString));
327 ansVersionProvided =
true;
338 if (!ansVersionProvided) {
341 LOGP(info,
"Internal per-TF CTF Dict will be created, ANS Version {}", std::string(
mANSVersion));
348template <
typename CTF,
typename BUF>
351 auto eeb = CTF::get(
buffer.data());
353 buffer.resize(eeb->size());
359template <
typename CTF>
364 const auto* dict = (std::vector<char>*)obj;
366 LOGP(info,
"Empty dictionary object fetched from CCDB, internal per-TF CTF Dict will be created");
368 std::vector<char> bufVec;
370 auto v = loadDictionaryFromTree<CTF>(
reinterpret_cast<TTree*
>(obj));
381 auto bcshift = trigOffsParam.customOffset[
mDet.getID()];
384 LOGP(info,
"Decoded IRs will be augmented by {} BCs, discarded if become prior to 1st orbit", bcshift);
387 LOGP(alarm,
"Decoding with {} BCs shift is requested, but the {} does not support this operation, ignoring request", bcshift,
mDet.
getName());
394template <
typename IT>
397 using source_type =
typename std::iterator_traits<IT>::value_type;
398 const size_t nSamples = std::distance(samplesBegin, samplesEnd);
399 return estimateBufferSize<source_type>(slot,
nSamples);
402template <
typename source_T>
406 std::any& coder =
mCoders[slot];
407 if (coder.has_value()) {
408 const size_t alphabetRangeBits = [
this, &coder]() {
410 const auto& encoder = std::any_cast<const rans::compat::encoder_type<source_T>&>(coder);
414 const auto& encoder = std::any_cast<const rans::denseEncoder_type<source_T>&>(coder);
418 throw std::runtime_error(
"unsupported ANS version");
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 s
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
char error[CURL_ERROR_SIZE]
Class to check if give InteractionRecord or IRFrame is selected by the external IRFrame vector.
Definition of the Names Generator class.
Class for time synchronization of RawReader instances.
static constexpr std::string_view CCDBOBJECT
static constexpr std::string_view CTFDICT
static const TriggerOffsetsParam & Instance()
size_t getIRFrameSelMarginBwd() const
ctf::ANSHeader & getANSVersion()
void createCoder(OpType op, const o2::rans::RenormedDenseHistogram< S > &renormedHistogram, int slot)
static bool readFromTree(TTree &tree, const std::string brname, T &dest, int ev=0)
void setTrigOffsBinding(const std::string &s)
void setSupportBCShifts(bool v=true)
void updateTimeDependentParams(o2::framework::ProcessingContext &pc, bool askTree=false)
long getIRFrameSelShift() const
size_t mIRFrameSelMarginFwd
void setDictBinding(const std::string &s)
void init(o2::framework::InitContext &ic)
const DetID getDet() const
CTFCoderBase(OpType op, int n, DetID det, float memFactor=1.f, const std::string &ctfdictOpt="none")
void setMemMarginFactor(float v)
void setANSVersion(const ctf::ANSHeader &ansVersion) noexcept
const ctf::ANSHeader & getANSVersion() const noexcept
std::vector< char > readDictionaryFromFile(const std::string &dictPath, bool mayFail=false)
void setSelectedIRFrames(const SPAN &sp)
bool canApplyBCShift(const o2::InteractionRecord &ir) const
bool getSupportBCShifts() const
void setBCShift(int64_t n)
const std::string & getDictBinding() const
float getMemMarginFactor() const
std::vector< std::any > mCoders
o2::utils::IRFrameSelector & getIRFramesSelector()
std::string mTrigOffsBinding
const CTFDictHeader & getExtDictHeader() const
std::vector< char > loadDictionaryFromTree(TTree *tree)
bool isTreeDictionary(const void *buff) const
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
CTFCoderBase(int n, DetID det, float memFactor=1.f, const std::string &ctfdictOpt="none")
void checkDictVersion(const CTFDictHeader &h) const
const std::string & getTrigOffsBinding() const
ctf::ANSHeader mANSVersion
size_t getIRFrameSelMarginFwd() const
std::string getPrefix() const
size_t mIRFrameSelMarginBwd
virtual void createCoders(const std::vector< char > &bufVec, o2::ctf::CTFCoderBase::OpType op)=0
auto getFirstTFOrbit() const
size_t finaliseCTFOutput(BUF &buffer)
size_t estimateBufferSize(size_t slot, source_IT samplesBegin, source_IT samplesEnd)
void createCodersFromFile(const std::string &dictPath, o2::ctf::CTFCoderBase::OpType op, bool mayFail=false)
o2::utils::IRFrameSelector mIRFrameSelector
void setFirstTFOrbit(uint32_t n)
virtual ~CTFCoderBase()=default
virtual void assignDictVersion(CTFDictHeader &h) const
size_t estimateBufferSize(size_t slot, const std::vector< source_T > &samples)
bool canApplyBCShift(const o2::InteractionRecord &ir, long shift) const
Static class with identifiers, bitmasks and names for ALICE detectors.
static constexpr const char * getName(ID id)
names of defined detectors
static constexpr o2h::DataOrigin getDataOrigin(ID id)
bool hasOption(const char *key) const
bool isSet(const char *key) const
T get(const char *key) const
ConfigParamRegistry const & options()
static constexpr decltype(auto) fromRenormed(const RenormedHistogramConcept< container_T > &renormed)
static constexpr decltype(auto) fromRenormed(const RenormedHistogramConcept< container_T > &renormed)
static constexpr decltype(auto) fromRenormed(const RenormedHistogramConcept< container_T > &renormed)
static constexpr decltype(auto) fromRenormed(const RenormedDenseHistogram< source_T > &renormed)
void setSelectedIRFrames(const SPAN &sp, size_t bwd=0, size_t fwd=0, long shift=0, bool removeOverlaps=true)
functionality to maintain compatibility with previous version of this library
bool match(const std::vector< std::string > &queries, const char *pattern)
static factory classes for building histograms, encoders and decoders.
public interface for building and renorming histograms from source data.
ANSHeader ansVersionFromString(const std::string &ansVersionString)
constexpr ANSHeader ANSVersionCompat
constexpr ANSHeader ANSVersion1
constexpr ANSHeader ANSVersionUnspecified
size_t calculateMaxBufferSizeB(size_t nElements, size_t rangeBits)
constexpr uint32_t getRangeBits(T min, T max) noexcept
auto makeHistogramView(container_T &container, std::ptrdiff_t offset) noexcept -> HistogramView< decltype(std::begin(container))>
HistogramView< Hist_IT > trim(const HistogramView< Hist_IT > &buffer)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
int64_t differenceInBC(const InteractionRecord &other) const
static std::string concat_string(Ts const &... ts)
o2::InteractionRecord ir(0, 0)
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))