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
18#include "Headers/DataHeader.h"
24#include <vector>
25#include <string>
26#include <algorithm>
27
28using namespace o2::framework;
30
31namespace o2
32{
33namespace itsmft
34{
35
36template <typename T>
39
42DataProcessorSpec getDigitWriterSpec(bool mctruth, bool dec, bool calib, o2::header::DataOrigin detOrig, o2::detectors::DetID detId)
43{
44 std::string detStr = o2::detectors::DetID::getName(detId);
45 std::string detStrL = dec ? "o2_" : ""; // for decoded digits prepend by o2
46 detStrL += detStr;
47 std::transform(detStrL.begin(), detStrL.end(), detStrL.begin(), ::tolower);
48 auto logger = [](std::vector<o2::itsmft::Digit> const& inDigits) {
49 LOG(info) << "RECEIVED DIGITS SIZE " << inDigits.size();
50 };
51
52 // the callback to be set as hook for custom action when the writer is closed
53 auto finishWriting = [](TFile* outputfile, TTree* outputtree) {
54 const auto* brArr = outputtree->GetListOfBranches();
55 int64_t nent = 0;
56 for (const auto* brc : *brArr) {
57 int64_t n = ((const TBranch*)brc)->GetEntries();
58 if (nent && (nent != n)) {
59 LOG(error) << "Branches have different number of entries";
60 }
61 nent = n;
62 }
63 outputtree->SetEntries(nent);
64 // do not use TTree::Write .. as this writes to default directory (not the associated file)
65 // instead of outputtree->Write("", TObject::kOverwrite)
66 // --> better use TFile::Write or TFile::WriteObject
67 outputfile->Write("", TObject::kOverwrite);
68 outputfile->Close();
69 };
70
71 // handler for labels
72 // This is necessary since we can't store the original label buffer in a ROOT entry -- as is -- if it exceeds a certain size.
73 // We therefore convert it to a special split class.
74 auto fillLabels = [](TBranch& branch, std::vector<char> const& labelbuffer, DataRef const& /*ref*/) {
76 LOG(info) << "WRITING " << labels.getNElements() << " LABELS ";
77
79 auto ptr = &outputcontainer;
81 outputcontainer.adopt(labelbuffer);
82 br->Fill();
83 br->ResetAddress();
84 };
85
86 return MakeRootTreeWriterSpec((detStr + "DigitWriter" + (dec ? "_dec" : "")).c_str(),
87 (detStrL + "digits.root").c_str(),
88 MakeRootTreeWriterSpec::TreeAttributes{"o2sim", "Digits tree"},
90 // in case of labels we first read them as std::vector<char> and process them correctly in the fillLabels hook
91 BranchDefinition<std::vector<char>>{InputSpec{(detStr + "_digitsMCTR").c_str(), detOrig, "DIGITSMCTR", 0},
92 (detStr + "DigitMCTruth").c_str(),
93 (mctruth ? 1 : 0), fillLabels},
94 BranchDefinition<std::vector<itsmft::MC2ROFRecord>>{InputSpec{(detStr + "_digitsMC2ROF").c_str(), detOrig, "DIGITSMC2ROF", 0},
95 (detStr + "DigitMC2ROF").c_str(),
96 (mctruth ? 1 : 0)},
97 BranchDefinition<std::vector<itsmft::Digit>>{InputSpec{(detStr + "digits").c_str(), detOrig, "DIGITS", 0},
98 (detStr + "Digit").c_str(),
99 logger},
100 BranchDefinition<std::vector<itsmft::GBTCalibData>>{InputSpec{(detStr + "calib").c_str(), detOrig, "GBTCALIB", 0},
101 (detStr + "Calib").c_str(),
102 (calib ? 1 : 0)},
103 BranchDefinition<std::vector<itsmft::ROFRecord>>{InputSpec{(detStr + "digitsROF").c_str(), detOrig, "DIGITSROF", 0},
104 (detStr + "DigitROF").c_str()})();
105}
106
107DataProcessorSpec getITSDigitWriterSpec(bool mctruth, bool dec, bool calib)
108{
110}
111
112DataProcessorSpec getMFTDigitWriterSpec(bool mctruth, bool dec, bool calib)
113{
115}
116
117} // end namespace itsmft
118} // end namespace o2
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
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:145
static constexpr ID ITS
Definition DetID.h:63
static constexpr ID MFT
Definition DetID.h:71
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
constexpr o2::header::DataOrigin gDataOriginMFT
Definition DataHeader.h:572
constexpr o2::header::DataOrigin gDataOriginITS
Definition DataHeader.h:570
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
o2::framework::DataProcessorSpec getITSDigitWriterSpec(bool mctruth=true, bool dec=false, bool calib=false)
DataProcessorSpec getDigitWriterSpec(bool mctruth, bool dec, bool calib, o2::header::DataOrigin detOrig, o2::detectors::DetID detId)
o2::framework::DataProcessorSpec getMFTDigitWriterSpec(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 ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"