Project
Loading...
Searching...
No Matches
digits-to-json.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
14#include "DigitTreeReader.h"
16#include <TFile.h>
17#include <boost/program_options.hpp>
18#include <fmt/format.h>
19#include <iostream>
20#include <rapidjson/document.h>
21#include <rapidjson/ostreamwrapper.h>
22#include <rapidjson/stringbuffer.h>
23#include <rapidjson/writer.h>
24#include <string>
25
26namespace po = boost::program_options;
27using namespace o2::mch::raw;
28
29std::string digitIdAsString(const o2::mch::Digit& digit,
30 const Digit2ElecMapper& digit2elec)
31{
32 auto optElecId = digit2elec(digit);
33 if (!optElecId.has_value()) {
34 return "UNKNOWN";
35 }
36 auto dsElecId = optElecId.value().first;
37 auto dschid = optElecId.value().second;
38 return fmt::format("{}-CH{}", asString(dsElecId), dschid);
39}
40
41void outputToJson(const std::vector<o2::mch::Digit>& digits,
42 std::function<std::optional<DsElecId>(DsDetId)> det2elec,
43 rapidjson::Writer<rapidjson::OStreamWrapper>& writer)
44
45{
46
47 auto digit2elec = createDigit2ElecMapper(det2elec);
48
49 writer.StartArray();
50 for (auto d : digits) {
51 auto sid = digitIdAsString(d, digit2elec);
52 if (sid == "UNKNOWN") {
53 continue;
54 }
55 writer.StartObject();
56 writer.Key("id");
57 writer.String(sid.c_str());
58 writer.Key("adc");
59 writer.Int(d.getADC());
60 writer.EndObject();
61 }
62 writer.EndArray();
63}
64
65int main(int argc, char* argv[])
66{
67 po::options_description generic("options");
68 bool dummyElecMap{false};
69 std::string input;
70 po::variables_map vm;
71
72 // clang-format off
73 generic.add_options()
74 ("help,h", "produce help message")
75 ("dummyElecMap,d",po::bool_switch(&dummyElecMap),"use a dummy electronic mapping (for testing only)")
76 ("infile,i",po::value<std::string>(&input)->required(),"input file name");
77 // clang-format on
78
79 po::options_description cmdline;
80 cmdline.add(generic);
81
82 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
83
84 if (vm.count("help")) {
85 std::cout << generic << "\n";
86 return 2;
87 }
88
89 try {
90 po::notify(vm);
91 } catch (boost::program_options::error& e) {
92 std::cout << "Error: " << e.what() << "\n";
93 exit(1);
94 }
95
96 po::notify(vm);
97
99
100 rapidjson::OStreamWrapper osw(std::cout);
101 rapidjson::Writer<rapidjson::OStreamWrapper> writer(osw);
102
103 TFile fin(input.c_str());
104 if (!fin.IsOpen()) {
105 return 3;
106 }
107 TTree* tree = static_cast<TTree*>(fin.Get("o2sim"));
108 if (!tree) {
109 return 4;
110 }
112 std::vector<o2::mch::Digit> digits;
114
115 while (dr.nextDigits(rof, digits)) {
116 writer.StartObject();
117 writer.Key("orbit");
118 writer.Int(rof.getBCData().orbit);
119 writer.Key("bc");
120 writer.Int(rof.getBCData().bc);
121 writer.Key("digits");
122 outputToJson(digits, det2elec, writer);
123 writer.EndObject();
124 }
125 return 0;
126}
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
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 Directory with events to Events directory is and not inside events d
MCH digit implementation.
Definition Digit.h:31
const BCData & getBCData() const
get the interaction record
Definition ROFRecord.h:46
bool nextDigits(o2::mch::ROFRecord &rof, std::vector< o2::mch::Digit > &digits)
A DsDetId is just a pair (detection element id, dual sampa id)
Definition DsDetId.h:22
void outputToJson(const std::vector< o2::mch::Digit > &digits, std::function< std::optional< DsElecId >(DsDetId)> det2elec, rapidjson::Writer< rapidjson::OStreamWrapper > &writer)
std::string digitIdAsString(const o2::mch::Digit &digit, const Digit2ElecMapper &digit2elec)
std::function< std::optional< DsElecId >(DsDetId)> createDet2ElecMapper< ElectronicMapperDummy >()
std::function< std::optional< std::pair< DsElecId, int > >(const o2::mch::Digit &digit)> Digit2ElecMapper
std::function< std::optional< DsElecId >(DsDetId)> createDet2ElecMapper< ElectronicMapperGenerated >()
Digit2ElecMapper createDigit2ElecMapper(Det2ElecMapper det2elec)
std::string asString(const SampaCluster &sc)
uint32_t orbit
LHC orbit.
uint16_t bc
bunch crossing ID of interaction
#define main
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
std::vector< Digit > digits