Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:37

0001 // -*- C++ -*-
0002 //
0003 //
0004 
0005 // class ParameterCollector provides a tool to parse blocks of PSets
0006 // like "PythiaParameters" where one can list blocks of vstrings to be
0007 // parsed inside another vstring named "parameterSets".  It is also
0008 // extended to allow nesting of blocks using "+block" statements
0009 // (something which is heavily used for Herwig++).
0010 // arbitrary vstring blocks can also be explicitly retrieved by name.
0011 
0012 #ifndef gen_ParameterCollector_h
0013 #define gen_ParameterCollector_h
0014 
0015 #include <ostream>
0016 #include <vector>
0017 #include <string>
0018 #include <map>
0019 
0020 #include <boost/iterator/iterator_facade.hpp>
0021 
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 
0024 namespace gen {
0025 
0026   class ParameterCollector {
0027   public:
0028     ParameterCollector();
0029     ParameterCollector(const edm::ParameterSet &pset);
0030     ~ParameterCollector();
0031 
0032     // this iterator makes begin()/end() look like it was
0033     // looping over a simple vector<string>
0034 
0035     class const_iterator
0036         : public boost::iterator_facade<const_iterator, const std::string, boost::forward_traversal_tag> {
0037     public:
0038       const_iterator() : collector_(nullptr), dump_(nullptr) {}
0039 
0040     protected:
0041       friend class ParameterCollector;
0042 
0043       inline const_iterator(const ParameterCollector *collector,
0044                             std::vector<std::string>::const_iterator begin,
0045                             std::vector<std::string>::const_iterator end,
0046                             bool special = false,
0047                             std::ostream *dump = nullptr);
0048 
0049     private:
0050       friend class boost::iterator_core_access;
0051 
0052       void increment();
0053       const std::string &dereference() const { return cache_; }
0054       bool equal(const const_iterator &other) const { return iter_ == other.iter_; }
0055 
0056       void next();
0057 
0058       typedef std::pair<std::vector<std::string>::const_iterator, std::vector<std::string>::const_iterator> IterPair;
0059 
0060       const ParameterCollector *collector_;
0061       std::ostream *dump_;
0062       bool special_;
0063       std::vector<IterPair> iter_;
0064       std::string cache_;
0065     };
0066 
0067     // start iterating over blocks listed in "parameterSets"
0068     const_iterator begin() const;
0069     const_iterator begin(std::ostream &dump) const;
0070 
0071     // start iterating over contents of this particular vstring block
0072     const_iterator begin(const std::string &block) const;
0073     const_iterator begin(const std::string &block, std::ostream &dump) const;
0074 
0075     // the iterator to mark the end of a loop
0076     const_iterator end() const { return const_iterator(); }
0077 
0078     // this replaces ${...} with environment variables
0079     // needed for ThePEG because you need full path to repository
0080     static std::string resolve(const std::string &line);
0081 
0082   private:
0083     friend class const_iterator;
0084 
0085     std::map<std::string, std::vector<std::string> > contents_;
0086   };
0087 
0088 }  // namespace gen
0089 
0090 #endif  // gen_ParameterCollector_h