CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/JetMETCorrections/FFTJetObjects/src/loadFFTJetInterpolationTable.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <sstream>
00003 
00004 #include "Alignment/Geners/interface/Reference.hh"
00005 
00006 #include "JetMETCorrections/FFTJetObjects/interface/loadFFTJetInterpolationTable.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 
00010 
00011 static void dumpArchiveMetadata(gs::StringArchive& ar, std::ostream& os)
00012 {
00013     const unsigned long long idSmall = ar.smallestId();
00014     if (!idSmall)
00015         os << "!!! No records in the archive !!!" << std::endl;
00016     else
00017     {
00018         const unsigned long long idLarge = ar.largestId();
00019         unsigned long long count = 0;
00020         for (unsigned long long id = idSmall; id <= idLarge; ++id)
00021             if (ar.itemExists(id))
00022             {
00023                 CPP11_shared_ptr<const gs::CatalogEntry> e = 
00024                     ar.catalogEntry(id);
00025                 os << '\n';
00026                 e->humanReadable(os);
00027                 ++count;
00028             }
00029         os << '\n' << count << " records in the archive" << std::endl;
00030     }
00031 }
00032 
00033 
00034 CPP11_auto_ptr<npstat::StorableMultivariateFunctor>
00035 loadFFTJetInterpolationTable(const edm::ParameterSet& ps,
00036                              gs::StringArchive& ar, const bool verbose)
00037 {
00038     gs::SearchSpecifier nameSearch(ps.getParameter<std::string>("name"),
00039                                    ps.getParameter<bool>("nameIsRegex"));
00040     gs::SearchSpecifier categorySearch(ps.getParameter<std::string>("category"),
00041                                        ps.getParameter<bool>("categoryIsRegex"));
00042     gs::Reference<npstat::StorableMultivariateFunctor> ref(
00043         ar, nameSearch, categorySearch);
00044 
00045     // Require that we get a unique item for this search
00046     if (!ref.unique())
00047     {
00048         std::ostringstream os;
00049         os << "Error in loadFFTJetInterpolationTable: table with name \""
00050            << nameSearch.pattern() << "\" ";
00051         if (nameSearch.useRegex())
00052             os << "(regex) ";
00053         os << "and category \""
00054            << categorySearch.pattern() << "\" ";
00055         if (categorySearch.useRegex())
00056             os << "(regex) ";
00057         os << "is not ";
00058         if (ref.empty())
00059             os << "found";
00060         else
00061             os << "unique";
00062         os << " in the archive. Archive contents are:\n";
00063         dumpArchiveMetadata(ar, os);
00064         throw cms::Exception("FFTJetBadConfig", os.str());
00065     }
00066 
00067     CPP11_auto_ptr<npstat::StorableMultivariateFunctor> p = ref.get(0);
00068     if (verbose)
00069     {
00070         std::cout << "In loadFFTJetInterpolationTable: loaded table with metadata"
00071                   << std::endl;
00072         CPP11_shared_ptr<const gs::CatalogEntry> e = ref.indexedCatalogEntry(0);
00073         e->humanReadable(std::cout);
00074         std::cout << std::endl;
00075         std::cout << "Actual table class name is \""
00076                   << p->classId().name() << '"' << std::endl;
00077     }
00078     return p;
00079 }