Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:02

0001 #ifndef DataFormats_Provenance_ProcessHistory_h
0002 #define DataFormats_Provenance_ProcessHistory_h
0003 
0004 #include "DataFormats/Provenance/interface/ProcessConfiguration.h"
0005 #include "DataFormats/Provenance/interface/ProcessHistoryID.h"
0006 
0007 #include <iosfwd>
0008 #include <string>
0009 #include <utility>
0010 #include <vector>
0011 
0012 namespace edm {
0013   class ProcessHistory {
0014   public:
0015     typedef ProcessConfiguration value_type;
0016     typedef std::vector<value_type> collection_type;
0017 
0018     typedef collection_type::iterator iterator;
0019     typedef collection_type::const_iterator const_iterator;
0020 
0021     typedef collection_type::reverse_iterator reverse_iterator;
0022     typedef collection_type::const_reverse_iterator const_reverse_iterator;
0023 
0024     typedef collection_type::reference reference;
0025     typedef collection_type::const_reference const_reference;
0026 
0027     typedef collection_type::size_type size_type;
0028 
0029     ProcessHistory() : data_(), transient_() {}
0030     explicit ProcessHistory(size_type n) : data_(n), transient_() {}
0031     explicit ProcessHistory(collection_type const& vec) : data_(vec), transient_() {}
0032 
0033     template <typename... Args>
0034     void emplace_back(Args&&... args) {
0035       data_.emplace_back(std::forward<Args>(args)...);
0036       phid() = ProcessHistoryID();
0037     }
0038 
0039     void push_front(const_reference t) {
0040       data_.insert(data_.begin(), t);
0041       phid() = ProcessHistoryID();
0042     }
0043     void push_back(const_reference t) {
0044       data_.push_back(t);
0045       phid() = ProcessHistoryID();
0046     }
0047     void swap(ProcessHistory& other) {
0048       data_.swap(other.data_);
0049       phid().swap(other.phid());
0050     }
0051     bool empty() const { return data_.empty(); }
0052     size_type size() const { return data_.size(); }
0053     size_type capacity() const { return data_.capacity(); }
0054     void reserve(size_type n) { data_.reserve(n); }
0055 
0056     reference operator[](size_type i) { return data_[i]; }
0057     const_reference operator[](size_type i) const { return data_[i]; }
0058 
0059     reference at(size_type i) { return data_.at(i); }
0060     const_reference at(size_type i) const { return data_.at(i); }
0061 
0062     const_iterator begin() const { return data_.begin(); }
0063     const_iterator end() const { return data_.end(); }
0064 
0065     const_reverse_iterator rbegin() const { return data_.rbegin(); }
0066     const_reverse_iterator rend() const { return data_.rend(); }
0067 
0068     //     iterator begin() {return data_.begin();}
0069     //     iterator end() {return data_.end();}
0070 
0071     //     reverse_iterator rbegin() {return data_.rbegin();}
0072     //     reverse_iterator rend() {return data_.rend();}
0073 
0074     collection_type const& data() const { return data_; }
0075     ProcessHistoryID id() const;
0076     ProcessHistoryID setProcessHistoryID();
0077 
0078     // Return true, and fill in config appropriately, if the a process
0079     // with the given name is recorded in this ProcessHistory. Return
0080     // false, and do not modify config, if process with the given name
0081     // is not found.
0082     bool getConfigurationForProcess(std::string const& name, ProcessConfiguration& config) const;
0083 
0084     void clear() {
0085       data_.clear();
0086       phid() = ProcessHistoryID();
0087     }
0088 
0089     ProcessHistory& reduce();
0090 
0091     void initializeTransients() { transient_.reset(); }
0092 
0093     struct Transients {
0094       Transients() : phid_() {}
0095       void reset() { phid_.reset(); }
0096       ProcessHistoryID phid_;
0097     };
0098 
0099   private:
0100     ProcessHistoryID& phid() { return transient_.phid_; }
0101     collection_type data_;
0102     Transients transient_;
0103   };
0104 
0105   // Free swap function
0106   inline void swap(ProcessHistory& a, ProcessHistory& b) { a.swap(b); }
0107 
0108   inline bool operator==(ProcessHistory const& a, ProcessHistory const& b) { return a.data() == b.data(); }
0109 
0110   inline bool operator!=(ProcessHistory const& a, ProcessHistory const& b) { return !(a == b); }
0111 
0112   bool isAncestor(ProcessHistory const& a, ProcessHistory const& b);
0113 
0114   inline bool isDescendant(ProcessHistory const& a, ProcessHistory const& b) { return isAncestor(b, a); }
0115 
0116   std::ostream& operator<<(std::ostream& ost, ProcessHistory const& ph);
0117 }  // namespace edm
0118 
0119 #endif