Project
Loading...
Searching...
No Matches
RawCreator.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
12#include <memory>
13#include <string>
14#include <vector>
15#include "Framework/Logger.h"
16
17#include <boost/program_options.hpp>
18
19#include <TFile.h>
20#include <TTree.h>
21#include <TTreeReader.h>
22#include <filesystem>
23
28#include "CPVBase/Geometry.h"
32
33namespace bpo = boost::program_options;
34
35constexpr int DefRDHVersion = o2::raw::RDHUtils::getVersion<o2::header::RAWDataHeader>();
36
37int main(int argc, const char** argv)
38{
39 bpo::variables_map vm;
40 bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
41 " <cmds/options>\n"
42 " Tool will encode cpv raw data from input file\n"
43 "Commands / Options");
44 bpo::options_description opt_hidden("");
45 bpo::options_description opt_all;
46 bpo::positional_options_description opt_pos;
47
48 try {
49 auto add_option = opt_general.add_options();
50 add_option("help,h", "Print this help message");
51 add_option("verbose,v", bpo::value<uint32_t>()->default_value(0), "Select verbosity level [0 = no output]");
52 add_option("input-file,i", bpo::value<std::string>()->default_value("cpvdigits.root"), "Specifies digit input file.");
53 add_option("file-for,f", bpo::value<std::string>()->default_value("all"), "single file per: all,cruendpoint,link");
54 add_option("output-dir,o", bpo::value<std::string>()->default_value("./"), "output directory for raw data");
55 add_option("rdh-version,r", bpo::value<uint32_t>()->default_value(DefRDHVersion), "RDH version to use");
56 add_option("enable-padding", bpo::value<bool>()->default_value(false)->implicit_value(true), "enable GBT word padding to 128 bits even for RDH V7");
57 add_option("debug,d", bpo::value<uint32_t>()->default_value(0), "Select debug output level [0 = no debug output]");
58 add_option("hbfutils-config,u", bpo::value<std::string>()->default_value(std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE)), "config file for HBFUtils (or none)");
59 add_option("configKeyValues", bpo::value<std::string>()->default_value(""), "comma-separated configKeyValues");
60
61 opt_all.add(opt_general).add(opt_hidden);
62 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
63
64 if (vm.count("help") || argc == 1) {
65 std::cout << opt_general << std::endl;
66 exit(0);
67 }
68
69 } catch (bpo::error& e) {
70 std::cerr << "ERROR: " << e.what() << std::endl
71 << std::endl;
72 std::cerr << opt_general << std::endl;
73 exit(1);
74 } catch (std::exception& e) {
75 std::cerr << e.what() << ", application will now exit" << std::endl;
76 exit(2);
77 }
78
79 std::string confDig = vm["hbfutils-config"].as<std::string>();
80 if (!confDig.empty() && confDig != "none") {
82 }
83 o2::conf::ConfigurableParam::updateFromString(vm["configKeyValues"].as<std::string>());
84
85 auto digitfilename = vm["input-file"].as<std::string>(),
86 outputdir = vm["output-dir"].as<std::string>(),
87 filefor = vm["file-for"].as<std::string>();
88
89 auto rdhV = vm["rdh-version"].as<uint32_t>();
90 auto enablePadding = vm["enable-padding"].as<bool>();
91
92 if (rdhV < 7 && !enablePadding) {
93 enablePadding = true;
94 LOG(info) << "padding is always ON for RDH version " << rdhV;
95 }
96
97 // if needed, create output directory
98 if (!std::filesystem::exists(outputdir)) {
99 if (!std::filesystem::create_directories(outputdir)) {
100 LOG(fatal) << "could not create output directory " << outputdir;
101 } else {
102 LOG(info) << "created output directory " << outputdir;
103 }
104 }
105
106 std::unique_ptr<TFile> digitfile(TFile::Open(digitfilename.data(), "READ"));
107 auto treereader = std::make_unique<TTreeReader>(static_cast<TTree*>(digitfile->Get("o2sim")));
108 TTreeReaderValue<std::vector<o2::cpv::Digit>> digitbranch(*treereader, "CPVDigit");
109 TTreeReaderValue<std::vector<o2::cpv::TriggerRecord>> triggerbranch(*treereader, "CPVDigitTrigRecords");
110
112 if ((filefor == "all") || (filefor == "cruendpoint")) { // CPV has only 1 cru so "all" is identical to "cruendpoint"
114 } else if (filefor == "link") {
116 }
117
118 std::string inputGRP = o2::base::NameConf::getGRPFileName();
119 const auto grp = o2::parameters::GRPObject::loadFrom(inputGRP);
120
121 o2::cpv::RawWriter rawwriter;
122 rawwriter.setOutputLocation(outputdir.data());
123 rawwriter.setFileFor(granularity);
125 rawwriter.setRDHVersion(rdhV);
126 rawwriter.setDataFormat(enablePadding ? 0 : 2);
127 rawwriter.init();
128 rawwriter.getWriter().setContinuousReadout(grp->isDetContinuousReadOut(o2::detectors::DetID::CPV)); // must be set explicitly
129
130 // Loop over all entries in the tree, where each tree entry corresponds to a time frame
131 // First version of for loop causes fault Optimizer???
132 // for (auto evnt = treereader->begin(); evnt != treereader->end(); ++evnt) {
133 // for (auto evnt : *treereader) {
134 while (treereader->Next()) {
135 // (void*)evnt;
136 rawwriter.digitsToRaw(*digitbranch, *triggerbranch);
137 }
138 rawwriter.getWriter().writeConfFile("CPV", "RAWDATA", o2::utils::Str::concat_string(outputdir, "/CPVraw.cfg"));
139
141
142 return 0;
143}
constexpr int DefRDHVersion
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 std::string getCCDBServer()
Definition NameConf.cxx:123
static void updateFromFile(std::string const &, std::string const &paramsList="", bool unchangedOnly=false)
static void updateFromString(std::string const &)
void setFileFor(FileFor_t filefor)
Definition RawWriter.h:85
void setDataFormat(unsigned char v)
Definition RawWriter.h:87
void setOutputLocation(const char *outputdir)
Definition RawWriter.h:83
o2::raw::RawFileWriter & getWriter() const
Definition RawWriter.h:81
void setRDHVersion(int v)
Definition RawWriter.h:86
void digitsToRaw(gsl::span< o2::cpv::Digit > digits, gsl::span< o2::cpv::TriggerRecord > triggers)
void setCcdbUrl(const char *ccdbUrl)
Definition RawWriter.h:84
static GRPObject * loadFrom(const std::string &grpFileName="")
void writeConfFile(std::string_view origin="FLP", std::string_view description="RAWDATA", std::string_view cfgname="raw.cfg", bool fullPath=true) const
void print() const
Definition HBFUtils.h:134
static std::string concat_string(Ts const &... ts)
#define main
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"