CMS 3D CMS Logo

TrigSystem.cc
Go to the documentation of this file.
2 
3 namespace l1t{
4 
5 TrigSystem::TrigSystem() : isConfigured_(false)
6 {
7  logText_ = NULL;
8 }
9 
11 {
12  if (logText_)
13  {
14  std::cout << "Printing all logs\n" << *logText_;
15  delete logText_;
16  }
17 }
18 
19 void TrigSystem::configureSystemFromFiles(const std::string& hwCfgFile, const std::string& topCfgFile, const std::string& key)
20 {
21  // read hw description xml
22  // this will set the sysId
23  {
24  XmlConfigReader xmlRdr;
25  xmlRdr.readDOMFromFile(hwCfgFile);
26  xmlRdr.readRootElement(*this);
27  }
28  // read configuration xml files
29  {
30  XmlConfigReader xmlRdr;
31  xmlRdr.readDOMFromFile(topCfgFile);
32  xmlRdr.buildGlobalDoc(key, topCfgFile);
33  xmlRdr.readContexts(key, sysId_, *this);
34  }
35  isConfigured_ = true;
36 }
37 
38 
39 void TrigSystem::addProcRole(const std::string& processor, const std::string& role)
40 {
41  for(auto it=procRole_.begin(); it!=procRole_.end(); ++it)
42  {
43  if ( it->second.compare(processor) == 0 && it->first.compare(role) != 0 )
44  throw std::runtime_error ("Processor: " + processor + " already exists but with different role");
45  }
46 
47  procRole_[processor] = role;
48 
49  roleProcs_[role].push_back(processor);
50 
51  procEnabled_[processor] = true;
52 
53 }
54 
55 void TrigSystem::addProcSlot(const std::string& processor, const std::string& slot)
56 {
57  procSlot_[processor] = atoi(slot.c_str());
58 }
59 
60 void TrigSystem::addProcCrate(const std::string& processor, const std::string& crate)
61 {
62  crateProcs_[crate].push_back(processor);
63 }
64 
65 void TrigSystem::addDaqRole(const std::string& daq, const std::string& role)
66 {
67  for(auto it=daqttcRole_.begin(); it!=daqttcRole_.end(); ++it)
68  {
69  if ( it->first.compare(daq) == 0 && it->second.compare(role) != 0 )
70  throw std::runtime_error ("DAQttc: " + daq + " already exists but with different role");
71  }
72 
73  roleDaqttcs_[role].push_back(daq);
74  daqttcRole_[daq] = role;
75 }
76 
77 void TrigSystem::addDaqCrate(const std::string& daq, const std::string& crate)
78 {
79  daqttcCrate_[daq] = crate;
80 }
81 
82 void TrigSystem::addSetting(const std::string& type, const std::string& id, const std::string& value, const std::string& procRole, const std::string& delim)
83 {
84  bool applyOnRole, foundRoleProc(false);
85 
86  if (procRole_.find(procRole) != procRole_.end())
87  {
88  applyOnRole = false;
89  foundRoleProc = true;
90  }
91  else if (roleProcs_.find(procRole) != roleProcs_.end())
92  {
93  applyOnRole = true;
94  foundRoleProc = true;
95  }
96 
97  if (!foundRoleProc)
98  throw std::runtime_error ("Processor or Role " + procRole + " was not found in the map");
99 
100  if (!applyOnRole)
101  {
102  if (!checkIdExistsAndSetSetting_(procSettings_[procRole], id, value, procRole))
103  procSettings_[procRole].push_back(Setting(type, id, value, procRole, logText_, delim));
104 
105  }
106  else
107  {
108  for( auto it = roleProcs_[procRole].begin(); it != roleProcs_[procRole].end(); ++it)
109  {
110  if ( procSettings_.find(*it) != procSettings_.end() )
111  {
112  bool SettingAlreadyExist(false);
113  for(auto is = procSettings_.at(*it).begin(); is != procSettings_.at(*it).end(); ++is)
114  {
115  if (is->getId().compare(id) == 0)
116  {
117  SettingAlreadyExist = true;
118  break;
119  }
120  }
121  if (!SettingAlreadyExist)
122  procSettings_.at(*it).push_back(Setting(type, id, value, procRole, logText_, delim));
123  }
124  else
125  procSettings_[*it].push_back(Setting(type, id, value, procRole, logText_, delim));
126  }
127 
128  }
129 }
130 
131 void TrigSystem::addSettingTable(const std::string& id, const std::string& columns, const std::string& types, const std::vector<std::string>& rows, const std::string& procRole, const std::string& delim)
132 {
133  bool applyOnRole, foundRoleProc(false);
134 
135  if (procRole_.find(procRole) != procRole_.end())
136  {
137  applyOnRole = false;
138  foundRoleProc = true;
139  }
140  else if (roleProcs_.find(procRole) != roleProcs_.end())
141  {
142  applyOnRole = true;
143  foundRoleProc = true;
144  }
145  if (!foundRoleProc)
146  throw std::runtime_error ("Processor or Role " + procRole + " was not found in the map");
147 
148  if (!applyOnRole)
149  {
150  if (!checkIdExistsAndSetSetting_(procSettings_[procRole], id, columns, types, rows, procRole, delim))
151  procSettings_[procRole].push_back(Setting(id, columns, types, rows, procRole, logText_, delim));
152 
153  }
154  else
155  {
156  for( auto it = roleProcs_[procRole].begin(); it != roleProcs_[procRole].end(); ++it)
157  {
158  if ( procSettings_.find(*it) != procSettings_.end() )
159  {
160  bool SettingAlreadyExist(false);
161  for(auto is = procSettings_.at(*it).begin(); is != procSettings_.at(*it).end(); ++is)
162  {
163  if (is->getId().compare(id) == 0)
164  {
165  SettingAlreadyExist = true;
166  break;
167  }
168  }
169  if (!SettingAlreadyExist)
170  procSettings_.at(*it).push_back(Setting(id, columns, types, rows, procRole, logText_, delim));
171  }
172  else
173  procSettings_[*it].push_back(Setting(id, columns, types, rows, procRole, logText_, delim));
174  }
175 
176  }
177 }
178 
179 std::map<std::string, Setting> TrigSystem::getSettings(const std::string& processor)
180 {
181  if (!isConfigured_)
182  throw std::runtime_error("TrigSystem is not configured yet. First call the configureSystem method");
183  if ( procRole_.find(processor) == procRole_.end() )
184  throw std::runtime_error ("Processor " + processor + " was not found in the TrigSystem object list");
185 
186  std::map<std::string, Setting> Settings;
187  std::vector<Setting> vecSettings = procSettings_.at(processor);
188  for(auto it=vecSettings.begin(); it!=vecSettings.end(); ++it)
189  Settings.insert(std::pair<std::string, Setting>(it->getId(), *it));
190 
191  return Settings;
192 }
193 
194 bool TrigSystem::checkIdExistsAndSetSetting_(std::vector<Setting>& vec, const std::string& id, const std::string& value, const std::string& procRole)
195 {
196  bool found(false);
197  for(auto it = vec.begin(); it != vec.end(); ++it)
198  {
199  if (it->getId().compare(id) == 0)
200  {
201  found = true;
202  it->setValue(value);
203  it->setProcRole(procRole);
204  }
205  }
206 
207  return found;
208 }
209 
210 bool TrigSystem::checkIdExistsAndSetSetting_(std::vector<Setting>& vec, const std::string& id, const std::string& columns, const std::string& types, const std::vector<std::string>& rows, const std::string& procRole, const std::string& delim)
211 {
212  bool found(false);
213  for(auto it = vec.begin(); it != vec.end(); ++it)
214  {
215  if (it->getId().compare(id) == 0)
216  {
217  found = true;
218 
219  it->resetTableRows();
220  //it->setRowTypes(types);
221  //it->setRowColumns(columns);
222  for(auto ir=rows.begin(); ir!=rows.end(); ++ir)
223  it->addTableRow(*ir, str2VecStr_(types, delim), str2VecStr_(columns, delim));
224 
225  }
226  }
227 
228  return found;
229 }
230 
231 void TrigSystem::addMask(const std::string& id, const std::string& procRole)
232 {
233  bool applyOnRole(false), foundRoleProc(false);
234 
235  if (procRole_.find(procRole) != procRole_.end())
236  {
237  applyOnRole = false;
238  foundRoleProc = true;
239  }
240  else if (roleProcs_.find(procRole) != roleProcs_.end())
241  {
242  applyOnRole = true;
243  foundRoleProc = true;
244  }
245 
246 
247  if (!applyOnRole && foundRoleProc)
248  procMasks_[procRole].push_back(Mask(id, procRole));
249 
250  else if (applyOnRole && foundRoleProc)
251  {
252  for( auto it = roleProcs_[procRole].begin(); it != roleProcs_[procRole].end(); ++it)
253  {
254  if ( procMasks_.find(*it) != procMasks_.end() )
255  {
256  bool MaskAlreadyExist(false);
257  for(auto is = procMasks_.at(*it).begin(); is != procMasks_.at(*it).end(); ++is)
258  {
259  if (is->getId().compare(id) == 0)
260  {
261  MaskAlreadyExist = true;
262  break;
263  }
264  }
265  if (!MaskAlreadyExist)
266  procMasks_.at(*it).push_back(Mask(id, procRole));
267  }
268  else
269  procMasks_[*it].push_back(Mask(id, procRole));
270  }
271 
272  }
273 
274  else if (!applyOnRole && !foundRoleProc)
275  {
276  if ( daqttcRole_.find(procRole) != daqttcRole_.end() )
277  {
278  for( auto it = crateProcs_[daqttcCrate_[procRole]].begin(); it != crateProcs_[daqttcCrate_[procRole]].end(); ++it)
279  {
280  if (procSlot_[*it] == atoi(id.substr(11,2).c_str()) )
281  procEnabled_.at(*it) = false;
282  }
283 
284  }
285  else if ( roleDaqttcs_.find(procRole) != roleDaqttcs_.end() )
286  {
287  for( auto it=roleDaqttcs_[procRole].begin(); it!=roleDaqttcs_[procRole].end(); ++it)
288  {
289  for( auto itt = crateProcs_[daqttcCrate_[*it]].begin(); itt != crateProcs_[daqttcCrate_[*it]].end(); ++itt)
290  {
291  if ( procSlot_[*itt] == atoi(id.substr(11,2).c_str()) )
292  procEnabled_.at(*itt) = false;
293  }
294  }
295 
296  }
297 
298  }
299  if (procRole_.find(procRole) == procRole_.end() && roleProcs_.find(procRole) == roleProcs_.end() && daqttcRole_.find(procRole) == daqttcRole_.end() && roleDaqttcs_.find(procRole) == roleDaqttcs_.end() )
300  throw std::runtime_error ("Processor/DAQ or Role " + procRole + " was not found in the map for masking");
301 
302 }
303 
304 std::map<std::string, Mask> TrigSystem::getMasks(const std::string& processor)
305 {
306  if (!isConfigured_)
307  throw std::runtime_error("TrigSystem is not configured yet. First call the configureSystem method");
308  if ( procRole_.find(processor) == procRole_.end() )
309  throw std::runtime_error ("Processor " + processor + " was not found in the TrigSystem object list");
310 
311  std::map<std::string, Mask> Masks;
312  std::vector<Mask> vecMasks= procMasks_.at(processor);
313  for(auto it=vecMasks.begin(); it!=vecMasks.end(); ++it)
314  Masks.insert(std::pair<std::string, Mask>(it->getId(), *it));
315 
316  return Masks;
317 }
318 
319 bool TrigSystem::isMasked(const std::string& processor, const std::string& id)
320 {
321 
322  if (!isConfigured_)
323  throw std::runtime_error("TrigSystem is not configured yet. First call the configureSystem method");
324 
325  bool isMasked = false;
326  std::vector<Mask> vecMasks= procMasks_.at(processor);
327  for(auto it=vecMasks.begin(); it!=vecMasks.end(); ++it)
328  {
329  if (it->getId() == id)
330  {
331  isMasked = true;
332  break;
333  }
334  }
335 
336  edm::LogInfo ("l1t::TrigSystem::isMasked") << "Returning " << isMasked << " for processor " << processor << " and port " << id;
337  return isMasked;
338 }
339 
341 {
342  if ( procRole_.find(daqProc) == procRole_.end() && roleProcs_.find(daqProc) == roleProcs_.end() && roleDaqttcs_.find(daqProc) == roleDaqttcs_.end() && daqttcRole_.find(daqProc) == daqttcRole_.end() )
343  throw std::runtime_error("Cannot Mask daq/processor " + daqProc + "! Not found in the system.");
344 
345  if ( procRole_.find(daqProc) != procRole_.end() )
346  procEnabled_.at(daqProc) = false;
347  else if ( roleProcs_.find(daqProc) != roleProcs_.end() )
348  {
349  for (auto it = roleProcs_[daqProc].begin(); it != roleProcs_[daqProc].end(); ++it)
350  procEnabled_.at(*it) = false;
351  }
352  else if ( daqttcRole_.find(daqProc) != daqttcRole_.end() )
353  {
354  for(auto it = crateProcs_[daqttcCrate_[daqProc]].begin(); it != crateProcs_[daqttcCrate_[daqProc]].end(); ++it)
355  procEnabled_.at(*it) = false;
356  }
357  else if ( roleDaqttcs_.find(daqProc) != roleDaqttcs_.end() )
358  {
359  for(auto it = roleDaqttcs_[daqProc].begin(); it != roleDaqttcs_[daqProc].end(); ++it)
360  {
361  for(auto itt = crateProcs_[daqttcCrate_[*it]].begin(); itt != crateProcs_[daqttcCrate_[*it]].begin(); ++itt)
362  procEnabled_.at(*itt) = false;
363  }
364  }
365 }
366 
368 {
369  if (!isConfigured_)
370  throw std::runtime_error("TrigSystem is not configured yet. First call the configureSystem method");
371 
372  edm::LogInfo ("l1t::TrigSystem::isProcEnabled") << "Returning " << procEnabled_[processor] << " for processor " << processor;
373  return procEnabled_[processor];
374 }
375 
376 }
void disableDaqProc(const std::string &daqProc)
Definition: TrigSystem.cc:340
type
Definition: HCALResponse.h:21
void readDOMFromFile(const std::string &fName, xercesc::DOMDocument *&doc)
bool isMasked(const std::string &proccessor, const std::string &id)
Definition: TrigSystem.cc:319
std::map< std::string, std::vector< std::string > > roleProcs_
Definition: TrigSystem.h:45
std::map< std::string, std::string > daqttcCrate_
Definition: TrigSystem.h:49
void readRootElement(TrigSystem &aTrigSystem, const std::string &sysId="")
#define NULL
Definition: scimark2.h:8
delete x;
Definition: CaloConfig.h:22
std::map< std::string, std::string > daqttcRole_
Definition: TrigSystem.h:48
void addMask(const std::string &id, const std::string &procRole)
Definition: TrigSystem.cc:231
void addDaqRole(const std::string &daq, const std::string &role)
Definition: TrigSystem.cc:65
bool isConfigured_
Definition: TrigSystem.h:55
void configureSystemFromFiles(const std::string &hwCfgFile, const std::string &topCfgFile, const std::string &key)
Definition: TrigSystem.cc:19
void addSetting(const std::string &type, const std::string &id, const std::string &value, const std::string &procRole, const std::string &delim="")
Definition: TrigSystem.cc:82
std::vector< std::string > str2VecStr_(const std::string &aStr, const std::string &delim)
Definition: Tools.cc:23
void addProcRole(const std::string &processor, const std::string &role)
Definition: TrigSystem.cc:39
std::map< std::string, std::vector< std::string > > crateProcs_
Definition: TrigSystem.h:46
void buildGlobalDoc(const std::string &key, const std::string &topPath="")
void addProcCrate(const std::string &processor, const std::string &crate)
Definition: TrigSystem.cc:60
std::string * logText_
Definition: TrigSystem.h:58
bool checkIdExistsAndSetSetting_(std::vector< Setting > &vec, const std::string &id, const std::string &value, const std::string &procRole)
Definition: TrigSystem.cc:194
std::map< std::string, std::vector< std::string > > roleDaqttcs_
Definition: TrigSystem.h:47
std::map< std::string, std::vector< Setting > > procSettings_
Definition: TrigSystem.h:51
std::map< std::string, int > procSlot_
Definition: TrigSystem.h:44
Definition: value.py:1
std::string sysId_
Definition: TrigSystem.h:56
bool isProcEnabled(const std::string &proccessor)
Definition: TrigSystem.cc:367
void readContexts(const std::string &key, const std::string &sysId, TrigSystem &aTrigSystem)
std::map< std::string, Setting > getSettings(const std::string &processor)
Definition: TrigSystem.cc:179
void addDaqCrate(const std::string &daq, const std::string &crate)
Definition: TrigSystem.cc:77
void addProcSlot(const std::string &processor, const std::string &slot)
Definition: TrigSystem.cc:55
#define begin
Definition: vmac.h:30
std::map< std::string, bool > procEnabled_
Definition: TrigSystem.h:53
std::map< std::string, std::vector< Mask > > procMasks_
Definition: TrigSystem.h:52
std::map< std::string, Mask > getMasks(const std::string &proccessor)
Definition: TrigSystem.cc:304
std::map< std::string, std::string > procRole_
Definition: TrigSystem.h:41
void addSettingTable(const std::string &id, const std::string &columns, const std::string &types, const std::vector< std::string > &rows, const std::string &procRole, const std::string &delim)
Definition: TrigSystem.cc:131
Definition: Mask.h:10