CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CompareToObjectMapRecord.cc
Go to the documentation of this file.
1 
19 
20 #include <algorithm>
21 #include <string>
22 #include <vector>
23 
35 
36 
38  m_l1GtObjectMapTag(pset.getParameter<edm::InputTag>("L1GtObjectMapTag")),
39  m_l1GtObjectMapsTag(pset.getParameter<edm::InputTag>("L1GtObjectMapsTag")),
40  verbose_(pset.getUntrackedParameter<bool>("verbose", false))
41 {
42 }
43 
45 }
46 
49 
50  // Read in the data in the old format
52  event.getByLabel(m_l1GtObjectMapTag, gtObjectMapRecord);
53 
54  // Read in the data in the new format
56  event.getByLabel(m_l1GtObjectMapsTag, gtObjectMaps);
57 
58  // In the new format the names are not in the event data,
59  // They are in the ParameterSet registry
61  edm::ParameterSet const* pset = psetRegistry->getMapped(gtObjectMaps->namesParameterSetID());
62  if (pset == 0) {
63  cms::Exception ex("L1GlobalTrigger");
64  ex << "Could not find L1 trigger names ParameterSet in the registry";
65  ex.addContext("Calling CompareToObjectMapRecord::analyze");
66  throw ex;
67  }
68 
69  // First compare the algorithm bit numbers
70  std::vector<int> algoBitNumbers1;
71  std::vector<L1GlobalTriggerObjectMap> const& vectorInRecord = gtObjectMapRecord->gtObjectMap();
72  algoBitNumbers1.reserve(vectorInRecord.size());
73  for (std::vector<L1GlobalTriggerObjectMap>::const_iterator i = vectorInRecord.begin(),
74  iEnd = vectorInRecord.end();
75  i != iEnd; ++i) {
76  algoBitNumbers1.push_back(i->algoBitNumber());
77  if (verbose_) {
78  // This will print out all the data from the L1GlobalTriggerObjectMapRecord
79  i->print(std::cout);
80  }
81  }
82  edm::sort_all(algoBitNumbers1);
83 
84  std::vector<int> algoBitNumbers2;
85  gtObjectMaps->getAlgorithmBitNumbers(algoBitNumbers2);
86  if (algoBitNumbers1 != algoBitNumbers2) {
87  cms::Exception ex("L1GlobalTrigger");
88  ex << "Algorithm bit numbers do not match";
89  ex.addContext("Calling CompareToObjectMapRecord::analyze");
90  throw ex;
91  }
92 
93  // Now test the algorithm names
94  std::vector<std::string> algoNames2 = pset->getParameter<std::vector<std::string> >("@algorithmNames");
95 
96  // In the ParameterSet, the algorithm names are referenced by position
97  // in the vector. If the bit number for a position in the vector is
98  // not assigned, then the algorithm name should be an empty string.
99  for (int i = 0; i < static_cast<int>(algoNames2.size()); ++i) {
100  if (!std::binary_search(algoBitNumbers1.begin(), algoBitNumbers1.end(), i)) {
101  if (algoNames2[i] != std::string("")) {
102  cms::Exception ex("L1GlobalTrigger");
103  ex << "Undefined algorithm should have empty name";
104  ex.addContext("Calling CompareToObjectMapRecord::analyze");
105  throw ex;
106  }
107  }
108  }
109 
110  // Main loop over algorithms
111  for (std::vector<int>::const_iterator iBit = algoBitNumbers1.begin(), endBits = algoBitNumbers1.end();
112  iBit != endBits; ++iBit) {
113 
114  L1GlobalTriggerObjectMap const* objMap = gtObjectMapRecord->getObjectMap(*iBit);
115  std::string algoName1 = objMap->algoName();
116 
117  if (algoName1 != algoNames2.at(*iBit)) {
118  cms::Exception ex("L1GlobalTrigger");
119  ex << "Algorithm names do not match";
120  ex.addContext("Calling CompareToObjectMapRecord::analyze");
121  throw ex;
122  }
123 
124  // Now test the algorithm results
125  if (objMap->algoGtlResult() != gtObjectMaps->algorithmResult(*iBit)) {
126  cms::Exception ex("L1GlobalTrigger");
127  ex << "Algorithm results do not match";
128  ex.addContext("Calling CompareToObjectMapRecord::analyze");
129  throw ex;
130  }
131 
132  std::vector<L1GtLogicParser::OperandToken> const& operandTokens1 =
133  objMap->operandTokenVector();
134 
135  L1GlobalTriggerObjectMaps::ConditionsInAlgorithm conditions2 = gtObjectMaps->getConditionsInAlgorithm(*iBit);
136  if (conditions2.nConditions() != operandTokens1.size()) {
137  cms::Exception ex("L1GlobalTrigger");
138  ex << "Number of conditions does not match";
139  ex.addContext("Calling CompareToObjectMapRecord::analyze");
140  throw ex;
141  }
142 
143  std::vector<std::string> conditionNames2;
144  conditionNames2 = pset->getParameter<std::vector<std::string> >(algoNames2.at(*iBit));
145 
146  // Print out data from L1GlobalTriggerObjectMaps and ParameterSet registry
147  if (verbose_) {
148  std::cout << *iBit
149  << " " << algoNames2[*iBit]
150  << " " << gtObjectMaps->algorithmResult(*iBit) << "\n";
151 
152  for (unsigned j = 0; j < gtObjectMaps->getNumberOfConditions(*iBit); ++j) {
153  L1GlobalTriggerObjectMaps::ConditionsInAlgorithm conditions = gtObjectMaps->getConditionsInAlgorithm(*iBit);
154  std::cout << " " << j
155  << " " << conditionNames2[j]
156  << " " << conditions.getConditionResult(j) << "\n";
157  L1GlobalTriggerObjectMaps::CombinationsInCondition combinations = gtObjectMaps->getCombinationsInCondition(*iBit, j);
158  for (unsigned m = 0; m < combinations.nCombinations(); ++m) {
159  std::cout << " ";
160  for (unsigned n = 0; n < combinations.nObjectsPerCombination(); ++n) {
161  std::cout << " " << static_cast<unsigned>(combinations.getObjectIndex(m,n));
162  }
163  std::cout << "\n";
164  }
165  }
166  }
167 
168  // Loop over conditions
169  unsigned iCondition = 0;
170  for (std::vector<L1GtLogicParser::OperandToken>::const_iterator iToken1 = operandTokens1.begin(),
171  endTokens1 = operandTokens1.end();
172  iToken1 != endTokens1;
173  ++iToken1, ++iCondition) {
174 
175  // Compare condition numbers
176  if (iToken1->tokenNumber != static_cast<int>(iCondition)) {
177  cms::Exception ex("L1GlobalTrigger");
178  ex << "Token numbers not sequential";
179  ex.addContext("Calling CompareToObjectMapRecord::analyze");
180  throw ex;
181  }
182 
183  // Compare condition names
184  if (iToken1->tokenResult != conditions2.getConditionResult(iCondition)) {
185  cms::Exception ex("L1GlobalTrigger");
186  ex << "Condition results do not match";
187  ex.addContext("Calling CompareToObjectMapRecord::analyze");
188  throw ex;
189  }
190 
191  // Compare condition names
192  if (iToken1->tokenName != conditionNames2.at(iCondition)) {
193  cms::Exception ex("L1GlobalTrigger");
194  ex << "Condition names do not match";
195  ex.addContext("Calling CompareToObjectMapRecord::analyze");
196  throw ex;
197  }
198 
199  // Compare the combinations of Indexes into the L1 collections
201  gtObjectMaps->getCombinationsInCondition(*iBit, iCondition);
202 
203  CombinationsInCond const* combinations1 = objMap->getCombinationsInCond(iToken1->tokenNumber);
204  if (combinations1->size() != combinations2.nCombinations()) {
205  cms::Exception ex("L1GlobalTrigger");
206  ex << "The number of combinations in a condition does not match";
207  ex.addContext("Calling CompareToObjectMapRecord::analyze");
208  throw ex;
209  }
210 
211  for (CombinationsInCond::const_iterator iCombo = combinations1->begin(),
212  endCombos = combinations1->end();
213  iCombo != endCombos; ++iCombo) {
214  if (iCombo->size() != combinations2.nObjectsPerCombination()) {
215  cms::Exception ex("L1GlobalTrigger");
216  ex << "The number of indexes in a combination does not match";
217  ex.addContext("Calling CompareToObjectMapRecord::analyze");
218  throw ex;
219  }
220 
221  for (std::vector<int>::const_iterator iIndex = iCombo->begin(),
222  endIndexes = iCombo->end();
223  iIndex != endIndexes; ++iIndex) {
224 
225  if (*iIndex != combinations2.getObjectIndex(iCombo - combinations1->begin(), iIndex - iCombo->begin())) {
226  cms::Exception ex("L1GlobalTrigger");
227  ex << "Object index does not match";
228  ex.addContext("Calling CompareToObjectMapRecord::analyze");
229  throw ex;
230  }
231  }
232  }
233  }
234  }
235 }
T getParameter(std::string const &) const
unsigned char getObjectIndex(unsigned combination, unsigned object) const
int i
Definition: DBlmapReader.cc:9
const std::vector< L1GtLogicParser::OperandToken > & operandTokenVector() const
static ThreadSafeRegistry * instance()
const std::string & algoName() const
get / set name for algorithm in the object map
bool getMapped(key_type const &k, value_type &result) const
const CombinationsInCond * getCombinationsInCond(const std::string &condNameVal) const
return all the combinations passing the requirements imposed in condition condNameVal ...
int j
Definition: DBlmapReader.cc:9
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
CompareToObjectMapRecord(const edm::ParameterSet &pset)
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:120
virtual void analyze(edm::Event const &event, edm::EventSetup const &es)
void addContext(std::string const &context)
Definition: Exception.cc:227
tuple cout
Definition: gather_cfg.py:121
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition