File indexing completed on 2023-10-25 09:46:43
0001
0002 #include "FWCore/Common/interface/TriggerResultsByName.h"
0003 #include "FWCore/Utilities/interface/EDMException.h"
0004 #include "DataFormats/Common/interface/TriggerResults.h"
0005 #include "FWCore/Common/interface/TriggerNames.h"
0006
0007 namespace edm {
0008
0009 TriggerResultsByName::TriggerResultsByName(TriggerResults const* triggerResults, TriggerNames const* triggerNames)
0010 : triggerResults_(triggerResults), triggerNames_(triggerNames) {
0011
0012 if (triggerResults_ == nullptr || triggerNames_ == nullptr) {
0013 return;
0014 }
0015
0016 if (triggerResults_->parameterSetID() != triggerNames_->parameterSetID()) {
0017 throw edm::Exception(edm::errors::Unknown)
0018 << "TriggerResultsByName::TriggerResultsByName, Trigger names vector and TriggerResults\n"
0019 "have different ParameterSetID's. This should be impossible when the object is obtained\n"
0020 "from the function named triggerResultsByName in the Event class, which is the way\n"
0021 "TriggerResultsByName should always be created. If this is the case, please send\n"
0022 "information to reproduce this problem to the edm developers. Otherwise, you are\n"
0023 "using this class incorrectly and in a way that is not supported.\n";
0024 }
0025
0026 if (triggerResults_->size() != triggerNames_->size()) {
0027 throw edm::Exception(edm::errors::Unknown)
0028 << "TriggerResultsByName::TriggerResultsByName, Trigger names vector\n"
0029 "and TriggerResults have different sizes. This should be impossible,\n"
0030 "please send information to reproduce this problem to the edm developers.\n";
0031 }
0032 }
0033
0034 bool TriggerResultsByName::isValid() const {
0035 if (triggerResults_ == nullptr || triggerNames_ == nullptr)
0036 return false;
0037 return true;
0038 }
0039
0040 ParameterSetID const& TriggerResultsByName::parameterSetID() const {
0041 if (triggerResults_ == nullptr)
0042 throwTriggerResultsMissing();
0043 return triggerResults_->parameterSetID();
0044 }
0045
0046 bool TriggerResultsByName::wasrun() const {
0047 if (triggerResults_ == nullptr)
0048 throwTriggerResultsMissing();
0049 return triggerResults_->wasrun();
0050 }
0051
0052 bool TriggerResultsByName::accept() const {
0053 if (triggerResults_ == nullptr)
0054 throwTriggerResultsMissing();
0055 return triggerResults_->accept();
0056 }
0057
0058 bool TriggerResultsByName::error() const {
0059 if (triggerResults_ == nullptr)
0060 throwTriggerResultsMissing();
0061 return triggerResults_->error();
0062 }
0063
0064 HLTPathStatus const& TriggerResultsByName::at(std::string const& pathName) const {
0065 if (triggerResults_ == nullptr)
0066 throwTriggerResultsMissing();
0067 unsigned i = getAndCheckIndex(pathName);
0068 return triggerResults_->at(i);
0069 }
0070
0071 HLTPathStatus const& TriggerResultsByName::at(unsigned i) const {
0072 if (triggerResults_ == nullptr)
0073 throwTriggerResultsMissing();
0074 return triggerResults_->at(i);
0075 }
0076
0077 HLTPathStatus const& TriggerResultsByName::operator[](std::string const& pathName) const {
0078 if (triggerResults_ == nullptr)
0079 throwTriggerResultsMissing();
0080 unsigned i = getAndCheckIndex(pathName);
0081 return triggerResults_->at(i);
0082 }
0083
0084 HLTPathStatus const& TriggerResultsByName::operator[](unsigned i) const {
0085 if (triggerResults_ == nullptr)
0086 throwTriggerResultsMissing();
0087 return triggerResults_->at(i);
0088 }
0089
0090 bool TriggerResultsByName::wasrun(std::string const& pathName) const {
0091 if (triggerResults_ == nullptr)
0092 throwTriggerResultsMissing();
0093 unsigned i = getAndCheckIndex(pathName);
0094 return triggerResults_->wasrun(i);
0095 }
0096
0097 bool TriggerResultsByName::wasrun(unsigned i) const {
0098 if (triggerResults_ == nullptr)
0099 throwTriggerResultsMissing();
0100 return triggerResults_->wasrun(i);
0101 }
0102
0103 bool TriggerResultsByName::accept(std::string const& pathName) const {
0104 if (triggerResults_ == nullptr)
0105 throwTriggerResultsMissing();
0106 unsigned i = getAndCheckIndex(pathName);
0107 return triggerResults_->accept(i);
0108 }
0109
0110 bool TriggerResultsByName::accept(unsigned i) const {
0111 if (triggerResults_ == nullptr)
0112 throwTriggerResultsMissing();
0113 return triggerResults_->accept(i);
0114 }
0115
0116 bool TriggerResultsByName::error(std::string const& pathName) const {
0117 if (triggerResults_ == nullptr)
0118 throwTriggerResultsMissing();
0119 unsigned i = getAndCheckIndex(pathName);
0120 return triggerResults_->error(i);
0121 }
0122
0123 bool TriggerResultsByName::error(unsigned i) const {
0124 if (triggerResults_ == nullptr)
0125 throwTriggerResultsMissing();
0126 return triggerResults_->error(i);
0127 }
0128
0129 hlt::HLTState TriggerResultsByName::state(std::string const& pathName) const {
0130 if (triggerResults_ == nullptr)
0131 throwTriggerResultsMissing();
0132 unsigned i = getAndCheckIndex(pathName);
0133 return triggerResults_->state(i);
0134 }
0135
0136 hlt::HLTState TriggerResultsByName::state(unsigned i) const {
0137 if (triggerResults_ == nullptr)
0138 throwTriggerResultsMissing();
0139 return triggerResults_->state(i);
0140 }
0141
0142 unsigned TriggerResultsByName::index(std::string const& pathName) const {
0143 if (triggerResults_ == nullptr)
0144 throwTriggerResultsMissing();
0145 unsigned i = getAndCheckIndex(pathName);
0146 return triggerResults_->index(i);
0147 }
0148
0149 unsigned TriggerResultsByName::index(unsigned i) const {
0150 if (triggerResults_ == nullptr)
0151 throwTriggerResultsMissing();
0152 return triggerResults_->index(i);
0153 }
0154
0155 std::vector<std::string> const& TriggerResultsByName::triggerNames() const {
0156 if (triggerResults_ == nullptr)
0157 throwTriggerResultsMissing();
0158 if (triggerNames_ == nullptr)
0159 throwTriggerNamesMissing();
0160 return triggerNames_->triggerNames();
0161 }
0162
0163 std::string const& TriggerResultsByName::triggerName(unsigned i) const {
0164 if (triggerResults_ == nullptr)
0165 throwTriggerResultsMissing();
0166 if (triggerNames_ == nullptr)
0167 throwTriggerNamesMissing();
0168 return triggerNames_->triggerName(i);
0169 }
0170
0171 unsigned TriggerResultsByName::triggerIndex(std::string const& pathName) const {
0172 if (triggerResults_ == nullptr)
0173 throwTriggerResultsMissing();
0174 if (triggerNames_ == nullptr)
0175 throwTriggerNamesMissing();
0176 return triggerNames_->triggerIndex(pathName);
0177 }
0178
0179 std::vector<std::string>::size_type TriggerResultsByName::size() const {
0180 if (triggerResults_ == nullptr)
0181 throwTriggerResultsMissing();
0182 return triggerResults_->size();
0183 }
0184
0185 unsigned TriggerResultsByName::getAndCheckIndex(std::string const& pathName) const {
0186 if (triggerNames_ == nullptr)
0187 throwTriggerNamesMissing();
0188 unsigned i = triggerNames_->triggerIndex(pathName);
0189 if (i == triggerNames_->size()) {
0190 throw edm::Exception(edm::errors::LogicError)
0191 << "TriggerResultsByName::getAndCheckIndex\n"
0192 << "Requested trigger name \"" << pathName << "\" does not match any known trigger.\n";
0193 }
0194 return i;
0195 }
0196
0197 void TriggerResultsByName::throwTriggerResultsMissing() const {
0198 throw edm::Exception(edm::errors::ProductNotFound)
0199 << "TriggerResultsByName has a null pointer to TriggerResults.\n"
0200 << "This probably means TriggerResults was not found in the Event\n"
0201 << "because the product was dropped or never created. It could also\n"
0202 << "mean it was requested for a process that does not exist or was\n"
0203 << "misspelled\n";
0204 }
0205
0206 void TriggerResultsByName::throwTriggerNamesMissing() const {
0207 throw edm::Exception(edm::errors::LogicError)
0208 << "TriggerResultsByName has a null pointer to TriggerNames.\n"
0209 << "This should never happen. It could indicate the ParameterSet\n"
0210 << "containing the names is missing from the ParameterSet registry.\n"
0211 << "Please report this to the edm developers along with instructions\n"
0212 << "to reproduce the problem\n";
0213 }
0214 }