CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/GeneratorInterface/Core/interface/ParameterCollector.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // 
00003 //
00004 
00005 // class ParameterCollector provides a tool to parse blocks of PSets
00006 // like "PythiaParameters" where one can list blocks of vstrings to be
00007 // parsed inside another vstring named "parameterSets".  It is also
00008 // extended to allow nesting of blocks using "+block" statements
00009 // (something which is heavily used for Herwig++).
00010 // arbitrary vstring blocks can also be explicitly retrieved by name.
00011 
00012 #ifndef gen_ParameterCollector_h
00013 #define gen_ParameterCollector_h
00014 
00015 #include <ostream>
00016 #include <vector>
00017 #include <string>
00018 #include <map>
00019 
00020 #include <boost/iterator/iterator_facade.hpp>
00021 
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 
00024 namespace gen {
00025 
00026 class ParameterCollector {
00027 public:
00028    ParameterCollector();
00029    ParameterCollector(const edm::ParameterSet &pset);
00030    ~ParameterCollector();
00031 
00032    // this iterator makes begin()/end() look like it was
00033    // looping over a simple vector<string>
00034 
00035    class const_iterator :
00036       public boost::iterator_facade<const_iterator, const std::string,
00037                                     boost::forward_traversal_tag> {
00038    public:
00039       const_iterator() : collector_(0), dump_(0) {}
00040 
00041    protected:
00042       friend class ParameterCollector;
00043 
00044       inline const_iterator(const ParameterCollector *collector,
00045                             std::vector<std::string>::const_iterator begin,
00046                             std::vector<std::string>::const_iterator end,
00047                             bool special = false, std::ostream *dump = 0);
00048 
00049    private:
00050       friend class boost::iterator_core_access;
00051 
00052       void increment();
00053       const std::string &dereference() const { return cache_; }
00054       bool equal(const const_iterator &other) const
00055       { return iter_ == other.iter_; }
00056 
00057       void next();
00058 
00059       typedef std::pair<std::vector<std::string>::const_iterator,
00060                         std::vector<std::string>::const_iterator> IterPair;
00061 
00062       const ParameterCollector  *collector_;
00063       std::ostream              *dump_;
00064       bool                      special_;
00065       std::vector<IterPair>     iter_;
00066       std::string               cache_;
00067    };
00068 
00069    // start iterating over blocks listed in "parameterSets"
00070    const_iterator begin() const;
00071    const_iterator begin(std::ostream &dump) const;
00072 
00073    // start iterating over contents of this particular vstring block
00074    const_iterator begin(const std::string &block) const;
00075    const_iterator begin(const std::string &block, std::ostream &dump) const;
00076 
00077    // the iterator to mark the end of a loop
00078    const_iterator end() const { return const_iterator(); }
00079 
00080    // this replaces ${...} with environment variables
00081    // needed for ThePEG because you need full path to repository
00082    static std::string resolve(const std::string &line);
00083 
00084 private:
00085    friend class const_iterator;
00086 
00087    std::map<std::string, std::vector<std::string> > contents_;
00088 };
00089 
00090 } // namespace gen
00091 
00092 #endif // gen_ParameterCollector_h