BranchDescription.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_BranchDescription_h
2 #define canvas_Persistency_Provenance_BranchDescription_h
3 // vim: set sw=2 expandtab :
4 
5 // ================================================================================
6 // BranchDescription: The full description of a data-product branch.
7 // Equivalently,
8 // the event-independent description of an EDProduct.
9 // This description also applies to every product instance on the branch.
10 //
11 // FIXME: A better design would be:
12 //
13 // BranchDescription --owns--> ProductDescription --owns--> TypeDescription
14 //
15 // The BranchDescription class is what retains information necessary for
16 // interactions with ROOT. The ProductDescription contains information
17 // that is relevant for core framework processing.
18 // ================================================================================
19 
27 
28 #include <iosfwd>
29 #include <map>
30 #include <set>
31 #include <string>
32 #include <vector>
33 
34 namespace art {
35  class TypeLabel;
36 
37  namespace detail {
38  class BranchDescriptionStreamer;
39  }
40 
42 
43  friend bool combinable(BranchDescription const&, BranchDescription const&);
44  friend bool operator<(BranchDescription const&, BranchDescription const&);
45  friend bool operator==(BranchDescription const&, BranchDescription const&);
46 
47  friend class detail::BranchDescriptionStreamer;
48 
49  public: // TYPES
50  static int constexpr invalidSplitLevel{-1};
51  static int constexpr invalidBasketSize{0};
52  static int constexpr invalidCompression{-1};
53 
54  struct Transients {
55 
56  Transients() = default;
57 
58  enum validity_state { Produced, PresentFromSource, Dropped, Invalid };
59 
60  // The branch name, which is currently derivable from the other
61  // attributes.
62  std::string branchName_{};
63 
64  // The wrapped class name, which is currently derivable from the
65  // other attributes.
66  std::string wrappedName_{};
67 
68  // Is the class of the branch marked as transient in the data
69  // dictionary
70  bool transient_{false};
71 
72  // Was this branch produced in this process rather than in a
73  // previous process
74  validity_state validity_{PresentFromSource};
75 
76  // N.B. ROOT-specific transient information will be fluffed by the
77  // BranchDescriptionStreamer::fluffRootTransients function.
78 
79  // The split level of the branch, as marked in the data
80  // dictionary.
81  int splitLevel_{};
82 
83  // The basket size of the branch, as marked in the data
84  // dictionary.
85  int basketSize_{};
86 
87  // The compression of the branch, as marked in the data
88  // dictionary.
89  int compression_{invalidCompression};
90  };
91 
92  BranchDescription() = default;
93 
95  TypeLabel const& tl,
96  std::string const& moduleLabel,
97  fhicl::ParameterSetID const& modulePSetID,
98  ProcessConfiguration const& processConfig);
99 
101  std::string const& moduleLabel,
102  std::string const& processName,
103  std::string const& producedClassName,
104  std::string const& productInstanceName,
105  fhicl::ParameterSetID const& psetID,
106  ProcessConfigurationID const& processConfigurationID,
108  bool supportsView,
109  bool transient);
110 
111  void write(std::ostream& os) const;
112 
113  std::string const&
114  moduleLabel() const noexcept
115  {
116  return moduleLabel_;
117  }
118  std::string const&
119  processName() const noexcept
120  {
121  return processName_;
122  }
123  std::string const&
125  {
126  return producedClassName_;
127  }
128  std::string const&
130  {
131  return friendlyClassName_;
132  }
133  std::string const&
135  {
136  return productInstanceName_;
137  }
138  InputTag
139  inputTag() const
140  {
141  return InputTag{moduleLabel(), productInstanceName(), processName()};
142  }
143 
144  bool
145  produced() const noexcept
146  {
147  return guts().validity_ == Transients::Produced;
148  }
149  bool
150  present() const noexcept
151  {
152  return guts().validity_ == Transients::PresentFromSource;
153  }
154  bool
155  dropped() const noexcept
156  {
157  return guts().validity_ == Transients::Dropped;
158  }
159  bool
160  transient() const noexcept
161  {
162  return guts().transient_;
163  }
164 
165  int
166  splitLevel() const noexcept
167  {
168  return guts().splitLevel_;
169  }
170  int
171  basketSize() const noexcept
172  {
173  return guts().basketSize_;
174  }
175  int
176  compression() const noexcept
177  {
178  return guts().compression_;
179  }
180 
181  std::set<fhicl::ParameterSetID> const&
182  psetIDs() const noexcept
183  {
184  return psetIDs_;
185  }
186 
187  ProductID
188  productID() const noexcept
189  {
190  return productID_;
191  }
192  BranchType
193  branchType() const noexcept
194  {
195  return branchType_;
196  }
197  bool
198  supportsView() const noexcept
199  {
200  return supportsView_;
201  }
202  std::string const&
203  branchName() const noexcept
204  {
205  return guts().branchName_;
206  }
207  std::string const&
208  wrappedName() const noexcept
209  {
210  return guts().wrappedName_;
211  }
212 
213  void merge(BranchDescription const& other);
214  void swap(BranchDescription& other);
215 
216  void
218  {
219  guts().validity_ = state;
220  }
221 
222  private:
223  fhicl::ParameterSetID const& psetID() const;
224 
225  void initProductID_();
226  void fluffTransients_() const;
227  bool transientsFluffed_() const noexcept;
228  bool isPsetIDUnique() const noexcept;
229 
230  std::set<ProcessConfigurationID> const& processConfigurationIDs() const
231  noexcept;
232 
233  Transients& guts() noexcept;
234  Transients const& guts() const noexcept;
235 
236  void throwIfInvalid_() const;
237 
238  // What tree is the branch in?
239  BranchType branchType_{InEvent};
240 
241  // A human-friendly string that uniquely identifies the EDProducer
242  // and becomes part of the identity of a product that it produces
243  std::string moduleLabel_{};
244 
245  // the physical process that this program was part of (e.g. production)
246  std::string processName_{};
247 
248  // An ID uniquely identifying the product
249  ProductID productID_{};
250 
251  // the full name of the type of product this is
252  std::string producedClassName_{};
253 
254  // a readable name of the type of product this is
255  std::string friendlyClassName_{};
256 
257  // a user-supplied name to distinguish multiple products of the same type
258  // that are produced by the same producer
259  std::string productInstanceName_{};
260 
261  // Does this product support the concept of a view?
262  bool supportsView_{false};
263 
264  // ID's of parameter set of the creators of products
265  // on this branch
266  std::set<fhicl::ParameterSetID> psetIDs_{};
267 
268  // ID's of process configurations for products
269  // on this branch
270  std::set<ProcessConfigurationID> processConfigurationIDs_{};
271 
272  // The things we do not want saved to disk.
273  mutable Transient<Transients> transients_{};
274  };
275 
276  std::ostream& operator<<(std::ostream&, BranchDescription const&);
277 
278  bool operator<(BranchDescription const&, BranchDescription const&);
279 
280  bool operator==(BranchDescription const&, BranchDescription const&);
281 
282  bool combinable(BranchDescription const&, BranchDescription const&);
283 
284  using ProductDescriptions = std::vector<BranchDescription>;
285  using ProductDescriptionsByID = std::map<ProductID, BranchDescription>;
286 
287 } // namespace art
288 
289 #endif /* canvas_Persistency_Provenance_BranchDescription_h */
290 
291 // Local Variables:
292 // mode: c++
293 // End:
bool produced() const noexcept
std::set< fhicl::ParameterSetID > const & psetIDs() const noexcept
std::string const & wrappedName() const noexcept
std::string string
Definition: nybbler.cc:12
int basketSize() const noexcept
size_t write(int, const char *, size_t)
Writes count bytes from buf to the filedescriptor fd.
std::vector< BranchDescription > ProductDescriptions
bool supportsView() const noexcept
InputTag inputTag() const
bool present() const noexcept
std::string const & processName() const noexcept
BranchType branchType() const noexcept
bool operator<(ProductInfo const &a, ProductInfo const &b)
Definition: ProductInfo.cc:51
bt
Definition: tracks.py:83
void swap(Handle< T > &a, Handle< T > &b)
bool dropped() const noexcept
int splitLevel() const noexcept
int compression() const noexcept
std::ostream & operator<<(std::ostream &os, Analyzer::Table< T > const &t)
Definition: Analyzer.h:136
bool combinable(BranchDescription const &a, BranchDescription const &b)
std::string const & moduleLabel() const noexcept
void setValidity(Transients::validity_state const state)
std::string const & productInstanceName() const noexcept
BranchType
Definition: BranchType.h:20
std::string const & producedClassName() const noexcept
std::map< ProductID, BranchDescription > ProductDescriptionsByID
std::string const & friendlyClassName() const noexcept
std::string const & branchName() const noexcept
ProductID productID() const noexcept
Definition: Hash.h:32
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept