Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:27

0001 #include <iostream>
0002 #include <sstream>
0003 
0004 #include "Alignment/Geners/interface/Reference.hh"
0005 
0006 #include "JetMETCorrections/FFTJetObjects/interface/loadFFTJetInterpolationTable.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 
0010 static void dumpArchiveMetadata(gs::StringArchive& ar, std::ostream& os) {
0011   const unsigned long long idSmall = ar.smallestId();
0012   if (!idSmall)
0013     os << "!!! No records in the archive !!!" << std::endl;
0014   else {
0015     const unsigned long long idLarge = ar.largestId();
0016     unsigned long long count = 0;
0017     for (unsigned long long id = idSmall; id <= idLarge; ++id)
0018       if (ar.itemExists(id)) {
0019         std::shared_ptr<const gs::CatalogEntry> e = ar.catalogEntry(id);
0020         os << '\n';
0021         e->humanReadable(os);
0022         ++count;
0023       }
0024     os << '\n' << count << " records in the archive" << std::endl;
0025   }
0026 }
0027 
0028 CPP11_auto_ptr<npstat::StorableMultivariateFunctor> loadFFTJetInterpolationTable(const edm::ParameterSet& ps,
0029                                                                                  gs::StringArchive& ar,
0030                                                                                  const bool verbose) {
0031   gs::SearchSpecifier nameSearch(ps.getParameter<std::string>("name"), ps.getParameter<bool>("nameIsRegex"));
0032   gs::SearchSpecifier categorySearch(ps.getParameter<std::string>("category"),
0033                                      ps.getParameter<bool>("categoryIsRegex"));
0034   gs::Reference<npstat::StorableMultivariateFunctor> ref(ar, nameSearch, categorySearch);
0035 
0036   // Require that we get a unique item for this search
0037   if (!ref.unique()) {
0038     std::ostringstream os;
0039     os << "Error in loadFFTJetInterpolationTable: table with name \"" << nameSearch.pattern() << "\" ";
0040     if (nameSearch.useRegex())
0041       os << "(regex) ";
0042     os << "and category \"" << categorySearch.pattern() << "\" ";
0043     if (categorySearch.useRegex())
0044       os << "(regex) ";
0045     os << "is not ";
0046     if (ref.empty())
0047       os << "found";
0048     else
0049       os << "unique";
0050     os << " in the archive. Archive contents are:\n";
0051     dumpArchiveMetadata(ar, os);
0052     throw cms::Exception("FFTJetBadConfig", os.str());
0053   }
0054 
0055   CPP11_auto_ptr<npstat::StorableMultivariateFunctor> p = ref.get(0);
0056   if (verbose) {
0057     std::cout << "In loadFFTJetInterpolationTable: loaded table with metadata" << std::endl;
0058     std::shared_ptr<const gs::CatalogEntry> e = ref.indexedCatalogEntry(0);
0059     e->humanReadable(std::cout);
0060     std::cout << std::endl;
0061     std::cout << "Actual table class name is \"" << p->classId().name() << '"' << std::endl;
0062   }
0063   return p;
0064 }