Project
Loading...
Searching...
No Matches
cli.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 <iostream>
13#include <fmt/format.h>
14#include <boost/program_options.hpp>
16#include <stdexcept>
17#include <fstream>
18
19namespace po = boost::program_options;
20using namespace o2::mch::raw;
21
22template <typename ELECMAP>
23int dump(const DsElecId& dsElecId,
24 const DsDetId& dsDetId)
25{
26 auto solar2fee = createSolar2FeeLinkMapper<ELECMAP>();
27 auto feelink = solar2fee(dsElecId.solarId());
28 if (!feelink.has_value()) {
29 std::cout << "Could not get FeeLinkId for solarId " << dsElecId.solarId() << "\n";
30 return 4;
31 }
32 std::cout << fmt::format("{} (elinkId {:d}) [ {} ] {}\n",
33 asString(dsElecId),
34 dsElecId.elinkId(),
35 asString(feelink.value()),
36 asString(dsDetId));
37 return 0;
38}
39
40template <typename ELECMAP>
41int convertElec2Det(uint16_t solarId, uint8_t groupId, uint8_t indexId)
42{
43 try {
44 std::cout << fmt::format("solarId {} groupId {} indexId {}\n",
45 solarId, groupId, indexId);
46 DsElecId dsElecId(solarId, groupId, indexId);
47 auto elec2det = createElec2DetMapper<ELECMAP>();
48 auto dsDetId = elec2det(dsElecId);
49 if (!dsDetId.has_value()) {
50 std::cout << asString(dsElecId) << " is not known to the electronic mapper\n";
51 return 3;
52 }
53 return dump<ELECMAP>(dsElecId, dsDetId.value());
54 } catch (const std::exception& e) {
55 std::cout << e.what() << "\n";
56 return 4;
57 }
58}
59
60template <typename ELECMAP>
61int convertDet2Elec(int deId, int dsId)
62{
63 try {
64 DsDetId dsDetId(deId, dsId);
65 auto det2elec = createDet2ElecMapper<ELECMAP>();
66 auto dsElecId = det2elec(dsDetId);
67 if (!dsElecId.has_value()) {
68 std::cout << asString(dsDetId) << " is not known to the electronic mapper\n";
69 return 3;
70 }
71 return dump<ELECMAP>(dsElecId.value(), dsDetId);
72 } catch (const std::exception& e) {
73 std::cout << e.what() << "\n";
74 return 5;
75 }
76}
77
78static std::string readFileContent(std::string& filename)
79{
80 std::string content;
81 std::string s;
82 std::ifstream in(filename);
83 while (std::getline(in, s)) {
84 content += s;
85 content += "\n";
86 }
87 return content;
88};
89
90void convertFeeLink2Solar(uint16_t feeId, uint8_t linkId, bool dummyElecMap,
91 std::string cruMap)
92{
93 FeeLink2SolarMapper feeLink2Solar;
94 if (cruMap.size() > 0) {
95 ElectronicMapperString::sCruMap = readFileContent(cruMap);
97 } else if (dummyElecMap) {
99 } else {
101 }
102 FeeLinkId f(feeId, linkId);
103 auto s = feeLink2Solar(f);
104 if (!s.has_value()) {
105 std::cout << asString(f) << " is not known to the mapping\n";
106 } else {
107 std::cout << asString(f) << " is handled by solar " << s.value() << "\n";
108 }
109}
110
111void generateCruMap(bool dummyElecMap, std::string cruMap)
112{
113 std::set<uint16_t> solarUIDs;
114 Solar2FeeLinkMapper solar2FeeLink;
115
116 if (cruMap.size() > 0) {
117 ElectronicMapperString::sCruMap = readFileContent(cruMap);
120 } else if (dummyElecMap) {
123 } else {
126 }
127 for (auto s : solarUIDs) {
128 auto f = solar2FeeLink(s).value();
129 std::cout << fmt::format("{:4d} {:4d} {:4d}\n", s, f.feeId(), f.linkId());
130 }
131}
132
133int usage(const po::options_description& generic)
134{
135 std::cout << "This program converts MCH electronic mapping information to detector mapping information\n";
136 std::cout << "(solarId,groupId,indexId)->(dsId,deId)";
137 std::cout << "As well as the reverse operation\n";
138 std::cout << generic << "\n";
139 return 2;
140}
141
142int main(int argc, char** argv)
143{
144 int solarId;
145 int groupId;
146 int indexId;
147 int deId;
148 int dsId;
149 int feeId;
150 int linkId;
151 bool dummyElecMap;
152 bool doGenerateCruMap{false};
153
154 po::variables_map vm;
155 po::options_description generic("Generic options");
156
157 // clang-format off
158 generic.add_options()
159 ("help,h", "produce help message")
160 ("solarId,s",po::value<int>(&solarId),"solar id")
161 ("groupId,g",po::value<int>(&groupId),"group id")
162 ("indexId,i",po::value<int>(&indexId),"index id")
163 ("dsId,d",po::value<int>(&dsId),"dual sampa id")
164 ("deId,e",po::value<int>(&deId),"detection element id")
165 ("feeId,f",po::value<int>(&feeId),"fee id")
166 ("linkId,l",po::value<int>(&linkId),"link id")
167 ("cru-map",po::value<std::string>()->default_value(""),"custom cru mapping from file")
168 ("generate-cru-map",po::bool_switch(&doGenerateCruMap),"generate cru.map file")
169 ("dummy-elecmap",po::value<bool>(&dummyElecMap)->default_value(false),"use dummy electronic mapping (only for debug!)")
170 ;
171 // clang-format on
172
173 po::options_description cmdline;
174 cmdline.add(generic);
175
176 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
177
178 if (vm.count("help")) {
179 return usage(generic);
180 }
181
182 try {
183 po::notify(vm);
184 } catch (boost::program_options::error& e) {
185 std::cout << "Error: " << e.what() << "\n";
186 exit(1);
187 }
188
189 if (vm.count("solarId") && vm.count("groupId") && vm.count("indexId")) {
190 if (dummyElecMap) {
191 return convertElec2Det<ElectronicMapperDummy>(static_cast<uint16_t>(solarId),
192 static_cast<uint8_t>(groupId),
193 static_cast<uint8_t>(indexId));
194 } else {
195 return convertElec2Det<ElectronicMapperGenerated>(static_cast<uint16_t>(solarId),
196 static_cast<uint8_t>(groupId),
197 static_cast<uint8_t>(indexId));
198 }
199 } else if (vm.count("deId") && vm.count("dsId")) {
200 if (dummyElecMap) {
201 return convertDet2Elec<ElectronicMapperDummy>(deId, dsId);
202 } else {
203 return convertDet2Elec<ElectronicMapperGenerated>(deId, dsId);
204 }
205 } else if (vm.count("feeId") && vm.count("linkId")) {
206 convertFeeLink2Solar(static_cast<uint16_t>(feeId),
207 static_cast<uint8_t>(linkId), dummyElecMap,
208 vm["cru-map"].as<std::string>());
209
210 } else if (doGenerateCruMap) {
211 generateCruMap(dummyElecMap,
212 vm["cru-map"].as<std::string>());
213 } else {
214 std::cout << "Incorrect mix of options\n";
215 return usage(generic);
216 }
217
218 return 0;
219}
unsigned short int uint16_t
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 s
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
int convertDet2Elec(int deId, int dsId)
Definition cli.cxx:61
int dump(const DsElecId &dsElecId, const DsDetId &dsDetId)
Definition cli.cxx:23
void convertFeeLink2Solar(uint16_t feeId, uint8_t linkId, bool dummyElecMap, std::string cruMap)
Definition cli.cxx:90
int convertElec2Det(uint16_t solarId, uint8_t groupId, uint8_t indexId)
Definition cli.cxx:41
void generateCruMap(bool dummyElecMap, std::string cruMap)
Definition cli.cxx:111
A DsDetId is just a pair (detection element id, dual sampa id)
Definition DsDetId.h:22
constexpr uint8_t elinkId() const
Definition DsElecId.h:44
constexpr uint16_t solarId() const
solarId is an identifier that uniquely identify a solar board
Definition DsElecId.h:50
GLdouble f
Definition glcorearb.h:310
GLsizeiptr const void GLenum usage
Definition glcorearb.h:659
FeeLink2SolarMapper createFeeLink2SolarMapper< ElectronicMapperString >()
std::function< std::optional< uint16_t >(FeeLinkId)> createFeeLink2SolarMapper< ElectronicMapperGenerated >()
std::set< uint16_t > getSolarUIDs< ElectronicMapperString >()
Solar2FeeLinkMapper createSolar2FeeLinkMapper< ElectronicMapperString >()
std::set< uint16_t > getSolarUIDs< ElectronicMapperGenerated >()
std::function< std::optional< uint16_t >(FeeLinkId id)> FeeLink2SolarMapper
From (feeId,linkId) to solarId.
Definition Mapper.h:52
std::string asString(const SampaCluster &sc)
std::function< std::optional< FeeLinkId >(uint16_t solarId)> Solar2FeeLinkMapper
From solarId to (feeId,linkId)
Definition Mapper.h:57
std::function< std::optional< uint16_t >(FeeLinkId)> createFeeLink2SolarMapper< ElectronicMapperDummy >()
std::function< std::optional< FeeLinkId >(uint16_t)> createSolar2FeeLinkMapper< ElectronicMapperDummy >()
std::set< uint16_t > getSolarUIDs< ElectronicMapperDummy >()
std::function< std::optional< FeeLinkId >(uint16_t)> createSolar2FeeLinkMapper< ElectronicMapperGenerated >()
std::string filename()
#define main