45DigitReader<N>::DigitReader(
bool useMC,
bool doStag,
bool useCalib,
bool triggerOut) : mUseMC(useMC), mDoStaggering(doStag), mUseCalib(useCalib), mTriggerOut(triggerOut), mDetNameLC(mDetName =
ID.
getName()), mDigTreeName(
"o2sim")
67 ic.
options().
get<std::string>((mDetNameLC +
"-digit-infile").c_str()));
71 connectTree(mFileName);
79 if (tinfo.globalRunNumberChanged && mUseIRFrames) {
82 auto rlim = ccdb.getRunDuration(tinfo.runNumber);
83 long ts = (rlim.first + rlim.second) / 2;
86 mROFBiasInBC = alpideParam.roFrameBiasInBC;
87 mROFLengthInBC = alpideParam.roFrameLengthInBC;
91 mROFBiasInBC = alpideParam.roFrameBiasInBC;
92 mROFLengthInBC = alpideParam.roFrameLengthInBC;
96 gsl::span<const o2::dataformats::IRFrame> irFrames{};
98 irFrames = pc.
inputs().
get<gsl::span<o2::dataformats::IRFrame>>(
"driverInfo");
101 auto ent = mTree->GetReadEntry();
104 assert(ent < mTree->GetEntries());
105 mTree->GetEntry(ent);
106 for (uint32_t iLayer = 0; iLayer < mLayers; ++iLayer) {
107 LOG(info) << mDetName <<
"DigitReader" << ((mDoStaggering) ? std::format(
": {}", iLayer) :
"") <<
" pushes " << mDigROFRec[iLayer]->
size() <<
" ROFRecords, " << mDigits[iLayer]->size() <<
" digits at entry " << ent;
112 mPLabels[iLayer]->copyandflatten(sharedlabels);
113 delete mPLabels[iLayer];
114 mPLabels[iLayer] =
nullptr;
116 static std::vector<o2::itsmft::MC2ROFRecord> dummyMC2ROF;
124 std::vector<o2::itsmft::PhysTrigger> dummyTrig;
127 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
133 std::vector<o2::itsmft::Digit> digitsSel;
134 std::vector<o2::itsmft::GBTCalibData> calibSel;
135 std::vector<o2::itsmft::ROFRecord> digROFRecSel;
138 if (irFrames.size()) {
144 const auto irMin = irfSel.
getIRFrames().front().getMin();
145 const auto irMax = irfSel.
getIRFrames().back().getMax();
146 LOGP(info,
"Selecting IRFrame {}-{}", irMin.asString(), irMax.asString());
147 while (ent < mTree->GetEntries()) {
149 if (ent > mTree->GetReadEntry()) {
152 mPLabels[0] =
nullptr;
153 mConstLabels[0].clear();
154 mTree->SetBranchAddress(mDigitMCTruthBranchName.c_str(), &mPLabels[0]);
156 mTree->GetEntry(ent);
158 mPLabels[0]->copyandflatten(mConstLabels[0]);
160 mPLabels[0] =
nullptr;
163 std::vector<int> rofOld2New;
164 rofOld2New.resize(mDigROFRec[0]->
size(), -1);
166 if (mDigROFRec[0]->front().getBCData() <= irMax && (mDigROFRec[0]->back().getBCData() + mROFLengthInBC - 1) >= irMin) {
167 for (
int irof = 0; irof < (
int)mDigROFRec[0]->
size(); irof++) {
168 const auto& rof = mDigROFRec[0]->at(irof);
169 if (irfSel.
check({rof.getBCData(), rof.getBCData() + mROFLengthInBC - 1}) != -1) {
170 rofOld2New[irof] = (
int)digROFRecSel.size();
171 LOGP(
debug,
"Adding selected ROF {}", rof.getBCData().asString());
172 digROFRecSel.push_back(rof);
173 int offs = digitsSel.size();
174 digROFRecSel.back().setFirstEntry(offs);
175 std::copy(mDigits[0]->begin() + rof.getFirstEntry(), mDigits[0]->begin() + rof.getFirstEntry() + rof.getNEntries(), std::back_inserter(digitsSel));
176 for (
int id = 0;
id < rof.getNEntries();
id++) {
177 digitLabelsSel.
addElements(
id + offs, mConstLabels[0].getLabels(
id + rof.getFirstEntry()));
179 if (mCalib.size() >=
size_t((irof + 1) * mNRUs)) {
180 std::copy(mCalib.begin() + irof * mNRUs, mCalib.begin() + (irof + 1) * mNRUs, std::back_inserter(calibSel));
185 if (mDigROFRec[0]->back().getBCData() + mROFLengthInBC - 1 < irMax) {
198 std::vector<o2::itsmft::PhysTrigger> dummyTrig;
206 if (!irFrames.size() || irFrames.back().isLast()) {
216 mTree.reset(
nullptr);
217 mFile.reset(TFile::Open(
filename.c_str()));
218 assert(mFile && !mFile->IsZombie());
219 mTree.reset((TTree*)mFile->Get(mDigTreeName.c_str()));
221 for (uint32_t iLayer = 0; iLayer < mLayers; ++iLayer) {
222 setBranchAddress(mDigitROFBranchName, mDigROFRec[iLayer], iLayer);
223 setBranchAddress(mDigitBranchName, mDigits[iLayer], iLayer);
225 if (!mTree->GetBranch(getBranchName(mDigitMCTruthBranchName, iLayer).c_str())) {
226 throw std::runtime_error(
"MC data requested but not found in the tree");
228 if (!mPLabels[iLayer]) {
229 setBranchAddress(mDigitMCTruthBranchName, mPLabels[iLayer], iLayer);
234 if (!mTree->GetBranch(mCalibBranchName.c_str())) {
235 throw std::runtime_error(
"GBT calibration data requested but not found in the tree");
237 setBranchAddress(mCalibBranchName, mCalibPtr);
239 LOG(info) <<
"Loaded tree from " <<
filename <<
" with " << mTree->GetEntries() <<
" entries";
252template <
typename Ptr>
255 const auto name = getBranchName(base,
layer);
256 if (Int_t ret = mTree->SetBranchAddress(
name.c_str(), &addr); ret != 0) {
257 LOGP(fatal,
"failed to set branch address for {} ret={}",
name, ret);
264std::vector<OutputSpec> makeOutChannels(
bool mctruth,
bool doStag,
bool useCalib)
267 std::vector<OutputSpec> outputs;
269 for (
int iLayer = 0; iLayer < nLayers; ++iLayer) {
270 outputs.emplace_back(Origin,
"DIGITS", iLayer, Lifetime::Timeframe);
271 outputs.emplace_back(Origin,
"DIGITSROF", iLayer, Lifetime::Timeframe);
273 outputs.emplace_back(Origin,
"DIGITSMC2ROF", iLayer, Lifetime::Timeframe);
274 outputs.emplace_back(Origin,
"DIGITSMCTR", iLayer, Lifetime::Timeframe);
278 outputs.emplace_back(Origin,
"GBTCALIB", 0, Lifetime::Timeframe);
280 outputs.emplace_back(Origin,
"PHYSTRIG", 0, Lifetime::Timeframe);
288 .
name =
"its-digit-reader",
290 .outputs = makeOutChannels<o2::detectors::DetID::ITS>(useMC, doStag, useCalib),
291 .algorithm =
AlgorithmSpec{adaptFromTask<ITSDigitReader>(useMC, doStag, useCalib, useTriggers)},
293 {
"its-digit-infile", VariantType::String, defname, {
"Name of the input digit file"}},
294 {
"input-dir", VariantType::String,
"none", {
"Input directory"}}}};
300 .
name =
"mft-digit-reader",
302 .outputs = makeOutChannels<o2::detectors::DetID::MFT>(useMC, doStag, useCalib),
303 .algorithm =
AlgorithmSpec{adaptFromTask<MFTDigitReader>(useMC, doStag, useCalib, useTriggers)},
305 {
"mft-digit-infile", VariantType::String, defname, {
"Name of the input digit file"}},
306 {
"input-dir", VariantType::String,
"none", {
"Input directory"}}}};
std::string getName(const TDataMember *dm, int index, int size)
A const (ready only) version of MCTruthContainer.
Class to check if give InteractionRecord or IRFrame is selected by the external IRFrame vector.
Class to delimit start and end IR of certain time period.
Definition of the Names Generator class.
Definition Physics trigger record extracted from the ITS/MFT stream.
static BasicCCDBManager & instance()
static const DPLAlpideParam< N > & Instance()
bool hasOption(const char *key) const
T get(const char *key) const
void snapshot(const Output &spec, T const &object)
decltype(auto) make(const Output &spec, Args... args)
ConfigParamRegistry const & options()
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.
static constexpr int getNRUs()
total number of chips
static constexpr Int_t getNRUs()
< total number of RUs
void setBranchAddress(const std::string &base, Ptr &addr, int layer=-1)
std::string mCalibBranchName
std::string getBranchName(const std::string &base, int index)
void run(ProcessingContext &pc) final
std::string mDigitBranchName
void init(InitContext &ic) final
void connectTree(const std::string &filename)
std::vector< std::vector< o2::itsmft::Digit > * > mDigits
std::string mDigitMCTruthBranchName
std::vector< o2::dataformats::IOMCTruthContainerView * > mPLabels
std::vector< std::vector< o2::itsmft::ROFRecord > * > mDigROFRec
std::string mDigitROFBranchName
long check(o2::dataformats::IRFrame fr, size_t bwd=0, size_t fwd=0)
void setSelectedIRFrames(const SPAN &sp, size_t bwd=0, size_t fwd=0, long shift=0, bool removeOverlaps=true)
GLuint const GLchar * name
GLenum GLuint GLint GLint layer
constexpr o2::header::DataOrigin gDataOriginMFT
constexpr o2::header::DataOrigin gDataOriginITS
Defining ITS Vertex explicitly as messageable.
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getITSDigitReaderSpec(bool useMC=true, bool doStag=false, bool useCalib=false, bool useTriggers=true, std::string defname="itsdigits.root")
framework::DataProcessorSpec getMFTDigitReaderSpec(bool useMC=true, bool doStag=false, bool useCalib=false, bool useTriggers=true, std::string defname="mftdigits.root")
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
static constexpr int getNLayers()
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"