CMS 3D CMS Logo

HLTPrescaleProvider.cc
Go to the documentation of this file.
1 
12 
13 #include <cassert>
14 #include <sstream>
15 
16 static const bool useL1EventSetup(true);
17 static const bool useL1GtTriggerMenuLite(false);
18 static const unsigned char countMax(2);
19 
21  const edm::EventSetup& iSetup,
22  const std::string& processName,
23  bool& changed) {
24 
25  count_[0]=0;
26  count_[1]=0;
27  count_[2]=0;
28  count_[3]=0;
29  count_[4]=0;
30 
31  const bool result(hltConfigProvider_.init(iRun, iSetup, processName, changed));
32 
33  const unsigned int l1tType(hltConfigProvider_.l1tType());
34  if (l1tType==1) {
37  } else if (l1tType==2) {
39  } else {
40  edm::LogError("HLTPrescaleProvider")
41  << " Unknown L1T Type " << l1tType << " - prescales will not be avaiable!";
42  }
43 
44  return result;
45 }
46 
48  const unsigned int l1tType(hltConfigProvider_.l1tType());
49  if (l1tType==1) {
50  // return hltPrescaleTable_.set();
52  int errorTech(0);
53  const int psfsiTech(l1GtUtils_.prescaleFactorSetIndex(iEvent,L1GtUtils::TechnicalTrigger,errorTech));
54  int errorPhys(0);
55  const int psfsiPhys(l1GtUtils_.prescaleFactorSetIndex(iEvent,L1GtUtils::AlgorithmTrigger,errorPhys));
56  assert(psfsiTech==psfsiPhys);
57  if ( (errorTech==0) && (errorPhys==0) &&
58  (psfsiTech>=0) && (psfsiPhys>=0) && (psfsiTech==psfsiPhys) ) {
59  return psfsiPhys;
60  } else {
62  if (count_[0]<countMax) {
63  count_[0] += 1;
64  edm::LogError("HLTPrescaleProvider")
65  << " Using processName '" << hltConfigProvider_.processName() <<"':"
66  << " Error in determining HLT prescale set index from L1 data using L1GtUtils:"
67  << " Tech/Phys error = " << errorTech << "/" << errorPhys
68  << " Tech/Phys psfsi = " << psfsiTech << "/" << psfsiPhys;
69  }
70  return -1;
71  }
72  } else if (l1tType==2) {
73  l1tGlobalUtil_.retrieveL1Event(iEvent,iSetup);
74  return static_cast<int>(l1tGlobalUtil_.prescaleColumn());
75  } else {
76  if (count_[0]<countMax) {
77  count_[0] += 1;
78  edm::LogError("HLTPrescaleProvider")
79  << " Using processName '" << hltConfigProvider_.processName() <<"':"
80  << " Unknown L1T Type " << l1tType << " - can not determine prescale set index!";
81  }
82  return -1;
83  }
84 
85 }
86 
88  const edm::EventSetup& iSetup,
89  const std::string& trigger) {
90  const int set(prescaleSet(iEvent,iSetup));
91  if (set<0) {
92  return 1;
93  } else {
94  return hltConfigProvider_.prescaleValue(static_cast<unsigned int>(set),trigger);
95  }
96 }
97 
98 std::pair<int,int>
100  const edm::EventSetup& iSetup,
101  const std::string& trigger) {
102 
103  // start with setting both L1T and HLT prescale values to 0
104  std::pair<int,int> result(std::pair<int,int>(0,0));
105 
106  // get HLT prescale (possible if HLT prescale set index is correctly found)
107  const int set(prescaleSet(iEvent,iSetup));
108  if (set<0) {
109  result.second = -1;
110  } else {
111  result.second = static_cast<int>(hltConfigProvider_.prescaleValue(static_cast<unsigned int>(set),trigger));
112  }
113 
114  // get L1T prescale - works only for those hlt trigger paths with
115  // exactly one L1GT seed module which has exactly one L1T name as seed
116 
117  const unsigned int l1tType(hltConfigProvider_.l1tType());
118  if (l1tType==1){
119  const unsigned int nL1GTSeedModules(hltConfigProvider_.hltL1GTSeeds(trigger).size());
120  if (nL1GTSeedModules==0) {
121  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
122  result.first=1;
123  } else if (nL1GTSeedModules==1) {
125  const std::string l1tname(hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second);
126  int l1error(0);
127  result.first = l1GtUtils_.prescaleFactor(iEvent,l1tname,l1error);
128  if (l1error!=0) {
129  if (count_[1]<countMax) {
130  count_[1] += 1;
131  edm::LogError("HLTPrescaleProvider")
132  << " Error in determining L1T prescale for HLT path: '" << trigger
133  << "' with L1T seed: '" << l1tname
134  << "' using L1GtUtils: error code = " << l1error << "." << std::endl
135  << " Note: for this method ('prescaleValues'), only a single L1T name (and not a bit number) is allowed as seed!"
136  << std::endl
137  << " For seeds being complex logical expressions, try the new method 'prescaleValuesInDetail'."<< std::endl;
138  }
139  result.first = -1;
140  }
141  } else {
143  if (count_[2]<countMax) {
144  count_[2] += 1;
145  std::string dump("'"+hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second+"'");
146  for (unsigned int i=1; i!=nL1GTSeedModules; ++i) {
147  dump += " * '"+hltConfigProvider_.hltL1GTSeeds(trigger).at(i).second+"'";
148  }
149  edm::LogError("HLTPrescaleProvider")
150  << " Error in determining L1T prescale for HLT path: '" << trigger
151  << "' has multiple L1GTSeed modules, " << nL1GTSeedModules
152  << ", with L1 seeds: " << dump
153  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
154  }
155  result.first = -1;
156  }
157  } else if (l1tType==2){
158  const unsigned int nL1TSeedModules(hltConfigProvider_.hltL1TSeeds(trigger).size());
159  if (nL1TSeedModules==0) {
160  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
161  result.first=1;
162  } else if (nL1TSeedModules==1) {
163  l1tGlobalUtil_.retrieveL1Event(iEvent,iSetup);
164  const std::string l1tname(hltConfigProvider_.hltL1TSeeds(trigger).at(0));
165  bool l1error(!l1tGlobalUtil_.getPrescaleByName(l1tname,result.first));
166  if (l1error) {
167  if (count_[1]<countMax) {
168  count_[1] += 1;
169  edm::LogError("HLTPrescaleProvider")
170  << " Error in determining L1T prescale for HLT path: '" << trigger
171  << "' with L1T seed: '" << l1tname
172  << "' using L1TGlobalUtil: error cond = " << l1error << "." << std::endl
173  << " Note: for this method ('prescaleValues'), only a single L1T name (and not a bit number) is allowed as seed!"
174  << std::endl
175  << " For seeds being complex logical expressions, try the new method 'prescaleValuesInDetail'."<< std::endl;
176  }
177  result.first = -1;
178  }
179  } else {
181  if (count_[2]<countMax) {
182  count_[2] += 1;
183  std::string dump("'"+hltConfigProvider_.hltL1TSeeds(trigger).at(0)+"'");
184  for (unsigned int i=1; i!=nL1TSeedModules; ++i) {
185  dump += " * '"+hltConfigProvider_.hltL1TSeeds(trigger).at(i)+"'";
186  }
187  edm::LogError("HLTPrescaleProvider")
188  << " Error in determining L1T prescale for HLT path: '" << trigger
189  << "' has multiple L1TSeed modules, " << nL1TSeedModules
190  << ", with L1T seeds: " << dump
191  << ". (Note: at most one L1TSeed module is allowed for a proper determination of the L1T prescale!)";
192  }
193  result.first = -1;
194  }
195  } else {
196  if (count_[1]<countMax) {
197  count_[1] += 1;
198  edm::LogError("HLTPrescaleProvider")
199  << " Unknown L1T Type " << l1tType << " - can not determine L1T prescale! ";
200  }
201  result.first = -1;
202  }
203 
204  return result;
205 }
206 
207 std::pair<std::vector<std::pair<std::string,int> >,int>
209  const edm::EventSetup& iSetup,
210  const std::string& trigger) {
211 
212  std::pair<std::vector<std::pair<std::string,int> >,int> result;
213  result.first.clear();
214 
215  // get HLT prescale (possible if HLT prescale set index is correctly found)
216  const int set(prescaleSet(iEvent,iSetup));
217  if (set<0) {
218  result.second = -1;
219  } else {
220  result.second = static_cast<int>(hltConfigProvider_.prescaleValue(static_cast<unsigned int>(set),trigger));
221  }
222 
223  // get L1T prescale - works only for those hlt trigger paths with
224  // exactly one L1GT seed module
225 
226  const unsigned int l1tType(hltConfigProvider_.l1tType());
227  if (l1tType==1){
228  const unsigned int nL1GTSeedModules(hltConfigProvider_.hltL1GTSeeds(trigger).size());
229  if (nL1GTSeedModules==0) {
230  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
231  result.first.clear();
232  } else if (nL1GTSeedModules==1) {
234  const std::string l1tname(hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second);
236  l1Logical.logicalExpressionRunUpdate(iEvent.getRun(),iSetup,l1tname);
237  const std::vector<std::pair<std::string, int> >& errorCodes(l1Logical.errorCodes(iEvent));
238  result.first = l1Logical.prescaleFactors();
239  int l1error(l1Logical.isValid() ? 0 : 1);
240  for (auto const & errorCode : errorCodes) {
241  l1error += std::abs(errorCode.second);
242  }
243  if (l1error!=0) {
244  if (count_[3]<countMax) {
245  count_[3] += 1;
246  std::ostringstream message;
247  message
248  << " Error in determining L1T prescales for HLT path: '" << trigger
249  << "' with complex L1T seed: '" << l1tname
250  << "' using L1GtUtils: " << std::endl
251  << " isValid=" << l1Logical.isValid()
252  << " l1tname/error/prescale " << errorCodes.size()
253  << std::endl;
254  for (unsigned int i=0; i< errorCodes.size(); ++i) {
255  message << " " << i << ":" << errorCodes[i].first << "/" << errorCodes[i].second << "/"
256  << result.first[i].second;
257  }
258  message << ".";
259  edm::LogError("HLTPrescaleProvider") << message.str();
260  }
261  result.first.clear();
262  }
263  } else {
265  if (count_[4]<countMax) {
266  count_[4] += 1;
267  std::string dump("'"+hltConfigProvider_.hltL1GTSeeds(trigger).at(0).second+"'");
268  for (unsigned int i=1; i!=nL1GTSeedModules; ++i) {
269  dump += " * '"+hltConfigProvider_.hltL1GTSeeds(trigger).at(i).second+"'";
270  }
271  edm::LogError("HLTPrescaleProvider")
272  << " Error in determining L1T prescale for HLT path: '" << trigger
273  << "' has multiple L1GTSeed modules, " << nL1GTSeedModules
274  << ", with L1 seeds: " << dump
275  << ". (Note: at most one L1GTSeed module is allowed for a proper determination of the L1T prescale!)";
276  }
277  result.first.clear();
278  }
279  } else if (l1tType==2){
280  const unsigned int nL1TSeedModules(hltConfigProvider_.hltL1TSeeds(trigger).size());
281  if (nL1TSeedModules==0) {
282  // no L1 seed module on path hence no L1 seed hence formally no L1 prescale
283  result.first.clear();
284  } else if (nL1TSeedModules==1) {
285  l1tGlobalUtil_.retrieveL1Event(iEvent,iSetup);
286  std::string l1tname(hltConfigProvider_.hltL1TSeeds(trigger).at(0));
287  GlobalLogicParser l1tGlobalLogicParser = GlobalLogicParser(l1tname);
288  const std::vector<GlobalLogicParser::OperandToken> l1tSeeds = l1tGlobalLogicParser.expressionSeedsOperandList();
289  int l1error(0);
290  int l1tPrescale(-1);
291  for (auto const & i : l1tSeeds) {
292  const string& l1tSeed = i.tokenName;
293  if (!l1tGlobalUtil_.getPrescaleByName(l1tSeed,l1tPrescale)) {
294  l1error += 1;
295  }
296  result.first.push_back(std::pair<std::string,int>(l1tSeed,l1tPrescale));
297  }
298  if (l1error!=0) {
299  if (count_[3]<countMax) {
300  count_[3] += 1;
301  string l1name = l1tname;
302  std::ostringstream message;
303  message
304  << " Error in determining L1T prescales for HLT path: '" << trigger
305  << "' with complex L1T seed: '" << l1tname
306  << "' using L1TGlobalUtil: " << std::endl
307  << " isValid=" << l1tGlobalLogicParser.checkLogicalExpression(l1name)
308  << " l1tname/error/prescale " << l1tSeeds.size()
309  << std::endl;
310  for (unsigned int i=0; i<l1tSeeds.size(); ++i) {
311  const string& l1tSeed = l1tSeeds[i].tokenName;
312  message << " " << i << ":" << l1tSeed << "/" << l1tGlobalUtil_.getPrescaleByName(l1tSeed,l1tPrescale) << "/"
313  << result.first[i].second;
314  }
315  message << ".";
316  edm::LogError("HLTPrescaleProvider") << message.str();
317  }
318  result.first.clear();
319  }
320  } else {
322  if (count_[4]<countMax) {
323  count_[4] += 1;
324  std::string dump("'"+hltConfigProvider_.hltL1TSeeds(trigger).at(0)+"'");
325  for (unsigned int i=1; i!=nL1TSeedModules; ++i) {
326  dump += " * '"+hltConfigProvider_.hltL1TSeeds(trigger).at(i)+"'";
327  }
328  edm::LogError("HLTPrescaleProvider")
329  << " Error in determining L1T prescale for HLT path: '" << trigger
330  << "' has multiple L1TSeed modules, " << nL1TSeedModules
331  << ", with L1T seeds: " << dump
332  << ". (Note: at most one L1TSeed module is allowed for a proper determination of the L1T prescale!)";
333  }
334  result.first.clear();
335  }
336  } else {
337  if (count_[3]<countMax) {
338  count_[3] += 1;
339  edm::LogError("HLTPrescaleProvider")
340  << " Unknown L1T Type " << l1tType << " - can not determine L1T prescale! ";
341  }
342  result.first.clear();
343  }
344 
345  return result;
346 }
HLTConfigProvider hltConfigProvider_
std::pair< std::vector< std::pair< std::string, int > >, int > prescaleValuesInDetail(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
unsigned int l1tType() const
L1T type (0=unknown, 1=legacy/stage-1 or 2=stage-2)
void retrieveL1Event(const edm::Event &iEvent, const edm::EventSetup &evSetup)
const std::vector< std::vector< std::string > > & hltL1TSeeds() const
const int prescaleFactorSetIndex(const edm::Event &iEvent, const TriggerCategory &trigCategory, int &errorCode) const
Definition: L1GtUtils.cc:1458
const std::vector< std::vector< std::pair< bool, std::string > > > & hltL1GTSeeds() const
Run const & getRun() const
Definition: Event.cc:66
static const unsigned char countMax(2)
unsigned int prescaleValue(unsigned int set, const std::string &trigger) const
HLT prescale value in specific prescale set for a specific trigger path.
int iEvent
Definition: GenABIO.cc:230
static const bool useL1GtTriggerMenuLite(false)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int prescaleColumn() const
l1t::L1TGlobalUtil l1tGlobalUtil_
const std::string & processName() const
process name
int prescaleSet(const edm::Event &iEvent, const edm::EventSetup &iSetup)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::pair< int, int > prescaleValues(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
Combined L1T (pair.first) and HLT (pair.second) prescales per HLT path.
void getL1GtRunCache(const edm::Run &, const edm::EventSetup &, const bool, const bool)
get all the run-constant quantities for L1 trigger and cache them
Definition: L1GtUtils.cc:319
unsigned char count_[5]
const bool getPrescaleByName(const std::string &algName, int &prescale) const
unsigned int prescaleValue(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
combining the two methods above
void retrieveL1Setup(const edm::EventSetup &evSetup)
static const bool useL1EventSetup(true)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
Definition: Run.h:42
const int prescaleFactor(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
return prescale factor for a given algorithm or technical trigger
Definition: L1GtUtils.cc:1223