forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRawCreator.cxx
More file actions
133 lines (114 loc) · 5.48 KB
/
RawCreator.cxx
File metadata and controls
133 lines (114 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include <memory>
#include <string>
#include <vector>
#include "Framework/Logger.h"
#include <fairlogger/Logger.h>
#include <boost/program_options.hpp>
#include <TFile.h>
#include <TTree.h>
#include <TTreeReader.h>
#include <filesystem>
#include "CommonUtils/ConfigurableParam.h"
#include "CommonUtils/StringUtils.h"
#include "DataFormatsEMCAL/Digit.h"
#include "DataFormatsEMCAL/TriggerRecord.h"
#include "EMCALBase/Geometry.h"
#include "EMCALSimulation/RawWriter.h"
#include "CommonUtils/NameConf.h"
namespace bpo = boost::program_options;
int main(int argc, const char** argv)
{
bpo::variables_map vm;
bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
" <cmds/options>\n"
" Tool will encode emcal raw data from input file\n"
"Commands / Options");
bpo::options_description opt_hidden("");
bpo::options_description opt_all;
bpo::positional_options_description opt_pos;
try {
auto add_option = opt_general.add_options();
add_option("help,h", "Print this help message");
add_option("verbose,v", bpo::value<uint32_t>()->default_value(0), "Select verbosity level [0 = no output]");
add_option("input-file,i", bpo::value<std::string>()->default_value("emcaldigits.root"), "Specifies digit input file.");
add_option("file-for,f", bpo::value<std::string>()->default_value("all"), "single file per: all,subdet,link");
add_option("output-dir,o", bpo::value<std::string>()->default_value("./"), "output directory for raw data");
add_option("debug,d", bpo::value<uint32_t>()->default_value(0), "Select debug output level [0 = no debug output]");
add_option("hbfutils-config,u", bpo::value<std::string>()->default_value(std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE)), "config file for HBFUtils (or none)");
add_option("configKeyValues", bpo::value<std::string>()->default_value(""), "comma-separated configKeyValues");
opt_all.add(opt_general).add(opt_hidden);
bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
if (vm.count("help") || argc == 1) {
std::cout << opt_general << std::endl;
exit(0);
}
} catch (bpo::error& e) {
std::cerr << "ERROR: " << e.what() << std::endl
<< std::endl;
std::cerr << opt_general << std::endl;
exit(1);
} catch (std::exception& e) {
std::cerr << e.what() << ", application will now exit" << std::endl;
exit(2);
}
auto debuglevel = vm["debug"].as<uint32_t>();
if (debuglevel > 0) {
fair::Logger::SetConsoleSeverity("DEBUG");
}
std::string confDig = vm["hbfutils-config"].as<std::string>();
if (!confDig.empty() && confDig != "none") {
o2::conf::ConfigurableParam::updateFromFile(confDig, "HBFUtils");
}
o2::conf::ConfigurableParam::updateFromString(vm["configKeyValues"].as<std::string>());
auto digitfilename = vm["input-file"].as<std::string>(),
outputdir = vm["output-dir"].as<std::string>(),
filefor = vm["file-for"].as<std::string>();
// if needed, create output directory
if (!std::filesystem::exists(outputdir)) {
if (!std::filesystem::create_directories(outputdir)) {
LOG(fatal) << "could not create output directory " << outputdir;
} else {
LOG(info) << "created output directory " << outputdir;
}
}
std::unique_ptr<TFile> digitfile(TFile::Open(digitfilename.data(), "READ"));
auto treereader = std::make_unique<TTreeReader>(static_cast<TTree*>(digitfile->Get("o2sim")));
TTreeReaderValue<std::vector<o2::emcal::Digit>> digitbranch(*treereader, "EMCALDigit");
TTreeReaderValue<std::vector<o2::emcal::TriggerRecord>> triggerbranch(*treereader, "EMCALDigitTRGR");
o2::emcal::RawWriter::FileFor_t granularity = o2::emcal::RawWriter::FileFor_t::kFullDet;
if (filefor == "all") {
granularity = o2::emcal::RawWriter::FileFor_t::kFullDet;
} else if (filefor == "subdet") {
granularity = o2::emcal::RawWriter::FileFor_t::kSubDet;
} else if (filefor == "crorc") {
granularity = o2::emcal::RawWriter::FileFor_t::kCRORC;
} else if (filefor == "link") {
granularity = o2::emcal::RawWriter::FileFor_t::kLink;
} else {
LOG(fatal) << "Unknown granularity, supported: all, subdet, crorc, link";
}
o2::emcal::RawWriter rawwriter;
rawwriter.setOutputLocation(outputdir.data());
rawwriter.setFileFor(granularity);
rawwriter.setGeometry(o2::emcal::Geometry::GetInstanceFromRunNumber(300000));
rawwriter.setNumberOfADCSamples(15); // @TODO Needs to come from CCDB
rawwriter.setPedestal(3); // @TODO Needs to come from CCDB
rawwriter.init();
// Loop over all entries in the tree, where each tree entry corresponds to a time frame
while (treereader->Next()) {
rawwriter.digitsToRaw(*digitbranch, *triggerbranch);
}
rawwriter.getWriter().writeConfFile("EMC", "RAWDATA", o2::utils::Str::concat_string(outputdir, "/EMCraw.cfg"));
o2::raw::HBFUtils::Instance().print();
return 0;
}