Project
Loading...
Searching...
No Matches
TOFRawWriterSpec.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
17#include "Framework/Logger.h"
19#include "TOFBase/Geo.h"
21#include <filesystem>
22#include <fstream>
23#include <iostream>
24#include <iomanip>
25#include <cstring>
27
28using namespace o2::framework;
29
30namespace o2
31{
32namespace tof
33{
35{
36 // get the option from the init context
37 mOutFileName = ic.options().get<std::string>("tof-raw-outfile");
38 mOutDirName = ic.options().get<std::string>("tof-raw-outdir");
39 mFileFor = ic.options().get<std::string>("file-for");
40 mOldFormat = ic.options().get<bool>("use-old-format");
41 LOG(debug) << "Raw output file: " << mOutFileName.c_str();
42
43 // if needed, create output directory
44 if (!std::filesystem::exists(mOutDirName)) {
45 if (!std::filesystem::create_directories(mOutDirName)) {
46 LOG(fatal) << "could not create output directory " << mOutDirName;
47 } else {
48 LOG(debug) << "created output directory " << mOutDirName;
49 }
50 }
51}
52
54{
55 auto digits = pc.inputs().get<std::vector<o2::tof::Digit>*>("tofdigits");
56 auto row = pc.inputs().get<std::vector<o2::tof::ReadoutWindowData>*>("readoutwin");
57 int nwindow = row->size();
58 LOG(debug) << "Encoding " << nwindow << " TOF readout windows";
59
60 int cache = 1024 * 1024; // 1 MB
61 int verbosity = 0;
62
64 encoder.setVerbose(verbosity);
65
66 if (mOldFormat) {
67 encoder.setEncoderCRUZEROES();
68 }
69
70 encoder.open(mOutFileName, mOutDirName, mFileFor);
71 encoder.alloc(cache);
72
73 int nwindowperorbit = Geo::NWINDOW_IN_ORBIT;
74 int nwindowintimeframe = o2::raw::HBFUtils::Instance().getNOrbitsPerTF() * nwindowperorbit;
75 int nwindowFilled = nwindow;
76 if (nwindowFilled % nwindowintimeframe) {
77 nwindowFilled = (nwindowFilled / nwindowintimeframe + 1) * nwindowintimeframe;
78 }
79
80 std::vector<o2::tof::Digit> emptyWindow;
81
82 std::vector<o2::tof::Digit> digitRO;
83
84 std::vector<std::vector<o2::tof::Digit>> digitWindows;
85
86 for (int i = 0; i < nwindow; i += nwindowperorbit) { // encode 3 tof windows (1 orbit)
87 if (verbosity) {
88 printf("----------\nwindow = %d - %d\n----------\n", i, i + nwindowperorbit - 1);
89 }
90
91 digitWindows.clear();
92
93 // push all windows in the current orbit in the structure
94 for (int j = i; j < i + nwindowperorbit; j++) {
95 if (j < nwindow) {
96 digitRO.clear();
97 for (int id = 0; id < row->at(j).size(); id++) {
98 digitRO.push_back((*digits)[row->at(j).first() + id]);
99 }
100 digitWindows.push_back(digitRO);
101 } else {
102 digitWindows.push_back(emptyWindow);
103 }
104 }
105
106 encoder.encode(digitWindows, i);
107 }
108
109 // create configuration file for rawreader
110 encoder.getWriter().writeConfFile("TOF", "RAWDATA", o2::utils::Str::concat_string(mOutDirName, '/', "TOFraw.cfg"));
111 encoder.close();
112}
113
115{
116 std::vector<InputSpec> inputs;
117 inputs.emplace_back("tofdigits", o2::header::gDataOriginTOF, "DIGITS", 0, Lifetime::Timeframe);
118 inputs.emplace_back("readoutwin", o2::header::gDataOriginTOF, "READOUTWINDOW", 0, Lifetime::Timeframe);
119
120 int rdhDefaultVersion = o2::raw::RDHUtils::getVersion<o2::header::RAWDataHeader>();
121
122 return DataProcessorSpec{
123 "TOFRawWriter",
124 inputs,
125 {}, // no output
126 AlgorithmSpec{adaptFromTask<RawWriter>()},
127 Options{
128 {"tof-raw-outfile", VariantType::String, "tof.raw", {"Name of the output file"}},
129 {"tof-raw-outdir", VariantType::String, ".", {"Name of the output dir"}},
130 {"file-for", VariantType::String, "cruendpoint", {"Single file per: all,cruendpoint,link"}},
131 {"use-old-format", VariantType::Bool, rdhDefaultVersion < 7, {"expecting zeroes in words 2 and 3 of the CRU payload"}}}};
132}
133} // namespace tof
134} // namespace o2
#define verbosity
int32_t i
uint32_t j
Definition RawData.h:0
std::ostringstream debug
ConfigParamRegistry const & options()
Definition InitContext.h:33
decltype(auto) get(R binding, int part=0) const
InputRecord & inputs()
The inputs associated with this processing context.
static constexpr int NWINDOW_IN_ORBIT
Definition Geo.h:163
void run(ProcessingContext &pc) final
void init(InitContext &ic) final
Encoder class for TOF.
Definition Encoder.h:39
bool encode(std::vector< std::vector< o2::tof::Digit > > digitWindow, int tofwindow=0)
Definition Encoder.cxx:248
void setVerbose(bool val)
Definition Encoder.h:53
void setEncoderCRUZEROES(bool val=true)
Definition Encoder.h:55
bool alloc(long size)
Definition Encoder.cxx:131
bool open(const std::string &name, const std::string &path=".", const std::string &fileFor="cruendpoint")
Definition Encoder.cxx:60
GLsizeiptr size
Definition glcorearb.h:659
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
o2::framework::DataProcessorSpec getTOFRawWriterSpec()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
int getNOrbitsPerTF() const
get IR corresponding to start of the HBF
Definition HBFUtils.h:49
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits
std::vector< int > row