13#include <fmt/format.h>
14#include <boost/program_options.hpp>
22template <
typename ELECMAP>
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";
32 std::cout << fmt::format(
"{} (elinkId {:d}) [ {} ] {}\n",
40template <
typename ELECMAP>
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";
53 return dump<ELECMAP>(dsElecId, dsDetId.value());
54 }
catch (
const std::exception& e) {
55 std::cout << e.what() <<
"\n";
60template <
typename ELECMAP>
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";
71 return dump<ELECMAP>(dsElecId.value(), dsDetId);
72 }
catch (
const std::exception& e) {
73 std::cout << e.what() <<
"\n";
78static std::string readFileContent(std::string&
filename)
83 while (std::getline(in, s)) {
94 if (cruMap.size() > 0) {
97 }
else if (dummyElecMap) {
103 auto s = feeLink2Solar(
f);
104 if (!s.has_value()) {
105 std::cout <<
asString(
f) <<
" is not known to the mapping\n";
107 std::cout <<
asString(
f) <<
" is handled by solar " << s.value() <<
"\n";
113 std::set<uint16_t> solarUIDs;
116 if (cruMap.size() > 0) {
120 }
else if (dummyElecMap) {
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());
133int usage(
const po::options_description& generic)
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";
152 bool doGenerateCruMap{
false};
154 po::variables_map vm;
155 po::options_description
generic(
"Generic options");
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!)")
173 po::options_description cmdline;
174 cmdline.add(generic);
176 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
178 if (vm.count(
"help")) {
179 return usage(generic);
184 }
catch (boost::program_options::error& e) {
185 std::cout <<
"Error: " << e.what() <<
"\n";
189 if (vm.count(
"solarId") && vm.count(
"groupId") && vm.count(
"indexId")) {
191 return convertElec2Det<ElectronicMapperDummy>(
static_cast<uint16_t
>(solarId),
192 static_cast<uint8_t
>(groupId),
193 static_cast<uint8_t
>(indexId));
195 return convertElec2Det<ElectronicMapperGenerated>(
static_cast<uint16_t
>(solarId),
196 static_cast<uint8_t
>(groupId),
197 static_cast<uint8_t
>(indexId));
199 }
else if (vm.count(
"deId") && vm.count(
"dsId")) {
201 return convertDet2Elec<ElectronicMapperDummy>(deId, dsId);
203 return convertDet2Elec<ElectronicMapperGenerated>(deId, dsId);
205 }
else if (vm.count(
"feeId") && vm.count(
"linkId")) {
207 static_cast<uint8_t
>(linkId), dummyElecMap,
208 vm[
"cru-map"].as<std::string>());
210 }
else if (doGenerateCruMap) {
212 vm[
"cru-map"].as<std::string>());
214 std::cout <<
"Incorrect mix of options\n";
215 return usage(generic);
int convertDet2Elec(int deId, int dsId)
int dump(const DsElecId &dsElecId, const DsDetId &dsDetId)
void convertFeeLink2Solar(uint16_t feeId, uint8_t linkId, bool dummyElecMap, std::string cruMap)
int convertElec2Det(uint16_t solarId, uint8_t groupId, uint8_t indexId)
void generateCruMap(bool dummyElecMap, std::string cruMap)
A DsDetId is just a pair (detection element id, dual sampa id)
constexpr uint8_t elinkId() const
constexpr uint16_t solarId() const
solarId is an identifier that uniquely identify a solar board
GLsizeiptr const void GLenum usage
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.
std::string asString(const SampaCluster &sc)
std::function< std::optional< FeeLinkId >(uint16_t solarId)> Solar2FeeLinkMapper
From solarId to (feeId,linkId)
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 >()
static std::string sCruMap