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 its3
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 outputtree->Write("", TObject::kOverwrite);
65 outputfile->Close();
66 };
67
68 // handler for labels
69 // This is necessary since we can't store the original label buffer in a ROOT entry -- as is -- if it exceeds a certain size.
70 // We therefore convert it to a special split class.
71 auto fillLabels = [](TBranch& branch, std::vector<char> const& labelbuffer, DataRef const& /*ref*/) {
73 LOG(info) << "WRITING " << labels.getNElements() << " LABELS ";
74
76 auto ptr = &outputcontainer;
78 outputcontainer.adopt(labelbuffer);
79 br->Fill();
80 br->ResetAddress();
81 };
82
83 return MakeRootTreeWriterSpec((detStr + "DigitWriter" + (dec ? "_dec" : "")).c_str(),
84 (detStrL + "digits.root").c_str(),
85 MakeRootTreeWriterSpec::TreeAttributes{"o2sim", "Digits tree"},
87 // in case of labels we first read them as std::vector<char> and process them correctly in the fillLabels hook
88 BranchDefinition<std::vector<char>>{InputSpec{"digitsMCTR", detOrig, "DIGITSMCTR", 0},
89 (detStr + "DigitMCTruth").c_str(),
90 (mctruth ? 1 : 0), fillLabels},
91 BranchDefinition<std::vector<itsmft::MC2ROFRecord>>{InputSpec{"digitsMC2ROF", detOrig, "DIGITSMC2ROF", 0},
92 (detStr + "DigitMC2ROF").c_str(),
93 (mctruth ? 1 : 0)},
94 BranchDefinition<std::vector<itsmft::Digit>>{InputSpec{"digits", detOrig, "DIGITS", 0},
95 (detStr + "Digit").c_str(),
96 logger},
97 BranchDefinition<std::vector<itsmft::GBTCalibData>>{InputSpec{"calib", detOrig, "GBTCALIB", 0},
98 (detStr + "Calib").c_str(),
99 (calib ? 1 : 0)},
100 BranchDefinition<std::vector<itsmft::ROFRecord>>{InputSpec{"digitsROF", detOrig, "DIGITSROF", 0},
101 (detStr + "DigitROF").c_str()})();
102}
103
104DataProcessorSpec getITS3DigitWriterSpec(bool mctruth, bool dec, bool calib)
105{
106 return getDigitWriterSpec(mctruth, dec, calib, o2::header::gDataOriginIT3, o2::detectors::DetID::IT3);
107}
108
109} // end namespace its3
110} // 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
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 gDataOriginIT3
Definition DataHeader.h:582
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
o2::framework::DataProcessorSpec getITS3DigitWriterSpec(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)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"