LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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  using collection_type = std::vector<value_type>;
23 
26 
27  using reverse_iterator = collection_type::reverse_iterator;
28  using const_reverse_iterator = collection_type::const_reverse_iterator;
29 
30  using reference = collection_type::reference;
31  using const_reference = collection_type::const_reference;
32 
33  using size_type = collection_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 
108 
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 
120 
123 
124  collection_type const& data() const;
125 
126  ProcessHistoryID const& id() const;
127 
128  std::optional<ProcessConfiguration> getConfigurationForProcess(
129  std::string const& name) const;
130 
131  private:
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  using ProcessHistoryMap = std::map<ProcessHistoryID const, ProcessHistory>;
144 
145  void swap(ProcessHistory& a, ProcessHistory& b);
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:
intermediate_table::iterator iterator
reference at(size_type i)
collection_type::iterator iterator
bool operator==(Provenance const &a, Provenance const &b) noexcept
Definition: Provenance.cc:141
const_iterator end() const
std::recursive_mutex mutex_
bool empty() const
Transient< Transients > transients_
const_iterator begin() const
std::recursive_mutex & get_mutex() const
size_type capacity() const
intermediate_table::const_iterator const_iterator
bool operator!=(ScheduleID const left, ScheduleID const right) noexcept
Definition: ScheduleID.cc:41
const_reverse_iterator rend() const
reference operator[](size_type i)
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
const_reverse_iterator crend() const
collection_type::reverse_iterator reverse_iterator
const_iterator cbegin() const
collection_type::const_iterator const_iterator
const_reverse_iterator crbegin() const
const_iterator cend() const
collection_type::reference reference
bool isAncestor(ProcessHistory const &a, ProcessHistory const &b)
collection_type data_
std::optional< ProcessConfiguration > getConfigurationForProcess(std::string const &name) const
const_reverse_iterator rbegin() const
collection_type::size_type size_type
size_type size() const
void reserve(size_type n)
Definition: MVAAlg.h:12
void swap(ProcessHistory &other)
Char_t n[5]
std::map< ProcessHistoryID const, ProcessHistory > ProcessHistoryMap
ProcessHistory & operator=(ProcessHistory const &)
std::vector< value_type > collection_type
void push_back(const_reference t)
collection_type::const_reverse_iterator const_reverse_iterator
collection_type const & data() const
ProcessHistoryID const & id() const
bool isDescendant(ProcessHistory const &a, ProcessHistory const &b)
collection_type::const_reference const_reference