CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
stor::InitMsgCollection Class Reference

#include <InitMsgCollection.h>

Public Member Functions

bool addIfUnique (InitMsgView const &initMsgView)
 
void clear ()
 
InitMsgSharedPtr getElementAt (const unsigned int index) const
 
InitMsgSharedPtr getElementForOutputModule (const std::string &requestedOMLabel) const
 
InitMsgSharedPtr getLastElement () const
 
std::string getOutputModuleName (const uint32_t outputModuleId) const
 
std::string getSelectionHelpString () const
 
 InitMsgCollection ()
 
size_t initMsgCount (const std::string &outputModuleLabel) const
 
size_t maxMsgCount () const
 
size_t size () const
 
 ~InitMsgCollection ()
 

Static Public Member Functions

static std::string stringsToText (Strings const &list, unsigned int maxCount=0)
 

Private Types

typedef std::vector
< InitMsgPtrAndCount
InitMsgList
 
typedef std::pair
< InitMsgSharedPtr, size_t > 
InitMsgPtrAndCount
 
typedef std::map< uint32_t,
std::string > 
OutModTable
 

Private Member Functions

void add (InitMsgView const &initMsgView)
 

Private Attributes

InitMsgList initMsgList_
 
boost::mutex listLock_
 
OutModTable outModNameTable_
 

Detailed Description

Definition at line 32 of file InitMsgCollection.h.

Member Typedef Documentation

Definition at line 168 of file InitMsgCollection.h.

Definition at line 167 of file InitMsgCollection.h.

typedef std::map<uint32_t, std::string> stor::InitMsgCollection::OutModTable
private

Definition at line 171 of file InitMsgCollection.h.

Constructor & Destructor Documentation

InitMsgCollection::InitMsgCollection ( )

InitMsgCollection constructor.

Definition at line 20 of file InitMsgCollection.cc.

21 {
22  clear();
23 }
InitMsgCollection::~InitMsgCollection ( )

InitMsgCollection destructor.

Definition at line 26 of file InitMsgCollection.cc.

27 {
28 }

Member Function Documentation

void InitMsgCollection::add ( InitMsgView const &  initMsgView)
private

Adds the specified INIT message to the collection (unconditionally).

Parameters
initMsgViewThe INIT message to add to the collection.

Definition at line 301 of file InitMsgCollection.cc.

References filterCSVwithJSON::copy, InitMsgView::outputModuleId(), InitMsgView::outputModuleLabel(), InitMsgView::size(), and InitMsgView::startAddress().

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 }
std::vector< unsigned char > InitMsgBuffer
boost::shared_ptr< InitMsgBuffer > InitMsgSharedPtr
bool InitMsgCollection::addIfUnique ( InitMsgView const &  initMsgView)

Adds the specified INIT message to the collection if it has a unique HLT output module label.

If we already have an INIT message with the same output module label as the input INIT message, the duplicate message is not added to the collection, and this method returns false.

If the output module label inside the INIT message is empty, an exception is thrown.

Parameters
initMsgViewThe INIT message to be added to the collection.
Returns
true if the message was added to the collection, false otherwise.
Exceptions
cms::Exceptionif one of the consistency checks fails.

Definition at line 31 of file InitMsgCollection.cc.

References Clusterizer1DCommons::add(), edm::hlt::Exception, and InitMsgView::outputModuleLabel().

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 }
void add(InitMsgView const &initMsgView)
boost::shared_ptr< InitMsgBuffer > InitMsgSharedPtr
void InitMsgCollection::clear ( void  )
InitMsgSharedPtr InitMsgCollection::getElementAt ( const unsigned int  index) const

Returns a shared pointer to the requested element in the collection or an empty pointer if the requested index if out of bounds.

Parameters
indexThe index of the requested element.
Returns
the InitMsgSharedPtr at the requested index in the collection.

Definition at line 143 of file InitMsgCollection.cc.

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 }
boost::shared_ptr< InitMsgBuffer > InitMsgSharedPtr
InitMsgSharedPtr InitMsgCollection::getElementForOutputModule ( const std::string &  requestedOMLabel) const

Fetches the single INIT message that matches the requested HLT output module label. If no messages match the request, an empty pointer is returned.

If the requested HLT output module label is empty, and there is only one INIT message in the collection, that INIT message is returned. However, if there is more than one INIT message in the collection, and an empty request is passed into this method, an exception will be thrown. (How can we decide which is the best match when we have nothing to work with?)

Parameters
requestedOMLabelThe HLT output module label of the INIT message to be returned.
Returns
a pointer to the INIT message that matches. If no matching INIT message is found, and empty pointer is returned.
Exceptions
cms::Exceptionif the input HLT output module label string is empty and there is more than one INIT message in the collection.

Definition at line 86 of file InitMsgCollection.cc.

References edm::hlt::Exception, runTheMatrix::msg, and InitMsgView::outputModuleLabel().

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 }
boost::shared_ptr< InitMsgBuffer > InitMsgSharedPtr
InitMsgSharedPtr InitMsgCollection::getLastElement ( ) const

Returns a shared pointer to the last element in the collection or an empty pointer if the collection has no elements.

Returns
the last InitMsgSharedPtr in the collection.

Definition at line 131 of file InitMsgCollection.cc.

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 }
boost::shared_ptr< InitMsgBuffer > InitMsgSharedPtr
std::string InitMsgCollection::getOutputModuleName ( const uint32_t  outputModuleId) const

Returns the name of the output module with the specified module ID, or an empty string of the specified module ID is not known.

Returns
the output module label or an empty string

Definition at line 264 of file InitMsgCollection.cc.

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 }
std::string InitMsgCollection::getSelectionHelpString ( ) const

Returns a string with information on which selections are available.

Returns
the help string.

Definition at line 214 of file InitMsgCollection.cc.

References InitMsgView::hltTriggerNames(), InitMsgView::hltTriggerSelections(), and InitMsgView::outputModuleLabel().

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 }
std::vector< std::string > Strings
Definition: MsgTools.h:18
boost::shared_ptr< InitMsgBuffer > InitMsgSharedPtr
size_t InitMsgCollection::initMsgCount ( const std::string &  outputModuleLabel) const

Returns the number of identical INIT messages received for the given module name

Returns
the integer number of received INIT messages

Definition at line 174 of file InitMsgCollection.cc.

References InitMsgView::outputModuleLabel().

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 }
boost::shared_ptr< InitMsgBuffer > InitMsgSharedPtr
size_t InitMsgCollection::maxMsgCount ( ) const

Returns the maximum number of identical INIT messages received for any output module

Returns
the integer number of maximum received INIT messages

Definition at line 196 of file InitMsgCollection.cc.

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 }
size_t InitMsgCollection::size ( void  ) const

Returns the number of unique INIT messages in the collection.

Returns
the integer number of messages.

Definition at line 167 of file InitMsgCollection.cc.

168 {
169  boost::mutex::scoped_lock sl(listLock_);
170  return initMsgList_.size();
171 }
std::string InitMsgCollection::stringsToText ( Strings const &  list,
unsigned int  maxCount = 0 
)
static

Creates a single text string from the elements in the specified list of strings. The specified maximum number of elements are included, however a zero value for the maximum number will include all elements.

Parameters
listthe list of strings to include (std::vector of strings);
maxCountthe maximum number of list elements to include.
Returns
the text string with the formatted list elements.

Definition at line 280 of file InitMsgCollection.cc.

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 }
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

Member Data Documentation

InitMsgList stor::InitMsgCollection::initMsgList_
private

Definition at line 169 of file InitMsgCollection.h.

boost::mutex stor::InitMsgCollection::listLock_
mutableprivate

Definition at line 173 of file InitMsgCollection.h.

OutModTable stor::InitMsgCollection::outModNameTable_
private

Definition at line 172 of file InitMsgCollection.h.