13#include <unordered_map>
16#include "fmt/format.h"
50 TPCDigitDumpDevice(
const std::vector<int>& sectors,
bool sendCEdigits) : mSectors(sectors), mSendCEdigits(sendCEdigits) {}
55 mMaxEvents =
static_cast<uint32_t
>(ic.options().get<
int>(
"max-events"));
56 mSyncOffsetReference = ic.options().get<uint32_t>(
"sync-offset-reference");
57 mDecoderType = ic.options().get<uint32_t>(
"decoder-type");
58 mUseTrigger = !ic.options().get<
bool>(
"ignore-trigger");
59 mUseOldSubspec = ic.options().get<
bool>(
"use-old-subspec");
60 const bool createOccupancyMaps = ic.options().get<
bool>(
"create-occupancy-maps");
61 mForceQuit = ic.options().get<
bool>(
"force-quit");
62 mCheckDuplicates = ic.options().get<
bool>(
"check-for-duplicates");
63 mApplyTailCancellation = ic.options().get<
bool>(
"apply-ion-tail-cancellation");
64 mRemoveDuplicates = ic.options().get<
bool>(
"remove-duplicates");
66 mRemoveCEdigits =
true;
68 mRemoveCEdigits = ic.options().get<
bool>(
"remove-ce-digits");
72 LOGP(info,
"Using old subspecification (CruId << 16) | ((LinkId + 1) << (CruEndPoint == 1 ? 8 : 0))");
78 if (!ic.options().get<
bool>(
"ignore-grp")) {
82 const auto nhbf = (
int)grp->getNHBFPerTF();
83 const int lastTimeBin = nhbf * 891 / 2;
85 LOGP(info,
"Using GRP NHBF = {} to set last time bin to {}, might be overwritte via --configKeyValues", nhbf, lastTimeBin);
91 const auto pedestalFile = ic.options().get<std::string>(
"pedestal-url");
92 if (pedestalFile.length()) {
93 if (pedestalFile.find(
"ccdb") != std::string::npos) {
94 LOGP(info,
"Loading pedestals from ccdb: {}", pedestalFile);
96 cdb.setURL(pedestalFile);
97 if (cdb.isHostReachable()) {
98 auto pedestalNoise = cdb.get<std::unordered_map<std::string, CalPad>>(
"TPC/Calib/PedestalNoise");
99 CalPad* pedestal =
nullptr;
101 pedestal = &pedestalNoise->at(
"Pedestals");
106 LOGP(error,
"could not load pedestals from {}", pedestalFile);
109 LOGP(error,
"ccdb access to {} requested, but host is not reachable. Cannot load Pedestals", pedestalFile);
112 LOGP(info,
"Setting pedestal file: {}", pedestalFile);
118 if (createOccupancyMaps) {
119 mClusterQC = std::make_unique<qc::Clusters>();
123 const int timeBins = mDigitDump.
update(padROCPos, cru,
data);
128 mRawReader.
setLinkZSCallback([
this](
int cru,
int rowInSector,
int padInRow,
int timeBin,
float adcValue) ->
bool {
133 mClusterQC->fillADCValue(cru, rowInSector, padInRow, timeBin, adcValue);
155 snapshotDigits(pc.outputs());
158 LOGP(info,
"Maximm number of events reached ({}), no more processing will be done", mMaxEvents);
162 pc.services().get<
ControlService>().readyToQuit(QuitRequest::All);
171 LOGP(info,
"endOfStream");
172 if (mActiveSectors) {
173 snapshotDigits(ec.outputs());
184 std::unique_ptr<qc::Clusters> mClusterQC;
186 uint32_t mMaxEvents{0};
187 uint32_t mSyncOffsetReference{144};
188 uint32_t mDecoderType{0};
189 bool mReadyToQuit{
false};
190 bool mCalibDumped{
false};
191 bool mUseOldSubspec{
false};
192 bool mForceQuit{
false};
193 bool mCheckDuplicates{
false};
194 bool mApplyTailCancellation{
false};
195 bool mRemoveDuplicates{
false};
196 bool mRemoveCEdigits{
false};
197 bool mSendCEdigits{
false};
198 bool mUseTrigger{
false};
199 uint64_t mActiveSectors{0};
200 std::vector<int> mSectors{};
205 if (mCheckDuplicates || mRemoveDuplicates) {
213 if (mRemoveCEdigits) {
217 if (mApplyTailCancellation) {
219 IonTailCorrection itCorr;
220 for (
auto isector : mSectors) {
221 itCorr.filterDigitsDirect(
digits[isector]);
225 for (
auto isector : mSectors) {
243 mClusterQC->normalize();
244 mClusterQC->dumpToFile(
"ClusterQC.root", 2);
252 std::vector<OutputSpec> outputs;
253 for (
auto isector : tpcSectors) {
254 outputs.emplace_back(
"TPC",
"DIGITS",
static_cast<SubSpecificationType>(isector), Lifetime::Timeframe);
256 outputs.emplace_back(
"TPC",
"CEDIGITS",
static_cast<SubSpecificationType>(isector), Lifetime::Timeframe);
260 std::vector<InputSpec> inputs;
261 if (inputSpec !=
"") {
262 inputs =
select(inputSpec.data());
265 if (!ignoreDistStf) {
266 inputs.emplace_back(
"stdDist",
"FLP",
"DISTSUBTIMEFRAME", 0, Lifetime::Timeframe);
271 fmt::format(
"tpc-raw-to-digits-{}", channel),
274 AlgorithmSpec{adaptFromTask<device>(tpcSectors, sendCEdigits)},
276 {
"max-events", VariantType::Int, 0, {
"maximum number of events to process"}},
277 {
"use-old-subspec", VariantType::Bool,
false, {
"use old subsecifiation definition"}},
278 {
"force-quit", VariantType::Bool,
false, {
"force quit after max-events have been reached"}},
279 {
"pedestal-url", VariantType::String,
"", {
"file with pedestals and noise or ccdb url for zero suppression"}},
280 {
"create-occupancy-maps", VariantType::Bool,
false, {
"create occupancy maps and store them to local root file for debugging"}},
281 {
"check-for-duplicates", VariantType::Bool,
false, {
"check if duplicate digits exist and only report them"}},
282 {
"apply-ion-tail-cancellation", VariantType::Bool,
false, {
"Apply ion tail cancellation"}},
283 {
"remove-duplicates", VariantType::Bool,
false, {
"check if duplicate digits exist and remove them"}},
284 {
"remove-ce-digits", VariantType::Bool,
false, {
"find CE position and remove digits around it"}},
285 {
"ignore-grp", VariantType::Bool,
false, {
"ignore GRP file"}},
286 {
"sync-offset-reference", VariantType::UInt32, 144u, {
"Reference BCs used for the global sync offset in the CRUs"}},
287 {
"decoder-type", VariantType::UInt32, 1u, {
"Decoder to use: 0 - TPC, 1 - GPU"}},
288 {
"ignore-trigger", VariantType::Bool,
false, {
"Ignore the trigger information"}},
Utils and constants for calibration and related workflows.
o2::framework::DataAllocator::SubSpecificationType SubSpecificationType
Header of the General Run Parameters object.
Implementation of the ion tail correction from TPC digits.
Definition of the Names Generator class.
static std::string getGRPFileName(const std::string_view prefix=STANDARDSIMPREFIX)
static BasicCCDBManager & instance()
o2::header::DataHeader::SubSpecificationType SubSpecificationType
static GRPObject * loadFrom(const std::string &grpFileName="")
unsigned char region() const
void setNumberOfProcessedTimeBins(size_t timeBins)
number of processed time bins in last event
Int_t update(const PadROCPos &padROCPos, const CRU &cru, const gsl::span< const uint32_t > data)
void incrementNEvents()
increment number of events
size_t getNumberOfProcessedEvents() const
number of processed events
size_t getNumberOfProcessedTimeBins() const
number of processed time bins in last event
Pedestal calibration class.
void clearDigits()
clear the digits
void setTimeBinRange(int first, int last)
set the timeBin range
void checkDuplicates(bool removeDuplicates=false)
check duplicates and remove the if removeDuplicates is true
void sortDigits()
sort the digits
void removeCEdigits(uint32_t removeNtimeBinsBefore=10, uint32_t removeNtimeBinsAfter=100, std::array< std::vector< Digit >, Sector::MAXSECTOR > *removedDigits=nullptr)
remove digits close to the CE
void setPedestals(const CalPad *pedestal)
Set a custom pedestal object.
void init()
initialize DigitDump from DigitDumpParam
std::vector< Digit > & getDigits(int sector)
return digits for specific sector
void setPedestalAndNoiseFile(std::string_view fileName)
pedestal file name
void setInMemoryOnly(bool mode=true)
set in memory only mode
Int_t updateCRU(const CRU &cru, const Int_t row, const Int_t pad, const Int_t timeBin, const Float_t signal) final
not used
static Mapper & instance(const std::string mappingDir="")
const PadRegionInfo & getPadRegionInfo(const unsigned char region) const
Pad and row inside a ROC.
unsigned char getGlobalRowOffset() const
static constexpr int MAXSECTOR
void init(o2::framework::InitContext &ic) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
TPCDigitDumpDevice(const std::vector< int > §ors, bool sendCEdigits)
void run(o2::framework::ProcessingContext &pc) final
RawReaderCRU & createReader(const std::string_view inputFileName, uint32_t numTimeBins=0, uint32_t link=0, uint32_t stream=0, uint32_t debugLevel=0, uint32_t verbosity=0, const std::string_view outputFilePrefix="")
create a new raw reader
auto & getReaders()
return vector of readers
void setLinkZSCallback(LinkZSCallback function)
set a callback function for decoded LinkZS data
void setADCDataCallback(ADCDataCallback function)
set a callback function
Defining PrimaryVertex explicitly as messageable.
std::vector< ConfigParamSpec > Options
header::DataHeader::SubSpecificationType SubSpecificationType
std::vector< InputSpec > select(char const *matcher="")
uint64_t processRawData(o2::framework::InputRecord &inputs, std::unique_ptr< o2::tpc::rawreader::RawReaderCRU > &reader, bool useOldSubspec=false, const std::vector< int > §ors={}, size_t *nerrors=nullptr, uint32_t syncOffsetReference=144, uint32_t decoderType=1, bool useTrigger=true, bool returnOnNoTrigger=false)
o2::framework::DataProcessorSpec getRawToDigitsSpec(int channel, const std::string inputSpec, bool ignoreDistStf, std::vector< int > const &tpcSectors, bool sendCEdigits=false)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::vector< Digit > digits