Project
Loading...
Searching...
No Matches
digi2raw.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
14#include <boost/program_options.hpp>
15#include <filesystem>
16#include <TFile.h>
17#include <TStopwatch.h>
18#include "Framework/Logger.h"
19#include <string>
20#include <iomanip>
27namespace bpo = boost::program_options;
28
29void digi2raw(const std::string& inpName, const std::string& outDir, int verbosity, const std::string& fileForLink, uint32_t rdhV = 4, bool noEmptyHBF = false,
30 bool zsIR = true, bool zsClass = true, bool enablePadding = true, int cruPageAlignment = 16, int superPageSizeInB = 1024 * 1024);
31
32int main(int argc, char** argv)
33{
34 bpo::variables_map vm;
35 bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
36 "Convert CTP digits to CRU raw data\n");
37 bpo::options_description opt_hidden("");
38 bpo::options_description opt_all;
39 bpo::positional_options_description opt_pos;
40
41 try {
42 auto add_option = opt_general.add_options();
43 add_option("help,h", "Print this help message");
44 add_option("verbosity,v", bpo::value<int>()->default_value(0), "verbosity level");
45 // add_option("input-file,i", bpo::value<std::string>()->default_value(o2::base::NameConf::getDigitsFileName(o2::detectors::DetID::CTP)),"input CTP digits file"); // why not used?
46 add_option("input-file,i", bpo::value<std::string>()->default_value("ctpdigits.root"), "input CTP digits file");
47 add_option("file-for,f", bpo::value<std::string>()->default_value("all"), "single file per: all,link,cruendpoint");
48 add_option("output-dir,o", bpo::value<std::string>()->default_value("./"), "output directory for raw data");
49 uint32_t defRDH = o2::raw::RDHUtils::getVersion<o2::header::RAWDataHeader>();
50 add_option("rdh-version,r", bpo::value<uint32_t>()->default_value(defRDH), "RDH version to use");
51 add_option("no-empty-hbf,e", bpo::value<bool>()->default_value(false)->implicit_value(true), "do not create empty HBF pages (except for HBF starting TF)");
52 add_option("no-zs-ir", bpo::value<bool>()->default_value(false)->implicit_value(true), "do not zero-suppress interaction records");
53 add_option("no-zs-class", bpo::value<bool>()->default_value(false)->implicit_value(true), "do not zero-suppress trigger class records");
54 add_option("enable-padding", bpo::value<bool>()->default_value(false)->implicit_value(true), "pad raw gbt data to 128 bits: 80 bits payload+48 bits 0");
55 add_option("cru-page-alignment,a", bpo::value<int>()->default_value(16), "CRU page alignment");
56 add_option("hbfutils-config,u", bpo::value<std::string>()->default_value(std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE)), "config file for HBFUtils (or none)");
57 add_option("configKeyValues", bpo::value<std::string>()->default_value(""), "comma-separated configKeyValues");
58
59 opt_all.add(opt_general).add(opt_hidden);
60 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
61
62 if (vm.count("help")) {
63 std::cout << opt_general << std::endl;
64 exit(0);
65 }
66
67 bpo::notify(vm);
68 } catch (bpo::error& e) {
69 std::cerr << "ERROR: " << e.what() << std::endl
70 << std::endl;
71 std::cerr << opt_general << std::endl;
72 exit(1);
73 } catch (std::exception& e) {
74 std::cerr << e.what() << ", application will now exit" << std::endl;
75 exit(2);
76 }
77
78 std::string confDig = vm["hbfutils-config"].as<std::string>();
79 if (!confDig.empty() && confDig != "none") {
81 }
82 o2::conf::ConfigurableParam::updateFromString(vm["configKeyValues"].as<std::string>());
83 digi2raw(vm["input-file"].as<std::string>(),
84 vm["output-dir"].as<std::string>(),
85 vm["verbosity"].as<int>(),
86 vm["file-for"].as<std::string>(),
87 vm["rdh-version"].as<uint32_t>(),
88 vm["no-empty-hbf"].as<bool>(),
89 !vm["no-zs-ir"].as<bool>(),
90 !vm["no-zs-class"].as<bool>(),
91 vm["enable-padding"].as<bool>(),
92 vm["cru-page-alignment"].as<int>());
93
95
96 return 0;
97}
98
99void digi2raw(const std::string& inpName, const std::string& outDir, int verbosity, const std::string& fileForLink, uint32_t rdhV, bool noEmptyHBF, bool zsIR, bool zsClass, bool enablePadding, int cruPageAlignment, int superPageSizeInB)
100{
101 TStopwatch swTot;
102 swTot.Start();
104 m2r.setFilePerLink(fileForLink == "link");
106 auto& wr = m2r.getWriter();
107 std::string inputGRP = o2::base::NameConf::getGRPFileName();
108 const auto grp = o2::parameters::GRPObject::loadFrom(inputGRP);
109 wr.setContinuousReadout(grp->isDetContinuousReadOut(o2::detectors::DetID::CTP)); // must be set explicitly
110 wr.setSuperPageSize(superPageSizeInB);
111 wr.useRDHVersion(rdhV);
112 wr.setDontFillEmptyHBF(noEmptyHBF);
113 if (rdhV < 7 && !enablePadding) {
114 enablePadding = true;
115 LOG(info) << "padding is always ON for RDH version " << rdhV;
116 }
117 std::string outDirName(outDir);
118 // if needed, create output directory
119 if (!std::filesystem::exists(outDirName)) {
120 std::error_code ec;
121 if (!std::filesystem::create_directories(outDirName, ec)) {
122 LOG(fatal) << "could not create output directory " << outDirName << ": " << ec.message();
123 } else {
124 LOG(info) << "created output directory " << outDirName;
125 }
126 }
127 if (outDirName.back() != '/') {
128 outDirName += '/';
129 }
130 m2r.setOutDir(outDirName);
131 m2r.setZeroSuppressedIntRec(zsIR);
132 m2r.setZeroSuppressedClassRec(zsClass);
133 m2r.getWriter().useRDHDataFormat(enablePadding ? 0 : 2);
134 m2r.setPadding(enablePadding);
135 if (!enablePadding) { // CRU page alignment padding is used only if no GBT word padding is used
136 // m2r.getWriter().setAlignmentSize(o2::ctp::CRUPageAlignment);
137 LOG(info) << "CRU Page Alignment:" << cruPageAlignment;
138 m2r.getWriter().setAlignmentSize(cruPageAlignment);
140 }
141 m2r.init();
142 m2r.processDigits(inpName);
143 wr.writeConfFile(wr.getOrigin().str, "RAWDATA", o2::utils::Str::concat_string(outDirName, wr.getOrigin().str, "raw.cfg"));
144 //
145 swTot.Stop();
146 swTot.Print();
147}
#define verbosity
Digits tw Raw translation.
void digi2raw(const std::string &inpName, const std::string &outDir, int verbosity, const std::string &fileForLink, uint32_t rdhV=4, bool noEmptyHBF=false, bool zsIR=true, bool zsClass=true, bool enablePadding=true, int cruPageAlignment=16, int superPageSizeInB=1024 *1024)
Definition digi2raw.cxx:99
unsigned int uint32_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
Header of the General Run Parameters object.
Definition of the Names Generator class.
static std::string getGRPFileName(const std::string_view prefix=STANDARDSIMPREFIX)
Definition NameConf.cxx:59
static constexpr std::string_view DIGITIZATIONCONFIGFILE
Definition NameConf.h:89
static void updateFromFile(std::string const &, std::string const &paramsList="", bool unchangedOnly=false)
static void updateFromString(std::string const &)
void processDigits(const std::string &fileDigitsName)
void setOutDir(std::string &outdir)
Definition Digits2Raw.h:40
void setZeroSuppressedIntRec(bool value)
Definition Digits2Raw.h:42
void setZeroSuppressedClassRec(bool value)
Definition Digits2Raw.h:43
void setFilePerLink(bool v)
Definition Digits2Raw.h:39
void setPadding(bool value)
Definition Digits2Raw.h:44
void setVerbosity(int v)
Definition Digits2Raw.h:38
o2::raw::RawFileWriter & getWriter()
Definition Digits2Raw.h:48
static GRPObject * loadFrom(const std::string &grpFileName="")
void setAlignmentSize(unsigned char v)
void useRDHDataFormat(unsigned char v)
void setAlignmentPaddingFiller(unsigned char v)
void print() const
Definition HBFUtils.h:134
static std::string concat_string(Ts const &... ts)
#define main
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"