CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/FWCore/Common/src/TriggerResultsByName.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/Common/interface/TriggerResultsByName.h"
00003 #include "FWCore/Utilities/interface/EDMException.h"
00004 #include "DataFormats/Common/interface/TriggerResults.h"
00005 #include "FWCore/Common/interface/TriggerNames.h"
00006 
00007 namespace edm {
00008 
00009   TriggerResultsByName::
00010   TriggerResultsByName(TriggerResults const* triggerResults,
00011                        TriggerNames const* triggerNames) :
00012     triggerResults_(triggerResults),
00013     triggerNames_(triggerNames) {
00014 
00015    // If either of these is true the object is in an invalid state
00016    if (triggerResults_ == 0 || triggerNames_ == 0) {
00017      return;
00018    }
00019 
00020    if (triggerResults_->parameterSetID() != triggerNames_->parameterSetID()) {
00021       throw edm::Exception(edm::errors::Unknown)
00022         << "TriggerResultsByName::TriggerResultsByName, Trigger names vector and TriggerResults\n"
00023            "have different ParameterSetID's.  This should be impossible when the object is obtained\n"
00024            "from the function named triggerResultsByName in the Event class, which is the way\n"
00025            "TriggerResultsByName should always be created. If this is the case, please send\n"
00026            "information to reproduce this problem to the edm developers.  Otherwise, you are\n"
00027            "using this class incorrectly and in a way that is not supported.\n";
00028     }
00029 
00030     if (triggerResults_->size() != triggerNames_->size()) {
00031       throw edm::Exception(edm::errors::Unknown)
00032         << "TriggerResultsByName::TriggerResultsByName, Trigger names vector\n"
00033            "and TriggerResults have different sizes.  This should be impossible,\n"
00034            "please send information to reproduce this problem to the edm developers.\n";
00035     }
00036   }
00037 
00038   bool
00039   TriggerResultsByName::
00040   isValid() const {
00041     if (triggerResults_ == 0 || triggerNames_ == 0) return false;
00042     return true;
00043   }
00044 
00045   ParameterSetID const&
00046   TriggerResultsByName::
00047   parameterSetID() const {
00048     if (triggerResults_ == 0) throwTriggerResultsMissing();
00049     return triggerResults_->parameterSetID();
00050   }
00051 
00052   bool
00053   TriggerResultsByName::
00054   wasrun() const {
00055     if (triggerResults_ == 0) throwTriggerResultsMissing();
00056     return triggerResults_->wasrun();
00057   }
00058 
00059   bool
00060   TriggerResultsByName::
00061   accept() const {
00062     if (triggerResults_ == 0) throwTriggerResultsMissing();
00063     return triggerResults_->accept();
00064   }
00065 
00066   bool
00067   TriggerResultsByName::
00068   error() const {
00069     if (triggerResults_ == 0) throwTriggerResultsMissing();
00070     return triggerResults_->error();
00071   }
00072 
00073   HLTPathStatus const& 
00074   TriggerResultsByName::
00075   at(std::string const& pathName) const {
00076     if (triggerResults_ == 0) throwTriggerResultsMissing();
00077     unsigned i = getAndCheckIndex(pathName);
00078     return triggerResults_->at(i);
00079   }
00080 
00081   HLTPathStatus const&
00082   TriggerResultsByName::
00083   at(unsigned i) const {
00084     if (triggerResults_ == 0) throwTriggerResultsMissing();
00085     return triggerResults_->at(i);
00086   }
00087 
00088   HLTPathStatus const& 
00089   TriggerResultsByName::
00090   operator[](std::string const& pathName) const {
00091     if (triggerResults_ == 0) throwTriggerResultsMissing();
00092     unsigned i = getAndCheckIndex(pathName);
00093     return triggerResults_->at(i);
00094   }
00095 
00096   HLTPathStatus const&
00097   TriggerResultsByName::
00098   operator[](unsigned i) const {
00099     if (triggerResults_ == 0) throwTriggerResultsMissing();
00100     return triggerResults_->at(i);
00101   }
00102 
00103   bool
00104   TriggerResultsByName::
00105   wasrun(std::string const& pathName) const {
00106     if (triggerResults_ == 0) throwTriggerResultsMissing();
00107     unsigned i = getAndCheckIndex(pathName);
00108     return triggerResults_->wasrun(i);
00109   }
00110 
00111   bool
00112   TriggerResultsByName::
00113   wasrun(unsigned i) const {
00114     if (triggerResults_ == 0) throwTriggerResultsMissing();
00115     return triggerResults_->wasrun(i);
00116   }
00117 
00118   bool
00119   TriggerResultsByName::
00120   accept(std::string const& pathName) const {
00121     if (triggerResults_ == 0) throwTriggerResultsMissing();
00122     unsigned i = getAndCheckIndex(pathName);
00123     return triggerResults_->accept(i);
00124   }
00125 
00126   bool
00127   TriggerResultsByName::
00128   accept(unsigned i) const {
00129     if (triggerResults_ == 0) throwTriggerResultsMissing();
00130     return triggerResults_->accept(i);
00131   }
00132 
00133   bool
00134   TriggerResultsByName::
00135   error(std::string const& pathName) const {
00136     if (triggerResults_ == 0) throwTriggerResultsMissing();
00137     unsigned i = getAndCheckIndex(pathName);
00138     return triggerResults_->error(i);
00139   }
00140 
00141   bool
00142   TriggerResultsByName::
00143   error(unsigned i) const {
00144     if (triggerResults_ == 0) throwTriggerResultsMissing();
00145     return triggerResults_->error(i);
00146   }
00147 
00148   hlt::HLTState
00149   TriggerResultsByName::
00150   state(std::string const& pathName) const {
00151     if (triggerResults_ == 0) throwTriggerResultsMissing();
00152     unsigned i = getAndCheckIndex(pathName);
00153     return triggerResults_->state(i);
00154   }
00155 
00156   hlt::HLTState
00157   TriggerResultsByName::
00158   state(unsigned i) const {
00159     if (triggerResults_ == 0) throwTriggerResultsMissing();
00160     return triggerResults_->state(i);
00161   }
00162 
00163   unsigned
00164   TriggerResultsByName::
00165   index(std::string const& pathName) const {
00166     if (triggerResults_ == 0) throwTriggerResultsMissing();
00167     unsigned i = getAndCheckIndex(pathName);
00168     return triggerResults_->index(i);
00169   }
00170 
00171   unsigned
00172   TriggerResultsByName::
00173   index(unsigned i) const {
00174     if (triggerResults_ == 0) throwTriggerResultsMissing();
00175     return triggerResults_->index(i);
00176   }
00177 
00178   std::vector<std::string> const&
00179   TriggerResultsByName::
00180   triggerNames() const {
00181     if (triggerResults_ == 0) throwTriggerResultsMissing();
00182     if (triggerNames_ == 0) throwTriggerNamesMissing(); 
00183     return triggerNames_->triggerNames();
00184   }
00185 
00186   std::string const&
00187   TriggerResultsByName::
00188   triggerName(unsigned i) const {
00189     if (triggerResults_ == 0) throwTriggerResultsMissing();
00190     if (triggerNames_ == 0) throwTriggerNamesMissing(); 
00191     return triggerNames_->triggerName(i);    
00192   }
00193 
00194   unsigned
00195   TriggerResultsByName::
00196   triggerIndex(std::string const& pathName) const {
00197     if (triggerResults_ == 0) throwTriggerResultsMissing();
00198     if (triggerNames_ == 0) throwTriggerNamesMissing(); 
00199     return triggerNames_->triggerIndex(pathName);    
00200   }
00201 
00202   std::vector<std::string>::size_type
00203   TriggerResultsByName::
00204   size() const {
00205     if (triggerResults_ == 0) throwTriggerResultsMissing();
00206     return triggerResults_->size();
00207   }
00208 
00209   unsigned
00210   TriggerResultsByName::
00211   getAndCheckIndex(std::string const& pathName) const {
00212     if (triggerNames_ == 0) throwTriggerNamesMissing(); 
00213     unsigned i = triggerNames_->triggerIndex(pathName);
00214     if (i == triggerNames_->size()) {
00215       throw edm::Exception(edm::errors::LogicError)
00216         << "TriggerResultsByName::getAndCheckIndex\n"
00217         << "Requested trigger name \""
00218         << pathName << "\" does not match any known trigger.\n";
00219     }
00220     return i;
00221   }
00222 
00223   void
00224   TriggerResultsByName::
00225   throwTriggerResultsMissing() const {
00226     throw edm::Exception(edm::errors::ProductNotFound)
00227       << "TriggerResultsByName has a null pointer to TriggerResults.\n"
00228       << "This probably means TriggerResults was not found in the Event\n"
00229       << "because the product was dropped or never created. It could also\n"
00230       << "mean it was requested for a process that does not exist or was\n"
00231       << "misspelled\n";
00232   }
00233 
00234   void
00235   TriggerResultsByName::
00236   throwTriggerNamesMissing() const {
00237     throw edm::Exception(edm::errors::LogicError)
00238       << "TriggerResultsByName has a null pointer to TriggerNames.\n"
00239       << "This should never happen. It could indicate the ParameterSet\n"
00240       << "containing the names is missing from the ParameterSet registry.\n"
00241       << "Please report this to the edm developers along with instructions\n"
00242       << "to reproduce the problem\n";
00243   }
00244 }