LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ProductMetaData.h
Go to the documentation of this file.
1 #ifndef art_Persistency_Provenance_ProductMetaData_h
2 #define art_Persistency_Provenance_ProductMetaData_h
3 // vim: set sw=2:
4 
5 //==========================================================
6 // ProductMetaData
7 //
8 // Singleton facade providing read-only access to the
9 // MasterProductRegistry.
10 //==========================================================
11 
18 #include "cetlib/exempt_ptr.h"
19 
20 #include <ostream>
21 #include <vector>
22 
23 // Used for testing
24 class MPRGlobalTestFixture;
25 
26 namespace art {
27 
28  class EventProcessor;
29 
31 
32  friend class EventProcessor;
33 
34  // Used for testing.
35  friend class ::MPRGlobalTestFixture;
36 
37  public:
38  // Give access to the only instance; throws if it is not yet made.
39  static ProductMetaData const&
41  {
42  if (!me) {
43  throw Exception(errors::LogicError) << "ProductMetaData::instance "
44  "called before the sole "
45  "instance was created.";
46  }
47  return *me;
48  }
49 
50  private:
51  // Only friends are permitted to create the instance.
53 
54  // Only the create_instance() member will create an instance.
55  static void
57  {
58  if (me) {
60  << "ProductMetaData::create_instance called more than once.";
61  }
62  me = new ProductMetaData(mpr);
63  }
64 
65  private:
66  // Singleton pattern instance pointer.
67  static ProductMetaData const* me;
68 
69  public:
70  ProductMetaData(ProductMetaData const&) = delete;
71  ProductMetaData& operator=(ProductMetaData const&) = delete;
72 
73  // Accessors: this is the facade presented by ProductMetaData for
74  // the MasterProductRegistry.
75 
76  ProductList const&
77  productList() const
78  {
79  return mpr_->productList();
80  }
81 
82  // Print all the BranchDescriptions we contain.
83  void
84  printBranchDescriptions(std::ostream& os) const
85  {
86  mpr_->print(os);
87  }
88 
89  // Return true if any product is produced in this process for the
90  // given branch type.
91  bool
92  productProduced(BranchType const which) const
93  {
94  return mpr_->productProduced(which);
95  }
96 
97  InputTag
99  {
100  for (auto const& pr : mpr_->productList()) {
101  auto const& pd = pr.second;
102  if (pd.productID() == pid) {
103  return pd.inputTag();
104  }
105  }
106  return art::InputTag{};
107  }
108 
109  private:
110  cet::exempt_ptr<MasterProductRegistry const> mpr_;
111  };
112 
113  inline std::ostream&
114  operator<<(std::ostream& os, ProductMetaData const& pmd)
115  {
116  pmd.printBranchDescriptions(os);
117  return os;
118  }
119 
120 } // namespace art
121 
122 // Local Variables:
123 // mode: c++
124 // End:
125 #endif /* art_Persistency_Provenance_ProductMetaData_h */
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
void printBranchDescriptions(std::ostream &os) const
ProductMetaData & operator=(ProductMetaData const &)=delete
std::map< BranchKey, BranchDescription > ProductList
Definition: ProductList.h:15
cet::exempt_ptr< MasterProductRegistry const > mpr_
static ProductMetaData const & instance()
InputTag inputTag(art::ProductID const pid) const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
ProductList const & productList() const
static ProductMetaData const * me
bool productProduced(BranchType const which) const
BranchType
Definition: BranchType.h:18
ProductMetaData(MasterProductRegistry const &mpr)
HLT enums.
static void create_instance(MasterProductRegistry const &mpr)