Project
Loading...
Searching...
No Matches
DigitsReaderSpec.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
14#include <vector>
15#include <TTree.h>
18#include "Framework/Logger.h"
22
23#include <random>
24#include <iostream>
25#include <fstream>
26#include <stdexcept>
27#include <array>
28#include <functional>
29#include <vector>
30
31#include "CommonUtils/StringUtils.h" // o2::utils::Str
32
36#include "Framework/Lifetime.h"
37#include "Framework/Output.h"
39#include "Framework/Logger.h"
42
46
47#include "HMPIDBase/Geo.h"
48
49using namespace o2::framework;
50using namespace o2;
51using namespace o2::header;
52
53namespace o2
54{
55namespace hmpid
56{
57
59{
61 ic.options().get<std::string>("hmpid-digit-infile"));
62 mFile.reset(TFile::Open(filename.c_str()));
63
64 LOG(info) << "HMPID DigitWriterSpec::init() : Trying to read File : " << filename.c_str();
65
66 mDigitsReceived = 0;
67 if (!mFile->IsOpen()) {
68 LOG(error) << "HMPID DigitWriterSpec::init() : Did not find any digits file " << filename.c_str() << " file !";
69 throw std::runtime_error("cannot open input digits file");
70 }
71
72 if ((TTree*)mFile->Get("o2sim") != nullptr) {
73 mTree.reset((TTree*)mFile->Get("o2sim"));
74 } else if ((TTree*)mFile->Get("o2hmp") != nullptr) {
75 mTree.reset((TTree*)mFile->Get("o2hmp"));
76 } else {
77 LOG(error) << "Did not find o2hmp tree in " << filename.c_str();
78 throw std::runtime_error("Did Not find Any correct Tree in HMPID Digits File");
79 }
80
81 if (!mTree) {
82 LOG(error) << "Did not find o2hmp tree in " << filename.c_str();
83 throw std::runtime_error("Did Not find Any correct Tree in HMPID Digits File");
84 } /*else {
85 LOG(info) << "HMPID DigitWriterSpec::init() : Reading From Branch o2hmp" << File : " << filename.c_str()";
86 } */
87}
88
90{
91 std::vector<o2::hmpid::Digit> mDigitsFromFile, *mDigitsFromFilePtr = &mDigitsFromFile;
92 std::vector<o2::hmpid::Trigger> mTriggersFromFile, *mTriggersFromFilePtr = &mTriggersFromFile;
93
94 /* */
95 if (mTree->GetBranchStatus("HMPDigit")) {
96 mTree->SetBranchAddress("HMPDigit", &mDigitsFromFilePtr);
97 } else if (mTree->GetBranchStatus("HMPIDDigits")) {
98 mTree->SetBranchAddress("HMPIDDigits", &mDigitsFromFilePtr);
99 } else {
100 LOG(error)
101 << "HMPID DigitWriterSpec::init() : Did not find any branch for Digits";
102 throw std::runtime_error("Did Not find Any correct Branch for Digits in HMPID Digits File");
103 }
104
105 if (mTree->GetBranchStatus("InteractionRecords")) {
106 mTree->SetBranchAddress("InteractionRecords", &mTriggersFromFilePtr);
107 } else {
108 LOG(error)
109 << "HMPID DigitWriterSpec::init() : Did not find branch for Triggers";
110 throw std::runtime_error("Did Not find Branch For triggers in HMPID Digits File");
111 }
112 // mTree->Print("toponly");
113
114 auto ent = mTree->GetReadEntry() + 1;
115 assert(ent < mTree->GetEntries()); // this should not happen
116 mTree->GetEntry(ent);
117
118 pc.outputs().snapshot(Output{"HMP", "DIGITS", 0}, mDigitsFromFile);
119 pc.outputs().snapshot(Output{"HMP", "INTRECORDS", 0}, mTriggersFromFile);
120 mDigitsReceived += mDigitsFromFile.size();
121 LOG(info) << "[HMPID DigitsReader - run() ] digits = " << mDigitsFromFile.size();
122
123 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
125 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
126 mExTimer.stop();
127 mExTimer.logMes("End DigitsReader ! digits = " +
128 std::to_string(mDigitsReceived));
129 }
130}
131
133{
134 std::vector<OutputSpec> outputs;
135 outputs.emplace_back("HMP", "DIGITS", 0, o2::framework::Lifetime::Timeframe);
136 outputs.emplace_back("HMP", "INTRECORDS", 0, o2::framework::Lifetime::Timeframe);
137
138 return DataProcessorSpec{
139 "HMP-DigitReader",
140 Inputs{},
141 outputs,
142 AlgorithmSpec{adaptFromTask<DigitReader>()},
143 Options{{"hmpid-digit-infile" /*"/qc-hmpid-digits"*/, VariantType::String, "hmpiddigits.root", {"Name of the input file with digits"}},
144 {"input-dir", VariantType::String, "./", {"Input directory"}}}};
145}
146
147} // namespace hmpid
148} // namespace o2
A raw page parser for DPL input.
A helper class to iteratate over all parts of all input routes.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the Names Generator class.
Definition of the RAW Data Header.
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
Definition InitContext.h:33
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
ServiceRegistryRef services()
The services registry associated with this processing context.
virtual void endOfStream(EndOfStreamContext &context)
This is invoked whenever we have an EndOfStream event.
Definition Task.h:43
void run(o2::framework::ProcessingContext &pc) final
void init(o2::framework::InitContext &ic) final
void stop()
stop : stops the timer
Definition Common.h:73
void logMes(std::string const message)
Definition Common.h:81
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
O2 data header classes and API, v0.1.
Definition DetID.h:49
o2::framework::DataProcessorSpec getDigitsReaderSpec()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"