Project
Loading...
Searching...
No Matches
FITDigitWriterSpec.h
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
14#ifndef O2_FITDIGITWRITER_H
15#define O2_FITDIGITWRITER_H
16
17#include <Framework/Logger.h>
20#include "Framework/InputSpec.h"
21#include <tuple>
22#include <vector>
23#include <string>
24
25using namespace o2::framework;
26
27namespace o2
28{
29namespace fit
30{
31template <typename RawReaderType, typename MCLabelContainerType /*For example: =o2::dataformats::MCTruthContainer<o2::ft0::MCLabel>*/>
33 typedef RawReaderType RawReader_t;
34 typedef MCLabelContainerType MCLabelContainer_t; //should be defined as type field within Digit structure
35 typedef typename RawReader_t::Digit_t Digit_t;
36 typedef typename Digit_t::DetTrigInput_t DetTrigInput_t;
37 typedef typename RawReader_t::SubDigit_t SubDigit_t; //tuple of vectors
38 typedef typename RawReader_t::SingleSubDigit_t SingleSubDigit_t; //tuple of vectors
39 typedef typename RawReader_t::IndexesSubDigit IndexesSubDigit_t;
40 typedef typename RawReader_t::IndexesSingleSubDigit IndexesSingleSubDigit_t;
41
42 template <typename T>
44
46 {
47 if (trigInp) {
48 return callMakeSpec<true>(mctruth, dataOrigin, IndexesSubDigit_t{}, IndexesSingleSubDigit_t{});
49 } else {
50 return callMakeSpec<false>(mctruth, dataOrigin, IndexesSubDigit_t{}, IndexesSingleSubDigit_t{});
51 }
52 }
53
54 template <typename T, typename... Args>
55 static auto getBranchDef(o2::header::DataOrigin dataOrigin, Args&&... args)
56 {
57 std::string detName = dataOrigin.template as<std::string>();
58 std::string detNameLower = detName;
59 std::for_each(detNameLower.begin(), detNameLower.end(), [](char& c) { c = ::tolower(c); });
60 auto dplName = T::sChannelNameDPL;
61 auto dplLabel = std::string{dplName};
62 std::for_each(dplLabel.begin(), dplLabel.end(), [](char& c) { c = ::tolower(c); });
63 //auto branchName = std::string{detName + dplName};
64 auto branchName = std::string{T::sDigitBranchName};
65 auto optionStr = std::string{detNameLower + "-" + dplName + "-branch-name"};
66 //LOG(info)<<"Branch: "<<dplLabel.c_str()<< "|" <<detName<<" | "<<T::sChannelNameDPL<<" | "<<branchName<<" | "<<optionStr<<" | "<<(detName+dplName);
67 return BranchDefinition<std::vector<T>>{InputSpec{dplLabel.c_str(), dataOrigin, T::sChannelNameDPL}, branchName.c_str(), optionStr.c_str(), std::forward<Args>(args)...};
68 }
69
70 template <std::size_t N, typename TupleType, typename... Args>
71 static auto getBranchDefFromTuple(o2::header::DataOrigin dataOrigin, Args&&... args)
72 {
73 using ObjType = typename std::tuple_element<N, TupleType>::type::value_type;
74 return getBranchDef<ObjType>(dataOrigin, std::forward<Args>(args)...);
75 }
76
77 template <bool trigInp, std::size_t... IsubDigits, std::size_t... IsingleSubDigits>
78 static auto callMakeSpec(bool mctruth, o2::header::DataOrigin dataOrigin, std::index_sequence<IsubDigits...>, std::index_sequence<IsingleSubDigits...>)
79 {
82
83 std::string detName = dataOrigin.template as<std::string>();
84 std::string detNameLower = detName;
85 std::for_each(detNameLower.begin(), detNameLower.end(), [](char& c) { c = ::tolower(c); });
86 // Spectators for logging
87 auto logger = [](std::vector<Digit_t> const& vecDigits) {
88 LOG(info) << "FITDigitWriter pulled " << vecDigits.size() << " digits";
89 };
90 // the callback to be set as hook for custom action when the writer is closed
91 auto finishWriting = [](TFile* outputfile, TTree* outputtree) {
92 const auto* brArr = outputtree->GetListOfBranches();
93 int64_t nent = 0;
94 for (const auto* brc : *brArr) {
95 int64_t n = ((const TBranch*)brc)->GetEntries();
96 if (nent && (nent != n)) {
97 LOG(error) << "Branches have different number of entries";
98 }
99 nent = n;
100 }
101 outputtree->SetEntries(nent);
102 outputtree->Write();
103 outputfile->Close();
104 };
105 auto digitsdef = getBranchDef<Digit_t>(dataOrigin, 1, logger);
106 auto trginputdef = getBranchDef<DetTrigInput_t>(dataOrigin);
107 auto labelsdef = BranchDefinition<MCLabelContainer_t>{InputSpec{"labelinput", dataOrigin, "DIGITSMCTR"}, std::string{detName + "DIGITSMCTR"}.c_str(), mctruth ? 1 : 0};
108 if constexpr (trigInp == false) {
110 std::string{detName + "DigitWriterRaw"}.c_str(),
111 std::string{"o2_" + detNameLower + "digits.root"}.c_str(),
112 "o2sim",
114 getBranchDefFromTuple<IsubDigits, SubDigit_t>(dataOrigin)...,
115 getBranchDefFromTuple<IsingleSubDigits, SingleSubDigit_t>(dataOrigin)...,
116 std::move(digitsdef),
117 std::move(labelsdef))();
118 } else {
120 std::string{detName + "DigitWriter"}.c_str(),
121 std::string{detNameLower + "digits.root"}.c_str(),
122 "o2sim",
124 getBranchDefFromTuple<IsubDigits, SubDigit_t>(dataOrigin)...,
125 getBranchDefFromTuple<IsingleSubDigits, SingleSubDigit_t>(dataOrigin)...,
126 std::move(digitsdef),
127 std::move(trginputdef),
128 std::move(labelsdef))();
129 }
130 }
131};
132} // namespace fit
133} // namespace o2
134
135#endif /* O2_FITDIGITWRITER_H */
Configurable generator for RootTreeWriter processor spec.
uint32_t c
Definition RawData.h:2
Generate a processor spec for the RootTreeWriter utility.
GLdouble n
Definition glcorearb.h:1982
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TFitResultPtr fit(const size_t nBins, const T *arr, const T xMin, const T xMax, TF1 &func, std::string_view option="")
Definition fit.h:59
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static auto getBranchDefFromTuple(o2::header::DataOrigin dataOrigin, Args &&... args)
RawReader_t::IndexesSingleSubDigit IndexesSingleSubDigit_t
static o2::framework::DataProcessorSpec getFITDigitWriterSpec(bool mctruth, bool trigInp, o2::header::DataOrigin dataOrigin)
RawReader_t::SingleSubDigit_t SingleSubDigit_t
static auto getBranchDef(o2::header::DataOrigin dataOrigin, Args &&... args)
Digit_t::DetTrigInput_t DetTrigInput_t
RawReader_t::IndexesSubDigit IndexesSubDigit_t
static auto callMakeSpec(bool mctruth, o2::header::DataOrigin dataOrigin, std::index_sequence< IsubDigits... >, std::index_sequence< IsingleSubDigits... >)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"