44DigitReader<N>::DigitReader(
bool useMC,
bool useCalib,
bool triggerOut) : mUseMC(useMC), 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 < RLayers; ++iLayer) {
107 LOG(info) << mDetName <<
"DigitReader:" << 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;
122 std::vector<o2::itsmft::PhysTrigger> dummyTrig;
125 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
131 std::vector<o2::itsmft::Digit> digitsSel;
132 std::vector<o2::itsmft::GBTCalibData> calibSel;
133 std::vector<o2::itsmft::ROFRecord> digROFRecSel;
134 std::vector<o2::itsmft::MC2ROFRecord> digMC2ROFsSel;
137 if (irFrames.size()) {
143 const auto irMin = irfSel.
getIRFrames().front().getMin();
144 const auto irMax = irfSel.
getIRFrames().back().getMax();
145 LOGP(info,
"Selecting IRFrame {}-{}", irMin.asString(), irMax.asString());
146 while (ent < mTree->GetEntries()) {
148 if (ent > mTree->GetReadEntry()) {
151 mPLabels[0] =
nullptr;
152 mConstLabels[0].clear();
153 mTree->SetBranchAddress(mDigitMCTruthBranchName.c_str(), &mPLabels[0]);
155 mTree->GetEntry(ent);
157 mPLabels[0]->copyandflatten(mConstLabels[0]);
159 mPLabels[0] =
nullptr;
162 std::vector<int> rofOld2New;
163 rofOld2New.resize(mDigROFRec[0]->
size(), -1);
165 if (mDigROFRec[0]->front().getBCData() <= irMax && (mDigROFRec[0]->back().getBCData() + mROFLengthInBC - 1) >= irMin) {
166 for (
int irof = 0; irof < (
int)mDigROFRec[0]->
size(); irof++) {
167 const auto& rof = mDigROFRec[0]->at(irof);
168 if (irfSel.
check({rof.getBCData(), rof.getBCData() + mROFLengthInBC - 1}) != -1) {
169 rofOld2New[irof] = (
int)digROFRecSel.size();
170 LOGP(
debug,
"Adding selected ROF {}", rof.getBCData().asString());
171 digROFRecSel.push_back(rof);
172 int offs = digitsSel.size();
173 digROFRecSel.back().setFirstEntry(offs);
174 std::copy(mDigits[0]->begin() + rof.getFirstEntry(), mDigits[0]->begin() + rof.getFirstEntry() + rof.getNEntries(), std::back_inserter(digitsSel));
175 for (
int id = 0;
id < rof.getNEntries();
id++) {
176 digitLabelsSel.
addElements(
id + offs, mConstLabels[0].getLabels(
id + rof.getFirstEntry()));
178 if (mCalib.size() >=
size_t((irof + 1) * mNRUs)) {
179 std::copy(mCalib.begin() + irof * mNRUs, mCalib.begin() + (irof + 1) * mNRUs, std::back_inserter(calibSel));
185 digMC2ROFsSel = *mDigMC2ROFs[0];
186 for (
auto& mc2rof : digMC2ROFsSel) {
187 if (mc2rof.rofRecordID < 0) {
190 unsigned int mn = 0xffff, mx = 0;
191 for (
int ir = mc2rof.minROF;
ir <= mc2rof.maxROF;
ir++) {
192 if (rofOld2New[
ir] >= 0) {
199 mc2rof.rofRecordID = mn == 0xffff ? -1 :
int(mn);
204 if (mDigROFRec[0]->back().getBCData() + mROFLengthInBC - 1 < irMax) {
217 std::vector<o2::itsmft::PhysTrigger> dummyTrig;
226 if (!irFrames.size() || irFrames.back().isLast()) {
236 mTree.reset(
nullptr);
237 mFile.reset(TFile::Open(
filename.c_str()));
238 assert(mFile && !mFile->IsZombie());
239 mTree.reset((TTree*)mFile->Get(mDigTreeName.c_str()));
241 for (uint32_t iLayer = 0; iLayer < RLayers; ++iLayer) {
242 setBranchAddress(mDigitROFBranchName, mDigROFRec[iLayer], iLayer);
243 setBranchAddress(mDigitBranchName, mDigits[iLayer], iLayer);
245 if (!mTree->GetBranch(getBranchName(mDigitMC2ROFBranchName, iLayer).c_str()) || !mTree->GetBranch(getBranchName(mDigitMCTruthBranchName, iLayer).c_str())) {
246 throw std::runtime_error(
"MC data requested but not found in the tree");
248 setBranchAddress(mDigitMC2ROFBranchName, mDigMC2ROFs[iLayer], iLayer);
249 if (!mPLabels[iLayer]) {
250 setBranchAddress(mDigitMCTruthBranchName, mPLabels[iLayer], iLayer);
255 if (!mTree->GetBranch(mCalibBranchName.c_str())) {
256 throw std::runtime_error(
"GBT calibration data requested but not found in the tree");
258 setBranchAddress(mCalibBranchName, mCalibPtr);
260 LOG(info) <<
"Loaded tree from " <<
filename <<
" with " << mTree->GetEntries() <<
" entries";
273template <
typename Ptr>
276 const auto name = getBranchName(base,
layer);
277 if (Int_t ret = mTree->SetBranchAddress(
name.c_str(), &addr); ret != 0) {
278 LOGP(fatal,
"failed to set branch address for {} ret={}",
name, ret);
285std::vector<OutputSpec> makeOutChannels(
bool mctruth,
bool useCalib)
288 std::vector<OutputSpec> outputs;
290 for (
int iLayer = 0; iLayer < RLayers; ++iLayer) {
291 outputs.emplace_back(Origin,
"DIGITS", iLayer, Lifetime::Timeframe);
292 outputs.emplace_back(Origin,
"DIGITSROF", iLayer, Lifetime::Timeframe);
294 outputs.emplace_back(Origin,
"DIGITSMC2ROF", iLayer, Lifetime::Timeframe);
295 outputs.emplace_back(Origin,
"DIGITSMCTR", iLayer, Lifetime::Timeframe);
299 outputs.emplace_back(Origin,
"GBTCALIB", 0, Lifetime::Timeframe);
301 outputs.emplace_back(Origin,
"PHYSTRIG", 0, Lifetime::Timeframe);
309 .
name =
"its-digit-reader",
311 .outputs = makeOutChannels<o2::detectors::DetID::ITS>(useMC, useCalib),
312 .algorithm =
AlgorithmSpec{adaptFromTask<ITSDigitReader>(useMC, useCalib)},
314 {
"its-digit-infile", VariantType::String, defname, {
"Name of the input digit file"}},
315 {
"input-dir", VariantType::String,
"none", {
"Input directory"}}}};
321 .
name =
"mft-digit-reader",
323 .outputs = makeOutChannels<o2::detectors::DetID::MFT>(useMC, useCalib),
324 .algorithm =
AlgorithmSpec{adaptFromTask<MFTDigitReader>(useMC, useCalib)},
326 {
"mft-digit-infile", VariantType::String, defname, {
"Name of the input digit file"}},
327 {
"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)
std::array< std::vector< o2::itsmft::ROFRecord > *, NLayers > mDigROFRec
static constexpr int NLayers
void run(ProcessingContext &pc) final
std::array< o2::dataformats::IOMCTruthContainerView *, NLayers > mPLabels
std::string mDigitBranchName
void init(InitContext &ic) final
void connectTree(const std::string &filename)
std::string mDigitMCTruthBranchName
std::array< std::vector< o2::itsmft::Digit > *, NLayers > mDigits
std::array< std::vector< o2::itsmft::MC2ROFRecord > *, NLayers > mDigMC2ROFs
std::string mDigitROFBranchName
std::string mDigitMC2ROFBranchName
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 PrimaryVertex explicitly as messageable.
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getITSDigitReaderSpec(bool useMC=true, bool useCalib=false, bool useTriggers=true, std::string defname="o2_itsdigits.root")
framework::DataProcessorSpec getMFTDigitReaderSpec(bool useMC=true, bool useCalib=false, bool useTriggers=true, std::string defname="o2_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 constexpr bool supportsStaggering() noexcept
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
o2::InteractionRecord ir(0, 0)