ATLAS Offline Software
Functions
TopoSteeringStructure.cxx File Reference
#include "L1TopoCoreSim/TopoSteeringStructure.h"
#include "L1TopoCommon/StringUtils.h"
#include "L1TopoCommon/Exception.h"
#include "L1TopoCommon/Types.h"
#include "L1TopoConfig/LayoutConstraints.h"
#include "L1TopoConfig/L1TopoMenu.h"
#include "L1TopoInterfaces/DecisionAlg.h"
#include "L1TopoInterfaces/SortingAlg.h"
#include "L1TopoInterfaces/CountingAlg.h"
#include "L1TopoCoreSim/Connector.h"
#include "L1TopoCoreSim/InputConnector.h"
#include "L1TopoCoreSim/SortingConnector.h"
#include "L1TopoCoreSim/DecisionConnector.h"
#include "L1TopoCoreSim/CountingConnector.h"
#include "L1TopoHardware/L1TopoHardware.h"
#include "TrigConfData/L1Menu.h"
#include <set>
#include <iostream>
#include <iomanip>
#include <memory>
#include <boost/lexical_cast.hpp>

Go to the source code of this file.

Functions

TCS::StatusCode TCS::TopoSteeringStructure::setupFromMenu ATLAS_NOT_THREAD_SAFE (const TrigConf::L1Menu &l1menu, bool legacy, bool debug)
 
TCS::StatusCode TCS::TopoSteeringStructure::instantiateAlgorithms ATLAS_NOT_THREAD_SAFE (bool debug)
 

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE() [1/2]

TCS::StatusCode TCS::TopoSteeringStructure::instantiateAlgorithms ATLAS_NOT_THREAD_SAFE ( bool  debug)

Definition at line 443 of file TopoSteeringStructure.cxx.

443  {
444 
445  for(TCS::Connector* conn: m_connectors) {
446 
447  if(conn->isInputConnector()) continue;
448 
449  // for each connector instantiate the algorithm and add to connector
450  const std::string & alg = conn->algorithmName();
451 
452  // split into name and type
453  std::string algType(alg, 0, alg.find('/'));
454  std::string algName(alg, alg.find('/')+1);
455 
456  ConfigurableAlg * algInstance = TCS::AlgFactory::mutable_instance().algorithm(algName);
457  if(algInstance==0) {
458  if(debug)
459  cout << "Instantiating " << alg << endl;
460  algInstance = TCS::AlgFactory::mutable_instance().create(algType, algName);
461  } else {
462  if(algInstance->className() != algType) {
463  TCS_EXCEPTION("L1 TopoSteering: duplicate algorithm names: algorithm " << algName << " has already been instantiated but with different type");
464  }
465  }
466  conn->setAlgorithm(algInstance);
467  }
469 }

◆ ATLAS_NOT_THREAD_SAFE() [2/2]

TCS::StatusCode TCS::TopoSteeringStructure::setupFromMenu ATLAS_NOT_THREAD_SAFE ( const TrigConf::L1Menu l1menu,
bool  legacy,
bool  debug 
)

Definition at line 125 of file TopoSteeringStructure.cxx.

125  {
126 
127  if(debug)
128  cout << "/***************************************************************************/" << endl
129  << " L1Topo steering structure: configuring from L1 Topo Menu " << endl
130  << "/***************************************************************************/" << endl;
131 
132  // set<TCS::inputTOBType_t> neededInputs; // Stores inputs for DecisionConnectors
133  vector<string> storedConn; // Stores decision connectors in order to avoid double counting
134  vector<vector<string>> confAlgorithms; // Stores algorithm name/category that have been configured in L1Menu to be used for setting the parameters
135  vector<string> confMultAlgorithms; // Stores algorithm names that have been configured in L1Menu to be used for setting the multiplicity thresholds
136  // Loop over boards in L1Menu and skip the ones that are not TOPO. Use Run-2 boards if legacy flag is on
137 
138  string AvailableMultAlgs[] = { "eEmMultiplicity",
139  "jEmMultiplicity",
140  "eTauMultiplicity",
141  "jTauMultiplicity",
142  "cTauMultiplicity",
143  "jJetMultiplicity",
144  "jLJetMultiplicity",
145  "gJetMultiplicity",
146  "gLJetMultiplicity",
147  "EnergyThreshold",
148  "LArSaturation" };
149 
150  for (const string & boardName : l1menu.boardNames() ){
151 
152  auto & l1board = l1menu.board(boardName);
153 
154  if (l1board.type() != "TOPO") continue;
155  if (l1board.legacy() != legacy) continue;
156 
157  // Access the connectors in the boards
158 
159  for (const string & connName : l1board.connectorNames() ){
160 
161  auto & l1conn = l1menu.connector(connName);
162 
163  // First configure decision algorithms
164  // Look at all Topo algorithms in each connector, and get inputs from each algorithm to configure SortingConnectors
165  if ( l1conn.connectorType() == TrigConf::L1Connector::ConnectorType::ELECTRICAL ) {
166 
167  for( size_t fpga : { 0, 1} ) {
168  for( size_t clock : { 0, 1} ) {
169  for( auto & tl : l1conn.triggerLines(fpga, clock) ) {
170 
171  const string & tlName = tl.name();
172  auto & algo = l1menu.algorithmFromTriggerline(tlName);
173  const string algoName = (legacy?"R2_"+algo.name():algo.name());
174 
175  // One algorithm can have multiple trigger lines. Check the connector/algorithm has not been stored already
176  auto it = find(storedConn.begin(), storedConn.end(), algoName);
177  if (it == storedConn.end()) { // Algorithm/Connector does not exist: create and store it
178 
179  storedConn.push_back(algoName);
180  vector<string> inputNames;
181  for( auto & input : algo.inputs() ) {
182  if( sortingConnector(input) == 0 ) { // if connector does not exist, create it
183  if(debug)
184  cout << "L1TopoSteering: Decision algo( " << algo.name() << " ) input is not defined: " << input << ". Creating sortingConnector" << endl;
185 
186  auto & sortAlgo = l1menu.algorithm(input, algo.category());
187  if(!(sortAlgo.type() == TrigConf::L1TopoAlgorithm::AlgorithmType::SORTING ) )
188  TCS_EXCEPTION("L1TopoSteering: Decision algo " << algo.name() << ") has as input " << input << " which is not associated to a sorting algorithm");
189 
190  // Create connector
191  SortingConnector * sortConn = new SortingConnector(sortAlgo.inputs().at(0), sortAlgo.klass()+"/"+input, sortAlgo.outputs().at(0));
192  if(debug)
193  cout << "Adding sorting connector " << "[" << *sortConn << "]" << endl;
194  addSortingConnector( sortConn );
195  confAlgorithms.push_back({sortAlgo.name(), sortAlgo.category()});
196 
197  } // if connector does not exist
198 
199  inputNames.push_back(input);
200 
201  } // loop over inputs
202 
203  DecisionConnector * conn = new DecisionConnector(algoName, inputNames, algo.klass()+"/"+algoName, algo.outputs());
204  conn->m_decision.setNBits( algo.outputs().size() );
205 
206  if(tl.name() != "UNDEF")
207  conn->m_triggers.push_back(tl);
208 
209  if(debug)
210  cout << "Adding decision connector " << "[" << *conn << "]" << endl;
211  addDecisionConnector( conn );
212  confAlgorithms.push_back({algo.name(), algo.category()});
213 
214  } else { // Connector already exists: look for it and add the trigger line
215  for(const auto & out : algo.outputs()){
216  auto c = m_outputLookup.find(out);
217  if (c != m_outputLookup.end()){
218  auto conn = c->second;
219  if(tl.name() != "UNDEF")
220  conn->m_triggers.push_back(tl);
221  break;
222  }
223  }
224  }
225 
226  } // Trigger Line
227 
228  } // Clock
229 
230  } // FPGA
231 
232  } else { // Configure optical connectors - multiplicity algorithms
233 
234  // In multiplicity boards all trigger lines are copied into the L1Menu::Connector 4 times (fpga 0,1 and clock 0,1)
235  // Take (fpga, clock) = (0, 0)
236 
237  for( auto & tl : l1conn.triggerLines(0, 0) ) {
238 
239  const string & tlName = tl.name();
240  auto & algo = l1menu.algorithmFromTriggerline(tlName);
241 
242  string algo_klass = algo.klass();
243  if(algo_klass=="eEmVarMultiplicity") algo_klass="eEmMultiplicity"; // in sim, use the same multiplicity algo for fixed and variable thresholds
244 
245  //Zero Bias events can't be simulated.
246  //The following line is set to simply ignore it in the simulation
247  //ZeroBias Multiplicity algorithms are not added to confMultAlgorithms
248  if ( algo_klass == "ZeroBias" ) continue;
249 
250  auto it = find(storedConn.begin(), storedConn.end(), algo.name());
251  if (it == storedConn.end()) { // Algorithm/Connector does not exist: create and store it
252 
253  storedConn.push_back(algo.name());
254  if(debug)
255  cout << "L1TopoSteering: Multiplicity algo( " << algo.name() << " ) has as input " << algo.inputs().at(0) << endl;
256 
257  CountingConnector * conn = new CountingConnector(algo.name(), algo.inputs().at(0), algo_klass+"/"+algo.name(), algo.outputs().at(0));
258  conn->m_count.setNBits( tl.nbits() );
259  conn->m_count.setFirstBit( tl.startbit() );
260 
261  if(tl.name() != "UNDEF")
262  conn->m_triggers.push_back(tl);
263 
264  if(debug)
265  cout << "Adding count connector " << "[" << *conn << "]" << endl;
266  addCountingConnector( conn );
267  confMultAlgorithms.push_back( algo.name() );
268  }
269 
270  } // Trigger Line
271 
272  } // Optical connectors - multiplicities
273 
274  } // Connector in l1board
275 
276  } // Board in l1menu
277 
278 
279  if(debug)
280  cout << "... building input connectors" << endl;
281  for(const auto & sortConn : m_sortedLookup) {
282  const string & in = sortConn.second->inputNames()[0]; // name of input
283 
284  if( m_inputLookup.count(in) > 0 ) continue; // InputConnector already exists
285 
286  InputConnector * conn = new InputConnector(in);
287  m_connectors.push_back(conn);
288  m_inputLookup[in] = conn;
289  if(debug)
290  cout << "Adding input connector " << "[" << *conn << "]" << endl;
291  }
292  for(const auto & countConn : m_countLookup) {
293  const string & in = countConn.second->inputNames()[0]; // name of input
294 
295  if( m_inputLookup.count(in) > 0 ) continue; // InputConnector already exists
296 
297  InputConnector * conn = new InputConnector(in);
298  m_connectors.push_back(conn);
299  m_inputLookup[in] = conn;
300  if(debug)
301  cout << "Adding input connector " << "[" << *conn << "]" << endl;
302  }
303 
304  // link the connector objects together
305  TCS::StatusCode sc = linkConnectors();
306 
307  // instantiate the algorithms from the algorithm names in the connectors
308  if(debug)
309  cout << "... instantiating algorithms" << endl;
310  sc &= instantiateAlgorithms(debug);
311 
312 
313  // set algorithm parameters
314  if(debug)
315  cout << "... setting algorithm parameters" << endl;
316 
317  for ( auto & confAlgo : confAlgorithms ) {
318 
319  auto & l1algo = l1menu.algorithm(confAlgo.at(0), confAlgo.at(1));
320  auto l1algoName = confAlgo.at(0);
322  l1algoName ="R2_"+confAlgo.at(0);
323 
324  if(debug)
325  cout << "TopoSteeringStructure: Parameters for algorithm with name " << l1algoName << " going to be configured." << endl;
326  ConfigurableAlg * alg = AlgFactory::mutable_instance().algorithm(l1algoName);
327 
328  if(alg->isDecisionAlg()){
329  ( static_cast<DecisionAlg *>(alg) )->setNumberOutputBits(l1algo.outputs().size());
330  }
331  // create ParameterSpace for this algorithm
332  auto ps = std::make_unique<ParameterSpace>(alg->name());
333 
334  for(auto & pe : l1algo.parameters()) {
335 
336  auto & pname = pe.name();
337  uint32_t val = pe.value();
338  uint32_t sel = pe.selection();
339 
340  if(debug)
341  cout << "Algo Name: " << l1algoName << " parameter " << ": " << setw(20) << left << pname << " value = " << setw(3) << left << val << " (selection " << sel << ")" << endl;
342  ps->addParameter( pname, val, sel);
343 
344  }
345 
346  for(auto & gen : l1algo.generics().getKeys()) {
347 
348  auto pe = l1algo.generics().getObject(gen);
349  string pname = gen;
350  uint32_t val = interpretGenericParam(pe.getAttribute("value"));
351  if (pname == "NumResultBits"){
352  if(val != l1algo.outputs().size()) {
353  TCS_EXCEPTION("Algorithm " << pname << " parameter OutputBits (" << val << ") is different from output size (" << l1algo.outputs().size() << ")");
354  }
355  continue; // ignore this, because it is defined through the output list
356  }
357  if(debug)
358  cout << " fixed parameter : " << setw(20) << left << pname << " value = " << setw(3) << left << val << endl;
359  ps->addParameter( pname, val );
360 
361  }
362 
363 
364  if(debug)
365  cout << " (setting parameters)";
366  alg->setParameters( *ps );
367 
368  if(debug)
369  cout << " --> (parameters set)";
370 
371  if(debug)
372  cout << " --> (parameters stored)" << endl;
373  } // Set parameters for Sorting/Decision algorithms
374 
375  // // set thresholds for multiplicity algorithms
376  for ( auto & multAlgo : confMultAlgorithms ) {
377 
378  auto & l1algo = l1menu.algorithm(multAlgo, "MULTTOPO");
379 
380  //Zero Bias events can't be simulated.
381  //The following line is set to simply ignore it in the simulation
382  if ( l1algo.klass() == "ZeroBias" ) continue;
383 
384  ConfigurableAlg * alg = AlgFactory::mutable_instance().algorithm(l1algo.name());
385 
386  // Get L1Threshold object and pass it to CountingAlg, from where it will be propagated to and decoded in each algorithm
387  // The output of each algorithm and the threshold name is the same - use output name to retrieve L1Threshold object
388  auto & l1thr = l1menu.threshold( l1algo.outputs().at(0) );
389  auto pCountAlg = dynamic_cast<CountingAlg *>(alg);
390  if (not pCountAlg) continue;
391  pCountAlg->setThreshold(l1thr);
392 
393  } // Set thresholds for multiplicity algorithms
394 
395 
396  m_isConfigured = true;
397 
398  if(debug)
399  cout << "... L1TopoSteering successfully configured" << endl;
400 
401  return sc;
402 }
TCS::ConfigurableAlg::className
const std::string & className() const
Definition: ConfigurableAlg.h:49
checkCorrelInHIST.conn
conn
Definition: checkCorrelInHIST.py:25
TCS::StatusCode::SUCCESS
@ SUCCESS
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:17
SGout2dot.alg
alg
Definition: SGout2dot.py:243
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TCS::Connector
Definition: Connector.h:22
xAOD::JetAlgorithmType::algName
const std::string & algName(ID id)
Converts a JetAlgorithmType::ID into a string.
Definition: JetContainerInfo.cxx:67
skel.it
it
Definition: skel.GENtoEVGEN.py:396
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
TCS::CountingConnector
Definition: CountingConnector.h:26
TCS::SortingConnector
Definition: SortingConnector.h:24
LArG4AODNtuplePlotter.pe
pe
Definition: LArG4AODNtuplePlotter.py:116
master.gen
gen
Definition: master.py:32
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TCS::DecisionAlg
Definition: Trigger/TrigT1/L1Topo/L1TopoInterfaces/L1TopoInterfaces/DecisionAlg.h:22
TrigConf::L1TopoAlgorithm::AlgorithmType::SORTING
@ SORTING
TCS::InputConnector
Definition: InputConnector.h:22
sel
sel
Definition: SUSYToolsTester.cxx:97
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
TrigConf::L1Connector::ConnectorType::ELECTRICAL
@ ELECTRICAL
TCS_EXCEPTION
#define TCS_EXCEPTION(MSG)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Exception.h:14
TCS::CountingAlg::setThreshold
void setThreshold(const TrigConf::L1Threshold &thr)
Definition: CountingAlg.h:44
TCS::ConfigurableAlg
Definition: ConfigurableAlg.h:30
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
TrigConf::L1TopoAlgorithm::AlgorithmType::DECISION
@ DECISION
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
MistimedStreamPhI_runStandalone.legacy
legacy
Definition: MistimedStreamPhI_runStandalone.py:110
python.XMLReader.l1menu
l1menu
Definition: XMLReader.py:73
dqt_zlumi_alleff_HIST.tl
tl
Definition: dqt_zlumi_alleff_HIST.py:73
TCS::Connector::inputNames
const std::vector< std::string > & inputNames() const
Definition: Connector.h:46
python.compressB64.c
def c
Definition: compressB64.py:93
TCS::DecisionConnector
Definition: DecisionConnector.h:23
TCS::CountingAlg
Definition: CountingAlg.h:25
TCS::StatusCode
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:15