Project
Loading...
Searching...
No Matches
global-mapper.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
13
21#include "boost/program_options.hpp"
22#include <cstdint>
23#include <fmt/format.h>
24#include <fstream>
25#include <gsl/span>
26#include <iostream>
27#include <iostream>
28#include <iterator>
29#include <limits>
30#include <map>
31#include <optional>
32#include <rapidjson/document.h>
33#include <rapidjson/stringbuffer.h>
34#include <rapidjson/writer.h>
35#include <stdexcept>
36#include <string>
37
38namespace po = boost::program_options;
39using namespace o2::mch::raw;
40
41uint16_t computeDsBinX(int feeId, int linkId, int elinkId)
42{
43 constexpr uint64_t maxLinkId = 12;
44 constexpr uint64_t maxElinkId = 40;
45
46 int v = feeId * maxLinkId * maxElinkId +
47 (linkId % maxLinkId) * maxElinkId + elinkId + 1;
48 return static_cast<uint16_t>(v & 0xFFFF);
49}
50
63
64std::vector<DualSampaInfo> dualSampaInfos;
65std::vector<DualSampaInfo> computeDualSampaInfos();
66
67using namespace std::literals;
68
69std::string stripAlias(std::string alias)
70{
71 std::vector<std::string> remove = {".vMon", ".iMon", "di.SenseVoltage", "an.SenseVoltage"};
72
73 for (auto r : remove) {
74 if (alias.find(r) != std::string::npos) {
75 alias.replace(alias.find(r), r.size(), "");
76 }
77 }
78 return alias;
79}
80
82{
83 rapidjson::StringBuffer buffer;
84 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
85
87
91
92 std::map<std::string, std::set<o2::mch::DsIndex>> dsIndicesPerAliasBase;
93
94 for (auto alias : aliases) {
95 auto s = stripAlias(alias);
97 dsIndicesPerAliasBase.emplace(s, indices);
98 }
99
100 writer.StartArray();
101 for (auto p : dsIndicesPerAliasBase) {
102 writer.StartObject();
103 writer.Key("alias");
104 auto s = p.first;
105 writer.String(s.c_str());
106 writer.Key("ds");
107 writer.StartArray();
108 for (auto i : p.second) {
109 for (const auto& dsi : dualSampaInfos) {
110 if (dsi.dsBin == i) {
111 writer.Int(dsi.dsBinX);
112 }
113 }
114 }
115 writer.EndArray();
116 writer.EndObject();
117 }
118 writer.EndArray();
119
120 std::cout << buffer.GetString() << "\n";
121}
122
123std::vector<DualSampaInfo> computeDualSampaInfos()
124{
128
129 for (o2::mch::DsIndex dsIndex = 0; dsIndex < o2::mch::NumberOfDualSampas; ++dsIndex) {
130 DsDetId det{o2::mch::getDsDetId(dsIndex)};
131 auto elec = det2elec(det);
132 if (!elec.has_value()) {
133 throw std::runtime_error("mapping is wrong somewhere...");
134 }
135 auto eLinkId = elec->elinkId();
136 auto solarId = elec->solarId();
137 auto s2f = solar2FeeLink(solarId);
138 if (!s2f.has_value()) {
139 throw std::runtime_error("mapping is wrong somewhere...");
140 }
141 auto feeId = s2f->feeId();
142 auto linkId = s2f->linkId();
143
144 auto dsBinX = computeDsBinX(feeId, linkId, eLinkId);
145
147
148 o2::mch::DsChannelId firstDsChannelId(solarId, eLinkId, 0);
149
150 auto dsId = det.dsId();
151 auto deId = det.deId();
152
153 dualSampaInfos.emplace_back(DualSampaInfo{dsIndex, dsBinX,
154 deId, dsId,
155 feeId, linkId,
156 eLinkId, solarId, nch,
157 firstDsChannelId.value()});
158 }
159 return dualSampaInfos;
160}
161
162void solar2json(bool mchview)
163{
164 rapidjson::StringBuffer buffer;
165 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
166
169
170 auto outputSolars = [&](uint16_t solarId) {
171 auto dualSampas = getDualSampas<ElectronicMapperGenerated>(solarId);
172 auto deId = dualSampas.begin()->deId();
173
174 writer.StartObject();
175 writer.Key("solarId");
176 writer.Int(solarId);
177 auto feelink = solar2FeeLink(solarId);
178 uint16_t feeId{std::numeric_limits<uint16_t>::max()};
179 uint8_t linkId{std::numeric_limits<uint8_t>::max()};
180 if (feelink.has_value()) {
181 feeId = feelink->feeId();
182 linkId = feelink->linkId();
183 writer.Key("FeeId");
184 writer.Int(feeId);
185 writer.Key("LinkId");
186 writer.Int(linkId);
187 }
188 writer.Key("deId");
189 writer.Int(deId);
190 writer.Key("ds");
191 writer.StartArray();
192 for (const auto& dsi : dualSampaInfos) {
193 if (dsi.feeId == feeId &&
194 dsi.linkId == linkId) {
195 writer.StartObject();
196 writer.Key("dsId");
197 writer.Int(dsi.dsId);
198 if (mchview) {
199 writer.Key("elinkId");
200 } else {
201 writer.Key("eLinkId");
202 }
203 writer.Int(dsi.eLinkId);
204 if (dsi.nch != 64) {
205 writer.Key("nch");
206 writer.Int(dsi.nch);
207 }
208 if (mchview) {
209 writer.Key("dsbin");
210 writer.Int(dsi.dsBinX);
211 writer.Key("dsIndex");
212 writer.Int(dsi.dsBin);
213 } else {
214 writer.Key("binX");
215 writer.Int(dsi.dsBinX);
216 writer.Key("bin");
217 writer.Int(dsi.dsBin);
218 writer.Key("fdci");
219 writer.Int(dsi.firstDsChannelId);
220 }
221 writer.EndObject();
222 }
223 }
224 writer.EndArray();
225 writer.EndObject();
226 };
227
229 writer.StartArray();
230 for (auto s : solarIds) {
231 outputSolars(s);
232 }
233 writer.EndArray();
234
235 std::cout << buffer.GetString() << "\n";
236}
237
238int main(int argc, char* argv[])
239{
240 po::variables_map vm;
241 po::options_description generic("Generic options");
242
243 // clang-format off
244 generic.add_options()
245 ("help,h", "produce help message")
246 ("solar,s","output solar based file")
247 ("mchview,m","output format suitable for mchview")
248 ("dcs,d","output dcs aliases -> dual sampa indices file")
249 ;
250 // clang-format on
251
252 po::options_description cmdline;
253 cmdline.add(generic);
254
255 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
256
257 if (vm.count("help")) {
258 std::cout << generic << "\n";
259 return 2;
260 }
261
262 try {
263 po::notify(vm);
264 } catch (boost::program_options::error& e) {
265 std::cout << "Error: " << e.what() << "\n";
266 exit(1);
267 }
268
269 if (vm.count("solar")) {
270 solar2json(vm.count("mchview"));
271 }
272
273 if (vm.count("dcs")) {
274 dcs2json();
275 }
276 return 0;
277}
unsigned char uint8_t
unsigned short int uint16_t
unsigned int uint32_t
int32_t i
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 Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_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 First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
void solar2json(bool mchview)
std::vector< DualSampaInfo > dualSampaInfos
std::string stripAlias(std::string alias)
void dcs2json()
std::vector< DualSampaInfo > computeDualSampaInfos()
uint16_t computeDsBinX(int feeId, int linkId, int elinkId)
uint32_t value() const
Definition DsChannelId.h:55
A DsDetId is just a pair (detection element id, dual sampa id)
Definition DsDetId.h:22
GLuint buffer
Definition glcorearb.h:655
const GLdouble * v
Definition glcorearb.h:832
GLsizei GLenum const void * indices
Definition glcorearb.h:400
std::set< DsIndex > aliasToDsIndices(std::string_view alias)
Definition Mapper.cxx:41
std::vector< std::string > aliases(std::vector< MeasurementType > types={ MeasurementType::HV_V, MeasurementType::HV_I, MeasurementType::LV_V_FEE_ANALOG, MeasurementType::LV_V_FEE_DIGITAL, MeasurementType::LV_V_SOLAR})
std::function< std::optional< DsDetId >(DsElecId)> createElec2DetMapper< ElectronicMapperGenerated >(uint64_t)
std::function< std::optional< DsElecId >(DsDetId)> createDet2ElecMapper< ElectronicMapperGenerated >()
std::set< uint16_t > getSolarUIDs< ElectronicMapperGenerated >()
std::set< DsDetId > getDualSampas< ElectronicMapperGenerated >(uint16_t solarId)
std::function< std::optional< FeeLinkId >(uint16_t)> createSolar2FeeLinkMapper< ElectronicMapperGenerated >()
uint16_t DsIndex
Definition DsIndex.h:26
uint8_t numberOfDualSampaChannels(DsIndex dsIndex)
Definition DsIndex.cxx:34
constexpr uint16_t NumberOfDualSampas
Definition DsIndex.h:28
o2::mch::raw::DsDetId getDsDetId(DsIndex dsIndex)
Definition DsIndex.cxx:90
uint32_t firstDsChannelId
#define main