Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:42

0001 #ifndef SimDataFormats_GeneratorProducts_LHERunInfoProduct_h
0002 #define SimDataFormats_GeneratorProducts_LHERunInfoProduct_h
0003 
0004 #include <iterator>
0005 #include <memory>
0006 #include <vector>
0007 #include <string>
0008 
0009 //#include <hepml.hpp>
0010 
0011 #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"
0012 
0013 class LHERunInfoProduct {
0014 public:
0015   typedef std::vector<std::pair<std::string, std::string> > weights_defs;
0016   class Header {
0017   public:
0018     typedef std::vector<std::string>::const_iterator const_iterator;
0019     typedef std::vector<std::string>::size_type size_type;
0020 
0021     Header() {}
0022     Header(const std::string &tag) : tag_(tag) {}
0023     ~Header() {}
0024 
0025     void addLine(const std::string &line) { lines_.push_back(line); }
0026 
0027     const std::string &tag() const { return tag_; }
0028     const std::vector<std::string> &lines() const { return lines_; }
0029 
0030     size_type size() const { return lines_.size(); }
0031     const_iterator begin() const { return lines_.begin(); }
0032     const_iterator end() const { return lines_.end(); }
0033 
0034     bool operator==(const Header &other) const { return tag_ == other.tag_ && lines_ == other.lines_; }
0035     inline bool operator!=(const Header &other) const { return !(*this == other); }
0036 
0037   private:
0038     std::string tag_;
0039     std::vector<std::string> lines_;
0040   };
0041 
0042   typedef std::vector<Header>::size_type size_type;
0043   typedef std::vector<Header>::const_iterator headers_const_iterator;
0044   typedef std::vector<std::string>::const_iterator comments_const_iterator;
0045 
0046   LHERunInfoProduct() {}
0047   LHERunInfoProduct(const lhef::HEPRUP &heprup) : heprup_(heprup) {}
0048   ~LHERunInfoProduct() {}
0049 
0050   bool find_if_checklist(const std::string x, std::vector<std::string> checklist);
0051 
0052   void addHeader(const Header &header) { headers_.push_back(header); }
0053   void addComment(const std::string &line) { comments_.push_back(line); }
0054 
0055   const lhef::HEPRUP &heprup() const { return heprup_; }
0056 
0057   size_type headers_size() const { return headers_.size(); }
0058   headers_const_iterator headers_begin() const { return headers_.begin(); }
0059   headers_const_iterator headers_end() const { return headers_.end(); }
0060 
0061   size_type comments_size() const { return comments_.size(); }
0062   comments_const_iterator comments_begin() const { return comments_.begin(); }
0063   comments_const_iterator comments_end() const { return comments_.end(); }
0064 
0065   class const_iterator {
0066   public:
0067     typedef std::forward_iterator_tag iterator_category;
0068     typedef std::string value_type;
0069     typedef std::ptrdiff_t difference_type;
0070     typedef std::string *pointer;
0071     typedef std::string &reference;
0072 
0073     const_iterator() : mode(kDone) {}
0074     ~const_iterator() {}
0075 
0076     bool operator==(const const_iterator &other) const;
0077     inline bool operator!=(const const_iterator &other) const { return !operator==(other); }
0078 
0079     inline const_iterator &operator++() {
0080       next();
0081       return *this;
0082     }
0083     inline const_iterator operator++(int dummy) {
0084       const_iterator orig = *this;
0085       next();
0086       return orig;
0087     }
0088 
0089     const std::string &operator*() const { return tmp; }
0090     const std::string *operator->() const { return &tmp; }
0091 
0092   private:
0093     friend class LHERunInfoProduct;
0094 
0095     void next();
0096 
0097     enum Mode { kHeader, kBody, kInit, kDone, kFooter };
0098 
0099     const LHERunInfoProduct *runInfo;
0100     headers_const_iterator header;
0101     Header::const_iterator iter;
0102     Mode mode;
0103     unsigned int line;
0104     std::string tmp;
0105   };
0106 
0107   const_iterator begin() const;
0108   const_iterator init() const;
0109   inline const_iterator end() const { return const_iterator(); }
0110 
0111   static const std::string &endOfFile();
0112 
0113   bool operator==(const LHERunInfoProduct &other) const {
0114     return heprup_ == other.heprup_ && headers_ == other.headers_ && comments_ == other.comments_;
0115   }
0116   inline bool operator!=(const LHERunInfoProduct &other) const { return !(*this == other); }
0117 
0118   bool mergeProduct(const LHERunInfoProduct &other);
0119   void swap(LHERunInfoProduct &other);
0120   bool isProductEqual(const LHERunInfoProduct &other) const { return *this == other; }
0121   static bool isTagComparedInMerge(const std::string &tag);
0122 
0123 private:
0124   lhef::HEPRUP heprup_;
0125   std::vector<Header> headers_;
0126   std::vector<std::string> comments_;
0127 };
0128 
0129 #endif  // GeneratorRunInfo_LHEInterface_LHERunInfoProduct_h