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 #include "hep_concurrency/RecursiveMutex.h"
9 
10 #include <iosfwd>
11 #include <map>
12 #include <string>
13 #include <vector>
14 
15 namespace art {
16 
17  // This class is a ProcessHistoryID and a vector of ProcessConfiguration.
19  public:
21  typedef std::vector<value_type> collection_type;
22 
23  typedef collection_type::iterator iterator;
24  typedef collection_type::const_iterator const_iterator;
25 
26  typedef collection_type::reverse_iterator reverse_iterator;
27  typedef collection_type::const_reverse_iterator const_reverse_iterator;
28 
29  typedef collection_type::reference reference;
30  typedef collection_type::const_reference const_reference;
31 
32  typedef collection_type::size_type size_type;
33 
34  // Note: threading: The ProcessHistoryID ctor can throw!
35  struct Transients {
37  };
38 
40  // Note: Cannot be noexcept because the ProcessHistoryID ctor can throw!
42 
43  // Note: Cannot be noexcept because the ProcessHistoryID ctor can throw!
44  explicit ProcessHistory(size_type n);
45 
46  // Note: Cannot be noexcept because the ProcessHistoryID ctor can throw!
47  explicit ProcessHistory(collection_type const& vec);
48 
49  // Note: Cannot be noexcept because the ProcessHistoryID ctor can throw!
50  // Note: We do not give the strong exception safety guarantee because
51  // data_ may be modified before the transients_ ctor throws.
52  // Note: We do give the basic exception safety guarantee.
54 
55  // Note: Cannot be noexcept because the ProcessHistoryID ctor can throw!
56  // Note: We do not give the strong exception safety guarantee because
57  // data_ may be modified before the transients_ ctor throws.
58  // Note: We do give the basic exception safety guarantee.
60 
61  // Note: We do not give the strong exception safety guarantee because
62  // data_ may be modified before the transients_ ctor throws.
63  // Note: We do give the basic exception safety guarantee.
65 
66  // Note: We do not give the strong exception safety guarantee because
67  // data_ may be modified before the transients_ ctor throws.
68  // Note: We do give the basic exception safety guarantee.
70 
71  public: // MEMBER FUNCTIONS
72  // FIXME: Try to find a way to avoid exposing this function!
73  hep::concurrency::RecursiveMutex& get_mutex() const;
74 
75  // Note: Cannot be noexcept because the ProcessHistoryID ctor can throw!
76  // Note: We do not give the strong exception safety guarantee because
77  // data_ may be modified before the transients_ ctor throws.
78  // Note: We do give the basic exception safety guarantee.
79  void swap(ProcessHistory& other);
80 
81  // Put the given ProcessConfiguration into the history.
82  // Note: Invalidates our ProcessHistoryID!
83  void push_back(const_reference t);
84 
85  // Note: threading: Any user that wants to iterate over data_ must lock the
86  // mutex, Note: threading: we cannot automatically protect them because
87  // modifications Note: threading: to data_ must also be matched by an insert
88  // into ProcessHistoryRegistry Note: threading: which is done by
89  // Principal::addToProcessHistory() and an update to Note: threading: either
90  // the event principal History data member or the Run, SubRun, Note:
91  // threading: or Results aux_ data member, and the only way to make all that
92  // atomic Note: threading: is to do it all in a critical section. We cannot
93  // use a tbb::concurrent_vector Note: threading: because it's not just data_
94  // we must protect but the ProcessHistoryRegistry Note: threading: and the
95  // aux_ and/or history_ members of the principals too. Note: threading: Also
96  // note there are several non-multi-threaded users of the iteration Note:
97  // threading: interface as well: orderedProcessNames, gallery,
98  // InfoDumperInputFile, and Note: threading: FileDumperOutput_module, not to
99  // mention any user module at all that calls Note: threading:
100  // processHistory() on the transaction object.
101 
102  bool empty() const;
103 
104  size_type size() const;
105 
106  size_type capacity() const;
107 
108  void reserve(size_type n);
109 
110  reference operator[](size_type i);
111 
112  const_reference operator[](size_type i) const;
113 
114  reference at(size_type i);
115 
116  const_reference at(size_type i) const;
117 
118  const_iterator begin() const;
119 
120  const_iterator end() const;
121 
122  const_iterator cbegin() const;
123 
124  const_iterator cend() const;
125 
126  const_reverse_iterator rbegin() const;
127 
128  const_reverse_iterator rend() const;
129 
130  const_reverse_iterator crbegin() const;
131 
132  const_reverse_iterator crend() const;
133 
134  collection_type const& data() const;
135 
136  ProcessHistoryID id() const;
137 
138  // Return true, and fill in config appropriately, if the a process
139  // with the given name is recorded in this ProcessHistory. Return
140  // false, and do not modify config, if process with the given name
141  // is found.
144 
145  private:
146  collection_type data_{};
148  // Note: threading: This is a recursive_mutex because sometimes
149  // Note: threading: we must call id() from Principal::addToProcessHistory()
150  // Note: threading: with the mutex already locked to stall other tasks
151  // Note: threading: trying to call id() or getConfigurationForProcess().
152  // Note: threading: We cannot protect the iteration interface, see notes
153  // above.
154  mutable hep::concurrency::RecursiveMutex mutex_{
155  "art::ProcessHistory::mutex_"};
156  };
157 
158  typedef std::map<ProcessHistoryID const, ProcessHistory> ProcessHistoryMap;
159 
161 
162  bool operator==(ProcessHistory const& a, ProcessHistory const& b);
163 
164  bool operator!=(ProcessHistory const& a, ProcessHistory const& b);
165 
166  bool isAncestor(ProcessHistory const& a, ProcessHistory const& b);
167 
168  bool isDescendant(ProcessHistory const& a, ProcessHistory const& b);
169 
170  std::ostream& operator<<(std::ostream& ost, ProcessHistory const& ph);
171 
172 } // namespace art
173 
174 #endif /* canvas_Persistency_Provenance_ProcessHistory_h */
175 
176 // Local Variables:
177 // mode: c++
178 // End:
const_iterator cbegin() const
const XML_Char * name
Definition: expat.h:151
const_reverse_iterator crend() const
collection_type::const_reference const_reference
reference operator[](size_type i)
const_reverse_iterator rend() const
bool empty() const
bool getConfigurationForProcess(std::string const &name, ProcessConfiguration &config) const
Transient< Transients > transients_
collection_type::reference reference
const_iterator end() const
Definition: config.py:1
const_reverse_iterator rbegin() const
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
collection_type::const_iterator const_iterator
ProcessHistoryID id() const
std::map< ProcessHistoryID const, ProcessHistory > ProcessHistoryMap
const_iterator begin() const
collection_type::const_reverse_iterator const_reverse_iterator
collection_type::iterator iterator
collection_type const & data() const
size_type size() const
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
std::void_t< T > n
const double a
ProcessHistory & operator=(ProcessHistory const &)
bool isAncestor(ProcessHistory const &a, ProcessHistory const &b)
collection_type data_
const_reverse_iterator crbegin() const
hep::concurrency::RecursiveMutex & get_mutex() const
reference at(size_type i)
std::vector< value_type > collection_type
const hit & b
Definition: hits.cxx:21
collection_type::reverse_iterator reverse_iterator
void reserve(size_type n)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
const_iterator cend() const
void swap(ProcessHistory &other)
bool operator==(Provenance const &a, Provenance const &b)
size_type capacity() const
ProcessConfiguration value_type
hep::concurrency::RecursiveMutex mutex_
void push_back(const_reference t)
collection_type::size_type size_type
bool isDescendant(ProcessHistory const &a, ProcessHistory const &b)
enum BeamMode string