ProcessHistory.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_ProcessHistory_h
2 #define canvas_Persistency_Provenance_ProcessHistory_h
3 // vim: set sw=2 expandtab :
4 
8 
9 #include <iosfwd>
10 #include <map>
11 #include <mutex>
12 #include <optional>
13 #include <string>
14 #include <vector>
15 
16 namespace art {
17 
18  // This class is a ProcessHistoryID and a vector of ProcessConfiguration.
20  public:
22  typedef std::vector<value_type> collection_type;
23 
26 
27  typedef collection_type::reverse_iterator reverse_iterator;
28  typedef collection_type::const_reverse_iterator const_reverse_iterator;
29 
30  typedef collection_type::reference reference;
31  typedef collection_type::const_reference const_reference;
32 
33  typedef collection_type::size_type size_type;
34 
35  // Note: threading: The ProcessHistoryID ctor can throw!
36  struct Transients {
38  };
39 
42 
43  // Note: Cannot be noexcept because the ProcessHistoryID ctor can throw!
44  explicit ProcessHistory(size_type n);
45  explicit ProcessHistory(collection_type const& vec);
46 
47  // Note: Cannot be noexcept because the ProcessHistoryID ctor can throw!
48  // Note: We do not give the strong exception safety guarantee because
49  // data_ may be modified before the transients_ ctor throws.
50  // Note: We do give the basic exception safety guarantee.
52 
53  // Note: Cannot be noexcept because the ProcessHistoryID ctor can throw!
54  // Note: We do not give the strong exception safety guarantee because
55  // data_ may be modified before the transients_ ctor throws.
56  // Note: We do give the basic exception safety guarantee.
58 
59  // Note: We do not give the strong exception safety guarantee because
60  // data_ may be modified before the transients_ ctor throws.
61  // Note: We do give the basic exception safety guarantee.
63 
64  // Note: We do not give the strong exception safety guarantee because
65  // data_ may be modified before the transients_ ctor throws.
66  // Note: We do give the basic exception safety guarantee.
68 
69  public: // MEMBER FUNCTIONS
70  // FIXME: Try to find a way to avoid exposing this function!
71  std::recursive_mutex& get_mutex() const;
72 
73  // Note: Cannot be noexcept because the ProcessHistoryID ctor can throw!
74  // Note: We do not give the strong exception safety guarantee because
75  // data_ may be modified before the transients_ ctor throws.
76  // Note: We do give the basic exception safety guarantee.
77  void swap(ProcessHistory& other);
78 
79  // Put the given ProcessConfiguration into the history.
80  // Note: Invalidates our ProcessHistoryID!
81  void push_back(const_reference t);
82 
83  // Note: threading: Any user that wants to iterate over data_ must lock the
84  // mutex, Note: threading: we cannot automatically protect them because
85  // modifications Note: threading: to data_ must also be matched by an insert
86  // into ProcessHistoryRegistry Note: threading: which is done by
87  // Principal::addToProcessHistory() and an update to Note: threading: either
88  // the event principal History data member or the Run, SubRun, Note:
89  // threading: or Results aux_ data member, and the only way to make all that
90  // atomic Note: threading: is to do it all in a critical section. We cannot
91  // use a tbb::concurrent_vector Note: threading: because it's not just data_
92  // we must protect but the ProcessHistoryRegistry Note: threading: and the
93  // aux_ and/or history_ members of the principals too. Note: threading: Also
94  // note there are several non-multi-threaded users of the iteration Note:
95  // threading: interface as well: orderedProcessNames, gallery,
96  // InfoDumperInputFile, and Note: threading: FileDumperOutput_module, not to
97  // mention any user module at all that calls Note: threading:
98  // processHistory() on the transaction object.
99 
100  bool empty() const;
101  size_type size() const;
102  size_type capacity() const;
103 
104  void reserve(size_type n);
105 
106  reference operator[](size_type i);
107  const_reference operator[](size_type i) const;
108 
109  reference at(size_type i);
110  const_reference at(size_type i) const;
111 
112  const_iterator begin() const;
113  const_iterator end() const;
114 
115  const_iterator cbegin() const;
116  const_iterator cend() const;
117 
118  const_reverse_iterator rbegin() const;
119  const_reverse_iterator rend() const;
120 
121  const_reverse_iterator crbegin() const;
122  const_reverse_iterator crend() const;
123 
124  collection_type const& data() const;
125 
126  ProcessHistoryID id() const;
127 
128  std::optional<ProcessConfiguration> getConfigurationForProcess(
129  std::string const& name) const;
130 
131  private:
132  collection_type data_{};
134  // FIXME-MT: This is a recursive_mutex because sometimes we must
135  // call id() from Principal::addToProcessHistory() with
136  // the mutex already locked to stall other tasks trying
137  // to call id() or getConfigurationForProcess(). We
138  // cannot protect the iteration interface, see notes
139  // above.
140  mutable std::recursive_mutex mutex_{};
141  };
142 
143  typedef std::map<ProcessHistoryID const, ProcessHistory> ProcessHistoryMap;
144 
146 
147  bool operator==(ProcessHistory const& a, ProcessHistory const& b);
148  bool operator!=(ProcessHistory const& a, ProcessHistory const& b);
149 
150  bool isAncestor(ProcessHistory const& a, ProcessHistory const& b);
151  bool isDescendant(ProcessHistory const& a, ProcessHistory const& b);
152 
153  std::ostream& operator<<(std::ostream& ost, ProcessHistory const& ph);
154 
155 } // namespace art
156 
157 #endif /* canvas_Persistency_Provenance_ProcessHistory_h */
158 
159 // Local Variables:
160 // mode: c++
161 // End:
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
reference at(size_type i)
bool operator==(Provenance const &a, Provenance const &b) noexcept
Definition: Provenance.cc:141
const_iterator end() const
std::recursive_mutex mutex_
collection_type::const_reference const_reference
std::string string
Definition: nybbler.cc:12
bool empty() const
Transient< Transients > transients_
const_iterator begin() const
collection_type::reference reference
std::recursive_mutex & get_mutex() const
size_type capacity() const
intermediate_table::const_iterator const_iterator
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
collection_type::const_iterator const_iterator
const_reverse_iterator rend() const
reference operator[](size_type i)
ProcessHistoryID id() const
std::map< ProcessHistoryID const, ProcessHistory > ProcessHistoryMap
collection_type::const_reverse_iterator const_reverse_iterator
collection_type::iterator iterator
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
const_reverse_iterator crend() const
std::void_t< T > n
const double a
const_iterator cbegin() const
const_reverse_iterator crbegin() const
const_iterator cend() const
bool isAncestor(ProcessHistory const &a, ProcessHistory const &b)
collection_type data_
std::optional< ProcessConfiguration > getConfigurationForProcess(std::string const &name) const
std::vector< value_type > collection_type
const_reverse_iterator rbegin() const
size_type size() const
collection_type::reverse_iterator reverse_iterator
static bool * b
Definition: config.cpp:1043
void reserve(size_type n)
void swap(ProcessHistory &other)
ProcessHistory & operator=(ProcessHistory const &)
ProcessConfiguration value_type
void push_back(const_reference t)
collection_type const & data() const
collection_type::size_type size_type
bool isDescendant(ProcessHistory const &a, ProcessHistory const &b)