Project
Loading...
Searching...
No Matches
digits-to-raw.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
15#include "DigitTreeReader.h"
16#include "Framework/Logger.h"
18#include <TBranch.h>
19#include <TFile.h>
20#include <TTree.h>
21#include <boost/program_options.hpp>
22#include <filesystem>
23#include <fmt/format.h>
24#include <fstream>
25#include <iostream>
26#include <limits>
27#include <string>
28
43namespace po = boost::program_options;
44using namespace o2::mch::raw;
45
46int main(int argc, char* argv[])
47{
48 po::options_description generic("options");
49 std::string input;
50 po::variables_map vm;
51
52 // clang-format off
53 generic.add_options()
54 ("help,h", "produce help message")
55 ("userLogic,u",po::bool_switch()->default_value(true),"user logic format")
56 ("dummy-elecmap,d",po::bool_switch()->default_value(false),"use a dummy electronic mapping (for testing only, to be removed at some point)")
57 ("output-dir,o",po::value<std::string>()->default_value("./"),"output directory for file(s)")
58 ("file-for,f", po::value<std::string>()->default_value("all"), "output one file (file-for=all), per link (file-for=link) or per cru end point (file-for=cruendpoint)")
59 ("input-file,i",po::value<std::string>(&input)->default_value("mchdigits.root"),"input file name")
60 ("configKeyValues", po::value<std::string>()->default_value(""), "comma-separated configKeyValues")
61 ("no-empty-hbf,e", po::value<bool>()->default_value(false), "do not create empty HBF pages (except for HBF starting TF)")
62 ("raw-file-writer-verbosity,v", po::value<int>()->default_value(0), "verbosity level of the RawFileWriter")
63 ("hbfutils-config", po::value<std::string>()->default_value(std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE)), "config file for HBFUtils (or none)")
64 ("rdh-version,r", po::value<int>()->default_value(o2::raw::RDHUtils::getVersion<o2::header::RAWDataHeader>()), "RDH version to use")
65 ("verbosity,v",po::value<std::string>()->default_value("verylow"), "(fair)logger verbosity");
66 // clang-format on
67
68 po::options_description cmdline;
69 cmdline.add(generic);
70
71 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
72
73 if (vm.count("help")) {
74 std::cout << generic << "\n";
75 return 2;
76 }
77
78 try {
79 po::notify(vm);
80 } catch (boost::program_options::error& e) {
81 std::cout << "Error: " << e.what() << "\n";
82 exit(1);
83 }
84
85 po::notify(vm);
86
87 // first things first : check the input path actually exists
88 std::ifstream in(input);
89 if (!in) {
90 LOGF(fatal, "could not open input file {}", input);
91 exit(2);
92 }
93
94 std::string confDig = vm["hbfutils-config"].as<std::string>();
95 if (!confDig.empty() && confDig != "none") {
97 }
98 o2::conf::ConfigurableParam::updateFromString(vm["configKeyValues"].as<std::string>());
99
100 if (vm.count("verbosity")) {
101 fair::Logger::SetVerbosity(vm["verbosity"].as<std::string>());
102 }
103
105
106 opts.noEmptyHBF = vm["no-empty-hbf"].as<bool>();
107 opts.outputDir = vm["output-dir"].as<std::string>();
108 auto fileFor = vm["file-for"].as<std::string>();
109 if (fileFor == "link") {
110 opts.splitMode = OutputSplit::PerLink;
111 } else if (fileFor == "cruendpoint") {
112 opts.splitMode = OutputSplit::PerCruEndpoint;
113 } else if (fileFor == "all") {
114 opts.splitMode = OutputSplit::None;
115 } else {
116 throw po::validation_error(po::validation_error::invalid_option_value, "file-for");
117 }
118 opts.userLogic = vm["userLogic"].as<bool>();
119 opts.dummyElecMap = vm["dummy-elecmap"].as<bool>();
120 opts.rawFileWriterVerbosity = vm["raw-file-writer-verbosity"].as<int>();
121 opts.rdhVersion = vm["rdh-version"].as<int>();
122
124
125 TFile fin(input.c_str());
126 if (!fin.IsOpen()) {
127 std::cout << "Can not open Root input file " << input << "\n";
128 return -1;
129 }
130 TTree* tree = static_cast<TTree*>(fin.Get("o2sim"));
131 if (!tree) {
132 std::cout << "Can not get input tree o2sim from file " << input << "\n";
133 return -2;
134 }
135
137
138 // here we implicitely assume that this digits-to-raw is only called for
139 // one timeframe so it's easy to detect the TF start...
140 // RS: why do you need such assumption? In general, it is not correct
141 uint32_t firstOrbitOfRun = o2::raw::HBFUtils::Instance().getFirstSampledTFIR().orbit; // RS note that this is not anymore 1st orbit of the run but of the 1st filled TF
143 dre.addHeartbeats(dsElecIds, firstOrbitOfRun);
144
146 std::vector<o2::mch::Digit> digits;
147
148 // Loop over digits (grouped per ROF) and encode them
149 while (dr.nextDigits(rof, digits)) {
150 if (rof.getNEntries() != digits.size()) {
151 LOGP(error, "Inconsistent rof number of entries {} != number of digits {}", rof.getNEntries(), digits.size());
152 }
153 dre.encodeDigits(digits, rof.getBCData().orbit, rof.getBCData().bc);
154 }
155
156 // write raw files configuration so it can be used to easily read them back
157 dre.writeConfig();
158
159 return 0;
160}
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
char error[CURL_ERROR_SIZE]
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 &)
int getNEntries() const
get the number of associated objects
Definition ROFRecord.h:55
const BCData & getBCData() const
get the interaction record
Definition ROFRecord.h:46
bool nextDigits(o2::mch::ROFRecord &rof, std::vector< o2::mch::Digit > &digits)
std::set< DsElecId > getAllDs< ElectronicMapperGenerated >()
std::set< DsElecId > getAllDs< ElectronicMapperDummy >()
uint32_t orbit
LHC orbit.
uint16_t bc
bunch crossing ID of interaction
IR getFirstSampledTFIR() const
get TF and HB (abs) for this IR
Definition HBFUtils.h:74
#define main
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
std::vector< Digit > digits