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 <fairlogger/Logger.h>
17
18#include <boost/program_options.hpp>
19
20#include <TFile.h>
21#include <TTree.h>
22#include <TTreeReader.h>
23#include <filesystem>
28#include "EMCALBase/Geometry.h"
31
32namespace bpo = boost::program_options;
33
34int main(int argc, const char** argv)
35{
36 bpo::variables_map vm;
37 bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
38 " <cmds/options>\n"
39 " Tool will encode emcal raw data from input file\n"
40 "Commands / Options");
41 bpo::options_description opt_hidden("");
42 bpo::options_description opt_all;
43 bpo::positional_options_description opt_pos;
44
45 try {
46 auto add_option = opt_general.add_options();
47 add_option("help,h", "Print this help message");
48 add_option("verbose,v", bpo::value<uint32_t>()->default_value(0), "Select verbosity level [0 = no output]");
49 add_option("input-file,i", bpo::value<std::string>()->default_value("emcaldigits.root"), "Specifies digit input file.");
50 add_option("file-for,f", bpo::value<std::string>()->default_value("all"), "single file per: all,subdet,link");
51 add_option("output-dir,o", bpo::value<std::string>()->default_value("./"), "output directory for raw data");
52 add_option("debug,d", bpo::value<uint32_t>()->default_value(0), "Select debug output level [0 = no debug output]");
53 add_option("hbfutils-config,u", bpo::value<std::string>()->default_value(std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE)), "config file for HBFUtils (or none)");
54 add_option("configKeyValues", bpo::value<std::string>()->default_value(""), "comma-separated configKeyValues");
55
56 opt_all.add(opt_general).add(opt_hidden);
57 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
58
59 if (vm.count("help") || argc == 1) {
60 std::cout << opt_general << std::endl;
61 exit(0);
62 }
63
64 } catch (bpo::error& e) {
65 std::cerr << "ERROR: " << e.what() << std::endl
66 << std::endl;
67 std::cerr << opt_general << std::endl;
68 exit(1);
69 } catch (std::exception& e) {
70 std::cerr << e.what() << ", application will now exit" << std::endl;
71 exit(2);
72 }
73
74 auto debuglevel = vm["debug"].as<uint32_t>();
75 if (debuglevel > 0) {
76 fair::Logger::SetConsoleSeverity("DEBUG");
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 // if needed, create output directory
90 if (!std::filesystem::exists(outputdir)) {
91 if (!std::filesystem::create_directories(outputdir)) {
92 LOG(fatal) << "could not create output directory " << outputdir;
93 } else {
94 LOG(info) << "created output directory " << outputdir;
95 }
96 }
97
98 std::unique_ptr<TFile> digitfile(TFile::Open(digitfilename.data(), "READ"));
99 auto treereader = std::make_unique<TTreeReader>(static_cast<TTree*>(digitfile->Get("o2sim")));
100 TTreeReaderValue<std::vector<o2::emcal::Digit>> digitbranch(*treereader, "EMCALDigit");
101 TTreeReaderValue<std::vector<o2::emcal::TriggerRecord>> triggerbranch(*treereader, "EMCALDigitTRGR");
102
104 if (filefor == "all") {
106 } else if (filefor == "subdet") {
108 } else if (filefor == "crorc") {
110 } else if (filefor == "link") {
112 } else {
113 LOG(fatal) << "Unknown granularity, supported: all, subdet, crorc, link";
114 }
115
116 o2::emcal::RawWriter rawwriter;
117 rawwriter.setOutputLocation(outputdir.data());
118 rawwriter.setFileFor(granularity);
120 rawwriter.setNumberOfADCSamples(15); // @TODO Needs to come from CCDB
121 rawwriter.setPedestal(3); // @TODO Needs to come from CCDB
122 rawwriter.init();
123
124 // Loop over all entries in the tree, where each tree entry corresponds to a time frame
125 while (treereader->Next()) {
126 rawwriter.digitsToRaw(*digitbranch, *triggerbranch);
127 }
128 rawwriter.getWriter().writeConfFile("EMC", "RAWDATA", o2::utils::Str::concat_string(outputdir, "/EMCraw.cfg"));
129
131
132 return 0;
133}
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 &)
static Geometry * GetInstanceFromRunNumber(Int_t runNumber, const std::string_view="", const std::string_view mcname="TGeant3", const std::string_view mctitle="")
Instanciate geometry depending on the run number. Mostly used in analysis and MC anchors.
Definition Geometry.cxx:219
Raw data creator for EMCAL raw data based on EMCAL digits.
Definition RawWriter.h:73
void setNumberOfADCSamples(int nsamples)
Set the number of ADC samples in the readout window.
Definition RawWriter.h:116
o2::raw::RawFileWriter & getWriter() const
Get access to underlying RawFileWriter.
Definition RawWriter.h:100
FileFor_t
Definition of the granularity of the raw files.
Definition RawWriter.h:77
@ kSubDet
Subdetector (EMCAL/DCAL separate)
@ kFullDet
Full detector (EMCAL + DCAL)
void setGeometry(o2::emcal::Geometry *geo)
Set the geometry parameters.
Definition RawWriter.h:128
void setOutputLocation(const char *outputdir)
Definition RawWriter.h:102
void setPedestal(int pedestal)
Set pedestal threshold used to accept ADC values when creating the bunches.
Definition RawWriter.h:124
void setFileFor(FileFor_t filefor)
Set the granularity of the output file.
Definition RawWriter.h:112
void digitsToRaw(gsl::span< o2::emcal::Digit > digits, gsl::span< o2::emcal::TriggerRecord > triggers)
Converting digits from a full timeframe to raw pages.
Definition RawWriter.cxx:77
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"