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.17 2012/04/20 10:48:02 mommsen Exp $
3 
14 
15 #include "boost/algorithm/string/trim.hpp"
16 #include <iostream>
17 
18 using namespace stor;
19 using namespace edm;
20 
22 {
23  clear();
24 }
25 
26 
28 {
29 }
30 
31 
33 {
34  boost::mutex::scoped_lock sl(listLock_);
35 
36  // check if the outputModuleId was already seen
37  const uint32_t outputModuleId = initMsgView.outputModuleId();
38  InitMsgMap::iterator pos = initMsgMap_.lower_bound(outputModuleId);
39  if ( pos != initMsgMap_.end() && !(initMsgMap_.key_comp()(outputModuleId, pos->first)))
40  return false; // init message already exists
41 
42  checkOutputModuleLabel(initMsgView);
43 
44  // add the message to the internal list
45  InitMsgSharedPtr serializedProds(new InitMsgBuffer(initMsgView.size()));
46  std::copy(
47  initMsgView.startAddress(),
48  initMsgView.startAddress()+initMsgView.size(),
49  &(*serializedProds)[0]
50  );
51  initMsgMap_.insert(pos, InitMsgMap::value_type(outputModuleId,serializedProds));
52 
53  return true; // new init message
54 }
55 
56 
57 bool InitMsgCollection::addIfUnique(I2OChain const& i2oChain, InitMsgSharedPtr& serializedProds)
58 {
59  boost::mutex::scoped_lock sl(listLock_);
60 
61  // check if the outputModuleId was already seen
62  const uint32_t outputModuleId = i2oChain.outputModuleId();
63  InitMsgMap::iterator pos = initMsgMap_.lower_bound(outputModuleId);
64  if ( pos != initMsgMap_.end() && !(initMsgMap_.key_comp()(outputModuleId, pos->first)))
65  return false; // init message already exists
66 
67  // build the init message view
68  serializedProds.reset( new InitMsgBuffer(i2oChain.totalDataSize()) );
69  i2oChain.copyFragmentsIntoBuffer( *serializedProds );
70  InitMsgView initMsgView(&(*serializedProds)[0]);
71 
72  checkOutputModuleLabel(initMsgView);
73 
74  // add the message to the internal list
75  initMsgMap_.insert(pos, InitMsgMap::value_type(outputModuleId,serializedProds));
76 
77  return true; // new init message
78 }
79 
80 
82 {
83  const std::string inputOMLabel = initMsgView.outputModuleLabel();
84  const std::string trimmedOMLabel = boost::algorithm::trim_copy(inputOMLabel);
85  if (trimmedOMLabel.empty()) {
86  throw cms::Exception("InitMsgCollection", "addIfUnique:")
87  << "Invalid INIT message: the HLT output module label is empty!"
88  << std::endl;
89  }
90 }
91 
92 
94 InitMsgCollection::getElementForOutputModuleId(const uint32_t& requestedOutputModuleId) const
95 {
96  boost::mutex::scoped_lock sl(listLock_);
97  InitMsgSharedPtr serializedProds;
98 
99  InitMsgMap::const_iterator it = initMsgMap_.find(requestedOutputModuleId);
100  if (it != initMsgMap_.end())
101  serializedProds = it->second;
102 
103  return serializedProds;
104 }
105 
106 
108 InitMsgCollection::getElementForOutputModuleLabel(const std::string& requestedOutputModuleLabel) const
109 {
110  boost::mutex::scoped_lock sl(listLock_);
111  InitMsgSharedPtr serializedProds;
112 
113  // handle the special case of an empty request
114  // (If we want to use class methods to check the collection size and
115  // fetch the last element in the collection, then we would need to
116  // switch to recursive mutexes...)
117  if (requestedOutputModuleLabel.empty()) {
118  if (initMsgMap_.size() == 1) {
119  serializedProds = initMsgMap_.begin()->second;
120  }
121  else if (initMsgMap_.size() > 1) {
122  std::string msg = "Invalid INIT message lookup: the requested ";
123  msg.append("HLT output module label is empty but there are multiple ");
124  msg.append("HLT output modules to choose from.");
125  throw cms::Exception("InitMsgCollection", "getElementForOutputModule:")
126  << msg << std::endl;
127  }
128  }
129 
130  else {
131  // loop over the existing messages
132  for (InitMsgMap::const_iterator msgIter = initMsgMap_.begin(),
133  msgIterEnd = initMsgMap_.end();
134  msgIter != msgIterEnd;
135  msgIter++)
136  {
137  InitMsgSharedPtr workingMessage = msgIter->second;
138  InitMsgView existingInitMsg(&(*workingMessage)[0]);
139  std::string existingOMLabel = existingInitMsg.outputModuleLabel();
140 
141  // check if the output module labels match
142  if (requestedOutputModuleLabel == existingOMLabel) {
143  serializedProds = workingMessage;
144  break;
145  }
146  }
147  }
148 
149  return serializedProds;
150 }
151 
152 
154 {
155  boost::mutex::scoped_lock sl(listLock_);
156 
157  InitMsgSharedPtr ptrToElement;
158  try
159  {
160  ptrToElement = initMsgMap_.at(index);
161  }
162  catch (std::out_of_range& e)
163  { }
164 
165  return ptrToElement;
166 }
167 
168 
170 {
171  boost::mutex::scoped_lock sl(listLock_);
172  initMsgMap_.clear();
173 }
174 
175 
177 {
178  boost::mutex::scoped_lock sl(listLock_);
179  return initMsgMap_.size();
180 }
181 
182 
184 {
185  boost::mutex::scoped_lock sl(listLock_);
186 
187  // nothing much we can say if the collection is empty
188  if (initMsgMap_.empty()) {
189  return "No information is available about the available triggers.";
190  }
191 
192  // list the full set of available triggers
193  std::string helpString;
194  helpString.append("The full list of trigger paths is the following:");
195 
196  // we can just use the list from the first entry since all
197  // subsequent entries are forced to be the same
198  InitMsgSharedPtr serializedProds = initMsgMap_.begin()->second;
199  InitMsgView existingInitMsg(&(*serializedProds)[0]);
200  Strings existingTriggerList;
201  existingInitMsg.hltTriggerNames(existingTriggerList);
202  for (unsigned int idx = 0; idx < existingTriggerList.size(); idx++) {
203  helpString.append("\n " + existingTriggerList[idx]);
204  }
205 
206  // list the output modules (INIT messages)
207  helpString.append("\nThe registered HLT output modules and their ");
208  helpString.append("trigger selections are the following:");
209 
210  // loop over the existing messages
211  for (InitMsgMap::const_iterator msgIter = initMsgMap_.begin(),
212  msgIterEnd = initMsgMap_.end();
213  msgIter != msgIterEnd;
214  msgIter++)
215  {
216  serializedProds = msgIter->second;
217  InitMsgView workingInitMsg(&(*serializedProds)[0]);
218  helpString.append("\n *** Output module \"");
219  helpString.append(workingInitMsg.outputModuleLabel());
220  helpString.append("\" ***");
221  Strings workingSelectionList;
222  workingInitMsg.hltTriggerSelections(workingSelectionList);
223  for (unsigned int idx = 0; idx < workingSelectionList.size(); idx++) {
224  helpString.append("\n " + workingSelectionList[idx]);
225  }
226  }
227 
228  // return the result
229  return helpString;
230 }
231 
232 
233 std::string InitMsgCollection::getOutputModuleName(const uint32_t outputModuleId) const
234 {
235  boost::mutex::scoped_lock sl(listLock_);
236 
237  InitMsgMap::const_iterator it = initMsgMap_.find(outputModuleId);
238 
239  if (it == initMsgMap_.end())
240  {
241  return "";
242  }
243  else {
244  InitMsgSharedPtr serializedProds = it->second;
245  const InitMsgView initMsgView(&(*serializedProds)[0]);
246  return initMsgView.outputModuleLabel();
247  }
248 }
249 
250 
252  unsigned int maxCount)
253 {
254  std::string resultString = "";
255  unsigned int elementCount = list.size();
256  if (maxCount > 0 && maxCount < elementCount) {elementCount = maxCount;}
257  for (unsigned int idx = 0; idx < elementCount; idx++)
258  {
259  resultString.append(list[idx]);
260  if (idx < (elementCount-1)) {
261  resultString.append(", ");
262  }
263  }
264  if (elementCount < list.size())
265  {
266  resultString.append(", ...");
267  }
268  return resultString;
269 }
270 
271 
std::vector< unsigned char > InitMsgBuffer
InitMsgSharedPtr getElementAt(const unsigned int index) const
std::vector< std::string > Strings
Definition: MsgTools.h:18
InitMsgSharedPtr getElementForOutputModuleId(const uint32_t &) const
boost::shared_ptr< InitMsgBuffer > InitMsgSharedPtr
void hltTriggerNames(Strings &save_here) const
Definition: InitMessage.cc:142
std::string getOutputModuleName(const uint32_t outputModuleId) const
uint8 * startAddress() const
Definition: InitMessage.h:68
void checkOutputModuleLabel(InitMsgView const &) const
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:168
InitMsgSharedPtr getElementForOutputModuleLabel(const std::string &) const
Container::value_type value_type
std::string getSelectionHelpString() const
unsigned int copyFragmentsIntoBuffer(std::vector< unsigned char > &buff) const
Definition: I2OChain.cc:469
std::string outputModuleLabel() const
Definition: InitMessage.cc:132
bool addIfUnique(InitMsgView const &initMsgView)
unsigned long totalDataSize() const
Definition: I2OChain.cc:432
uint32 outputModuleId() const
Definition: InitMessage.h:76
static std::string stringsToText(Strings const &list, unsigned int maxCount=0)
uint32 size() const
Definition: InitMessage.h:67
void hltTriggerSelections(Strings &save_here) const
Definition: InitMessage.cc:147
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
uint32_t outputModuleId() const
Definition: I2OChain.cc:505