Project
Loading...
Searching...
No Matches
CalibInfoReaderSpec.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 <unistd.h>
16
17#include "TChain.h"
18#include "TTree.h"
19
22#include "Framework/Logger.h"
25
26using namespace o2::framework;
27using namespace o2::tof;
28
29namespace o2
30{
31namespace tof
32{
33
34constexpr o2::header::DataDescription ddCalib{"CALIBDATA"}, ddCalib_tpc{"CALIBDATA_TPC"}, ddDia{"DIAFREQ"};
35
37{
38 LOG(debug) << "Init CalibInfo reader!";
39 auto fname = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")), mFileName);
40 mFile = fopen(fname.c_str(), "r");
41 if (!mFile) {
42 LOG(error) << "Cannot open the " << fname << " file !";
43 mState = 0;
44 return;
45 }
46 mState = 1;
47}
48
50{
51 if (mState != 1) {
52 return;
53 }
54 auto& timingInfo = pc.services().get<o2::framework::TimingInfo>();
55 char filename[100];
56
57 if ((mTree && mCurrentEntry < mTree->GetEntries()) || fscanf(mFile, "%s", filename) == 1) {
58 if (!mTree || mCurrentEntry >= mTree->GetEntries()) {
59 TFile* fin = TFile::Open(filename);
60 mTree = (TTree*)fin->Get("calibTOF");
61 mCurrentEntry = 0;
62 if (mTree->GetBranch("TOFCalibInfo")) {
63 mTree->SetBranchAddress("TOFCalibInfo", &mPvect);
64 }
65 mTree->SetBranchAddress("TOFDiaInfo", &mPdia);
66
67 LOG(debug) << "Open " << filename;
68
69 mIndices.clear();
70 for (unsigned long i = 0; i < mTree->GetEntries(); i++) { // check time order inside the tree
71 mTree->GetEvent(i);
72 const auto& info = mDia.getTFIDInfo();
73 mIndices.push_back(std::make_pair(i, info.tfCounter));
74 }
75 std::sort(mIndices.begin(), mIndices.end(),
76 [&](const auto& a, const auto& b) {
77 return a.second < b.second;
78 });
79 }
80 if ((mGlobalEntry % mNinstances) == mInstance) {
81 mTree->GetEvent(mIndices[mCurrentEntry].first);
82
83 // add TFIDInfo
84 const auto& info = mDia.getTFIDInfo();
85 timingInfo.firstTForbit = info.firstTForbit;
86 timingInfo.tfCounter = info.tfCounter;
87 timingInfo.runNumber = info.runNumber;
88 // timingInfo.timeslice = info.startTime; // NOT TO BE SET (done by DPL)
89 timingInfo.creation = info.creation;
90 // printf("TF=%ld, creationTime=%ld: firstTForbit=%ld, runNumber=%d, startTime=%ld\n",timingInfo.tfCounter,timingInfo.creation,timingInfo.firstTForbit,timingInfo.runNumber,timingInfo.timeslice);
91
92 LOG(debug) << "Current entry " << mCurrentEntry;
93 LOG(debug) << "Send " << mVect.size() << " calib infos";
94
96
98 usleep(100);
99 }
100 mGlobalEntry++;
101 mCurrentEntry++;
102 } else {
103 mState = 2;
105 }
106 return;
107}
108
109DataProcessorSpec getCalibInfoReaderSpec(int instance, int ninstances, const char* filename, bool toftpc)
110{
111 std::vector<OutputSpec> outputs;
112 outputs.emplace_back(o2::header::gDataOriginTOF, toftpc ? ddCalib_tpc : ddCalib, 0, Lifetime::Timeframe);
113
114 std::string nameSpec = "tof-calibinfo-reader";
115 if (toftpc) {
116 nameSpec += "-tpc";
117 }
118 if (ninstances > 1) {
119 nameSpec += fmt::format("-{:d}", instance);
120 }
121
122 outputs.emplace_back(o2::header::gDataOriginTOF, ddDia, 0, Lifetime::Timeframe);
123
124 return DataProcessorSpec{
125 nameSpec,
126 Inputs{},
127 outputs,
128 AlgorithmSpec{adaptFromTask<CalibInfoReader>(instance, ninstances, filename)},
129 Options{{"input-dir", VariantType::String, "none", {"Input directory"}}}};
130}
131} // namespace tof
132} // namespace o2
int32_t i
Definition of the Names Generator class.
std::ostringstream debug
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(ProcessingContext &pc) final
void init(InitContext &ic) final
const o2::dataformats::TFIDInfo & getTFIDInfo() const
Definition Diagnostic.h:94
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
constexpr o2::header::DataDescription ddDia
constexpr o2::header::DataDescription ddCalib
framework::DataProcessorSpec getCalibInfoReaderSpec(int instance, int ninstances, const char *filename, bool toftpc=false)
constexpr o2::header::DataDescription ddCalib_tpc
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
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"