CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConvertObjectMapRecord.cc
Go to the documentation of this file.
1 
19 
20 #include <limits>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
35 
37  m_l1GtObjectMapTag(pset.getParameter<edm::InputTag>("L1GtObjectMapTag")) {
38 
39  produces<L1GlobalTriggerObjectMaps>();
40 }
41 
43 }
44 
47 
48  // Read in the existing object from the data
50  event.getByLabel(m_l1GtObjectMapTag, gtObjectMapRecord);
51 
52  if (!gtObjectMapRecord.isValid()) {
53  return;
54  }
55 
56  // Create the new object we are going to copy the information to
57  std::auto_ptr<L1GlobalTriggerObjectMaps> gtObjectMaps(new L1GlobalTriggerObjectMaps);
58 
59  // get the algorithm bit numbers and sort them
60  std::vector<int> algoBitNumbers;
61  std::vector<L1GlobalTriggerObjectMap> const& vectorInRecord = gtObjectMapRecord->gtObjectMap();
62  algoBitNumbers.reserve(vectorInRecord.size());
63  for (std::vector<L1GlobalTriggerObjectMap>::const_iterator i = vectorInRecord.begin(),
64  iEnd = vectorInRecord.end();
65  i != iEnd; ++i) {
66  algoBitNumbers.push_back(i->algoBitNumber());
67  }
68  edm::sort_all(algoBitNumbers);
69 
70  gtObjectMaps->reserveForAlgorithms(algoBitNumbers.size());
71 
72  if (!algoBitNumbers.empty() && algoBitNumbers[0] < 0) {
73  cms::Exception ex("L1GlobalTrigger");
74  ex << "Negative algorithm bit number";
75  ex.addContext("Calling ConvertObjectMapRecord::produce");
76  throw ex;
77  }
78 
79  unsigned sizeOfNamesVector = 0;
80  if (!algoBitNumbers.empty()) {
81  sizeOfNamesVector = static_cast<unsigned>(algoBitNumbers.back()) + 1;
82  }
83  std::vector<std::string> savedNames(sizeOfNamesVector);
84 
85  // Loop over the object map record and copy the algorithm information
86  // Just count the condition and index information so we can reserve
87  // memory for them before filling them.
88  unsigned startIndexOfConditions = 0;
89  unsigned nIndexes = 0;
90 
91  for (std::vector<int>::const_iterator iBit = algoBitNumbers.begin(), endBits = algoBitNumbers.end();
92  iBit != endBits; ++iBit) {
93  L1GlobalTriggerObjectMap const* objMap = gtObjectMapRecord->getObjectMap(*iBit);
94 
95  gtObjectMaps->pushBackAlgorithm(startIndexOfConditions,
96  objMap->algoBitNumber(),
97  objMap->algoGtlResult());
98 
99  savedNames.at(static_cast<unsigned>(*iBit)) = objMap->algoName();
100 
101  std::vector<L1GtLogicParser::OperandToken> const& operandTokens =
102  objMap->operandTokenVector();
103 
104  startIndexOfConditions += operandTokens.size();
105 
106  int tokenCounter = 0;
107  for (std::vector<L1GtLogicParser::OperandToken>::const_iterator iToken = operandTokens.begin(),
108  endTokens = operandTokens.end();
109  iToken != endTokens;
110  ++iToken, ++tokenCounter) {
111 
112  if (tokenCounter != iToken->tokenNumber) {
113  cms::Exception ex("L1GlobalTrigger");
114  ex << "Token numbers not sequential";
115  ex.addContext("Calling ConvertObjectMapRecord::produce");
116  throw ex;
117  }
118 
119  CombinationsInCond const* combos = objMap->getCombinationsInCond(iToken->tokenNumber);
120  for (CombinationsInCond::const_iterator iCombo = combos->begin(),
121  endCombos = combos->end();
122  iCombo != endCombos; ++iCombo) {
123  for (std::vector<int>::const_iterator iIndex = iCombo->begin(),
124  endIndexes = iCombo->end();
125  iIndex != endIndexes; ++iIndex) {
126  ++nIndexes;
127  }
128  }
129  }
130  }
131  gtObjectMaps->reserveForConditions(startIndexOfConditions);
132  gtObjectMaps->reserveForObjectIndexes(nIndexes);
133 
134  edm::ParameterSet namesPset;
135  namesPset.addParameter<std::vector<std::string> >(std::string("@algorithmNames"), savedNames);
136 
137  // Now loop a second time and fill the condition and index
138  // information.
139  unsigned startIndexOfCombinations = 0;
140  for (std::vector<int>::const_iterator iBit = algoBitNumbers.begin(), endBits = algoBitNumbers.end();
141  iBit != endBits; ++iBit) {
142  L1GlobalTriggerObjectMap const* objMap = gtObjectMapRecord->getObjectMap(*iBit);
143 
144  std::vector<L1GtLogicParser::OperandToken> const& operandTokens =
145  objMap->operandTokenVector();
146 
147  savedNames.clear();
148  if (savedNames.capacity() < operandTokens.size()) {
149  savedNames.reserve(operandTokens.size());
150  }
151 
152  for (std::vector<L1GtLogicParser::OperandToken>::const_iterator iToken = operandTokens.begin(),
153  endTokens = operandTokens.end();
154  iToken != endTokens; ++iToken) {
155 
156  savedNames.push_back(iToken->tokenName);
157 
158  unsigned short nObjectsPerCombination = 0;
159  bool first = true;
160  unsigned nIndexesInCombination = 0;
161 
162  CombinationsInCond const* combos = objMap->getCombinationsInCond(iToken->tokenNumber);
163  for (CombinationsInCond::const_iterator iCombo = combos->begin(),
164  endCombos = combos->end();
165  iCombo != endCombos; ++iCombo) {
166  if (first) {
167  if (iCombo->size() > std::numeric_limits<unsigned short>::max()) {
168  cms::Exception ex("L1GlobalTrigger");
169  ex << "Number of objects per combination out of range";
170  ex.addContext("Calling ConvertObjectMapRecord::produce");
171  throw ex;
172  }
173  nObjectsPerCombination = iCombo->size();
174  first = false;
175  } else {
176  if (nObjectsPerCombination != iCombo->size()) {
177  cms::Exception ex("L1GlobalTrigger");
178  ex << "inconsistent number of objects per condition";
179  ex.addContext("Calling ConvertObjectMapRecord::produce");
180  throw ex;
181  }
182  }
183 
184  for (std::vector<int>::const_iterator iIndex = iCombo->begin(),
185  endIndexes = iCombo->end();
186  iIndex != endIndexes; ++iIndex) {
187 
188  if (*iIndex < 0 || *iIndex > std::numeric_limits<unsigned char>::max()) {
189  cms::Exception ex("L1GlobalTrigger");
190  ex << "object index too large, out of range";
191  ex.addContext("Calling ConvertObjectMapRecord::produce");
192  throw ex;
193  }
194  gtObjectMaps->pushBackObjectIndex(*iIndex);
195  ++nIndexesInCombination;
196  }
197  }
198  gtObjectMaps->pushBackCondition(startIndexOfCombinations,
199  nObjectsPerCombination,
200  iToken->tokenResult);
201  startIndexOfCombinations += nIndexesInCombination;
202  }
203  namesPset.addParameter<std::vector<std::string> >(objMap->algoName(), savedNames);
204  }
205  namesPset.registerIt();
206  gtObjectMaps->setNamesParameterSetID(namesPset.id());
207 
208  gtObjectMaps->consistencyCheck();
209  event.put(gtObjectMaps);
210 }
int i
Definition: DBlmapReader.cc:9
ParameterSetID id() const
const std::vector< L1GtLogicParser::OperandToken > & operandTokenVector() const
ConvertObjectMapRecord(const edm::ParameterSet &pset)
const std::string & algoName() const
get / set name for algorithm in the object map
const T & max(const T &a, const T &b)
const CombinationsInCond * getCombinationsInCond(const std::string &condNameVal) const
return all the combinations passing the requirements imposed in condition condNameVal ...
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:145
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
bool first
Definition: L1TdeRCT.cc:94
bool isValid() const
Definition: HandleBase.h:76
virtual void produce(edm::Event &event, const edm::EventSetup &es)
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:120
void addContext(std::string const &context)
Definition: Exception.cc:227
int algoBitNumber() const
get / set bit number for algorithm in the object map
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
ParameterSet const & registerIt()