Project
Loading...
Searching...
No Matches
convert-bad-channels.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 <boost/program_options.hpp>
13#include <stdexcept>
14#include <TFile.h>
15#include <string>
16#include <iostream>
17#include <fmt/format.h>
19
20namespace po = boost::program_options;
21
22int convertRootToCSV(const std::string rootFileName)
23{
24 TFile* f = TFile::Open(rootFileName.c_str());
25 if (f->IsZombie()) {
26 throw std::runtime_error("can not open " + rootFileName);
27 }
28 auto& tinfo = typeid(std::vector<o2::mch::DsChannelId>*);
29 TClass* cl = TClass::GetClass(tinfo);
30 auto channels = static_cast<std::vector<o2::mch::DsChannelId>*>(f->GetObjectChecked("ccdb_object", cl));
31
32 std::cout << fmt::format("solarid,dsid,ch\n");
33
34 for (auto c : *channels) {
35 std::cout << fmt::format("{},{},{}\n",
36 c.getSolarId(), c.getElinkId(), c.getChannel());
37 }
38
39 delete f;
40 return 0;
41}
42
43int main(int argc, char** argv)
44{
45 po::variables_map vm;
46 po::options_description options;
47
48 // clang-format off
49 options.add_options()
50 ("help,h","help")
51 ("input",po::value<std::string>()->required(),"path to input root file to be converted to csv");
52 // clang-format on
53
54 po::options_description cmdline;
55 cmdline.add(options);
56
57 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
58
59 if (vm.count("help")) {
60 std::cout << R"(
61This program converts a Root file containing bad channels information into the
62same information in CSV format.
63
64The output file format is :
65
66solarid, dsid, ch
67
68where solarid, dsid and ch are integers.
69
70)";
71 std::cout
72 << options << "\n";
73 std::cout << "\n";
74 return 2;
75 }
76
77 try {
78 po::notify(vm);
79 } catch (boost::program_options::error& e) {
80 std::cout << "Error: " << e.what() << "\n";
81 std::cout << options << "\n";
82 exit(1);
83 }
84
85 return convertRootToCSV(vm["input"].as<std::string>());
86}
uint32_t c
Definition RawData.h:2
int convertRootToCSV(const std::string rootFileName)
GLdouble f
Definition glcorearb.h:310
#define main
std::vector< ChannelData > channels