124 {
125
127 cout << "/***************************************************************************/" << endl
128 << " L1Topo steering structure: configuring from L1 Topo Menu " << endl
129 << "/***************************************************************************/" << endl;
130
131
132 vector<string> storedConn;
133 vector<vector<string>> confAlgorithms;
134 vector<string> confMultAlgorithms;
135
136
137 string AvailableMultAlgs[] = { "eEmMultiplicity",
138 "jEmMultiplicity",
139 "eTauMultiplicity",
140 "jTauMultiplicity",
141 "cTauMultiplicity",
142 "jJetMultiplicity",
143 "jLJetMultiplicity",
144 "gJetMultiplicity",
145 "gLJetMultiplicity",
146 "EnergyThreshold",
147 "LArSaturation" };
148
149 for (
const string & boardName :
l1menu.boardNames() ){
150
151 auto & l1board =
l1menu.board(boardName);
152
153 if (l1board.type() != "TOPO") continue;
154 if (l1board.legacy() != legacy) continue;
155
156
157
158 for (const string & connName : l1board.connectorNames() ){
159
160 auto & l1conn =
l1menu.connector(connName);
161
162
163
165
166 for( size_t fpga : { 0, 1} ) {
167 for( size_t clock : { 0, 1} ) {
168 for( auto & tl : l1conn.triggerLines(fpga, clock) ) {
169
170 const string & tlName =
tl.name();
171 auto & algo =
l1menu.algorithmFromTriggerline(tlName);
172 const string algoName = (legacy?"R2_"+algo.name():algo.name());
173
174
175 auto it =
find(storedConn.begin(), storedConn.end(), algoName);
176 if (it == storedConn.end()) {
177
178 storedConn.push_back(algoName);
179 vector<string> inputNames;
180 for( auto & input : algo.inputs() ) {
181 if( sortingConnector(input) == 0 ) {
183 cout <<
"L1TopoSteering: Decision algo( " << algo.name() <<
" ) input is not defined: " <<
input <<
". Creating sortingConnector" << endl;
184
185 auto & sortAlgo =
l1menu.algorithm(input, algo.category());
187 TCS_EXCEPTION(
"L1TopoSteering: Decision algo " << algo.name() <<
") has as input " << input <<
" which is not associated to a sorting algorithm");
188
189
192 cout << "Adding sorting connector " << "[" << *sortConn << "]" << endl;
193 addSortingConnector( sortConn );
194 confAlgorithms.push_back({sortAlgo.name(), sortAlgo.category()});
195
196 }
197
198 inputNames.push_back(input);
199
200 }
201
203 conn->m_decision.setNBits( algo.outputs().size() );
204
205 if(
tl.name() !=
"UNDEF")
206 conn->m_triggers.push_back(tl);
207
209 cout <<
"Adding decision connector " <<
"[" << *
conn <<
"]" << endl;
210 addDecisionConnector( conn );
211 confAlgorithms.push_back({algo.name(), algo.category()});
212
213 } else {
214 for(const auto & out : algo.outputs()){
215 auto c = m_outputLookup.find(out);
216 if (c != m_outputLookup.end()){
217 auto conn =
c->second;
218 if(
tl.name() !=
"UNDEF")
219 conn->m_triggers.push_back(tl);
220 break;
221 }
222 }
223 }
224
225 }
226
227 }
228
229 }
230
231 } else {
232
233
234
235
236 for( auto & tl : l1conn.triggerLines(0, 0) ) {
237
238 const string & tlName =
tl.name();
239 auto & algo =
l1menu.algorithmFromTriggerline(tlName);
240
241 string algo_klass = algo.klass();
242 if(algo_klass=="eEmVarMultiplicity") algo_klass="eEmMultiplicity";
243
244
245
246
247 if ( algo_klass == "ZeroBias" ) continue;
248
249 auto it =
find(storedConn.begin(), storedConn.end(), algo.name());
250 if (it == storedConn.end()) {
251
252 storedConn.push_back(algo.name());
254 cout << "L1TopoSteering: Multiplicity algo( " << algo.name() << " ) has as input " << algo.inputs().at(0) << endl;
255
257 conn->m_count.setNBits(
tl.nbits() );
258 conn->m_count.setFirstBit(
tl.startbit() );
259
260 if(
tl.name() !=
"UNDEF")
261 conn->m_triggers.push_back(tl);
262
264 cout <<
"Adding count connector " <<
"[" << *
conn <<
"]" << endl;
265 addCountingConnector( conn );
266 confMultAlgorithms.push_back( algo.name() );
267 }
268
269 }
270
271 }
272
273 }
274
275 }
276
277
279 cout << "... building input connectors" << endl;
280 for(const auto & sortConn : m_sortedLookup) {
281 const string & in = sortConn.second->
inputNames()[0];
282
283 if( m_inputLookup.count(in) > 0 ) continue;
284
286 m_connectors.push_back(conn);
287 m_inputLookup[in] =
conn;
289 cout <<
"Adding input connector " <<
"[" << *
conn <<
"]" << endl;
290 }
291 for(const auto & countConn : m_countLookup) {
292 const string & in = countConn.second->inputNames()[0];
293
294 if( m_inputLookup.count(in) > 0 ) continue;
295
297 m_connectors.push_back(conn);
298 m_inputLookup[in] =
conn;
300 cout <<
"Adding input connector " <<
"[" << *
conn <<
"]" << endl;
301 }
302
303
305
306
308 cout << "... instantiating algorithms" << endl;
309 sc &= instantiateAlgorithms(
debug);
310
311
312
314 cout << "... setting algorithm parameters" << endl;
315
316 for ( auto & confAlgo : confAlgorithms ) {
317
318 auto & l1algo =
l1menu.algorithm(confAlgo.at(0), confAlgo.at(1));
319 auto l1algoName = confAlgo.at(0);
321 l1algoName ="R2_"+confAlgo.at(0);
322
324 cout << "TopoSteeringStructure: Parameters for algorithm with name " << l1algoName << " going to be configured." << endl;
326
327 if(
alg->isDecisionAlg()){
328 (
static_cast<DecisionAlg *
>(
alg) )->setNumberOutputBits(l1algo.outputs().size());
329 }
330
331 auto ps = std::make_unique<ParameterSpace>(
alg->name());
332
333 for(auto & pe : l1algo.parameters()) {
334
335 auto & pname =
pe.name();
338
340 cout <<
"Algo Name: " << l1algoName <<
" parameter " <<
": " << setw(20) << left << pname <<
" value = " << setw(3) << left <<
val <<
" (selection " <<
sel <<
")" << endl;
341 ps->addParameter( pname, val,
sel);
342
343 }
344
345 for(auto & gen : l1algo.generics().getKeys()) {
346
347 auto pe = l1algo.generics().getObject(gen);
349 uint32_t val = interpretGenericParam(
pe.getAttribute(
"value"));
350 if (pname == "NumResultBits"){
351 if(val != l1algo.outputs().size()) {
352 TCS_EXCEPTION(
"Algorithm " << pname <<
" parameter OutputBits (" << val <<
") is different from output size (" << l1algo.outputs().size() <<
")");
353 }
354 continue;
355 }
357 cout <<
" fixed parameter : " << setw(20) << left << pname <<
" value = " << setw(3) << left <<
val << endl;
358 ps->addParameter( pname, val );
359
360 }
361
362
364 cout << " (setting parameters)";
365 alg->setParameters( *ps );
366
368 cout << " --> (parameters set)";
369
371 cout << " --> (parameters stored)" << endl;
372 }
373
374
375 for ( auto & multAlgo : confMultAlgorithms ) {
376
377 auto & l1algo =
l1menu.algorithm(multAlgo,
"MULTTOPO");
378
379
380
381 if ( l1algo.klass() == "ZeroBias" ) continue;
382
384
385
386
387 auto & l1thr =
l1menu.threshold( l1algo.outputs().at(0) );
389 if (not pCountAlg) continue;
391
392 }
393
394
395 m_isConfigured = true;
396
398 cout << "... L1TopoSteering successfully configured" << endl;
399
401}
const std::vector< std::string > & inputNames() const
void setThreshold(const TrigConf::L1Threshold &thr)
std::string find(const std::string &s)
return a remapped string