Project
Loading...
Searching...
No Matches
TOFClusterWriterSplitterSpec.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_TOFCLUSTER_SPLITTER_WRITER_H
13#define O2_TOFCLUSTER_SPLITTER_WRITER_H
14
17
21#include "Framework/Task.h"
23#include "Framework/Logger.h"
24#include <TTree.h>
25#include <TFile.h>
26#include <gsl/span>
27
28using namespace o2::framework;
29
30namespace o2
31{
32namespace tof
33{
35{
36 using OutputType = std::vector<o2::tof::Cluster>;
37
38 std::string mBaseName;
39
40 public:
41 TOFClusterWriterSplitter(int nTF) : mTFthr(nTF) {}
42
44 {
45 TString filename = TString::Format("%s_%06d.root", mBaseName.c_str(), mCount);
46 LOG(debug) << "opening file " << filename.Data();
47 mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE"));
48 mOutputTree = std::make_unique<TTree>("o2sim", "Tree with TOF clusters");
49 mOutputTree->Branch("TOFCluster", &mPClusters);
50
51 mNTF = 0;
52 }
53
55 {
56 mBaseName = ic.options().get<std::string>("output-base-name");
57
58 mCount = 0;
60 }
61
63 {
64 auto clusters = pc.inputs().get<OutputType>("clusters");
65 mPClusters = &clusters;
66 mOutputTree->Fill();
67
68 mNTF++;
69
70 if (mNTF >= mTFthr) {
71 sendOutput();
72 }
73 }
74
76 {
77 mIsEndOfStream = true;
78 sendOutput();
79 }
80
81 private:
82 int mCount = 0; // how many times we filled the tree
83 int mNTF = 0;
84 int mTFthr = 1;
85 bool mIsEndOfStream = false;
86 OutputType mClusters;
87 const OutputType* mPClusters = &mClusters;
88
89 std::unique_ptr<TTree> mOutputTree;
90 std::unique_ptr<TFile> mfileOut = nullptr; // file in which to write the output
91
92 //________________________________________________________________
93 void sendOutput()
94 {
95 // This is to fill the tree.
96 // One file with an empty tree will be created at the end, because we have to have a
97 // tree opened before processing, since we do not know a priori if something else
98 // will still come. The size of this extra file is ~6.5 kB
99
100 mfileOut->cd();
101 mOutputTree->Write();
102 mOutputTree.reset();
103 mfileOut.reset();
104 mCount++;
105 if (!mIsEndOfStream) {
107 }
108 }
109};
110} // namespace tof
111
112namespace framework
113{
114
115DataProcessorSpec getTOFClusterWriterSplitterSpec(int nTF)
116{
117 std::vector<InputSpec> inputs;
118 inputs.emplace_back("clusters", o2::header::gDataOriginTOF, "CLUSTERS");
119
120 std::vector<OutputSpec> outputs; // empty
121
122 return DataProcessorSpec{
123 "tof-cluster-splitter-writer",
124 inputs,
125 outputs,
126 AlgorithmSpec{adaptFromTask<o2::tof::TOFClusterWriterSplitter>(nTF)},
127 Options{{"output-base-name", VariantType::String, "tofclusters", {"Name of the input file (root extension will be added)"}}}};
128}
129
130} // namespace framework
131} // namespace o2
132
133#endif
Definition of the TOF cluster.
std::ostringstream debug
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void init(o2::framework::InitContext &ic) final
void run(o2::framework::ProcessingContext &pc) final
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< o2::tof::CalibInfoCluster > OutputType
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"
std::vector< Cluster > clusters