CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
InitMsgCollection.cc
Go to the documentation of this file.
1 // $Id: InitMsgCollection.cc,v 1.15 2011/03/07 15:31:32 mommsen Exp $
3 
13 
14 #include "boost/algorithm/string/trim.hpp"
15 #include <iostream>
16 
17 using namespace stor;
18 using namespace edm;
19 
21 {
22  clear();
23 }
24 
25 
27 {
28 }
29 
30 
32 {
33  boost::mutex::scoped_lock sl(listLock_);
34 
35  // test the output module label for validity
36  std::string inputOMLabel = initMsgView.outputModuleLabel();
37  std::string trimmedOMLabel = boost::algorithm::trim_copy(inputOMLabel);
38  if (trimmedOMLabel.empty()) {
39  throw cms::Exception("InitMsgCollection", "addIfUnique:")
40  << "Invalid INIT message: the HLT output module label is empty!"
41  << std::endl;
42  }
43 
44  // initially, assume that we will want to include the new message
45  bool addToList = true;
46 
47  // if this is the first INIT message that we've seen, we just add it
48  if (initMsgList_.empty()) {
49  this->add(initMsgView);
50  }
51 
52  // if this is a subsequent INIT message, check if it is unique
53  else {
54 
55  // loop over the existing messages
56  for (InitMsgList::iterator msgIter = initMsgList_.begin(),
57  msgIterEnd = initMsgList_.end();
58  msgIter != msgIterEnd;
59  msgIter++)
60  {
61  InitMsgSharedPtr serializedProds = msgIter->first;
62  InitMsgView existingInitMsg(&(*serializedProds)[0]);
63  std::string existingOMLabel = existingInitMsg.outputModuleLabel();
64 
65  // check if the output module labels match
66  if (inputOMLabel == existingOMLabel) {
67  // we already have a copy of the INIT message
68  addToList = false;
69  ++msgIter->second;
70  break;
71  }
72  }
73 
74  // if we've found no problems, add the new message to the collection
75  if (addToList) {
76  this->add(initMsgView);
77  }
78  }
79 
80  // indicate whether the message was added or not
81  return addToList;
82 }
83 
84 
86 InitMsgCollection::getElementForOutputModule(const std::string& requestedOMLabel) const
87 {
88  boost::mutex::scoped_lock sl(listLock_);
89  InitMsgSharedPtr serializedProds;
90 
91  // handle the special case of an empty request
92  // (If we want to use class methods to check the collection size and
93  // fetch the last element in the collection, then we would need to
94  // switch to recursive mutexes...)
95  if (requestedOMLabel.empty()) {
96  if (initMsgList_.size() == 1) {
97  serializedProds = initMsgList_.back().first;
98  }
99  else if (initMsgList_.size() > 1) {
100  std::string msg = "Invalid INIT message lookup: the requested ";
101  msg.append("HLT output module label is empty but there are multiple ");
102  msg.append("HLT output modules to choose from.");
103  throw cms::Exception("InitMsgCollection", "getElementForOutputModule:")
104  << msg << std::endl;
105  }
106  }
107 
108  else {
109  // loop over the existing messages
110  for (InitMsgList::const_iterator msgIter = initMsgList_.begin(),
111  msgIterEnd = initMsgList_.end();
112  msgIter != msgIterEnd;
113  msgIter++)
114  {
115  InitMsgSharedPtr workingMessage = msgIter->first;
116  InitMsgView existingInitMsg(&(*workingMessage)[0]);
117  std::string existingOMLabel = existingInitMsg.outputModuleLabel();
118 
119  // check if the output module labels match
120  if (requestedOMLabel == existingOMLabel) {
121  serializedProds = workingMessage;
122  break;
123  }
124  }
125  }
126 
127  return serializedProds;
128 }
129 
130 
132 {
133  boost::mutex::scoped_lock sl(listLock_);
134 
135  InitMsgSharedPtr ptrToLast;
136  if (!initMsgList_.empty()) {
137  ptrToLast = initMsgList_.back().first;
138  }
139  return ptrToLast;
140 }
141 
142 
144 {
145  boost::mutex::scoped_lock sl(listLock_);
146 
147  InitMsgSharedPtr ptrToElement;
148  try
149  {
150  ptrToElement = initMsgList_.at(index).first;
151  }
152  catch (std::out_of_range& e)
153  { }
154 
155  return ptrToElement;
156 }
157 
158 
160 {
161  boost::mutex::scoped_lock sl(listLock_);
162  initMsgList_.clear();
163  outModNameTable_.clear();
164 }
165 
166 
168 {
169  boost::mutex::scoped_lock sl(listLock_);
170  return initMsgList_.size();
171 }
172 
173 
174 size_t InitMsgCollection::initMsgCount(const std::string& outputModuleLabel) const
175 {
176  boost::mutex::scoped_lock sl(listLock_);
177 
178  for (InitMsgList::const_iterator msgIter = initMsgList_.begin(),
179  msgIterEnd = initMsgList_.end();
180  msgIter != msgIterEnd;
181  msgIter++)
182  {
183  InitMsgSharedPtr workingMessage = msgIter->first;
184  InitMsgView existingInitMsg(&(*workingMessage)[0]);
185  std::string existingOMLabel = existingInitMsg.outputModuleLabel();
186 
187  // check if the output module labels match
188  if (outputModuleLabel == existingOMLabel) {
189  return msgIter->second;
190  }
191  }
192  return 0;
193 }
194 
195 
197 {
198  boost::mutex::scoped_lock sl(listLock_);
199 
200  size_t maxCount = 0;
201 
202  for (InitMsgList::const_iterator msgIter = initMsgList_.begin(),
203  msgIterEnd = initMsgList_.end();
204  msgIter != msgIterEnd;
205  msgIter++)
206  {
207  if (msgIter->second > maxCount)
208  maxCount = msgIter->second;
209  }
210  return maxCount;
211 }
212 
213 
215 {
216  boost::mutex::scoped_lock sl(listLock_);
217 
218  // nothing much we can say if the collection is empty
219  if (initMsgList_.empty()) {
220  return "No information is available about the available triggers.";
221  }
222 
223  // list the full set of available triggers
224  std::string helpString;
225  helpString.append("The full list of trigger paths is the following:");
226 
227  // we can just use the list from the first entry since all
228  // subsequent entries are forced to be the same
229  InitMsgSharedPtr serializedProds = initMsgList_[0].first;
230  InitMsgView existingInitMsg(&(*serializedProds)[0]);
231  Strings existingTriggerList;
232  existingInitMsg.hltTriggerNames(existingTriggerList);
233  for (unsigned int idx = 0; idx < existingTriggerList.size(); idx++) {
234  helpString.append("\n " + existingTriggerList[idx]);
235  }
236 
237  // list the output modules (INIT messages)
238  helpString.append("\nThe registered HLT output modules and their ");
239  helpString.append("trigger selections are the following:");
240 
241  // loop over the existing messages
242  for (InitMsgList::const_iterator msgIter = initMsgList_.begin(),
243  msgIterEnd = initMsgList_.end();
244  msgIter != msgIterEnd;
245  msgIter++)
246  {
247  serializedProds = msgIter->first;
248  InitMsgView workingInitMsg(&(*serializedProds)[0]);
249  helpString.append("\n *** Output module \"");
250  helpString.append(workingInitMsg.outputModuleLabel());
251  helpString.append("\" ***");
252  Strings workingSelectionList;
253  workingInitMsg.hltTriggerSelections(workingSelectionList);
254  for (unsigned int idx = 0; idx < workingSelectionList.size(); idx++) {
255  helpString.append("\n " + workingSelectionList[idx]);
256  }
257  }
258 
259  // return the result
260  return helpString;
261 }
262 
263 
264 std::string InitMsgCollection::getOutputModuleName(const uint32_t outputModuleId) const
265 {
266  boost::mutex::scoped_lock sl(listLock_);
267 
268  OutModTable::const_iterator it = outModNameTable_.find(outputModuleId);
269 
270  if (it == outModNameTable_.end())
271  {
272  return "";
273  }
274  else {
275  return it->second;
276  }
277 }
278 
279 
281  unsigned int maxCount)
282 {
283  std::string resultString = "";
284  unsigned int elementCount = list.size();
285  if (maxCount > 0 && maxCount < elementCount) {elementCount = maxCount;}
286  for (unsigned int idx = 0; idx < elementCount; idx++)
287  {
288  resultString.append(list[idx]);
289  if (idx < (elementCount-1)) {
290  resultString.append(", ");
291  }
292  }
293  if (elementCount < list.size())
294  {
295  resultString.append(", ...");
296  }
297  return resultString;
298 }
299 
300 
301 void InitMsgCollection::add(InitMsgView const& initMsgView)
302 {
303  // add the message to the internal list
304  InitMsgSharedPtr serializedProds(new InitMsgBuffer(initMsgView.size()));
305  initMsgList_.push_back( std::make_pair(serializedProds,1) );
306  std::copy(initMsgView.startAddress(),
307  initMsgView.startAddress()+initMsgView.size(),
308  &(*serializedProds)[0]);
309 
310  // add the module ID name to the name map
311  outModNameTable_[initMsgView.outputModuleId()] =
312  initMsgView.outputModuleLabel();
313 }
314 
315 
316 
std::vector< unsigned char > InitMsgBuffer
InitMsgSharedPtr getElementAt(const unsigned int index) const
std::vector< std::string > Strings
Definition: MsgTools.h:18
void add(InitMsgView const &initMsgView)
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
boost::shared_ptr< InitMsgBuffer > InitMsgSharedPtr
size_t initMsgCount(const std::string &outputModuleLabel) const
void hltTriggerNames(Strings &save_here) const
Definition: InitMessage.cc:122
std::string getOutputModuleName(const uint32_t outputModuleId) const
uint8 * startAddress() const
Definition: InitMessage.h:67
InitMsgSharedPtr getElementForOutputModule(const std::string &requestedOMLabel) const
std::string getSelectionHelpString() const
std::string outputModuleLabel() const
Definition: InitMessage.cc:112
bool addIfUnique(InitMsgView const &initMsgView)
InitMsgSharedPtr getLastElement() const
uint32 outputModuleId() const
Definition: InitMessage.h:75
static std::string stringsToText(Strings const &list, unsigned int maxCount=0)
uint32 size() const
Definition: InitMessage.h:66
void hltTriggerSelections(Strings &save_here) const
Definition: InitMessage.cc:127
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 list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run