SND@LHC Software
Loading...
Searching...
No Matches
boardMappingParser.cxx File Reference
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <map>
#include <tuple>
#include "nlohmann/json.hpp"
#include "TString.h"
Include dependency graph for boardMappingParser.cxx:

Go to the source code of this file.

Classes

struct  quicktype::Info
 
struct  quicktype::Info_scifi
 

Namespaces

namespace  quicktype
 
namespace  nlohmann
 

Typedefs

using json = nlohmann::json
 

Functions

json quicktype::get_untyped (const json &j, const char *property)
 
void nlohmann::from_json (const json &_j, struct quicktype::Info &_x)
 
void nlohmann::to_json (json &_j, const struct quicktype::Info &_x)
 
void nlohmann::from_json (const json &_j, struct quicktype::Info_scifi &_x)
 
void nlohmann::to_json (json &_j, const struct quicktype::Info_scifi &_x)
 
tuple< map< string, map< string, map< string, int > > >, map< string, map< string, map< string, string > > > > getBoardMapping (json j)
 

Variables

map< string, map< string, map< string, int > > > boardMaps {}
 
map< string, map< string, map< string, string > > > boardMapsMu {}
 

Typedef Documentation

◆ json

typedef nlohmann::json json

Definition at line 12 of file boardMappingParser.cxx.

Function Documentation

◆ getBoardMapping()

tuple< map< string, map< string, map< string, int > > >, map< string, map< string, map< string, string > > > > getBoardMapping ( json  j)

Definition at line 65 of file boardMappingParser.cxx.

66{
67 /*
68 the mapping is structured as: {<subsystem>: {<plane>: {<settings>...}, ...}, ...}
69 subsystem is veto, scifi, us, ds
70 plane depends on subsystem (e.g. '1x', '1y'... for Scifi)
71 settings depends on sybsystem as well
72 more info here: https://gitlab.cern.ch/snd-scifi/software/-/wikis/Board-Mapping
73 */
74
75 // Seperate structure for scifi than other subsystems
77 quicktype::Info_scifi info_scifi;
78
79 string bString;
80 char c;
81
82 for (auto& el : j.items())
83 {
84 // Loop over the planes in the subsystem
85 for (auto& subel : el.value().items())
86 {
87 string jsonStr = subel.value().dump();
88
89 // Each subsystem is treated separately
90 if (el.key() =="scifi")
91 {
92 info_scifi = nlohmann::json::parse(jsonStr);
93 // sanity check that the settings are correct
94 if (info_scifi.Class != "multiboard" || info_scifi.type != "snd_scifi")
95 {
96 cout << "Wrong class/type: " << info_scifi.Class << "/" << info_scifi.type << endl;
97 break;
98 }
99 // Loop over the boards (for SciFi)
100 for (int i = 0; i < info_scifi.boards.size(); i++)
101 {
102 bString = Form("board_%i", info_scifi.boards.at(i));
103 c =::toupper(subel.key()[1]);
104 boardMaps["Scifi"][bString][Form("M%c%c", subel.key()[0], c )] = i;
105 }
106 }
107 else if (el.key() =="veto")
108 {
109 info = nlohmann::json::parse(jsonStr);
110 // sanity check that the settings are correct
111 if (info.Class != "multislot" || info.type != "snd_veto")
112 {
113 cout << "Wrong class/type: " << info.Class << "/" << info.type << endl;
114 break;
115 }
116 // Add the "board_XX' entry in the dictionary if not already there
117 bString = Form("board_%i", info.board);
118 if (boardMapsMu["MuFilter"].find(bString.c_str()) == boardMapsMu["MuFilter"].end())
119 {
120 boardMapsMu["MuFilter"][bString] = {};
121 }
122 // Loop over the slots (the first is always left, the second always right)
123 for (int i = 0; i < info.slots.size(); i++)
124 {
125 bString = Form("board_%i", info.board);
126 if (stoi(subel.key())<3){
127 if (i==0) boardMapsMu["MuFilter"][bString][info.slots.at(i)] = Form("Veto_%iLeft", stoi(subel.key()));
128 else if (i==1) boardMapsMu["MuFilter"][bString][info.slots.at(i)] = Form("Veto_%iRight", stoi(subel.key()));
129 }
130 if (stoi(subel.key())==3) boardMapsMu["MuFilter"][bString][info.slots.at(i)] = Form("Veto_%iVert", stoi(subel.key()));
131 }
132 }
133 else if (el.key() =="us")
134 {
135 info = nlohmann::json::parse(jsonStr);
136 // sanity check that the settings are correct
137 if (info.Class != "multislot" || info.type != "snd_us")
138 {
139 cout << "Wrong class/type: " << info.Class << "/" << info.type << endl;
140 break;
141 }
142 // Add the "board_XX' entry in the dictionary if not already there
143 bString = Form("board_%i", info.board);
144 if (boardMapsMu["MuFilter"].find(bString.c_str()) == boardMapsMu["MuFilter"].end())
145 {
146 boardMapsMu["MuFilter"][bString] = {};
147 }
148 // Loop over the slots (the first is always left, the second always right)
149 for (int i = 0; i < info.slots.size(); i++)
150 {
151 bString = Form("board_%i", info.board);
152 if (i==0) boardMapsMu["MuFilter"][bString][info.slots.at(i)] = Form("US_%iLeft", stoi(subel.key()));
153 else if (i==1) boardMapsMu["MuFilter"][bString][info.slots.at(i)] = Form("US_%iRight", stoi(subel.key()));
154 }
155 }
156 else if (el.key() =="ds")
157 {
158 info = nlohmann::json::parse(jsonStr);
159 // sanity check that the settings are correct
160 if (info.Class != "multislot" || (info.type != "snd_dsh" && info.type != "snd_dsv"))
161 {
162 cout << "Wrong class/type: " << info.Class << "/" << info.type << endl;
163 break;
164 }
165 // Add the "board_XX' entry in the dictionary if not already there
166 bString = Form("board_%i", info.board);
167 if (boardMapsMu["MuFilter"].find(bString.c_str()) == boardMapsMu["MuFilter"].end())
168 {
169 boardMapsMu["MuFilter"][bString] = {};
170 }
171 // for DS we have the additional complication of vertival planes,
172 // but they are two different plane types (snd_dsh and snd_dsv)
173 if(info.type == "snd_dsh")
174 {
175 // Loop over the slots (the first is always left, the second always right)
176 for (int i = 0; i < info.slots.size(); i++)
177 {
178 bString = Form("board_%i", info.board);
179 if (i==0) boardMapsMu["MuFilter"][bString][info.slots.at(i)] = Form("DS_%iLeft", stoi(subel.key()));
180 else if (i==1) boardMapsMu["MuFilter"][bString][info.slots.at(i)] = Form("DS_%iRight", stoi(subel.key()));
181 }
182 }
183 else
184 {
185 boardMapsMu["MuFilter"][bString][info.slots.at(0)] = Form("DS_%iVert", stoi(subel.key()));
186 }
187 }
188 else
189 {
190 cout << "Unknown subsystem " << el.key() <<endl;
191 break;
192 }
193 }
194 }
195 return make_tuple(boardMaps, boardMapsMu);
196}
map< string, map< string, map< string, int > > > boardMaps
map< string, map< string, map< string, string > > > boardMapsMu
int i
Definition ShipAna.py:86
c
Definition hnl.py:100

Variable Documentation

◆ boardMaps

map<string, map<string, map<string, int> > > boardMaps {}

Definition at line 14 of file boardMappingParser.cxx.

14{};

◆ boardMapsMu

map<string, map<string, map<string, string> > > boardMapsMu {}

Definition at line 15 of file boardMappingParser.cxx.

15{};