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#include <filesystem>
17#include <boost/program_options.hpp>
18
19#include <TFile.h>
20#include <TTree.h>
21#include <TTreeReader.h>
22
27#include "PHOSBase/Geometry.h"
30
31namespace bpo = boost::program_options;
32
33int main(int argc, const char** argv)
34{
35 bpo::variables_map vm;
36 bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
37 " <cmds/options>\n"
38 " Tool will encode phos raw data from input file\n"
39 "Commands / Options");
40 bpo::options_description opt_hidden("");
41 bpo::options_description opt_all;
42 bpo::positional_options_description opt_pos;
43
44 try {
45 auto add_option = opt_general.add_options();
46 add_option("help,h", "Print this help message");
47 add_option("verbose,v", bpo::value<uint32_t>()->default_value(0), "Select verbosity level [0 = no output]");
48 add_option("input-file,i", bpo::value<std::string>()->default_value("phosdigits.root"), "Specifies digit input file.");
49 add_option("file-for,f", bpo::value<std::string>()->default_value("all"), "single file per: all,link");
50 add_option("output-dir,o", bpo::value<std::string>()->default_value("./"), "output directory for raw data");
51 add_option("debug,d", bpo::value<uint32_t>()->default_value(0), "Select debug output level [0 = no debug output]");
52 add_option("hbfutils-config,u", bpo::value<std::string>()->default_value(std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE)), "config file for HBFUtils (or none)");
53 add_option("configKeyValues", bpo::value<std::string>()->default_value(""), "comma-separated configKeyValues");
54
55 opt_all.add(opt_general).add(opt_hidden);
56 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
57
58 if (vm.count("help") || argc == 1) {
59 std::cout << opt_general << std::endl;
60 exit(0);
61 }
62
63 } catch (bpo::error& e) {
64 std::cerr << "ERROR: " << e.what() << std::endl
65 << std::endl;
66 std::cerr << opt_general << std::endl;
67 exit(1);
68 } catch (std::exception& e) {
69 std::cerr << e.what() << ", application will now exit" << std::endl;
70 exit(2);
71 }
72
73 std::string confDig = vm["hbfutils-config"].as<std::string>();
74 if (!confDig.empty() && confDig != "none") {
76 }
77 o2::conf::ConfigurableParam::updateFromString(vm["configKeyValues"].as<std::string>());
78
79 auto digitfilename = vm["input-file"].as<std::string>(),
80 outputdir = vm["output-dir"].as<std::string>(),
81 filefor = vm["file-for"].as<std::string>();
82
83 // if needed, create output directory
84 if (!std::filesystem::exists(outputdir)) {
85 if (!std::filesystem::create_directories(outputdir)) {
86 LOG(fatal) << "could not create output directory " << outputdir;
87 } else {
88 LOG(info) << "created output directory " << outputdir;
89 }
90 }
91
92 std::unique_ptr<TFile> digitfile(TFile::Open(digitfilename.data(), "READ"));
93 auto treereader = std::make_unique<TTreeReader>(static_cast<TTree*>(digitfile->Get("o2sim")));
94 TTreeReaderValue<std::vector<o2::phos::Digit>> digitbranch(*treereader, "PHOSDigit");
95 TTreeReaderValue<std::vector<o2::phos::TriggerRecord>> triggerbranch(*treereader, "PHOSDigitTrigRecords");
96
98 if (filefor == "all") {
100 } else if (filefor == "crorc") {
102 } else if (filefor == "link") {
104 }
105
106 o2::phos::RawWriter rawwriter;
107 rawwriter.setOutputLocation(outputdir.data());
108 rawwriter.setFileFor(granularity);
109 rawwriter.init();
110
111 // Loop over all entries in the tree, where each tree entry corresponds to a time frame
112 while (treereader->Next()) {
113 rawwriter.digitsToRaw(*digitbranch, *triggerbranch);
114 }
115 rawwriter.getWriter().writeConfFile("PHS", "RAWDATA", o2::utils::Str::concat_string(outputdir, "/PHSraw.cfg"));
116
118
119 return 0;
120}
Definition of the Names Generator class.
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 &)
o2::raw::RawFileWriter & getWriter() const
Definition RawWriter.h:65
void setFileFor(FileFor_t filefor)
Definition RawWriter.h:68
void setOutputLocation(const char *outputdir)
Definition RawWriter.h:67
void digitsToRaw(gsl::span< o2::phos::Digit > digits, gsl::span< o2::phos::TriggerRecord > triggers)
Definition RawWriter.cxx:67
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"