CMS 3D CMS Logo

ProductResolverIndexHelper.h
Go to the documentation of this file.
1 #ifndef DataFormats_Provenance_ProductResolverIndexHelper_h
2 #define DataFormats_Provenance_ProductResolverIndexHelper_h
3 
58 
59 #include <iosfwd>
60 #include <memory>
61 #include <set>
62 #include <string>
63 #include <vector>
64 #include <tuple>
65 #include <unordered_map>
66 
67 namespace edm {
68 
69  class TypeWithDict;
70 
71  namespace productholderindexhelper {
72  // The next function supports views. For the given wrapped type,
73  // which must be Wrapper<T>,
74  // this function returns the type of the contained type of T.
75  // If the type is not a recongnized container, it returns
76  // a TypeID(typeid(void)).
77  TypeID getContainedTypeFromWrapper(TypeID const& wrappedtypeID, std::string const& className);
78 
79  // The next function supports views. For the given type T,
80  // this function returns the type of the contained type of T.
81  // If the type is not a recongnized container, it returns
82  // a TypeID(typeid(void)).
83  // This calls getContainedTypefromWrapped internally
84  // If the TypeID for the wrapped type is already available,
85  // it is faster to call getContainedTypeFromWrapper directly.
86  TypeID getContainedType(TypeID const& typeID);
87  } // namespace productholderindexhelper
88 
90  public:
92 
93  // The accessors below return a ProductResolverIndex that matches
94  // the arguments or a set of matching indexes using the Matches
95  // class. A returned index can have a value that indicates that it
96  // is invalid or ambiguous and the client should check for these
97  // values before using the index (see ProductIndexHolder.h).
98 
99  // If no matches are found or the ProductResolverIndexHelper
100  // has not been frozen yet, then an invalid index or a Matches
101  // object with numberOfMatches equal to 0 will be returned.
102 
103  // The ambiguous values can occur when the kind of type is ELEMENT_TYPE
104  // type. ELEMENT_TYPE is the type or base type of an object
105  // stored in a container that is the product. These types are used
106  // with data requests that use Views. For PRODUCT_TYPE types, ambiguity
107  // is not possible.
108 
109  // The next function returns the index for the one group that
110  // matches the type, module label, instance, and process.
111  // The 3 pointer arguments must point to C style strings terminated
112  // by a '\0' with the one following possible exception. If the
113  // process pointer is null or the process string empty, then
114  // this returns the index of the special ProductResolver that
115  // knows how to search for the product matching the type, module
116  // label, and instance and which is from the most recent process.
118  TypeID const& typeID,
119  char const* moduleLabel,
120  char const* instance,
121  char const* process = nullptr) const;
122 
123  using ModulesToIndiciesMap =
124  std::unordered_multimap<std::string, std::tuple<TypeID const*, const char*, ProductResolverIndex>>;
126 
127  class Matches {
128  public:
129  Matches(ProductResolverIndexHelper const* productResolverIndexHelper,
130  unsigned int startInIndexAndNames,
131  unsigned int numberOfMatches);
132 
133  ProductResolverIndex index(unsigned int i) const;
134  unsigned int numberOfMatches() const { return numberOfMatches_; }
135  bool isFullyResolved(unsigned int i) const;
136  char const* moduleLabel(unsigned int i) const;
137  char const* processName(unsigned int i) const;
138 
139  private:
141  unsigned int startInIndexAndNames_;
142  unsigned int numberOfMatches_;
143  };
144 
145  // Return ProductResolverIndex's for all product holders that
146  // match the type, module label, and product instance name.
147  // The pointer arguments must be C style strings terminated
148  // by a '\0'.
149  Matches relatedIndexes(KindOfType kindOfType,
150  TypeID const& typeID,
151  char const* moduleLabel,
152  char const* instance) const;
153 
154  // Return indexes for all groups that match the type.
155  Matches relatedIndexes(KindOfType kindOfType, TypeID const& typeID) const;
156 
157  // This will throw if called after the object is frozen.
158  // The typeID must be for a type with a dictionary
159  // (the calling function is expected to check that)
160  // The pointer arguments must point at C style strings
161  // terminated by '\0'.
162  // 1. This creates an entry and new ProductResolverIndex for
163  // the product if it does not already exist. If it
164  // does exist then it throws.
165  // 2. If it does not already exist, this will create an
166  // entry and new ProductResolverIndex for the ProductResolver
167  // that will search for the matching type, label, and
168  // instance for the most recent process (internally indicated
169  // by an empty process string).
170  // This will then loop over the contained class (if it exists)
171  // and the base classes of the contained class.
172  // 1. If the matching type, label, instance, and process
173  // already exist then that entry is modified and marked
174  // ambiguous. If not, it inserts an entry which uses the same
175  // ProductResolverIndex as the containing product.
176  // 2. If it does not already exist it inserts a new
177  // entry with a new ProductResolverIndex for the case
178  // which searches for the most recent process.
179  ProductResolverIndex insert(TypeID const& typeID,
180  char const* moduleLabel,
181  char const* instance,
182  char const* process,
183  TypeID const& containedTypeID,
184  std::vector<TypeWithDict>* baseTypesOfContainedType);
185 
186  ProductResolverIndex insert(TypeID const& typeID,
187  char const* moduleLabel,
188  char const* instance,
189  char const* process);
190 
191  // Before the object is frozen the accessors above will
192  // fail to find a match. Once frozen, no more new entries
193  // can be added with insert.
194  void setFrozen();
195 
196  std::vector<std::string> const& lookupProcessNames() const;
197 
198  class Range {
199  public:
200  Range(unsigned int begin, unsigned int end) : begin_(begin), end_(end) {}
201  unsigned int begin() const { return begin_; }
202  unsigned int end() const { return end_; }
203 
204  private:
205  unsigned int begin_;
206  unsigned int end_;
207  };
208 
210  public:
211  IndexAndNames(ProductResolverIndex index, unsigned int start, unsigned int startProcess)
213  ProductResolverIndex index() const { return index_; }
214  unsigned int startInBigNamesContainer() const { return startInBigNamesContainer_; }
215  unsigned int startInProcessNames() const { return startInProcessNames_; }
216 
217  private:
220  unsigned int startInProcessNames_;
221  };
222 
223  unsigned int beginElements() const { return beginElements_; }
224  std::vector<TypeID> const& sortedTypeIDs() const { return sortedTypeIDs_; }
225  std::vector<Range> const& ranges() const { return ranges_; }
226  std::vector<IndexAndNames> const& indexAndNames() const { return indexAndNames_; }
227  std::vector<char> const& processNames() const { return processNames_; }
228 
229  // The next few functions are intended for internal use
230  // but are public so tests can use them also.
231 
232  unsigned int indexToIndexAndNames(KindOfType kindOfType,
233  TypeID const& typeID,
234  char const* moduleLabel,
235  char const* instance,
236  char const* process) const;
237 
238  // Returns the index into sortedTypeIDs_. Returns the maximum unsigned
239  // int value if the type is not there.
240  unsigned int indexToType(KindOfType kindOfType, TypeID const& typeID) const;
241 
242  // Returns the index of the process name in processNames_. Returns the
243  // maximum unsigned int value if the process name is not found.
244  unsigned int processIndex(char const* process) const;
245 
246  // This will throw if it detects problems, but unless there is a bug
247  // there should never be any. Mostly it is checking for things which
248  // might cause out of bounds errors when accessing the vectors.
249  void sanityCheck() const;
250 
252 
253  // For debugging only
254  void print(std::ostream& os) const;
255 
256  private:
257  // Next available value for a ProductResolverIndex. This just
258  // increments by one each time a new value is assigned.
260 
261  // This is an index into sortedTypeIDs_ that tells where
262  // the entries corresponding to types of elements in containers
263  // start.
264  unsigned int beginElements_;
265 
266  // Sorted by putting all the product entries first and
267  // then the element entries. Then sorted by TypeID value.
268  // Most lookups start here by finding the TypeID and
269  // then using its position to find the corresponding Range
270  // in the ranges_ vector below.
271  std::vector<TypeID> sortedTypeIDs_;
272 
273  // There is a one to one correspondence between this vector
274  // and sortedTypeIDs_ and the corresponding elements appear
275  // in the same order. Each Range object holds the beginning and
276  // end of the corresponding elements in the indexAndNames_
277  // vector below.
278  std::vector<Range> ranges_;
279 
280  // Each element of this vector contains a ProductResolverIndex.
281  // It also contains indexes into vectors of characters that
282  // hold the corresponding moduleLabel, instance, and process
283  // name. Note this is sorted with product entries first then
284  // element entries, then by TypeID, then by moduleLabel,
285  // then by instance, and finally by process. Note that in
286  // a subset of entries that have matching type/label/instance
287  // the entry with an empty process name will always be the
288  // first process and startInProcessNames_ will always be 0
289  // for the empty process name.
290  std::vector<IndexAndNames> indexAndNames_;
291 
292  // These contain C style strings terminated
293  // by '\0' all concatenated together. In the
294  // first vector the strings come in pairs,
295  // always module label then instance. The pairs
296  // are ordered the same as the IndexAndNames
297  // vector. Within a TypeID, the moduleLabel/instance
298  // pair is not duplicated if it appears multiple times.
299  // The second vector contains all the process names
300  // in alphabetical order with no duplication. The
301  // first element is always the empty string.
302  std::vector<char> bigNamesContainer_;
303  std::vector<char> processNames_;
304 
305  // Duplicates the entries in processNames_ in
306  // a convenient format.
307  std::vector<std::string> lookupProcessNames_;
308 
309  // The rest of the data members are for temporary use
310  // while the data structure is being filled.
311 
312  class Item {
313  public:
315  TypeID const& typeID,
316  std::string const& moduleLabel,
317  std::string const& instance,
318  std::string const& process,
320  KindOfType kindOfType() const { return kindOfType_; }
321  TypeID const& typeID() const { return typeID_; }
322  std::string const& moduleLabel() const { return moduleLabel_; }
323  std::string const& instance() const { return instance_; }
324  std::string const& process() const { return process_; }
325  ProductResolverIndex index() const { return index_; }
326 
327  void clearProcess() { process_.clear(); }
329 
330  bool operator<(Item const& right) const;
331 
332  private:
339  };
340 
342 
344  };
345 } // namespace edm
346 #endif
edm::ProductResolverIndexHelper::Item::setIndex
void setIndex(ProductResolverIndex v)
Definition: ProductResolverIndexHelper.h:328
edm::ProductResolverIndexHelper::indexAndNames_
std::vector< IndexAndNames > indexAndNames_
Definition: ProductResolverIndexHelper.h:290
edm::ProductResolverIndexHelper::items_
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_
Definition: ProductResolverIndexHelper.h:341
edm::ProductResolverIndex
unsigned int ProductResolverIndex
Definition: ProductResolverIndex.h:8
mps_fire.i
i
Definition: mps_fire.py:355
edm::ProductResolverIndexHelper::Item::index_
ProductResolverIndex index_
Definition: ProductResolverIndexHelper.h:338
start
Definition: start.py:1
edm::ProductResolverIndexHelper::Item::process
std::string const & process() const
Definition: ProductResolverIndexHelper.h:324
edm::ProductResolverIndexHelper::Matches::productResolverIndexHelper_
ProductResolverIndexHelper const * productResolverIndexHelper_
Definition: ProductResolverIndexHelper.h:140
edm::productholderindexhelper::getContainedType
TypeID getContainedType(TypeID const &typeID)
Definition: ProductResolverIndexHelper.cc:67
edm::ProductResolverIndexHelper::Matches::Matches
Matches(ProductResolverIndexHelper const *productResolverIndexHelper, unsigned int startInIndexAndNames, unsigned int numberOfMatches)
Definition: ProductResolverIndexHelper.cc:94
edm::ProductResolverIndexHelper::Item::Item
Item(KindOfType kindOfType, TypeID const &typeID, std::string const &moduleLabel, std::string const &instance, std::string const &process, ProductResolverIndex index)
Definition: ProductResolverIndexHelper.cc:637
edm::ProductResolverIndexHelper::Item::operator<
bool operator<(Item const &right) const
Definition: ProductResolverIndexHelper.cc:650
edm::ProductResolverIndexHelper::Range::end_
unsigned int end_
Definition: ProductResolverIndexHelper.h:206
propagate_const.h
edm::ProductResolverIndexHelper::Range::begin_
unsigned int begin_
Definition: ProductResolverIndexHelper.h:205
edm
HLT enums.
Definition: AlignableModifier.h:19
ProductResolverIndex.h
edm::ProductResolverIndexHelper::Range
Definition: ProductResolverIndexHelper.h:198
edm::ProductResolverIndexHelper::Range::begin
unsigned int begin() const
Definition: ProductResolverIndexHelper.h:201
edm::ProductResolverIndexHelper::Item::moduleLabel
std::string const & moduleLabel() const
Definition: ProductResolverIndexHelper.h:322
TypeID.h
edm::ProductResolverIndexHelper::index
ProductResolverIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=nullptr) const
Definition: ProductResolverIndexHelper.cc:81
edm::ProductResolverIndexHelper::IndexAndNames::startInProcessNames_
unsigned int startInProcessNames_
Definition: ProductResolverIndexHelper.h:220
edm::ProductResolverIndexHelper::ModulesToIndiciesMap
std::unordered_multimap< std::string, std::tuple< TypeID const *, const char *, ProductResolverIndex > > ModulesToIndiciesMap
Definition: ProductResolverIndexHelper.h:124
edm::ProductResolverIndexHelper::beginElements
unsigned int beginElements() const
Definition: ProductResolverIndexHelper.h:223
edm::ProductResolverIndexHelper::relatedIndexes
Matches relatedIndexes(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance) const
Definition: ProductResolverIndexHelper.cc:142
edm::ProductResolverIndexHelper
Definition: ProductResolverIndexHelper.h:89
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::ProductResolverIndexHelper::Matches
Definition: ProductResolverIndexHelper.h:127
edm::ProductResolverIndexHelper::indexToIndexAndNames
unsigned int indexToIndexAndNames(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process) const
Definition: ProductResolverIndexHelper.cc:420
edm::productholderindexhelper::getContainedTypeFromWrapper
TypeID getContainedTypeFromWrapper(TypeID const &wrappedtypeID, std::string const &className)
Definition: ProductResolverIndexHelper.cc:19
edm::ProductResolverIndexHelper::bigNamesContainer_
std::vector< char > bigNamesContainer_
Definition: ProductResolverIndexHelper.h:302
edm::ProductResolverIndexHelper::sortedTypeIDs_
std::vector< TypeID > sortedTypeIDs_
Definition: ProductResolverIndexHelper.h:271
edm::ProductResolverIndexHelper::lookupProcessNames
std::vector< std::string > const & lookupProcessNames() const
Definition: ProductResolverIndexHelper.cc:412
edm::propagate_const
Definition: propagate_const.h:32
edm::ProductResolverIndexHelper::Matches::startInIndexAndNames_
unsigned int startInIndexAndNames_
Definition: ProductResolverIndexHelper.h:141
edm::ProductResolverIndexHelper::IndexAndNames::IndexAndNames
IndexAndNames(ProductResolverIndex index, unsigned int start, unsigned int startProcess)
Definition: ProductResolverIndexHelper.h:211
edm::ProductResolverIndexHelper::lookupProcessNames_
std::vector< std::string > lookupProcessNames_
Definition: ProductResolverIndexHelper.h:307
edm::ProductResolverIndexHelper::Matches::index
ProductResolverIndex index(unsigned int i) const
Definition: ProductResolverIndexHelper.cc:107
edm::ProductResolverIndexHelper::IndexAndNames
Definition: ProductResolverIndexHelper.h:209
edm::ProductResolverIndexHelper::Range::end
unsigned int end() const
Definition: ProductResolverIndexHelper.h:202
edm::ProductResolverIndexHelper::setFrozen
void setFrozen()
Definition: ProductResolverIndexHelper.cc:278
edm::ProductResolverIndexHelper::beginElements_
unsigned int beginElements_
Definition: ProductResolverIndexHelper.h:264
edm::ProductResolverIndexHelper::Item::instance
std::string const & instance() const
Definition: ProductResolverIndexHelper.h:323
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ProductResolverIndexHelper::Item::typeID_
TypeID typeID_
Definition: ProductResolverIndexHelper.h:334
edm::ProductResolverIndexHelper::processNames_
std::vector< char > processNames_
Definition: ProductResolverIndexHelper.h:303
edm::ProductResolverIndexHelper::processNames
std::vector< char > const & processNames() const
Definition: ProductResolverIndexHelper.h:227
edm::ProductResolverIndexHelper::IndexAndNames::index
ProductResolverIndex index() const
Definition: ProductResolverIndexHelper.h:213
edm::ProductResolverIndexHelper::IndexAndNames::index_
ProductResolverIndex index_
Definition: ProductResolverIndexHelper.h:218
edm::ProductResolverIndexHelper::Matches::numberOfMatches_
unsigned int numberOfMatches_
Definition: ProductResolverIndexHelper.h:142
edm::ProductResolverIndexHelper::Range::Range
Range(unsigned int begin, unsigned int end)
Definition: ProductResolverIndexHelper.h:200
LaserDQM_cfg.process
process
Definition: LaserDQM_cfg.py:3
edm::ProductResolverIndexHelper::Item::kindOfType
KindOfType kindOfType() const
Definition: ProductResolverIndexHelper.h:320
edm::ProductResolverIndexHelper::Matches::isFullyResolved
bool isFullyResolved(unsigned int i) const
Definition: ProductResolverIndexHelper.cc:114
edm::ProductResolverIndexHelper::indiciesForModulesInProcess
ModulesToIndiciesMap indiciesForModulesInProcess(const std::string &iProcessName) const
Definition: ProductResolverIndexHelper.cc:553
edm::ProductResolverIndexHelper::Item::moduleLabel_
std::string moduleLabel_
Definition: ProductResolverIndexHelper.h:335
edm::ProductResolverIndexHelper::indexToType
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const
Definition: ProductResolverIndexHelper.cc:506
edm::ProductResolverIndexHelper::Item
Definition: ProductResolverIndexHelper.h:312
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
edm::ProductResolverIndexHelper::IndexAndNames::startInBigNamesContainer
unsigned int startInBigNamesContainer() const
Definition: ProductResolverIndexHelper.h:214
edm::TypeID
Definition: TypeID.h:22
edm::KindOfType
KindOfType
Definition: ProductKindOfType.h:5
edm::ProductResolverIndexHelper::Item::instance_
std::string instance_
Definition: ProductResolverIndexHelper.h:336
edm::ProductResolverIndexHelper::processItems_
edm::propagate_const< std::unique_ptr< std::set< std::string > > > processItems_
Definition: ProductResolverIndexHelper.h:343
edm::ProductResolverIndexHelper::Item::typeID
TypeID const & typeID() const
Definition: ProductResolverIndexHelper.h:321
edm::ProductResolverIndexHelper::insert
ProductResolverIndex insert(TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process, TypeID const &containedTypeID, std::vector< TypeWithDict > *baseTypesOfContainedType)
Definition: ProductResolverIndexHelper.cc:178
edm::ProductResolverIndexHelper::ranges
std::vector< Range > const & ranges() const
Definition: ProductResolverIndexHelper.h:225
className
std::string className(const T &t)
Definition: ClassName.h:31
edm::ProductResolverIndexHelper::indexAndNames
std::vector< IndexAndNames > const & indexAndNames() const
Definition: ProductResolverIndexHelper.h:226
edm::ProductResolverIndexHelper::Item::process_
std::string process_
Definition: ProductResolverIndexHelper.h:337
edm::ProductResolverIndexHelper::Matches::processName
char const * processName(unsigned int i) const
Definition: ProductResolverIndexHelper.cc:122
edm::ProductResolverIndexHelper::processIndex
unsigned int processIndex(char const *process) const
Definition: ProductResolverIndexHelper.cc:529
edm::ProductResolverIndexHelper::Item::index
ProductResolverIndex index() const
Definition: ProductResolverIndexHelper.h:325
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
edm::ProductResolverIndexHelper::ProductResolverIndexHelper
ProductResolverIndexHelper()
Definition: ProductResolverIndexHelper.cc:75
edm::ProductResolverIndexHelper::ranges_
std::vector< Range > ranges_
Definition: ProductResolverIndexHelper.h:278
edm::ProductResolverIndexHelper::sanityCheck
void sanityCheck() const
Definition: ProductResolverIndexHelper.cc:572
edm::ProductResolverIndexHelper::nextIndexValue
ProductResolverIndex nextIndexValue() const
Definition: ProductResolverIndexHelper.h:251
edm::ProductResolverIndexHelper::Matches::moduleLabel
char const * moduleLabel(unsigned int i) const
Definition: ProductResolverIndexHelper.cc:132
edm::ProductResolverIndexHelper::Item::clearProcess
void clearProcess()
Definition: ProductResolverIndexHelper.h:327
edm::ProductResolverIndexHelper::print
void print(std::ostream &os) const
Definition: ProductResolverIndexHelper.cc:670
edm::ProductResolverIndexHelper::nextIndexValue_
ProductResolverIndex nextIndexValue_
Definition: ProductResolverIndexHelper.h:259
ProductKindOfType.h
edm::ProductResolverIndexHelper::IndexAndNames::startInProcessNames
unsigned int startInProcessNames() const
Definition: ProductResolverIndexHelper.h:215
edm::ProductResolverIndexHelper::Item::kindOfType_
KindOfType kindOfType_
Definition: ProductResolverIndexHelper.h:333
edm::ProductResolverIndexHelper::IndexAndNames::startInBigNamesContainer_
unsigned int startInBigNamesContainer_
Definition: ProductResolverIndexHelper.h:219
edm::ProductResolverIndexHelper::Matches::numberOfMatches
unsigned int numberOfMatches() const
Definition: ProductResolverIndexHelper.h:134
edm::ProductResolverIndexHelper::sortedTypeIDs
std::vector< TypeID > const & sortedTypeIDs() const
Definition: ProductResolverIndexHelper.h:224