Project
Loading...
Searching...
No Matches
DigitWriterSpec.cxx
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
13
16#include "Framework/DataRef.h"
17#include "TRKBase/AlmiraParam.h"
21#include "Headers/DataHeader.h"
27#include <vector>
28#include <string>
29#include <algorithm>
30#include <format>
31
32using namespace o2::framework;
34
35namespace o2
36{
37namespace trk
38{
39
40template <typename T>
43
44DataProcessorSpec getTRKDigitWriterSpec(bool mctruth, bool dec, bool calib)
45{
46 static constexpr o2::header::DataOrigin Origin = o2::header::gDataOriginTRK;
47 const int mLayers = o2::trk::AlmiraParam::kNLayers;
48 std::string detStr = "TRK";
49 std::string detStrL = dec ? "o2_trk" : "trk";
50
51 auto digitSizes = std::make_shared<std::vector<size_t>>(mLayers, 0);
52 auto digitSizeGetter = [digitSizes](std::vector<o2::itsmft::Digit> const& inDigits, DataRef const& ref) {
53 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
54 (*digitSizes)[dh->subSpecification] = inDigits.size();
55 };
56 auto rofSizes = std::make_shared<std::vector<size_t>>(mLayers, 0);
57 auto rofSizeGetter = [rofSizes](std::vector<o2::itsmft::ROFRecord> const& inROFs, DataRef const& ref) {
58 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
59 (*rofSizes)[dh->subSpecification] = inROFs.size();
60 };
61
62 // the callback to be set as hook for custom action when the writer is closed
63 auto finishWriting = [](TFile* outputfile, TTree* outputtree) {
64 const auto* brArr = outputtree->GetListOfBranches();
65 int64_t nent = 0;
66 for (const auto* brc : *brArr) {
67 int64_t n = ((const TBranch*)brc)->GetEntries();
68 if (nent && (nent != n)) {
69 LOG(error) << "Branches have different number of entries";
70 }
71 nent = n;
72 }
73 outputtree->SetEntries(nent);
74 outputfile->Write("", TObject::kOverwrite);
75 outputfile->Close();
76 };
77
78 // handler for labels
79 auto fillLabels = [detStr, digitSizes, rofSizes](TBranch& branch, std::vector<char> const& labelbuffer, DataRef const& ref) {
81 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
82 auto layer = static_cast<size_t>(dh->subSpecification);
83 LOG(info) << detStr << ": WRITING " << labels.getNElements() << " LABELS"
84 << std::format(" FOR LAYER {}", layer) << " WITH " << (*digitSizes)[layer]
85 << " DIGITS IN " << (*rofSizes)[layer] << " ROFS";
86
88 auto ptr = &outputcontainer;
90 outputcontainer.adopt(labelbuffer);
91 br->Fill();
92 br->ResetAddress();
93 };
94
95 auto getIndex = [](DataRef const& ref) -> size_t {
96 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
97 return static_cast<size_t>(dh->subSpecification);
98 };
99 auto getName = [](std::string base, size_t index) -> std::string {
100 return base + "_" + std::to_string(index);
101 };
102
103 std::vector<InputSpec> vecInpSpecDig, vecInpSpecROF, vecInpSpecLbl;
104 vecInpSpecDig.reserve(mLayers);
105 vecInpSpecROF.reserve(mLayers);
106 vecInpSpecLbl.reserve(mLayers);
107 for (int iLayer = 0; iLayer < mLayers; iLayer++) {
108 vecInpSpecDig.emplace_back(getName(detStr + "digits", iLayer), Origin, "DIGITS", iLayer);
109 vecInpSpecROF.emplace_back(getName(detStr + "digitsROF", iLayer), Origin, "DIGITSROF", iLayer);
110 vecInpSpecLbl.emplace_back(getName(detStr + "_digitsMCTR", iLayer), Origin, "DIGITSMCTR", iLayer);
111 }
112
113 return MakeRootTreeWriterSpec(("TRKDigitWriter" + std::string(dec ? "_dec" : "")).c_str(),
114 (detStrL + "digits.root").c_str(),
115 MakeRootTreeWriterSpec::TreeAttributes{.name = "o2sim", .title = detStr + " Digits tree"},
118 detStr + "Digit", "digit-branch",
119 mLayers,
120 digitSizeGetter,
121 getIndex,
122 getName},
124 detStr + "DigitROF", "digit-rof-branch",
125 mLayers,
126 rofSizeGetter,
127 getIndex,
128 getName},
130 detStr + "DigitMCTruth", "digit-mctruth-branch",
131 (mctruth ? mLayers : 0),
132 fillLabels,
133 getIndex,
134 getName},
136 detStr + "Calib", "digit-calib-branch",
137 (calib ? 1 : 0)})();
138}
139
140} // end namespace trk
141} // end namespace o2
std::vector< std::string > labels
std::string getName(const TDataMember *dm, int index, int size)
A const (ready only) version of MCTruthContainer.
Definition of the ITSMFT digit.
o2::framework::DataAllocator::SubSpecificationType SubSpecificationType
Calibration data from GBT data.
A special IO container - splitting a given vector to enable ROOT IO.
Definition of the ITSMFT ROFrame (trigger) record.
Configurable generator for RootTreeWriter processor spec.
TBranch * ptr
A read-only version of MCTruthContainer allowing for storage optimisation.
void adopt(gsl::span< const char > const input)
"adopt" (without taking ownership) from an existing buffer
o2::header::DataHeader::SubSpecificationType SubSpecificationType
Generate a processor spec for the RootTreeWriter utility.
static TBranch * remapBranch(TBranch &branchRef, T **newdata)
GLdouble n
Definition glcorearb.h:1982
GLuint index
Definition glcorearb.h:781
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLint ref
Definition glcorearb.h:291
constexpr o2::header::DataOrigin gDataOriginTRK
Definition DataHeader.h:584
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
o2::framework::DataProcessorSpec getTRKDigitWriterSpec(bool mctruth=true, bool dec=false, bool calib=false)
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)
Definition common.h:52
static constexpr size_t kNLayers
Definition AlmiraParam.h:28
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"