Go to the documentation of this file.00001
00003
00004 #include "DataFormats/Streamer/interface/StreamedProducts.h"
00005 #include "EventFilter/StorageManager/interface/InitMsgCollection.h"
00006 #include "FWCore/Framework/interface/EventSelector.h"
00007 #include "FWCore/Utilities/interface/DebugMacros.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 #include "IOPool/Streamer/interface/DumpTools.h"
00010 #include "IOPool/Streamer/interface/OtherMessage.h"
00011 #include "IOPool/Streamer/interface/StreamerInputSource.h"
00012 #include "IOPool/Streamer/interface/Utilities.h"
00013
00014 #include "boost/algorithm/string/trim.hpp"
00015 #include <iostream>
00016
00017 using namespace stor;
00018 using namespace edm;
00019
00020 InitMsgCollection::InitMsgCollection()
00021 {
00022 clear();
00023 }
00024
00025
00026 InitMsgCollection::~InitMsgCollection()
00027 {
00028 }
00029
00030
00031 bool InitMsgCollection::addIfUnique(InitMsgView const& initMsgView)
00032 {
00033 boost::mutex::scoped_lock sl(listLock_);
00034
00035
00036 std::string inputOMLabel = initMsgView.outputModuleLabel();
00037 std::string trimmedOMLabel = boost::algorithm::trim_copy(inputOMLabel);
00038 if (trimmedOMLabel.empty()) {
00039 throw cms::Exception("InitMsgCollection", "addIfUnique:")
00040 << "Invalid INIT message: the HLT output module label is empty!"
00041 << std::endl;
00042 }
00043
00044
00045 bool addToList = true;
00046
00047
00048 if (initMsgList_.empty()) {
00049 this->add(initMsgView);
00050 }
00051
00052
00053 else {
00054
00055
00056 for (InitMsgList::iterator msgIter = initMsgList_.begin(),
00057 msgIterEnd = initMsgList_.end();
00058 msgIter != msgIterEnd;
00059 msgIter++)
00060 {
00061 InitMsgSharedPtr serializedProds = msgIter->first;
00062 InitMsgView existingInitMsg(&(*serializedProds)[0]);
00063 std::string existingOMLabel = existingInitMsg.outputModuleLabel();
00064
00065
00066 if (inputOMLabel == existingOMLabel) {
00067
00068 addToList = false;
00069 ++msgIter->second;
00070 break;
00071 }
00072 }
00073
00074
00075 if (addToList) {
00076 this->add(initMsgView);
00077 }
00078 }
00079
00080
00081 return addToList;
00082 }
00083
00084
00085 InitMsgSharedPtr
00086 InitMsgCollection::getElementForOutputModule(const std::string& requestedOMLabel) const
00087 {
00088 boost::mutex::scoped_lock sl(listLock_);
00089 InitMsgSharedPtr serializedProds;
00090
00091
00092
00093
00094
00095 if (requestedOMLabel.empty()) {
00096 if (initMsgList_.size() == 1) {
00097 serializedProds = initMsgList_.back().first;
00098 }
00099 else if (initMsgList_.size() > 1) {
00100 std::string msg = "Invalid INIT message lookup: the requested ";
00101 msg.append("HLT output module label is empty but there are multiple ");
00102 msg.append("HLT output modules to choose from.");
00103 throw cms::Exception("InitMsgCollection", "getElementForOutputModule:")
00104 << msg << std::endl;
00105 }
00106 }
00107
00108 else {
00109
00110 for (InitMsgList::const_iterator msgIter = initMsgList_.begin(),
00111 msgIterEnd = initMsgList_.end();
00112 msgIter != msgIterEnd;
00113 msgIter++)
00114 {
00115 InitMsgSharedPtr workingMessage = msgIter->first;
00116 InitMsgView existingInitMsg(&(*workingMessage)[0]);
00117 std::string existingOMLabel = existingInitMsg.outputModuleLabel();
00118
00119
00120 if (requestedOMLabel == existingOMLabel) {
00121 serializedProds = workingMessage;
00122 break;
00123 }
00124 }
00125 }
00126
00127 return serializedProds;
00128 }
00129
00130
00131 InitMsgSharedPtr InitMsgCollection::getLastElement() const
00132 {
00133 boost::mutex::scoped_lock sl(listLock_);
00134
00135 InitMsgSharedPtr ptrToLast;
00136 if (!initMsgList_.empty()) {
00137 ptrToLast = initMsgList_.back().first;
00138 }
00139 return ptrToLast;
00140 }
00141
00142
00143 InitMsgSharedPtr InitMsgCollection::getElementAt(const unsigned int index) const
00144 {
00145 boost::mutex::scoped_lock sl(listLock_);
00146
00147 InitMsgSharedPtr ptrToElement;
00148 try
00149 {
00150 ptrToElement = initMsgList_.at(index).first;
00151 }
00152 catch (std::out_of_range& e)
00153 { }
00154
00155 return ptrToElement;
00156 }
00157
00158
00159 void InitMsgCollection::clear()
00160 {
00161 boost::mutex::scoped_lock sl(listLock_);
00162 initMsgList_.clear();
00163 outModNameTable_.clear();
00164 }
00165
00166
00167 size_t InitMsgCollection::size() const
00168 {
00169 boost::mutex::scoped_lock sl(listLock_);
00170 return initMsgList_.size();
00171 }
00172
00173
00174 size_t InitMsgCollection::initMsgCount(const std::string& outputModuleLabel) const
00175 {
00176 boost::mutex::scoped_lock sl(listLock_);
00177
00178 for (InitMsgList::const_iterator msgIter = initMsgList_.begin(),
00179 msgIterEnd = initMsgList_.end();
00180 msgIter != msgIterEnd;
00181 msgIter++)
00182 {
00183 InitMsgSharedPtr workingMessage = msgIter->first;
00184 InitMsgView existingInitMsg(&(*workingMessage)[0]);
00185 std::string existingOMLabel = existingInitMsg.outputModuleLabel();
00186
00187
00188 if (outputModuleLabel == existingOMLabel) {
00189 return msgIter->second;
00190 }
00191 }
00192 return 0;
00193 }
00194
00195
00196 size_t InitMsgCollection::maxMsgCount() const
00197 {
00198 boost::mutex::scoped_lock sl(listLock_);
00199
00200 size_t maxCount = 0;
00201
00202 for (InitMsgList::const_iterator msgIter = initMsgList_.begin(),
00203 msgIterEnd = initMsgList_.end();
00204 msgIter != msgIterEnd;
00205 msgIter++)
00206 {
00207 if (msgIter->second > maxCount)
00208 maxCount = msgIter->second;
00209 }
00210 return maxCount;
00211 }
00212
00213
00214 std::string InitMsgCollection::getSelectionHelpString() const
00215 {
00216 boost::mutex::scoped_lock sl(listLock_);
00217
00218
00219 if (initMsgList_.empty()) {
00220 return "No information is available about the available triggers.";
00221 }
00222
00223
00224 std::string helpString;
00225 helpString.append("The full list of trigger paths is the following:");
00226
00227
00228
00229 InitMsgSharedPtr serializedProds = initMsgList_[0].first;
00230 InitMsgView existingInitMsg(&(*serializedProds)[0]);
00231 Strings existingTriggerList;
00232 existingInitMsg.hltTriggerNames(existingTriggerList);
00233 for (unsigned int idx = 0; idx < existingTriggerList.size(); idx++) {
00234 helpString.append("\n " + existingTriggerList[idx]);
00235 }
00236
00237
00238 helpString.append("\nThe registered HLT output modules and their ");
00239 helpString.append("trigger selections are the following:");
00240
00241
00242 for (InitMsgList::const_iterator msgIter = initMsgList_.begin(),
00243 msgIterEnd = initMsgList_.end();
00244 msgIter != msgIterEnd;
00245 msgIter++)
00246 {
00247 serializedProds = msgIter->first;
00248 InitMsgView workingInitMsg(&(*serializedProds)[0]);
00249 helpString.append("\n *** Output module \"");
00250 helpString.append(workingInitMsg.outputModuleLabel());
00251 helpString.append("\" ***");
00252 Strings workingSelectionList;
00253 workingInitMsg.hltTriggerSelections(workingSelectionList);
00254 for (unsigned int idx = 0; idx < workingSelectionList.size(); idx++) {
00255 helpString.append("\n " + workingSelectionList[idx]);
00256 }
00257 }
00258
00259
00260 return helpString;
00261 }
00262
00263
00264 std::string InitMsgCollection::getOutputModuleName(const uint32_t outputModuleId) const
00265 {
00266 boost::mutex::scoped_lock sl(listLock_);
00267
00268 OutModTable::const_iterator it = outModNameTable_.find(outputModuleId);
00269
00270 if (it == outModNameTable_.end())
00271 {
00272 return "";
00273 }
00274 else {
00275 return it->second;
00276 }
00277 }
00278
00279
00280 std::string InitMsgCollection::stringsToText(Strings const& list,
00281 unsigned int maxCount)
00282 {
00283 std::string resultString = "";
00284 unsigned int elementCount = list.size();
00285 if (maxCount > 0 && maxCount < elementCount) {elementCount = maxCount;}
00286 for (unsigned int idx = 0; idx < elementCount; idx++)
00287 {
00288 resultString.append(list[idx]);
00289 if (idx < (elementCount-1)) {
00290 resultString.append(", ");
00291 }
00292 }
00293 if (elementCount < list.size())
00294 {
00295 resultString.append(", ...");
00296 }
00297 return resultString;
00298 }
00299
00300
00301 void InitMsgCollection::add(InitMsgView const& initMsgView)
00302 {
00303
00304 InitMsgSharedPtr serializedProds(new InitMsgBuffer(initMsgView.size()));
00305 initMsgList_.push_back( std::make_pair(serializedProds,1) );
00306 std::copy(initMsgView.startAddress(),
00307 initMsgView.startAddress()+initMsgView.size(),
00308 &(*serializedProds)[0]);
00309
00310
00311 outModNameTable_[initMsgView.outputModuleId()] =
00312 initMsgView.outputModuleLabel();
00313 }
00314
00315
00316