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"
18#include "TRKBase/Specs.h"
22#include "Headers/DataHeader.h"
28#include <vector>
29#include <string>
30#include <algorithm>
31#include <cctype>
32#include <format>
33
34using namespace o2::framework;
36
37namespace o2
38{
39namespace trk
40{
41
42template <typename T>
45
46template <int DetID>
47DataProcessorSpec getDigitWriterSpec(bool mctruth, bool dec, bool calib)
48{
49 static_assert(DetID == o2::detectors::DetID::TRK || DetID == o2::detectors::DetID::FT3, "only TRK and FT3 digit writers are supported");
50 static constexpr o2::header::DataOrigin Origin = DetID == o2::detectors::DetID::TRK ? o2::header::gDataOriginTRK : o2::header::gDataOriginFT3;
51 const int mLayers = DetID == o2::detectors::DetID::TRK ? o2::trk::AlmiraParam::kNLayers : o2::trk::constants::MLOTDisks::nLayers;
52 std::string detStr = o2::detectors::DetID(DetID).getName();
53 auto detStrL = detStr;
54 std::transform(detStrL.begin(), detStrL.end(), detStrL.begin(), [](unsigned char c) { return std::tolower(c); });
55 if (dec) {
56 detStrL = "o2_" + detStrL;
57 }
58
59 auto digitSizes = std::make_shared<std::vector<size_t>>(mLayers, 0);
60 auto digitSizeGetter = [digitSizes](std::vector<o2::trkft3::Digit> const& inDigits, DataRef const& ref) {
61 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
62 (*digitSizes)[dh->subSpecification] = inDigits.size();
63 };
64 auto rofSizes = std::make_shared<std::vector<size_t>>(mLayers, 0);
65 auto rofSizeGetter = [rofSizes](std::vector<o2::trkft3::ROFRecord> const& inROFs, DataRef const& ref) {
66 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
67 (*rofSizes)[dh->subSpecification] = inROFs.size();
68 };
69
70 // the callback to be set as hook for custom action when the writer is closed
71 auto finishWriting = [](TFile* outputfile, TTree* outputtree) {
72 const auto* brArr = outputtree->GetListOfBranches();
73 int64_t nent = 0;
74 for (const auto* brc : *brArr) {
75 int64_t n = ((const TBranch*)brc)->GetEntries();
76 if (nent && (nent != n)) {
77 LOG(error) << "Branches have different number of entries";
78 }
79 nent = n;
80 }
81 outputtree->SetEntries(nent);
82 outputfile->Write("", TObject::kOverwrite);
83 outputfile->Close();
84 };
85
86 // handler for labels
87 auto fillLabels = [detStr, digitSizes, rofSizes](TBranch& branch, std::vector<char> const& labelbuffer, DataRef const& ref) {
89 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
90 auto layer = static_cast<size_t>(dh->subSpecification);
91 LOG(info) << detStr << ": WRITING " << labels.getNElements() << " LABELS"
92 << std::format(" FOR LAYER {}", layer) << " WITH " << (*digitSizes)[layer]
93 << " DIGITS IN " << (*rofSizes)[layer] << " ROFS";
94
96 auto ptr = &outputcontainer;
98 outputcontainer.adopt(labelbuffer);
99 br->Fill();
100 br->ResetAddress();
101 };
102
103 auto getIndex = [](DataRef const& ref) -> size_t {
104 auto const* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
105 return static_cast<size_t>(dh->subSpecification);
106 };
107 auto getName = [](std::string base, size_t index) -> std::string {
108 return base + "_" + std::to_string(index);
109 };
110
111 std::vector<InputSpec> vecInpSpecDig, vecInpSpecROF, vecInpSpecLbl;
112 vecInpSpecDig.reserve(mLayers);
113 vecInpSpecROF.reserve(mLayers);
114 vecInpSpecLbl.reserve(mLayers);
115 for (int iLayer = 0; iLayer < mLayers; iLayer++) {
116 vecInpSpecDig.emplace_back(getName(detStr + "digits", iLayer), Origin, "DIGITS", iLayer);
117 vecInpSpecROF.emplace_back(getName(detStr + "digitsROF", iLayer), Origin, "DIGITSROF", iLayer);
118 vecInpSpecLbl.emplace_back(getName(detStr + "_digitsMCTR", iLayer), Origin, "DIGITSMCTR", iLayer);
119 }
120
121 return MakeRootTreeWriterSpec((detStr + "DigitWriter" + std::string(dec ? "_dec" : "")).c_str(),
122 (detStrL + "digits.root").c_str(),
123 MakeRootTreeWriterSpec::TreeAttributes{.name = "o2sim", .title = detStr + " Digits tree"},
126 detStr + "Digit", "digit-branch",
127 mLayers,
128 digitSizeGetter,
129 getIndex,
130 getName},
132 detStr + "DigitROF", "digit-rof-branch",
133 mLayers,
134 rofSizeGetter,
135 getIndex,
136 getName},
138 detStr + "DigitMCTruth", "digit-mctruth-branch",
139 (mctruth ? mLayers : 0),
140 fillLabels,
141 getIndex,
142 getName},
144 detStr + "Calib", "digit-calib-branch",
145 (calib ? 1 : 0)})();
146}
147
148DataProcessorSpec getTRKDigitWriterSpec(bool mctruth, bool dec, bool calib)
149{
150 return getDigitWriterSpec<o2::detectors::DetID::TRK>(mctruth, dec, calib);
151}
152
153DataProcessorSpec getFT3DigitWriterSpec(bool mctruth, bool dec, bool calib)
154{
155 return getDigitWriterSpec<o2::detectors::DetID::FT3>(mctruth, dec, calib);
156}
157
158} // end namespace trk
159} // 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.
o2::framework::DataAllocator::SubSpecificationType SubSpecificationType
Calibration data from GBT data.
A special IO container - splitting a given vector to enable ROOT IO.
Configurable generator for RootTreeWriter processor spec.
uint32_t c
Definition RawData.h:2
specs of the ALICE3 TRK
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
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
static constexpr const char * getName(ID id)
names of defined detectors
Definition DetID.h:146
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
constexpr o2::header::DataOrigin gDataOriginFT3
Definition DataHeader.h:585
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
DataProcessorSpec getDigitWriterSpec(bool mctruth, bool dec, bool calib)
o2::framework::DataProcessorSpec getFT3DigitWriterSpec(bool mctruth=true, bool dec=false, bool calib=false)
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:29
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"