CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes

stor::InitMsgCollection Class Reference

#include <InitMsgCollection.h>

List of all members.

Public Member Functions

bool addIfUnique (InitMsgView const &initMsgView)
bool addIfUnique (I2OChain const &, InitMsgSharedPtr &)
void clear ()
InitMsgSharedPtr getElementAt (const unsigned int index) const
InitMsgSharedPtr getElementForOutputModuleId (const uint32_t &) const
InitMsgSharedPtr getElementForOutputModuleLabel (const std::string &) const
std::string getOutputModuleName (const uint32_t outputModuleId) const
std::string getSelectionHelpString () const
 InitMsgCollection ()
size_t size () const
 ~InitMsgCollection ()

Static Public Member Functions

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

Private Types

typedef std::map< uint32_t,
InitMsgSharedPtr
InitMsgMap

Private Member Functions

void checkOutputModuleLabel (InitMsgView const &) const

Private Attributes

InitMsgMap initMsgMap_
boost::mutex listLock_

Detailed Description

Definition at line 35 of file InitMsgCollection.h.


Member Typedef Documentation

typedef std::map<uint32_t,InitMsgSharedPtr> stor::InitMsgCollection::InitMsgMap [private]

Definition at line 174 of file InitMsgCollection.h.


Constructor & Destructor Documentation

InitMsgCollection::InitMsgCollection ( )

InitMsgCollection constructor.

Definition at line 21 of file InitMsgCollection.cc.

References hitfit::clear().

{
  clear();
}
InitMsgCollection::~InitMsgCollection ( )

InitMsgCollection destructor.

Definition at line 27 of file InitMsgCollection.cc.

{
}

Member Function Documentation

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 32 of file InitMsgCollection.cc.

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

{
  boost::mutex::scoped_lock sl(listLock_);
  
  // check if the outputModuleId was already seen
  const uint32_t outputModuleId = initMsgView.outputModuleId();
  InitMsgMap::iterator pos = initMsgMap_.lower_bound(outputModuleId);
  if ( pos != initMsgMap_.end() && !(initMsgMap_.key_comp()(outputModuleId, pos->first)))
    return false; // init message already exists
  
  checkOutputModuleLabel(initMsgView);
  
  // add the message to the internal list
  InitMsgSharedPtr serializedProds(new InitMsgBuffer(initMsgView.size()));
  std::copy(
    initMsgView.startAddress(),
    initMsgView.startAddress()+initMsgView.size(),
    &(*serializedProds)[0]
  );
  initMsgMap_.insert(pos, InitMsgMap::value_type(outputModuleId,serializedProds));
  
  return true; // new init message
}
bool InitMsgCollection::addIfUnique ( I2OChain const &  i2oChain,
InitMsgSharedPtr serializedProds 
)

Adds the INIT message contained in the specified I2OChain 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 INIT message is new, the InitMsgView will contain the view of INIT message and the method returns true.

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

Parameters:
i2oChainthe I2OChain containing an INIT message
initMsgViewthe INIT view which was 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 57 of file InitMsgCollection.cc.

References stor::I2OChain::copyFragmentsIntoBuffer(), stor::I2OChain::outputModuleId(), pos, and stor::I2OChain::totalDataSize().

{
  boost::mutex::scoped_lock sl(listLock_);

  // check if the outputModuleId was already seen
  const uint32_t outputModuleId = i2oChain.outputModuleId();
  InitMsgMap::iterator pos = initMsgMap_.lower_bound(outputModuleId);
  if ( pos != initMsgMap_.end() && !(initMsgMap_.key_comp()(outputModuleId, pos->first)))
    return false; // init message already exists
  
  // build the init message view
  serializedProds.reset( new InitMsgBuffer(i2oChain.totalDataSize()) );
  i2oChain.copyFragmentsIntoBuffer( *serializedProds );
  InitMsgView initMsgView(&(*serializedProds)[0]);
  
  checkOutputModuleLabel(initMsgView);
  
  // add the message to the internal list
  initMsgMap_.insert(pos, InitMsgMap::value_type(outputModuleId,serializedProds));

  return true; // new init message
}
void InitMsgCollection::checkOutputModuleLabel ( InitMsgView const &  initMsgView) const [private]

Definition at line 81 of file InitMsgCollection.cc.

References Exception, and InitMsgView::outputModuleLabel().

{
  const std::string inputOMLabel = initMsgView.outputModuleLabel();
  const 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;
  }
}
void InitMsgCollection::clear ( void  )

Removes all entries from the collection.

Definition at line 169 of file InitMsgCollection.cc.

{
  boost::mutex::scoped_lock sl(listLock_);
  initMsgMap_.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.

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

Definition at line 153 of file InitMsgCollection.cc.

References alignCSCRings::e.

{
  boost::mutex::scoped_lock sl(listLock_);

  InitMsgSharedPtr ptrToElement;
  try
  {
    ptrToElement = initMsgMap_.at(index);
  }
  catch (std::out_of_range& e)
  { }

  return ptrToElement;
}
InitMsgSharedPtr InitMsgCollection::getElementForOutputModuleId ( const uint32_t &  requestedOutputModuleId) const

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

Parameters:
requestedOutputModuleIdThe HLT output module id 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.

Definition at line 94 of file InitMsgCollection.cc.

{
  boost::mutex::scoped_lock sl(listLock_);
  InitMsgSharedPtr serializedProds;
  
  InitMsgMap::const_iterator it = initMsgMap_.find(requestedOutputModuleId);
  if (it != initMsgMap_.end())
    serializedProds = it->second;

  return serializedProds;
}
InitMsgSharedPtr InitMsgCollection::getElementForOutputModuleLabel ( const std::string &  requestedOutputModuleLabel) 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:
requestedOutputModuleLabelThe 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 108 of file InitMsgCollection.cc.

References Exception, lumiQueryAPI::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 (requestedOutputModuleLabel.empty()) {
    if (initMsgMap_.size() == 1) {
      serializedProds = initMsgMap_.begin()->second;
    }
    else if (initMsgMap_.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 (InitMsgMap::const_iterator msgIter = initMsgMap_.begin(),
           msgIterEnd = initMsgMap_.end();
         msgIter != msgIterEnd;
         msgIter++)
    {
      InitMsgSharedPtr workingMessage = msgIter->second;
      InitMsgView existingInitMsg(&(*workingMessage)[0]);
      std::string existingOMLabel = existingInitMsg.outputModuleLabel();
      
      // check if the output module labels match
      if (requestedOutputModuleLabel == existingOMLabel) {
        serializedProds = workingMessage;
        break;
      }
    }
  }

  return serializedProds;
}
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 233 of file InitMsgCollection.cc.

References InitMsgView::outputModuleLabel().

{
  boost::mutex::scoped_lock sl(listLock_);

  InitMsgMap::const_iterator it = initMsgMap_.find(outputModuleId);

  if (it == initMsgMap_.end())
  {
    return "";
  }
  else {
    InitMsgSharedPtr serializedProds = it->second;
    const InitMsgView initMsgView(&(*serializedProds)[0]);
    return initMsgView.outputModuleLabel();
  }
}
std::string InitMsgCollection::getSelectionHelpString ( ) const

Returns a string with information on which selections are available.

Returns:
the help string.

Definition at line 183 of file InitMsgCollection.cc.

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

{
  boost::mutex::scoped_lock sl(listLock_);

  // nothing much we can say if the collection is empty
  if (initMsgMap_.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 = initMsgMap_.begin()->second;
  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 (InitMsgMap::const_iterator msgIter = initMsgMap_.begin(),
           msgIterEnd = initMsgMap_.end();
         msgIter != msgIterEnd;
         msgIter++)
    {
    serializedProds = msgIter->second;
    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::size ( void  ) const

Returns the number of unique INIT messages in the collection.

Returns:
the integer number of messages.

Definition at line 176 of file InitMsgCollection.cc.

{
  boost::mutex::scoped_lock sl(listLock_);
  return initMsgMap_.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.

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 251 of file InitMsgCollection.cc.

References UserOptions_cff::idx.

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

Member Data Documentation

Definition at line 175 of file InitMsgCollection.h.

Definition at line 176 of file InitMsgCollection.h.