Project
Loading...
Searching...
No Matches
TOFCalibCollectorWriterSpec.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
12#ifndef O2_CALIBRATION_TOFCALIB_COLLECTOR_WRITER_H
13#define O2_CALIBRATION_TOFCALIB_COLLECTOR_WRITER_H
14
17
20#include <TTree.h>
21#include <gsl/span>
22
23using namespace o2::framework;
24
25namespace o2
26{
27namespace calibration
28{
29
31{
32
33 using Geo = o2::tof::Geo;
34
35 public:
37 {
38 TString filename = TString::Format("collTOF_%d.root", mCount);
39 LOG(debug) << "opening file " << filename.Data();
40 mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE"));
41 mOutputTree = std::make_unique<TTree>("treeCollectedCalibInfo", "Tree with TOF calib info for Time Slewing");
42 mOutputTree->Branch(mOutputBranchName.data(), &mPTOFCalibInfoOut);
43 }
44
46 {
47 mCount = 0;
49 mTOFCalibInfoOut.reserve(500 * o2::tof::Geo::NCHANNELS); // should be a reasonable number of entries per channel, which allows 1 GB of data
50 }
51
53 {
54 auto collectedInfo = pc.inputs().get<gsl::span<o2::dataformats::CalibInfoTOF>>("collectedInfo");
55 auto entriesPerChannel = pc.inputs().get<gsl::span<int>>("entriesCh");
56 int offsetStart = 0;
57 for (int ich = 0; ich < o2::tof::Geo::NCHANNELS; ich++) {
58 mTOFCalibInfoOut.clear();
59 if (entriesPerChannel[ich] > 0) {
60 mTOFCalibInfoOut.resize(entriesPerChannel[ich]);
61 auto subSpanVect = collectedInfo.subspan(offsetStart, entriesPerChannel[ich]);
62 memcpy(&mTOFCalibInfoOut[0], subSpanVect.data(), sizeof(o2::dataformats::CalibInfoTOF) * subSpanVect.size());
63 const o2::dataformats::CalibInfoTOF* tmp = subSpanVect.data();
64 }
65 mOutputTree->Fill();
66 offsetStart += entriesPerChannel[ich];
67 }
68 sendOutput(pc.outputs());
69 }
70
72 {
73 mIsEndOfStream = true;
74 sendOutput(ec.outputs());
75 }
76
77 private:
78 int mCount = 0; // how many times we filled the tree
79 bool mIsEndOfStream = false;
80 std::vector<o2::dataformats::CalibInfoTOF> mTOFCalibInfoOut, *mPTOFCalibInfoOut = &mTOFCalibInfoOut;
81 std::unique_ptr<TTree> mOutputTree;
82 std::string mTOFCalibInfoBranchName = "TOFCalibInfo";
83 std::string mOutputBranchName = "TOFCollectedCalibInfo";
84 std::unique_ptr<TFile> mfileOut = nullptr; // file in which to write the output
85
86 //________________________________________________________________
87 void sendOutput(DataAllocator& output)
88 {
89 // This is to fill the tree.
90 // One file with an empty tree will be created at the end, because we have to have a
91 // tree opened before processing, since we do not know a priori if something else
92 // will still come. The size of this extra file is ~6.5 kB
93
94 mfileOut->cd();
95 mOutputTree->Write();
96 mOutputTree.reset();
97 mfileOut.reset();
98 mCount++;
99 if (!mIsEndOfStream) {
101 }
102 }
103};
104} // namespace calibration
105
106namespace framework
107{
108
109DataProcessorSpec getTOFCalibCollectorWriterSpec()
110{
112 std::vector<InputSpec> inputs;
113 inputs.emplace_back("collectedInfo", o2::header::gDataOriginTOF, "COLLECTEDINFO");
114 inputs.emplace_back("entriesCh", o2::header::gDataOriginTOF, "ENTRIESCH");
115
116 std::vector<OutputSpec> outputs; // empty
117
118 return DataProcessorSpec{
119 "calib-tofcalib-collector-writer",
120 inputs,
121 outputs,
122 AlgorithmSpec{adaptFromTask<device>()},
123 Options{}};
124}
125
126} // namespace framework
127} // namespace o2
128
129#endif
Class to store the output of the matching to TOF for calibration.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
std::ostringstream debug
void init(o2::framework::InitContext &ic) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void run(o2::framework::ProcessingContext &pc) final
TOF geo parameters (only statics)
Definition Geo.h:28
static constexpr int NCHANNELS
Definition Geo.h:124
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"