CMS 3D CMS Logo

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