ProcessHistory

Transients

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
#ifndef DataFormats_Provenance_ProcessHistory_h
#define DataFormats_Provenance_ProcessHistory_h

#include "DataFormats/Provenance/interface/ProcessConfiguration.h"
#include "DataFormats/Provenance/interface/ProcessHistoryID.h"

#include <iosfwd>
#include <string>
#include <utility>
#include <vector>

namespace edm {
  class ProcessHistory {
  public:
    typedef ProcessConfiguration value_type;
    typedef std::vector<value_type> collection_type;

    typedef collection_type::iterator iterator;
    typedef collection_type::const_iterator const_iterator;

    typedef collection_type::reverse_iterator reverse_iterator;
    typedef collection_type::const_reverse_iterator const_reverse_iterator;

    typedef collection_type::reference reference;
    typedef collection_type::const_reference const_reference;

    typedef collection_type::size_type size_type;

    ProcessHistory() : data_(), transient_() {}
    explicit ProcessHistory(size_type n) : data_(n), transient_() {}
    explicit ProcessHistory(collection_type const& vec) : data_(vec), transient_() {}

    template <typename... Args>
    void emplace_back(Args&&... args) {
      data_.emplace_back(std::forward<Args>(args)...);
      phid() = ProcessHistoryID();
    }

    void push_front(const_reference t) {
      data_.insert(data_.begin(), t);
      phid() = ProcessHistoryID();
    }
    void push_back(const_reference t) {
      data_.push_back(t);
      phid() = ProcessHistoryID();
    }
    void swap(ProcessHistory& other) {
      data_.swap(other.data_);
      phid().swap(other.phid());
    }
    bool empty() const { return data_.empty(); }
    size_type size() const { return data_.size(); }
    size_type capacity() const { return data_.capacity(); }
    void reserve(size_type n) { data_.reserve(n); }

    reference operator[](size_type i) { return data_[i]; }
    const_reference operator[](size_type i) const { return data_[i]; }

    reference at(size_type i) { return data_.at(i); }
    const_reference at(size_type i) const { return data_.at(i); }

    const_iterator begin() const { return data_.begin(); }
    const_iterator end() const { return data_.end(); }

    const_reverse_iterator rbegin() const { return data_.rbegin(); }
    const_reverse_iterator rend() const { return data_.rend(); }

    //     iterator begin() {return data_.begin();}
    //     iterator end() {return data_.end();}

    //     reverse_iterator rbegin() {return data_.rbegin();}
    //     reverse_iterator rend() {return data_.rend();}

    collection_type const& data() const { return data_; }
    ProcessHistoryID id() const;
    ProcessHistoryID setProcessHistoryID();

    // Return true, and fill in config appropriately, if the a process
    // with the given name is recorded in this ProcessHistory. Return
    // false, and do not modify config, if process with the given name
    // is not found.
    bool getConfigurationForProcess(std::string const& name, ProcessConfiguration& config) const;

    void clear() {
      data_.clear();
      phid() = ProcessHistoryID();
    }

    ProcessHistory& reduce();

    void initializeTransients() { transient_.reset(); }

    struct Transients {
      Transients() : phid_() {}
      void reset() { phid_.reset(); }
      ProcessHistoryID phid_;
    };

  private:
    ProcessHistoryID& phid() { return transient_.phid_; }
    collection_type data_;
    Transients transient_;
  };

  // Free swap function
  inline void swap(ProcessHistory& a, ProcessHistory& b) { a.swap(b); }

  inline bool operator==(ProcessHistory const& a, ProcessHistory const& b) { return a.data() == b.data(); }

  inline bool operator!=(ProcessHistory const& a, ProcessHistory const& b) { return !(a == b); }

  bool isAncestor(ProcessHistory const& a, ProcessHistory const& b);

  inline bool isDescendant(ProcessHistory const& a, ProcessHistory const& b) { return isAncestor(b, a); }

  std::ostream& operator<<(std::ostream& ost, ProcessHistory const& ph);
}  // namespace edm

#endif