#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_ |
Definition at line 32 of file InitMsgCollection.h.
typedef std::vector<InitMsgPtrAndCount> stor::InitMsgCollection::InitMsgList [private] |
Definition at line 168 of file InitMsgCollection.h.
typedef std::pair<InitMsgSharedPtr, size_t> stor::InitMsgCollection::InitMsgPtrAndCount [private] |
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.
InitMsgCollection::InitMsgCollection | ( | ) |
InitMsgCollection::~InitMsgCollection | ( | ) |
void InitMsgCollection::add | ( | InitMsgView const & | initMsgView | ) | [private] |
Adds the specified INIT message to the collection (unconditionally).
initMsgView | The 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().
{ // add the message to the internal list InitMsgSharedPtr serializedProds(new InitMsgBuffer(initMsgView.size())); initMsgList_.push_back( std::make_pair(serializedProds,1) ); std::copy(initMsgView.startAddress(), initMsgView.startAddress()+initMsgView.size(), &(*serializedProds)[0]); // add the module ID name to the name map outModNameTable_[initMsgView.outputModuleId()] = initMsgView.outputModuleLabel(); }
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.
initMsgView | The INIT message to be added to the collection. |
cms::Exception | if one of the consistency checks fails. |
Definition at line 31 of file InitMsgCollection.cc.
References Clusterizer1DCommons::add(), Exception, and InitMsgView::outputModuleLabel().
{ boost::mutex::scoped_lock sl(listLock_); // test the output module label for validity std::string inputOMLabel = initMsgView.outputModuleLabel(); std::string trimmedOMLabel = boost::algorithm::trim_copy(inputOMLabel); if (trimmedOMLabel.empty()) { throw cms::Exception("InitMsgCollection", "addIfUnique:") << "Invalid INIT message: the HLT output module label is empty!" << std::endl; } // initially, assume that we will want to include the new message bool addToList = true; // if this is the first INIT message that we've seen, we just add it if (initMsgList_.empty()) { this->add(initMsgView); } // if this is a subsequent INIT message, check if it is unique else { // loop over the existing messages for (InitMsgList::iterator msgIter = initMsgList_.begin(), msgIterEnd = initMsgList_.end(); msgIter != msgIterEnd; msgIter++) { InitMsgSharedPtr serializedProds = msgIter->first; InitMsgView existingInitMsg(&(*serializedProds)[0]); std::string existingOMLabel = existingInitMsg.outputModuleLabel(); // check if the output module labels match if (inputOMLabel == existingOMLabel) { // we already have a copy of the INIT message addToList = false; ++msgIter->second; break; } } // if we've found no problems, add the new message to the collection if (addToList) { this->add(initMsgView); } } // indicate whether the message was added or not return addToList; }
void InitMsgCollection::clear | ( | void | ) |
Removes all entries from the collection.
Definition at line 159 of file InitMsgCollection.cc.
{ boost::mutex::scoped_lock sl(listLock_); initMsgList_.clear(); outModNameTable_.clear(); }
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.
index | The index of the requested element. |
Definition at line 143 of file InitMsgCollection.cc.
References ExpressReco_HICollisions_FallBack::e.
{ boost::mutex::scoped_lock sl(listLock_); InitMsgSharedPtr ptrToElement; try { ptrToElement = initMsgList_.at(index).first; } catch (std::out_of_range& e) { } return ptrToElement; }
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?)
requestedOMLabel | The HLT output module label of the INIT message to be returned. |
cms::Exception | if 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 Exception, runTheMatrix::msg, and InitMsgView::outputModuleLabel().
{ boost::mutex::scoped_lock sl(listLock_); InitMsgSharedPtr serializedProds; // handle the special case of an empty request // (If we want to use class methods to check the collection size and // fetch the last element in the collection, then we would need to // switch to recursive mutexes...) if (requestedOMLabel.empty()) { if (initMsgList_.size() == 1) { serializedProds = initMsgList_.back().first; } else if (initMsgList_.size() > 1) { std::string msg = "Invalid INIT message lookup: the requested "; msg.append("HLT output module label is empty but there are multiple "); msg.append("HLT output modules to choose from."); throw cms::Exception("InitMsgCollection", "getElementForOutputModule:") << msg << std::endl; } } else { // loop over the existing messages for (InitMsgList::const_iterator msgIter = initMsgList_.begin(), msgIterEnd = initMsgList_.end(); msgIter != msgIterEnd; msgIter++) { InitMsgSharedPtr workingMessage = msgIter->first; InitMsgView existingInitMsg(&(*workingMessage)[0]); std::string existingOMLabel = existingInitMsg.outputModuleLabel(); // check if the output module labels match if (requestedOMLabel == existingOMLabel) { serializedProds = workingMessage; break; } } } return serializedProds; }
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.
Definition at line 131 of file InitMsgCollection.cc.
{ boost::mutex::scoped_lock sl(listLock_); InitMsgSharedPtr ptrToLast; if (!initMsgList_.empty()) { ptrToLast = initMsgList_.back().first; } return ptrToLast; }
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.
Definition at line 264 of file InitMsgCollection.cc.
{ boost::mutex::scoped_lock sl(listLock_); OutModTable::const_iterator it = outModNameTable_.find(outputModuleId); if (it == outModNameTable_.end()) { return ""; } else { return it->second; } }
std::string InitMsgCollection::getSelectionHelpString | ( | ) | const |
Returns a string with information on which selections are available.
Definition at line 214 of file InitMsgCollection.cc.
References InitMsgView::hltTriggerNames(), InitMsgView::hltTriggerSelections(), and InitMsgView::outputModuleLabel().
{ boost::mutex::scoped_lock sl(listLock_); // nothing much we can say if the collection is empty if (initMsgList_.empty()) { return "No information is available about the available triggers."; } // list the full set of available triggers std::string helpString; helpString.append("The full list of trigger paths is the following:"); // we can just use the list from the first entry since all // subsequent entries are forced to be the same InitMsgSharedPtr serializedProds = initMsgList_[0].first; InitMsgView existingInitMsg(&(*serializedProds)[0]); Strings existingTriggerList; existingInitMsg.hltTriggerNames(existingTriggerList); for (unsigned int idx = 0; idx < existingTriggerList.size(); idx++) { helpString.append("\n " + existingTriggerList[idx]); } // list the output modules (INIT messages) helpString.append("\nThe registered HLT output modules and their "); helpString.append("trigger selections are the following:"); // loop over the existing messages for (InitMsgList::const_iterator msgIter = initMsgList_.begin(), msgIterEnd = initMsgList_.end(); msgIter != msgIterEnd; msgIter++) { serializedProds = msgIter->first; InitMsgView workingInitMsg(&(*serializedProds)[0]); helpString.append("\n *** Output module \""); helpString.append(workingInitMsg.outputModuleLabel()); helpString.append("\" ***"); Strings workingSelectionList; workingInitMsg.hltTriggerSelections(workingSelectionList); for (unsigned int idx = 0; idx < workingSelectionList.size(); idx++) { helpString.append("\n " + workingSelectionList[idx]); } } // return the result return helpString; }
size_t InitMsgCollection::initMsgCount | ( | const std::string & | outputModuleLabel | ) | const |
Returns the number of identical INIT messages received for the given module name
Definition at line 174 of file InitMsgCollection.cc.
References InitMsgView::outputModuleLabel().
{ boost::mutex::scoped_lock sl(listLock_); for (InitMsgList::const_iterator msgIter = initMsgList_.begin(), msgIterEnd = initMsgList_.end(); msgIter != msgIterEnd; msgIter++) { InitMsgSharedPtr workingMessage = msgIter->first; InitMsgView existingInitMsg(&(*workingMessage)[0]); std::string existingOMLabel = existingInitMsg.outputModuleLabel(); // check if the output module labels match if (outputModuleLabel == existingOMLabel) { return msgIter->second; } } return 0; }
size_t InitMsgCollection::maxMsgCount | ( | ) | const |
Returns the maximum number of identical INIT messages received for any output module
Definition at line 196 of file InitMsgCollection.cc.
{ boost::mutex::scoped_lock sl(listLock_); size_t maxCount = 0; for (InitMsgList::const_iterator msgIter = initMsgList_.begin(), msgIterEnd = initMsgList_.end(); msgIter != msgIterEnd; msgIter++) { if (msgIter->second > maxCount) maxCount = msgIter->second; } return maxCount; }
size_t InitMsgCollection::size | ( | void | ) | const |
Returns the number of unique INIT messages in the collection.
Definition at line 167 of file InitMsgCollection.cc.
{ boost::mutex::scoped_lock sl(listLock_); return initMsgList_.size(); }
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.
list | the list of strings to include (std::vector of strings); |
maxCount | the maximum number of list elements to include. |
Definition at line 280 of file InitMsgCollection.cc.
{ std::string resultString = ""; unsigned int elementCount = list.size(); if (maxCount > 0 && maxCount < elementCount) {elementCount = maxCount;} for (unsigned int idx = 0; idx < elementCount; idx++) { resultString.append(list[idx]); if (idx < (elementCount-1)) { resultString.append(", "); } } if (elementCount < list.size()) { resultString.append(", ..."); } return resultString; }
Definition at line 169 of file InitMsgCollection.h.
boost::mutex stor::InitMsgCollection::listLock_ [mutable, private] |
Definition at line 173 of file InitMsgCollection.h.
Definition at line 172 of file InitMsgCollection.h.