CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/FWCore/ParameterSet/src/FillDescriptionFromPSet.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/ParameterSet/interface/FillDescriptionFromPSet.h"
00003 #include "FWCore/ParameterSet/interface/ParameterDescriptionNode.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/ParameterSet/interface/Entry.h"
00007 
00008 #include <string>
00009 #include <map>
00010 #include <vector>
00011 
00012 namespace edm {
00013   class EventID;
00014   class LuminosityBlockID;
00015   class LuminosityBlockRange;
00016   class EventRange;
00017   class InputTag;
00018   class FileInPath;
00019 }
00020 
00021 typedef void (*FillDescriptionFromParameter)(edm::ParameterSet const&, std::string const&, bool, edm::ParameterSetDescription&);
00022 
00023 static std::map<edm::ParameterTypes, FillDescriptionFromParameter> s_findTheRightFunction;
00024 
00025 namespace {
00026 
00027   template<typename T>
00028   void fillDescriptionFromParameter(edm::ParameterSet const& pset,
00029                                     std::string const& name,
00030                                     bool isTracked,
00031                                     edm::ParameterSetDescription& desc) {
00032     if (isTracked) {
00033       desc.add<T>(name, pset.getParameter<T>(name));
00034     }
00035     else {
00036       desc.addUntracked<T>(name, pset.getUntrackedParameter<T>(name));
00037     }
00038   }
00039 
00040   void initMap() {
00041     s_findTheRightFunction[static_cast<edm::ParameterTypes>('I')] = &fillDescriptionFromParameter<int>;
00042     s_findTheRightFunction[static_cast<edm::ParameterTypes>('i')] = &fillDescriptionFromParameter<std::vector<int> >;
00043     s_findTheRightFunction[static_cast<edm::ParameterTypes>('U')] = &fillDescriptionFromParameter<unsigned>;
00044     s_findTheRightFunction[static_cast<edm::ParameterTypes>('u')] = &fillDescriptionFromParameter<std::vector<unsigned> >;
00045     s_findTheRightFunction[static_cast<edm::ParameterTypes>('L')] = &fillDescriptionFromParameter<long long>;
00046     s_findTheRightFunction[static_cast<edm::ParameterTypes>('l')] = &fillDescriptionFromParameter<std::vector<long long> >;
00047     s_findTheRightFunction[static_cast<edm::ParameterTypes>('X')] = &fillDescriptionFromParameter<unsigned long long>;
00048     s_findTheRightFunction[static_cast<edm::ParameterTypes>('x')] = &fillDescriptionFromParameter<std::vector<unsigned long long> >;
00049     s_findTheRightFunction[static_cast<edm::ParameterTypes>('D')] = &fillDescriptionFromParameter<double>;
00050     s_findTheRightFunction[static_cast<edm::ParameterTypes>('d')] = &fillDescriptionFromParameter<std::vector<double> >;
00051     s_findTheRightFunction[static_cast<edm::ParameterTypes>('B')] = &fillDescriptionFromParameter<bool>;
00052     s_findTheRightFunction[static_cast<edm::ParameterTypes>('S')] = &fillDescriptionFromParameter<std::string>;
00053     s_findTheRightFunction[static_cast<edm::ParameterTypes>('s')] = &fillDescriptionFromParameter<std::vector<std::string> >;
00054     s_findTheRightFunction[static_cast<edm::ParameterTypes>('E')] = &fillDescriptionFromParameter<edm::EventID>;
00055     s_findTheRightFunction[static_cast<edm::ParameterTypes>('e')] = &fillDescriptionFromParameter<std::vector<edm::EventID> >;
00056     s_findTheRightFunction[static_cast<edm::ParameterTypes>('M')] = &fillDescriptionFromParameter<edm::LuminosityBlockID>;
00057     s_findTheRightFunction[static_cast<edm::ParameterTypes>('m')] = &fillDescriptionFromParameter<std::vector<edm::LuminosityBlockID> >;
00058     s_findTheRightFunction[static_cast<edm::ParameterTypes>('t')] = &fillDescriptionFromParameter<edm::InputTag>;
00059     s_findTheRightFunction[static_cast<edm::ParameterTypes>('v')] = &fillDescriptionFromParameter<std::vector<edm::InputTag> >;
00060     s_findTheRightFunction[static_cast<edm::ParameterTypes>('F')] = &fillDescriptionFromParameter<edm::FileInPath>;
00061     s_findTheRightFunction[static_cast<edm::ParameterTypes>('A')] = &fillDescriptionFromParameter<edm::LuminosityBlockRange>;
00062     s_findTheRightFunction[static_cast<edm::ParameterTypes>('a')] = &fillDescriptionFromParameter<std::vector<edm::LuminosityBlockRange> >;
00063     s_findTheRightFunction[static_cast<edm::ParameterTypes>('R')] = &fillDescriptionFromParameter<edm::EventRange>;
00064     s_findTheRightFunction[static_cast<edm::ParameterTypes>('r')] = &fillDescriptionFromParameter<std::vector<edm::EventRange> >;
00065   }
00066 
00067   std::map<edm::ParameterTypes, FillDescriptionFromParameter>& findTheRightFunction() {
00068     if (s_findTheRightFunction.empty()) initMap();
00069     return s_findTheRightFunction;
00070   }
00071 }
00072 
00073 namespace edm {
00074 
00075   // Note that the description this fills is used for purposes
00076   // of printing documentation from edmPluginHelp and writing
00077   // cfi files.  In general, it will not be useful for validation
00078   // purposes.  First of all, if the ParameterSet contains a
00079   // vector of ParameterSets, then the description of that vector
00080   // of ParameterSets will have an empty ParameterSetDescription
00081   // (so if you try to validate with such a description, it will
00082   // always fail).  Also, the ParameterSet has no concept of "optional"
00083   // or the logical relationships between parameters in the
00084   // description (like "and", "xor", "switches", ...), so there is
00085   // no way a description generated from a ParameterSet can properly
00086   // express those concepts.
00087 
00088   void fillDescriptionFromPSet(ParameterSet const& pset,
00089                                ParameterSetDescription& desc) {
00090     ParameterSet::table const& entries = pset.tbl();
00091     for (ParameterSet::table::const_iterator entry = entries.begin(),
00092            endEntries = entries.end();
00093          entry != endEntries;
00094          ++entry) {
00095       std::map<edm::ParameterTypes, FillDescriptionFromParameter>::iterator iter =
00096         findTheRightFunction().find(static_cast<edm::ParameterTypes>(entry->second.typeCode()));
00097       if (iter != findTheRightFunction().end()) {
00098         iter->second(pset, entry->first, entry->second.isTracked(), desc);
00099       }
00100     }
00101 
00102     ParameterSet::psettable const& pset_entries = pset.psetTable();
00103     for (ParameterSet::psettable::const_iterator pset_entry = pset_entries.begin(),
00104            endEntries = pset_entries.end();
00105          pset_entry != endEntries;
00106          ++pset_entry) {
00107       edm::ParameterSet nestedPset;
00108       if (pset_entry->second.isTracked()) {
00109         nestedPset = pset.getParameterSet(pset_entry->first);
00110       }
00111       else {
00112         nestedPset = pset.getUntrackedParameterSet(pset_entry->first);
00113       }
00114       ParameterSetDescription nestedDescription;
00115       fillDescriptionFromPSet(nestedPset, nestedDescription);
00116       if (pset_entry->second.isTracked()) {
00117         desc.add<edm::ParameterSetDescription>(pset_entry->first, nestedDescription);
00118       }
00119       else {
00120         desc.addUntracked<edm::ParameterSetDescription>(pset_entry->first, nestedDescription);
00121       }
00122     }
00123 
00124     ParameterSet::vpsettable const& vpset_entries = pset.vpsetTable();
00125     for (ParameterSet::vpsettable::const_iterator vpset_entry = vpset_entries.begin(),
00126            endEntries = vpset_entries.end();
00127          vpset_entry != endEntries;
00128          ++vpset_entry) {
00129       std::vector<edm::ParameterSet> nestedVPset;
00130       if (vpset_entry->second.isTracked()) {
00131         nestedVPset = pset.getParameterSetVector(vpset_entry->first);
00132       }
00133       else {
00134         nestedVPset = pset.getUntrackedParameterSetVector(vpset_entry->first);
00135       }
00136       ParameterSetDescription emptyDescription;
00137 
00138       std::auto_ptr<ParameterDescription<std::vector<ParameterSet> > >
00139         pd(new ParameterDescription<std::vector<ParameterSet> >(vpset_entry->first, emptyDescription, vpset_entry->second.isTracked(), nestedVPset));
00140 
00141       pd->setPartOfDefaultOfVPSet(true);
00142       std::auto_ptr<ParameterDescriptionNode> node(pd);
00143       desc.addNode(node);
00144     }
00145   }
00146 }