Project
Loading...
Searching...
No Matches
DigitsWriterSpec.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
18
19#include <random>
20#include <iostream>
21#include <fstream>
22#include <stdexcept>
23#include <array>
24#include <functional>
25#include <vector>
26#include <algorithm>
27
30
31#include "TTree.h"
32#include "TFile.h"
33
34#include <gsl/span>
35
37#include "Framework/InputSpec.h"
42#include "Framework/Lifetime.h"
43#include "Framework/Output.h"
44#include "Framework/Task.h"
46#include "Framework/Logger.h"
48
51
52#include "HMPIDBase/Geo.h"
54
55namespace o2
56{
57namespace hmpid
58{
59
60using namespace o2;
61using namespace o2::framework;
63
64//=======================
66{
67 LOG(info) << "[HMPID Write Root File From Digits stream - init()]";
68
69 // get line command options
70 mOutRootFileName = ic.options().get<std::string>("out-file");
71
72 mTriggers.clear();
73 mDigits.clear();
74
75 TString filename = TString::Format("%s", mOutRootFileName.c_str());
76 TString tit = TString::Format("HMPID Digits File Decoding");
77
78 LOG(info) << "Create the ROOT file " << filename.Data();
79 mfileOut = new TFile(TString::Format("%s", filename.Data()), "RECREATE");
80
81 mTheTree = new TTree("o2hmp", tit);
82 mTheTree->Branch("InteractionRecords", &mTriggers);
83 mTheTree->Branch("HMPIDDigits", &mDigits);
84
85 mExTimer.start();
86 return;
87}
88
90{
91 std::vector<o2::hmpid::Trigger> triggers;
92 std::vector<o2::hmpid::Digit> digits;
93
94 for (auto const& ref : InputRecordWalker(pc.inputs())) {
96 triggers = pc.inputs().get<std::vector<o2::hmpid::Trigger>>(ref);
97 LOG(info) << "We receive triggers =" << triggers.size();
98 }
100 digits = pc.inputs().get<std::vector<o2::hmpid::Digit>>(ref);
101 LOG(info) << "The size of the vector =" << digits.size();
102 }
103
104 for (int i = 0; i < triggers.size(); i++) {
105 LOG(info) << "Trigger Event Orbit = " << triggers[i].getOrbit() << " BC = " << triggers[i].getBc();
106 int startDigitsIndex = mDigits.size();
107 int numberOfDigits = 0;
108 for (int j = triggers[i].getFirstEntry(); j <= triggers[i].getLastEntry(); j++) {
109 mDigits.push_back(digits[j]); // append the cluster
110 numberOfDigits++;
111 }
112 mTriggers.push_back(triggers[i]);
113 mTriggers.back().setDataRange(startDigitsIndex, numberOfDigits);
114 }
115 }
116 mExTimer.stop();
117 return;
118}
119
121{
122 mExTimer.logMes("Received an End Of Stream !");
123 LOG(info) << "The size of digits vector =" << mDigits.size();
124 mTheTree->Fill();
125 mTheTree->Write();
126 mfileOut->Close();
127 mExTimer.logMes("Register Tree ! ");
128 return;
129}
130
131//_________________________________________________________________________________________________
133{
134 std::vector<o2::framework::InputSpec> inputs;
135 inputs.emplace_back("clusters", o2::header::gDataOriginHMP, "DIGITS", 0, Lifetime::Timeframe);
136 inputs.emplace_back("intrecord", o2::header::gDataOriginHMP, "INTRECORDS", 0, Lifetime::Timeframe);
137
138 std::vector<o2::framework::OutputSpec> outputs;
139
140 return DataProcessorSpec{
141 "HMP-DigitsToRoot",
142 inputs,
143 outputs,
144 AlgorithmSpec{adaptFromTask<DigitsToRootTask>()},
145 Options{{"out-file", VariantType::String, "hmpDigits.root", {"name of the output file"}}}};
146}
147
148} // namespace hmpid
149} // end namespace o2
A raw page parser for DPL input.
int32_t i
A helper class to iteratate over all parts of all input routes.
Configurable generator for RootTreeWriter processor spec.
Definition of the RAW Data Header.
uint32_t j
Definition RawData.h:0
ConfigParamRegistry const & options()
Definition InitContext.h:33
A helper class to iteratate over all parts of all input routes.
decltype(auto) get(R binding, int part=0) const
InputRecord & inputs()
The inputs associated with this processing context.
void init(framework::InitContext &ic) final
void endOfStream(framework::EndOfStreamContext &ec) override
This is invoked whenever we have an EndOfStream event.
void run(framework::ProcessingContext &pc) final
void stop()
stop : stops the timer
Definition Common.h:73
void start()
start : starts the timer
Definition Common.h:64
void logMes(std::string const message)
Definition Common.h:81
GLint ref
Definition glcorearb.h:291
constexpr o2::header::DataOrigin gDataOriginHMP
Definition DataHeader.h:569
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
o2::framework::DataProcessorSpec getDigitsToRootSpec(std::string inputSpec="HMP/DIGITS")
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
static bool match(DataRef const &ref, const char *binding)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits