Conversion of L1 menu.
83 std::cout <<
"No CTPConfig, no L1Menu file will be produced" << std::endl;
93 item[
"name"] = sourceItem->name();
94 item[
"legacy"] =
true;
95 item[
"ctpid"] = sourceItem->ctpId();
96 auto [definition, bunchgroups] = decodeItemDefinition(sourceItem);
97 item[
"definition"] = definition;
98 item[
"bunchgroups"] = bunchgroups;
100 item[
"partition"] = sourceItem->partition();
101 std::string smon(
"LF:");
102 smon += (sourceItem->monitor() & 0x04 ?
'1' :
'0');
103 smon += (sourceItem->monitor() & 0x02 ?
'1' :
'0');
104 smon += (sourceItem->monitor() & 0x01 ?
'1' :
'0');
106 smon += (sourceItem->monitor() & 0x20 ?
'1' :
'0');
107 smon += (sourceItem->monitor() & 0x10 ?
'1' :
'0');
108 smon += (sourceItem->monitor() & 0x08 ?
'1' :
'0');
109 item[
"monitor"] = smon;
114 json thresholds = json::object_t{};
115 std::unordered_set<std::string> legacyThrTypes{
"EM",
"TAU",
"JET",
"JB",
"JE",
"JF",
"XE",
"XS",
"TE",
"ZB",
"R2TOPO"};
117 std::string thrType = sourceThr->type();
118 if(thrType==
"BGRP" || thrType==
"RNDM") {
121 if(thrType==
"MUON") {
124 else if(thrType==
"TOPO") {
128 bool isLegacyCalo = legacyThrTypes.count(thrType) > 0;
129 json &jThisType = isLegacyCalo ? thresholds[
"legacyCalo"][thrType] : thresholds[thrType];
130 bool firstOfItsType = jThisType.empty();
133 jThisType[
"type"] = thrType;
136 size_t mapping = sourceThr->mapping();
141 jThisType[
"type"] =
"MU";
142 jThisType[
"exclusionLists"] = json::object_t{};
143 jThisType[
"roads"][
"rpc"] = json::object_t{};
144 jThisType[
"roads"][
"tgc"] = json::object_t{};
146 int ptCut = sourceThr->triggerThresholdValue(0,0)->ptCutCount();
147 thr[
"baThr"] = ptCut;
148 thr[
"ecThr"] = ptCut;
149 thr[
"fwThr"] = ptCut;
153 thr[
"tgcFlags"] =
"";
154 thr[
"rpcFlags"] =
"";
155 thr[
"region"] =
"ALL";
159 else if (thrType ==
"EM")
161 thr[
"thrValues"] = json::array_t{};
166 jtv[
"value"] =
static_cast<unsigned int>(tv->ptcut());
167 std::string isobits =
"00000";
168 auto isomask =
cl->isolationMask();
169 for (
size_t b = 0;
b < 5; ++
b)
171 if (isomask & (1 <<
b))
173 isobits[4 -
b] =
'1';
176 jtv[
"isobits"] = isobits;
177 jtv[
"etamin"] = tv->etamin();
178 jtv[
"etamax"] = tv->etamax();
179 jtv[
"phimin"] = tv->phimin();
180 jtv[
"phimax"] = tv->phimax();
181 jtv[
"priority"] =
static_cast<unsigned int>(tv->priority());
182 thr[
"thrValues"] += jtv;
185 else if (thrType ==
"TAU")
188 int ptCut = (
int)
cl->ptcut();
189 thr[
"value"] = ptCut;
190 std::string isobits =
"00000";
191 auto isomask =
cl->isolationMask();
192 for (
size_t b = 0;
b < 5; ++
b)
194 if (isomask & (1 <<
b))
196 isobits[4 -
b] =
'1';
199 thr[
"isobits"] = isobits;
201 else if (thrType ==
"JET" || thrType ==
"JB" || thrType ==
"JF")
203 thr[
"thrValues"] = json::array_t{};
208 jtv[
"value"] =
static_cast<unsigned int>(tv->ptcut());
209 jtv[
"etamin"] = tv->
etamin();
210 jtv[
"etamax"] = tv->etamax();
211 jtv[
"phimin"] = tv->phimin();
212 jtv[
"phimax"] = tv->phimax();
214 jtv[
"priority"] =
static_cast<unsigned int>(tv->priority());
215 thr[
"thrValues"] += jtv;
218 else if (thrType ==
"XE" || thrType ==
"TE" || thrType ==
"XS" || thrType ==
"JE")
220 thr[
"value"] =
static_cast<unsigned int>(sourceThr->thresholdValueVector().at(0)->ptcut());
222 else if (thrType ==
"ZB")
224 thr[
"seed"] = sourceThr->zbSeedingThresholdName();
225 thr[
"seedMultiplicity"] = sourceThr->zbSeedingThresholdMulti();
226 thr[
"seedBcdelay"] = sourceThr->bcDelay();
228 jThisType[
"thresholds"][sourceThr->name()] = thr;
233 thresholds[
"legacyCalo"][
"EM"][
"ptMinToTopo"] = ci.
minTobEM().
ptmin;
234 thresholds[
"legacyCalo"][
"EM"][
"resolutionMeV"] = (
int)(1000/ci.
globalEmScale());
235 thresholds[
"legacyCalo"][
"TAU"][
"ptMinToTopo"] = ci.
minTobTau().
ptmin;
239 json isoHAforEM{ {
"thrtype",
"HAIsoForEMthr"}, {
"Parametrization", json::array_t{}} };
240 json isoEMforEM{ {
"thrtype",
"EMIsoForEMthr"}, {
"Parametrization", json::array_t{}} };
241 json isoEMforTAU{ {
"thrtype",
"EMIsoForTAUthr"}, {
"Parametrization", json::array_t{}} };
243 json p{ {
"etamax", iso.etamax()}, {
"etamin", iso.etamin()}, {
"isobit", iso.isobit()}, {
"mincut", iso.mincut()},
244 {
"offset", iso.offset()}, {
"priority", iso.priority()}, {
"slope", iso.slope()}, {
"upperlimit", iso.upperlimit()} };
245 isoHAforEM[
"Parametrization"] +=
p;
248 json p{ {
"etamax", iso.etamax()}, {
"etamin", iso.etamin()}, {
"isobit", iso.isobit()}, {
"mincut", iso.mincut()},
249 {
"offset", iso.offset()}, {
"priority", iso.priority()}, {
"slope", iso.slope()}, {
"upperlimit", iso.upperlimit()} };
250 isoEMforEM[
"Parametrization"] +=
p;
253 json p{ {
"etamax", iso.etamax()}, {
"etamin", iso.etamin()}, {
"isobit", iso.isobit()}, {
"mincut", iso.mincut()},
254 {
"offset", iso.offset()}, {
"priority", iso.priority()}, {
"slope", iso.slope()}, {
"upperlimit", iso.upperlimit()} };
255 isoEMforTAU[
"Parametrization"] +=
p;
257 thresholds[
"legacyCalo"][
"EM"][
"isolation"][
"HAIsoForEMthr"] = isoHAforEM;
258 thresholds[
"legacyCalo"][
"EM"][
"isolation"][
"EMIsoForEMthr"] = isoEMforEM;
259 thresholds[
"legacyCalo"][
"TAU"][
"isolation"][
"EMIsoForTAUthr"] = isoEMforTAU;
262 thresholds[
"legacyCalo"][
"XS"][
"significance"] = json::object_t{
263 {
"xsSigmaScale", xs.
xsSigmaScale()}, {
"xsSigmaOffset", xs.
xsSigmaOffset()}, {
"xeMin", xs.
xeMin()}, {
"xeMax", xs.
xeMax()}, {
"teSqrtMin", xs.
teSqrtMin()}, {
"teSqrtMax", xs.
teSqrtMax()}};
266 json boards = json::object_t{};
267 boards[
"Ctpin7"] = json::object_t{ {
"type",
"CTPIN"}, {
"legacy",
true},
268 {
"connectors", std::vector<std::string>{
"EM1",
"EM2",
"TAU1",
"TAU2"}} };
269 boards[
"Ctpin8"] = json::object_t{ {
"type",
"CTPIN"}, {
"legacy",
true},
270 {
"connectors", std::vector<std::string>{
"JET1",
"JET2",
"EN1",
"EN2"}} };
271 boards[
"Ctpin9"] = json::object_t{ {
"type",
"CTPIN"}, {
"legacy",
true},
272 {
"connectors", std::vector<std::string>{
"MUCTPI",
"CTPCAL",
"NIM1",
"NIM2"}} };
273 boards[
"LegacyTopo0"] = json::object_t{ {
"type",
"TOPO"}, {
"legacy",
true},
274 {
"connectors", std::vector<std::string>{
"LegacyTopo0"}} };
275 boards[
"LegacyTopo1"] = json::object_t{ {
"type",
"TOPO"}, {
"legacy",
true},
276 {
"connectors", std::vector<std::string>{
"LegacyTopo1"}} };
279 json connectors = json::object_t{};
280 std::map<std::string,std::vector<const TrigConf::TriggerThreshold*>> triggerlinesMap;
282 if(sourceThr->isInternal()) {
285 std::string cableName = sourceThr->cableName();
286 if(cableName==
"ALFA") {
287 cableName =
"AlfaCtpin";
289 else if(cableName==
"TOPO1") {
290 cableName =
"LegacyTopo0";
292 else if(cableName==
"TOPO2") {
293 cableName =
"LegacyTopo1";
295 triggerlinesMap[cableName].push_back(sourceThr);
297 for(
auto & [
type, triggerlines] : triggerlinesMap) {
301 if(!connectors.contains(
type)) {
302 if(thr->input()==
"ctpcore") {
303 connectors[
type][
"type"] =
"electrical";
304 if(
type==
"AlfaCtpin") {
305 connectors[
type][
"triggerlines"][
"clock0"] = json::array_t{};
306 connectors[
type][
"triggerlines"][
"clock1"] = json::array_t{};
308 connectors[
type][
"triggerlines"][
"fpga0"][
"clock0"] = json::array_t{};
309 connectors[
type][
"triggerlines"][
"fpga0"][
"clock1"] = json::array_t{};
310 connectors[
type][
"triggerlines"][
"fpga1"][
"clock0"] = json::array_t{};
311 connectors[
type][
"triggerlines"][
"fpga1"][
"clock1"] = json::array_t{};
313 }
else if(thr->input()==
"ctpin") {
314 connectors[
type][
"type"] =
"ctpin";
315 connectors[
type][
"triggerlines"] = json::array_t{};
317 throw std::runtime_error(
"Unknown connector type" + thr->input());
319 connectors[
type][
"legacy"] =
true;
321 size_t start = thr->cableStart();
322 size_t nbits = thr->cableEnd() - thr->cableStart() + 1;
323 if(thr->input()==
"ctpcore") {
324 unsigned int clock = thr->clock();
325 if(
type==
"AlfaCtpin") {
326 json tl{{
"name", thr->name()}, {
"startbit",
start}, {
"nbits", nbits}};
334 json tl{{
"name",
"R2TOPO_" + thr->name()}, {
"startbit",
start}, {
"nbits", nbits}};
338 json tl{{
"name", thr->name()}, {
"startbit",
start}, {
"nbits", nbits}};
339 connectors[
type][
"triggerlines"] +=
tl;
345 json::object_t decAlgos;
346 json::object_t sortAlgos;
349 jAlg[
"algId"] =
alg.algoID();
350 jAlg[
"klass"] =
alg.type();
351 jAlg[
"fixedParameters"][
"generics"] = json::object_t{};
356 auto vInt = std::stoi(fixP.value);
357 jAlg[
"fixedParameters"][
"generics"][fixP.name] = json::object_t{{
"value", vInt}, {
"position",
pos++}};
359 catch (std::invalid_argument &)
361 jAlg[
"fixedParameters"][
"generics"][fixP.name] = json::object_t{{
"value", fixP.value}, {
"position",
pos++}};
364 jAlg[
"variableParameters"] = json::array_t{};
367 if (regP.name ==
"MaxMSqr") {
368 unsigned val = std::stoul(regP.value);
372 jAlg[
"variableParameters"] += json::object_t{{
"name", regP.name}, {
"selection", regP.selection}, {
"value",
val}};
375 jAlg[
"variableParameters"] += json::object_t{{
"name", regP.name}, {
"selection", regP.selection}, {
"value", std::stoi(regP.value)}};
378 if(
alg.isSortAlg()) {
379 jAlg[
"input"] =
alg.getInputNames()[0];
380 jAlg[
"output"] =
alg.output();
381 sortAlgos[
alg.name()] = jAlg;
382 }
else if(
alg.isDecAlg()) {
383 jAlg[
"input"] =
alg.getInputNames();
384 jAlg[
"output"] =
alg.getOutputNames();
385 decAlgos[
alg.name()] = jAlg;
388 json topo = json::object_t{};
390 topo[
"R2TOPO"][
"decisionAlgorithms"] = decAlgos;
391 topo[
"R2TOPO"][
"sortingAlgorithms"] = sortAlgos;
396 ctp[
"inputs"][
"ctpin"][
"slot7"] = json::object_t{{
"connector0",
"EM1"}, {
"connector1",
"EM2"},
397 {
"connector2",
"TAU1"}, {
"connector3",
"TAU2"}};
398 ctp[
"inputs"][
"ctpin"][
"slot8"] = json::object_t{{
"connector0",
"JET1"}, {
"connector1",
"JET2"},
399 {
"connector2",
"EN1"}, {
"connector3",
"EN2"}};
400 ctp[
"inputs"][
"ctpin"][
"slot9"] = json::object_t{{
"connector0",
"MUCTPI"}, {
"connector1",
"CTPCAL"},
401 {
"connector2",
"NIM1"}, {
"connector3",
"NIM2"}};
403 ctp[
"inputs"][
"electrical"] = json::object_t{{
"connector0",
"AlfaCtpin"}, {
"connector1",
"LegacyTopo0"}, {
"connector2",
"LegacyTopo1"}};
405 ctp[
"inputs"][
"electrical"] = json::object_t{};
407 ctp[
"inputs"][
"optical"] = json::object_t{};
408 ctp[
"monitoring"][
"ctpmon"] = json::object_t{};
412 menu[
"filetype"] =
"l1menu";
416 menu[
"thresholds"] = thresholds;
417 menu[
"topoAlgorithms"] = topo;
418 menu[
"boards"] = boards;
419 menu[
"connectors"] = connectors;
426 std::cout <<
"Wrote tmp" <<
filename << std::endl;
428 std::stringstream
ss;
431 boost::property_tree::read_json(
ss,
top);