Project
Loading...
Searching...
No Matches
trap2raw.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// TRD Raw data format generation //
15// Take the output of the trapsimulator the [2-4]x32 bit words and //
16// associated headers and links etc. and produce the output of the cru. //
17// Hence the incredibly original name. //
18// Now also digits.
19// //
21
22#include "fairlogger/Logger.h"
23
30
31#include <boost/program_options.hpp>
32#include <filesystem>
33#include <TStopwatch.h>
34#include <string>
35#include <iomanip>
36#include <iostream>
37#include <iomanip>
38
39namespace bpo = boost::program_options;
40constexpr uint32_t DefRDHVersion = o2::raw::RDHUtils::getVersion<o2::header::RAWDataHeader>();
41
42void trap2raw(const std::string& inpDigitsName, const std::string& inpTrackletsName,
43 const std::string& outDir, int verbosity, std::string filePerLink,
44 uint32_t rdhV = DefRDHVersion, bool noEmptyHBF = false, int tracklethcheader = 0, int superPageSizeInB = 1024 * 1024, long startTime = 1547590800000);
45
46int main(int argc, char** argv)
47{
48 bpo::variables_map vm;
49 bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
50 "Convert TRD sim otuput to CRU raw data\n");
51 bpo::options_description opt_hidden("");
52 bpo::options_description opt_all;
53 bpo::positional_options_description opt_pos;
54
55 try {
56 auto add_option = opt_general.add_options();
57 add_option("help,h", "Print this help message");
58 add_option("verbosity,v", bpo::value<int>()->default_value(0), "verbosity level");
59 add_option("input-file-digits,d", bpo::value<std::string>()->default_value("trddigits.root"), "input Trapsim digits file");
60 add_option("input-file-tracklets,t", bpo::value<std::string>()->default_value("trdtracklets.root"), "input Trapsim tracklets file");
61 add_option("file-for,l", bpo::value<std::string>()->default_value("cruendpoint"), "all : raw file(false), cruendpoint : cru end point, cru : one file per cru, sm: one file per supermodule");
62 add_option("output-dir,o", bpo::value<std::string>()->default_value("./"), "output directory for raw data");
63 add_option("tracklethcheader,x", bpo::value<int>()->default_value(2), "include tracklet half chamber header (for run3). 0 never, 1 if there is tracklet data, 2 always");
64 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)");
65 add_option("rdh-version,r", bpo::value<uint32_t>()->default_value(DefRDHVersion), "rdh version in use");
66 add_option("configKeyValues", bpo::value<std::string>()->default_value(""), "comma-separated configKeyValues");
67 add_option("hbfutils-config,u", bpo::value<std::string>()->default_value(std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE)), "config file for HBFUtils (or none)");
68
69 opt_all.add(opt_general).add(opt_hidden);
70 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
71
72 if (vm.count("help")) {
73 std::cout << opt_general << std::endl;
74 exit(0);
75 }
76
77 bpo::notify(vm);
78 } catch (bpo::error& e) {
79 std::cerr << "ERROR: " << e.what() << std::endl
80 << std::endl;
81 std::cerr << opt_general << std::endl;
82 exit(1);
83 } catch (std::exception& e) {
84 std::cerr << e.what() << ", application will now exit" << std::endl;
85 exit(2);
86 }
87 std::string confDig = vm["hbfutils-config"].as<std::string>();
88 if (!confDig.empty() && confDig != "none") {
90 }
91 o2::conf::ConfigurableParam::updateFromString(vm["configKeyValues"].as<std::string>());
92
93 const auto& hbfu = o2::raw::HBFUtils::Instance(); // we need the creation time for the link mapping from CCDB
94
95 trap2raw(vm["input-file-digits"].as<std::string>(), vm["input-file-tracklets"].as<std::string>(), vm["output-dir"].as<std::string>(), vm["verbosity"].as<int>(), vm["file-for"].as<std::string>(), vm["rdh-version"].as<uint32_t>(), vm["no-empty-hbf"].as<bool>(), vm["tracklethcheader"].as<int>(), 1024 * 1024, hbfu.startTime);
96
97 return 0;
98}
99
100void trap2raw(const std::string& inpDigitsName, const std::string& inpTrackletsName, const std::string& outDir, int verbosity, std::string filePer, uint32_t rdhV, bool noEmptyHBF, int trackletHCHeader, int superPageSizeInB, long startTime)
101{
102 TStopwatch swTot;
103 swTot.Start();
104 LOG(info) << "timer started";
105 o2::trd::Trap2CRU mc2raw(outDir, inpDigitsName, inpTrackletsName); //,superPageSizeInB);
106 LOG(info) << "class instantiated";
107 mc2raw.setFilePer(filePer);
108 mc2raw.setVerbosity(verbosity);
109 mc2raw.setTrackletHCHeader(trackletHCHeader); // run3 or run2
110 mc2raw.setTimeStamp(startTime);
111 auto& wr = mc2raw.getWriter();
112 std::string inputGRP = o2::base::NameConf::getGRPFileName();
113 const auto grp = o2::parameters::GRPObject::loadFrom(inputGRP);
114 wr.setContinuousReadout(grp->isDetContinuousReadOut(o2::detectors::DetID::TRD)); // must be set explicitly
115 wr.setSuperPageSize(superPageSizeInB);
116 wr.useRDHVersion(rdhV);
117 wr.setDontFillEmptyHBF(noEmptyHBF);
118
120
121 std::string outDirName(outDir);
122 if (outDirName.back() != '/') {
123 outDirName += '/';
124 }
125
126 mc2raw.readTrapData();
127 wr.writeConfFile(wr.getOrigin().str, "RAWDATA", o2::utils::Str::concat_string(outDirName, wr.getOrigin().str, "raw.cfg"));
128 //
129 swTot.Stop();
130 swTot.Print();
131}
#define verbosity
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:58
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 &)
static constexpr ID TRD
Definition DetID.h:65
static GRPObject * loadFrom(const std::string &grpFileName="")
void setTimeStamp(long ts)
Definition Trap2CRU.h:58
void setFilePer(std::string fileper)
Definition Trap2CRU.h:54
o2::raw::RawFileWriter & getWriter()
Definition Trap2CRU.h:61
void setTrackletHCHeader(int tracklethcheader)
Definition Trap2CRU.h:57
void setVerbosity(int verbosity)
Definition Trap2CRU.h:56
void assertOutputDirectory(std::string_view outDirName)
static std::string concat_string(Ts const &... ts)
#define main
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
constexpr uint32_t DefRDHVersion
Definition trap2raw.cxx:40
void trap2raw(const std::string &inpDigitsName, const std::string &inpTrackletsName, const std::string &outDir, int verbosity, std::string filePerLink, uint32_t rdhV=DefRDHVersion, bool noEmptyHBF=false, int tracklethcheader=0, int superPageSizeInB=1024 *1024, long startTime=1547590800000)
Definition trap2raw.cxx:100