CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Types | Public Member Functions | Private Attributes
edm::ProductResolverIndexHelper Class Reference

#include <ProductResolverIndexHelper.h>

Classes

class  IndexAndNames
 
class  Item
 
class  Matches
 
class  Range
 

Public Types

using ModulesToIndiciesMap = std::unordered_multimap< std::string, std::tuple< TypeID const *, const char *, ProductResolverIndex >>
 

Public Member Functions

unsigned int beginElements () const
 
ProductResolverIndex index (KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=nullptr) const
 
std::vector< IndexAndNames >
const & 
indexAndNames () const
 
unsigned int indexToIndexAndNames (KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process) const
 
unsigned int indexToType (KindOfType kindOfType, TypeID const &typeID) const
 
ModulesToIndiciesMap indiciesForModulesInProcess (const std::string &iProcessName) const
 
ProductResolverIndex insert (TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process, TypeID const &containedTypeID, std::vector< TypeWithDict > *baseTypesOfContainedType)
 
ProductResolverIndex insert (TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process)
 
std::vector< std::string > const & lookupProcessNames () const
 
ProductResolverIndex nextIndexValue () const
 
void print (std::ostream &os) const
 
unsigned int processIndex (char const *process) const
 
std::vector< char > const & processNames () const
 
 ProductResolverIndexHelper ()
 
std::vector< Range > const & ranges () const
 
Matches relatedIndexes (KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance) const
 
Matches relatedIndexes (KindOfType kindOfType, TypeID const &typeID) const
 
void sanityCheck () const
 
void setFrozen ()
 
std::vector< TypeID > const & sortedTypeIDs () const
 

Private Attributes

unsigned int beginElements_
 
std::vector< char > bigNamesContainer_
 
std::vector< IndexAndNamesindexAndNames_
 
edm::propagate_const
< std::unique_ptr< std::set
< Item > > > 
items_
 
std::vector< std::string > lookupProcessNames_
 
ProductResolverIndex nextIndexValue_
 
edm::propagate_const
< std::unique_ptr< std::set
< std::string > > > 
processItems_
 
std::vector< char > processNames_
 
std::vector< Rangeranges_
 
std::vector< TypeIDsortedTypeIDs_
 

Detailed Description

This class assigns and gets the ProductResolverIndex associated with a type, module label, instance, and process. The ProductResolverIndex is used to tell the Principal where to store a ProductResolver and how to find it quickly.

One can also look up the same ProductResolverIndex's using the type or base type of an element in a container in the product (if the product is a container). In this case the KindOfType argument to the Principal::getByLabel function is ELEMENT_TYPE, whereas normally it is PRODUCT_TYPE.

There are also special ProductResolverIndex's generated where the process name is empty. These indexes refer to a special ProductResolvers that search for a matching product from the most recent process that has a matching type, label and instance. There is ProductResolverIndex generated for each type/label/instance combination which has at least one entry in the tables in this class. Both PRODUCT_TYPEs and ELEMENT_TYPEs get these special ProductResolvers.

The ProductResolverIndex for a particular product will not change during a process after the ProductRegistry has been frozen. Nor will any of the other member data of this class. Multiple threads can access it concurrently without problems. The ProductResolverIndexes can be safely cached in InputTags and possibly other places, because they never change within a process. The ProductResolverIndex for a particular product is not intended to be persistent and will be different in different processes.

The ProductResolverIndex is used to order the placement of the ProductResolvers in the Principal that are either present in the input or produced in the current process. Be aware that there are other ProductResolvers for products that come after ProductResolvers placed by this class. For example, the placement of dropped products is not handled by this class, instead by the ProductRegistry. The reason for this distinction is that those other ProductResolvers can change and be added as a process runs. The content of this class never changes after the ProductRegistry is frozen.

Author
W. David Dagenhart, created 10 December, 2012

Definition at line 89 of file ProductResolverIndexHelper.h.

Member Typedef Documentation

using edm::ProductResolverIndexHelper::ModulesToIndiciesMap = std::unordered_multimap<std::string, std::tuple<TypeID const*, const char*, ProductResolverIndex>>

Definition at line 124 of file ProductResolverIndexHelper.h.

Constructor & Destructor Documentation

edm::ProductResolverIndexHelper::ProductResolverIndexHelper ( )

Definition at line 75 of file ProductResolverIndexHelper.cc.

76  : nextIndexValue_(0),
77  beginElements_(0),
78  items_(new std::set<ProductResolverIndexHelper::Item>),
79  processItems_(new std::set<std::string>) {}
edm::propagate_const< std::unique_ptr< std::set< std::string > > > processItems_
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_

Member Function Documentation

unsigned int edm::ProductResolverIndexHelper::beginElements ( ) const
inline

Definition at line 224 of file ProductResolverIndexHelper.h.

References beginElements_.

ProductResolverIndex edm::ProductResolverIndexHelper::index ( KindOfType  kindOfType,
TypeID const &  typeID,
char const *  moduleLabel,
char const *  instance,
char const *  process = nullptr 
) const

Definition at line 81 of file ProductResolverIndexHelper.cc.

References indexAndNames_, indexToIndexAndNames(), SiStripPI::max, and edm::ProductResolverIndexInvalid.

Referenced by BeautifulSoup.PageElement::_invert(), edm::Principal::findProductByLabel(), edm::PrincipalGetAdapter::getBranchDescription(), edm::EDConsumerBase::modulesWhoseProductsAreConsumed(), and edm::EDConsumerBase::updateLookup().

85  {
86  unsigned int iToIndexAndNames = indexToIndexAndNames(kindOfType, typeID, moduleLabel, instance, process);
87 
88  if (iToIndexAndNames == std::numeric_limits<unsigned int>::max()) {
90  }
91  return indexAndNames_[iToIndexAndNames].index();
92  }
static PFTauRenderPlugin instance
unsigned int indexToIndexAndNames(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process) const
std::vector< IndexAndNames > indexAndNames_
tuple process
Definition: LaserDQM_cfg.py:3
std::vector<IndexAndNames> const& edm::ProductResolverIndexHelper::indexAndNames ( ) const
inline

Definition at line 227 of file ProductResolverIndexHelper.h.

References indexAndNames_.

Referenced by indiciesForModulesInProcess().

227 { return indexAndNames_; }
std::vector< IndexAndNames > indexAndNames_
unsigned int edm::ProductResolverIndexHelper::indexToIndexAndNames ( KindOfType  kindOfType,
TypeID const &  typeID,
char const *  moduleLabel,
char const *  instance,
char const *  process 
) const

Definition at line 431 of file ProductResolverIndexHelper.cc.

References SplitLinear::begin, edm::ProductResolverIndexHelper::Range::begin(), bigNamesContainer_, edm::ProductResolverIndexHelper::Range::end(), dataset::end, indexAndNames_, indexToType(), instance, label, SiStripPI::max, processIndex(), sistrip::SpyUtilities::range(), and ranges_.

Referenced by index(), and relatedIndexes().

435  {
436  // Look for the type and check to see if it found it
437  unsigned iType = indexToType(kindOfType, typeID);
439  unsigned startProcess = 0;
440  if (process) {
441  startProcess = processIndex(process);
442  if (startProcess == std::numeric_limits<unsigned int>::max()) {
444  }
445  }
446 
448  unsigned int begin = range.begin();
449  unsigned int end = range.end();
450 
451  while (begin < end) {
452  unsigned int midpoint = begin + ((end - begin) / 2);
453  char const* namePtr = &bigNamesContainer_[indexAndNames_[midpoint].startInBigNamesContainer()];
454 
455  // Compare the module label
456  char const* label = moduleLabel;
457  while (*namePtr && (*namePtr == *label)) {
458  ++namePtr;
459  ++label;
460  }
461  if (*namePtr == *label) { // true only if both are at the '\0' at the end of the C string
462  ++namePtr; // move to the next C string
463 
464  // Compare the instance name
465  char const* instanceName = instance;
466  while (*namePtr && (*namePtr == *instanceName)) {
467  ++namePtr;
468  ++instanceName;
469  }
470  if (*namePtr == *instanceName) {
471  // Compare the process name
472  if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
473  return midpoint;
474  } else {
475  if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
476  while (true) {
477  --midpoint;
478  if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
479  return midpoint;
480  }
481  if (indexAndNames_[midpoint].startInProcessNames() == 0)
482  break;
483  }
484  } else {
485  while (true) {
486  ++midpoint;
487  if (midpoint == indexAndNames_.size())
488  break;
489  if (indexAndNames_[midpoint].startInProcessNames() == 0)
490  break;
491  if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
492  return midpoint;
493  }
494  }
495  }
496  break;
497  }
498  } else if (*namePtr < *instanceName) {
499  if (begin == midpoint)
500  break;
501  begin = midpoint;
502  } else {
503  end = midpoint;
504  }
505  } else if (*namePtr < *label) {
506  if (begin == midpoint)
507  break;
508  begin = midpoint;
509  } else {
510  end = midpoint;
511  }
512  } // end while (begin < end)
513  }
515  }
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const
static PFTauRenderPlugin instance
PixelRecoRange< float > Range
unsigned int processIndex(char const *process) const
const uint16_t range(const Frame &aFrame)
char const * label
std::vector< IndexAndNames > indexAndNames_
string end
Definition: dataset.py:937
tuple process
Definition: LaserDQM_cfg.py:3
unsigned int edm::ProductResolverIndexHelper::indexToType ( KindOfType  kindOfType,
TypeID const &  typeID 
) const

Definition at line 517 of file ProductResolverIndexHelper.cc.

References beginElements_, edm::ELEMENT_TYPE, SiStripPI::max, and sortedTypeIDs_.

Referenced by indexToIndexAndNames(), and relatedIndexes().

517  {
518  unsigned int beginType = 0;
519  unsigned int endType = beginElements_;
520  if (kindOfType == ELEMENT_TYPE) {
521  beginType = beginElements_;
522  endType = sortedTypeIDs_.size();
523  }
524 
525  while (beginType < endType) {
526  unsigned int midpointType = beginType + ((endType - beginType) / 2);
527  if (sortedTypeIDs_[midpointType] == typeID) {
528  return midpointType; // Found it
529  } else if (sortedTypeIDs_[midpointType] < typeID) {
530  if (beginType == midpointType)
531  break;
532  beginType = midpointType;
533  } else {
534  endType = midpointType;
535  }
536  }
537  return std::numeric_limits<unsigned int>::max(); // Failed to find it
538  }
ProductResolverIndexHelper::ModulesToIndiciesMap edm::ProductResolverIndexHelper::indiciesForModulesInProcess ( const std::string &  iProcessName) const

Definition at line 564 of file ProductResolverIndexHelper.cc.

References beginElements_, bigNamesContainer_, mps_fire::i, indexAndNames(), indexAndNames_, dqmiolumiharvest::j, cmsLHEtoEOSManager::l, processNames_, sistrip::SpyUtilities::range(), ranges_, mps_fire::result, and sortedTypeIDs_.

565  {
567  for (unsigned int i = 0; i < beginElements_; ++i) {
568  auto const& range = ranges_[i];
569  for (unsigned int j = range.begin(); j < range.end(); ++j) {
570  auto const& indexAndNames = indexAndNames_[j];
571  if (0 == strcmp(&processNames_[indexAndNames.startInProcessNames()], iProcessName.c_str())) {
572  //The first null terminated string is the module label
573  auto pModLabel = &bigNamesContainer_[indexAndNames.startInBigNamesContainer()];
574  auto l = strlen(pModLabel);
575  auto pInstance = pModLabel + l + 1;
576  result.emplace(pModLabel, std::make_tuple(&sortedTypeIDs_[i], pInstance, indexAndNames.index()));
577  }
578  }
579  }
580  return result;
581  }
std::unordered_multimap< std::string, std::tuple< TypeID const *, const char *, ProductResolverIndex >> ModulesToIndiciesMap
const uint16_t range(const Frame &aFrame)
tuple result
Definition: mps_fire.py:311
std::vector< IndexAndNames > const & indexAndNames() const
std::vector< IndexAndNames > indexAndNames_
ProductResolverIndex edm::ProductResolverIndexHelper::insert ( TypeID const &  typeID,
char const *  moduleLabel,
char const *  instance,
char const *  process,
TypeID const &  containedTypeID,
std::vector< TypeWithDict > *  baseTypesOfContainedType 
)

Definition at line 189 of file ProductResolverIndexHelper.cc.

References edm::ProductResolverIndexHelper::Item::clearProcess(), edm::ELEMENT_TYPE, Exception, B2GTnPMonitor_cfi::item, items_, edm::errors::LogicError, nextIndexValue_, edm::PRODUCT_TYPE, edm::ProductResolverIndexAmbiguous, edm::ProductResolverIndexHelper::Item::setIndex(), and edm::TypeIDBase::typeInfo().

Referenced by BeautifulSoup.PageElement::_invert(), SequenceTypes.Schedule::_replaceIfHeldDirectly(), and insert().

194  {
195  if (!items_) {
197  << "ProductResolverIndexHelper::insert - Attempt to insert more elements after frozen.\n";
198  }
199 
200  if (process == nullptr || *process == '\0') {
201  throw Exception(errors::LogicError) << "ProductResolverIndexHelper::insert - Empty process.\n";
202  }
203 
204  // Throw if this has already been inserted
205  Item item(PRODUCT_TYPE, typeID, moduleLabel, instance, process, 0);
206  std::set<Item>::iterator iter = items_->find(item);
207  if (iter != items_->end()) {
209  << "ProductResolverIndexHelper::insert - Attempt to insert duplicate entry.\n";
210  }
211 
212  // Put in an entry for the product
213  item.setIndex(nextIndexValue_);
214  unsigned int savedProductIndex = nextIndexValue_;
215  ++nextIndexValue_;
216  items_->insert(item);
217 
218  // Put in an entry for the product with an empty process name
219  // if it is not already there
220  item.clearProcess();
221  iter = items_->find(item);
222  if (iter == items_->end()) {
223  item.setIndex(nextIndexValue_);
224  ++nextIndexValue_;
225  items_->insert(item);
226  }
227 
228  // Now put in entries for a contained class if this is a
229  // recognized container.
230  if (containedTypeID != TypeID(typeid(void)) && containedTypeID != TypeID()) {
231  TypeWithDict containedType(containedTypeID.typeInfo());
232 
233  Item containedItem(ELEMENT_TYPE, containedTypeID, moduleLabel, instance, process, savedProductIndex);
234  iter = items_->find(containedItem);
235  if (iter != items_->end()) {
236  containedItem.setIndex(ProductResolverIndexAmbiguous);
237  items_->erase(iter);
238  }
239  items_->insert(containedItem);
240 
241  containedItem.clearProcess();
242  iter = items_->find(containedItem);
243  if (iter == items_->end()) {
244  containedItem.setIndex(nextIndexValue_);
245  ++nextIndexValue_;
246  items_->insert(containedItem);
247  }
248 
249  // Repeat this for all public base classes of the contained type
250  if (baseTypesOfContainedType) {
251  for (TypeWithDict const& baseType : *baseTypesOfContainedType) {
252  TypeID baseTypeID(baseType.typeInfo());
253  Item baseItem(ELEMENT_TYPE, baseTypeID, moduleLabel, instance, process, savedProductIndex);
254  iter = items_->find(baseItem);
255  if (iter != items_->end()) {
256  baseItem.setIndex(ProductResolverIndexAmbiguous);
257  items_->erase(iter);
258  }
259  items_->insert(baseItem);
260 
261  baseItem.clearProcess();
262  iter = items_->find(baseItem);
263  if (iter == items_->end()) {
264  baseItem.setIndex(nextIndexValue_);
265  ++nextIndexValue_;
266  items_->insert(baseItem);
267  }
268  }
269  }
270  }
271  return savedProductIndex;
272  }
static PFTauRenderPlugin instance
tuple process
Definition: LaserDQM_cfg.py:3
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_
ProductResolverIndex edm::ProductResolverIndexHelper::insert ( TypeID const &  typeID,
char const *  moduleLabel,
char const *  instance,
char const *  process 
)

Definition at line 274 of file ProductResolverIndexHelper.cc.

References edm::productholderindexhelper::getContainedType(), insert(), and edm::public_base_classes().

Referenced by BeautifulSoup.PageElement::_invert(), and SequenceTypes.Schedule::_replaceIfHeldDirectly().

277  {
278  TypeID containedTypeID = productholderindexhelper::getContainedType(typeID);
279  bool hasContainedType = (containedTypeID != TypeID(typeid(void)) && containedTypeID != TypeID());
280  std::vector<TypeWithDict> baseTypes;
281  std::vector<TypeWithDict>* baseTypesOfContainedType = &baseTypes;
282  if (hasContainedType) {
283  std::vector<std::string> missingDictionaries;
284  public_base_classes(missingDictionaries, containedTypeID, baseTypes);
285  }
286  return insert(typeID, moduleLabel, instance, process, containedTypeID, baseTypesOfContainedType);
287  }
TypeID getContainedType(TypeID const &typeID)
static PFTauRenderPlugin instance
bool public_base_classes(std::vector< std::string > &missingDictionaries, TypeID const &typeID, std::vector< TypeWithDict > &baseTypes)
ProductResolverIndex insert(TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process, TypeID const &containedTypeID, std::vector< TypeWithDict > *baseTypesOfContainedType)
tuple process
Definition: LaserDQM_cfg.py:3
std::vector< std::string > const & edm::ProductResolverIndexHelper::lookupProcessNames ( ) const

Definition at line 423 of file ProductResolverIndexHelper.cc.

References Exception, items_, edm::errors::LogicError, and lookupProcessNames_.

423  {
424  if (items_) {
426  << "ProductResolverIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
427  }
428  return lookupProcessNames_;
429  }
std::vector< std::string > lookupProcessNames_
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_
ProductResolverIndex edm::ProductResolverIndexHelper::nextIndexValue ( ) const
inline

Definition at line 252 of file ProductResolverIndexHelper.h.

References nextIndexValue_.

252 { return nextIndexValue_; }
void edm::ProductResolverIndexHelper::print ( std::ostream &  os) const

Definition at line 681 of file ProductResolverIndexHelper.cc.

References beginElements_, bigNamesContainer_, gather_cfg::cout, mps_fire::i, indexAndNames_, B2GTnPMonitor_cfi::item, items_, nextIndexValue_, processItems_, processNames_, ranges_, and sortedTypeIDs_.

681  {
682  os << "\n******* Dump ProductResolverIndexHelper *************************\n";
683 
684  os << "\nnextIndexValue_ = " << nextIndexValue_ << "\n";
685  os << "beginElements_ = " << beginElements_ << "\n";
686 
687  os << "\n******* sortedTypeIDs_ \n";
688  for (auto const& i : sortedTypeIDs_) {
689  os << i << "\n";
690  }
691  os << "******* ranges_ \n";
692  for (auto const& i : ranges_) {
693  os << i.begin() << " " << i.end() << "\n";
694  }
695  os << "******* indexAndNames_ \n";
696  for (auto const& i : indexAndNames_) {
697  os << i.index() << " " << i.startInBigNamesContainer() << " ";
698  char const* ptr = &bigNamesContainer_[i.startInBigNamesContainer()];
699  while (*ptr) {
700  os << *ptr;
701  ++ptr;
702  }
703  ++ptr;
704  os << " ";
705  while (*ptr) {
706  os << *ptr;
707  ++ptr;
708  }
709  os << " " << i.startInProcessNames() << " ";
710  ptr = &processNames_[i.startInProcessNames()];
711  while (*ptr) {
712  os << *ptr;
713  ++ptr;
714  }
715  os << "\n";
716  }
717  os << "******* bigNamesContainer_ \n";
718  for (auto i : bigNamesContainer_) {
719  if (i == '\0')
720  os << '\\' << '0';
721  else
722  os << i;
723  }
724  if (!bigNamesContainer_.empty())
725  os << "\n";
726  os << "******* processNames_ \n";
727  for (auto i : processNames_) {
728  if (i == '\0')
729  os << '\\' << '0';
730  else
731  os << i;
732  }
733  if (!processNames_.empty())
734  os << "\n";
735  if (items_) {
736  os << "******* items_ \n";
737  for (auto const& item : *items_) {
738  std::cout << item.kindOfType() << " " << item.moduleLabel() << " " << item.instance() << " " << item.process()
739  << " " << item.index() << " " << item.typeID() << "\n";
740  }
741  }
742  if (processItems_) {
743  os << "******* processItems_ \n";
744  for (auto const& item : *processItems_) {
745  os << item << "\n";
746  }
747  }
748  os << "sortedTypeIDs_.size() = " << sortedTypeIDs_.size() << "\n";
749  os << "indexAndNames_.size() = " << indexAndNames_.size() << "\n";
750  os << "bigNamesContainer_.size() = " << bigNamesContainer_.size() << "\n";
751  os << "processNames_.size() = " << processNames_.size() << "\n";
752  os << "\n";
753  }
edm::propagate_const< std::unique_ptr< std::set< std::string > > > processItems_
std::vector< IndexAndNames > indexAndNames_
tuple cout
Definition: gather_cfg.py:144
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_
unsigned int edm::ProductResolverIndexHelper::processIndex ( char const *  process) const

Definition at line 540 of file ProductResolverIndexHelper.cc.

References SplitLinear::begin, SiStripPI::max, AlCaHLTBitMon_ParallelJobs::p, LaserDQM_cfg::process, and processNames_.

Referenced by indexToIndexAndNames(), and setFrozen().

540  {
541  char const* ptr = &processNames_[0];
542  char const* begin = ptr;
543  while (true) {
544  char const* p = process;
545  char const* beginName = ptr;
546  while (*ptr && (*ptr == *p)) {
547  ++ptr;
548  ++p;
549  }
550  if (*ptr == *p) {
551  return beginName - begin;
552  }
553  while (*ptr) {
554  ++ptr;
555  }
556  ++ptr;
557  if (static_cast<unsigned>(ptr - begin) >= processNames_.size()) {
559  }
560  }
561  return 0;
562  }
tuple process
Definition: LaserDQM_cfg.py:3
std::vector<char> const& edm::ProductResolverIndexHelper::processNames ( ) const
inline

Definition at line 228 of file ProductResolverIndexHelper.h.

References processNames_.

228 { return processNames_; }
std::vector<Range> const& edm::ProductResolverIndexHelper::ranges ( ) const
inline

Definition at line 226 of file ProductResolverIndexHelper.h.

References ranges_.

226 { return ranges_; }
ProductResolverIndexHelper::Matches edm::ProductResolverIndexHelper::relatedIndexes ( KindOfType  kindOfType,
TypeID const &  typeID,
char const *  moduleLabel,
char const *  instance 
) const

Definition at line 153 of file ProductResolverIndexHelper.cc.

References indexAndNames_, indexToIndexAndNames(), dqmiolumiharvest::j, and SiStripPI::max.

Referenced by edm::Principal::getManyByType(), edm::EDConsumerBase::modulesWhoseProductsAreConsumed(), and edm::EDConsumerBase::updateLookup().

156  {
157  unsigned int startInIndexAndNames = indexToIndexAndNames(kindOfType, typeID, moduleLabel, instance, nullptr);
158  unsigned int numberOfMatches = 1;
159 
160  if (startInIndexAndNames == std::numeric_limits<unsigned int>::max()) {
161  numberOfMatches = 0;
162  } else {
163  auto vSize = indexAndNames_.size();
164  for (unsigned int j = startInIndexAndNames + 1U; j < vSize && (indexAndNames_[j].startInProcessNames() != 0U);
165  ++j) {
166  ++numberOfMatches;
167  }
168  }
169  return Matches(this, startInIndexAndNames, numberOfMatches);
170  }
static PFTauRenderPlugin instance
unsigned int indexToIndexAndNames(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process) const
std::vector< IndexAndNames > indexAndNames_
ProductResolverIndexHelper::Matches edm::ProductResolverIndexHelper::relatedIndexes ( KindOfType  kindOfType,
TypeID const &  typeID 
) const

Definition at line 172 of file ProductResolverIndexHelper.cc.

References edm::ProductResolverIndexHelper::Range::begin(), edm::ProductResolverIndexHelper::Range::end(), indexToType(), SiStripPI::max, sistrip::SpyUtilities::range(), and ranges_.

173  {
174  unsigned int startInIndexAndNames = std::numeric_limits<unsigned int>::max();
175  unsigned int numberOfMatches = 0;
176 
177  // Look for the type and check to see if it found it
178  unsigned iType = indexToType(kindOfType, typeID);
180  // Get the range of entries with a matching TypeID
181  Range const& range = ranges_[iType];
182 
183  startInIndexAndNames = range.begin();
184  numberOfMatches = range.end() - range.begin();
185  }
186  return Matches(this, startInIndexAndNames, numberOfMatches);
187  }
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const
PixelRecoRange< float > Range
const uint16_t range(const Frame &aFrame)
void edm::ProductResolverIndexHelper::sanityCheck ( ) const

Definition at line 583 of file ProductResolverIndexHelper.cc.

References bigNamesContainer_, Exception, indexAndNames_, dqmiolumiharvest::j, edm::errors::LogicError, nextIndexValue_, processNames_, edm::ProductResolverIndexAmbiguous, sistrip::SpyUtilities::range(), ranges_, and sortedTypeIDs_.

Referenced by setFrozen().

583  {
584  bool sanityChecksPass = true;
585  if (sortedTypeIDs_.size() != ranges_.size())
586  sanityChecksPass = false;
587 
588  unsigned int previousEnd = 0;
589  for (auto const& range : ranges_) {
590  if (range.begin() != previousEnd)
591  sanityChecksPass = false;
592  if (range.begin() >= range.end())
593  sanityChecksPass = false;
594  previousEnd = range.end();
595  }
596  if (previousEnd != indexAndNames_.size())
597  sanityChecksPass = false;
598 
599  unsigned maxStart = 0;
600  unsigned maxStartProcess = 0;
601  for (auto const& indexAndName : indexAndNames_) {
602  if (indexAndName.index() >= nextIndexValue_ && indexAndName.index() != ProductResolverIndexAmbiguous)
603  sanityChecksPass = false;
604 
605  if (indexAndName.startInBigNamesContainer() >= bigNamesContainer_.size())
606  sanityChecksPass = false;
607  if (indexAndName.startInProcessNames() >= processNames_.size())
608  sanityChecksPass = false;
609 
610  if (indexAndName.startInBigNamesContainer() > maxStart)
611  maxStart = indexAndName.startInBigNamesContainer();
612  if (indexAndName.startInProcessNames() > maxStartProcess)
613  maxStartProcess = indexAndName.startInProcessNames();
614  }
615 
616  if (!indexAndNames_.empty()) {
617  if (bigNamesContainer_.back() != '\0')
618  sanityChecksPass = false;
619  if (processNames_.back() != '\0')
620  sanityChecksPass = false;
621  if (maxStart >= bigNamesContainer_.size())
622  sanityChecksPass = false;
623  unsigned int countZeroes = 0;
624  for (unsigned j = maxStart; j < bigNamesContainer_.size(); ++j) {
625  if (bigNamesContainer_[j] == '\0') {
626  ++countZeroes;
627  }
628  }
629  if (countZeroes != 2)
630  sanityChecksPass = false;
631  if (maxStartProcess >= processNames_.size())
632  sanityChecksPass = false;
633  countZeroes = 0;
634  for (unsigned j = maxStartProcess; j < processNames_.size(); ++j) {
635  if (processNames_[j] == '\0') {
636  ++countZeroes;
637  }
638  }
639  if (countZeroes != 1)
640  sanityChecksPass = false;
641  }
642 
643  if (!sanityChecksPass) {
644  throw Exception(errors::LogicError) << "ProductResolverIndexHelper::setFrozen - Detected illegal state.\n";
645  }
646  }
const uint16_t range(const Frame &aFrame)
std::vector< IndexAndNames > indexAndNames_
void edm::ProductResolverIndexHelper::setFrozen ( )

Definition at line 289 of file ProductResolverIndexHelper.cc.

References beginElements_, bigNamesContainer_, c, edm::ELEMENT_TYPE, Exception, indexAndNames_, B2GTnPMonitor_cfi::item, items_, dqmiolumiharvest::j, edm::errors::LogicError, lookupProcessNames_, SiStripPI::max, processIndex(), processItems_, processNames_, edm::PRODUCT_TYPE, ranges_, sanityCheck(), sortedTypeIDs_, and AlCaHLTBitMon_QueryRunRegistry::string.

289  {
290  if (!items_)
291  return;
292 
293  // Make a first pass and count things so we
294  // can reserve memory in the vectors. Also
295  // fill processItems_ on the first pass.
296  bool iFirstThisType = true;
297  bool beginElementsWasSet = false;
298  TypeID previousTypeID;
299  KindOfType previousKindOfType = PRODUCT_TYPE;
300  std::string previousModuleLabel;
301  std::string previousInstance;
302  unsigned int iCountTypes = 0;
303  unsigned int iCountCharacters = 0;
304  for (auto const& item : *items_) {
305  if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
306  ++iCountTypes;
307  iFirstThisType = true;
308 
309  if (!beginElementsWasSet) {
310  if (item.kindOfType() == ELEMENT_TYPE) {
311  beginElementsWasSet = true;
312  } else {
313  beginElements_ = iCountTypes;
314  }
315  }
316  }
317 
318  processItems_->insert(item.process());
319 
320  if (iFirstThisType || item.moduleLabel() != previousModuleLabel || item.instance() != previousInstance) {
321  iCountCharacters += item.moduleLabel().size();
322  iCountCharacters += item.instance().size();
323  iCountCharacters += 2;
324  }
325 
326  iFirstThisType = false;
327  previousTypeID = item.typeID();
328  previousKindOfType = item.kindOfType();
329  previousModuleLabel = item.moduleLabel();
330  previousInstance = item.instance();
331  }
332 
333  // Size and fill the process name vector
334  unsigned int processNamesSize = 0;
335  for (auto const& processItem : *processItems_) {
336  processNamesSize += processItem.size();
337  ++processNamesSize;
338  }
339  processNames_.reserve(processNamesSize);
340  for (auto const& processItem : *processItems_) {
341  for (auto const& c : processItem) {
342  processNames_.push_back(c);
343  }
344  processNames_.push_back('\0');
345  lookupProcessNames_.push_back(processItem);
346  }
347 
348  // Reserve memory in the vectors
349  sortedTypeIDs_.reserve(iCountTypes);
350  ranges_.reserve(iCountTypes);
351  indexAndNames_.reserve(items_->size());
352  bigNamesContainer_.reserve(iCountCharacters);
353 
354  // Second pass. Really fill the vectors this time.
355  bool iFirstType = true;
356  iFirstThisType = true;
357  previousTypeID = TypeID();
358  unsigned int iCount = 0;
359  unsigned int iBeginning = 0;
360  iCountCharacters = 0;
361  unsigned int previousCharacterCount = 0;
362  if (!items_->empty()) {
363  for (auto const& item : *items_) {
364  if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
365  iFirstThisType = true;
366  sortedTypeIDs_.push_back(item.typeID());
367  if (iFirstType) {
368  iFirstType = false;
369  } else {
370  ranges_.push_back(Range(iBeginning, iCount));
371  }
372  iBeginning = iCount;
373  }
374  ++iCount;
375 
376  if (iFirstThisType || item.moduleLabel() != previousModuleLabel || item.instance() != previousInstance) {
377  unsigned int labelSize = item.moduleLabel().size();
378  for (unsigned int j = 0; j < labelSize; ++j) {
379  bigNamesContainer_.push_back(item.moduleLabel()[j]);
380  }
381  bigNamesContainer_.push_back('\0');
382 
383  unsigned int instanceSize = item.instance().size();
384  for (unsigned int j = 0; j < instanceSize; ++j) {
385  bigNamesContainer_.push_back(item.instance()[j]);
386  }
387  bigNamesContainer_.push_back('\0');
388 
389  previousCharacterCount = iCountCharacters;
390 
391  iCountCharacters += labelSize;
392  iCountCharacters += instanceSize;
393  iCountCharacters += 2;
394  }
395 
396  unsigned int processStart = processIndex(item.process().c_str());
397  if (processStart == std::numeric_limits<unsigned int>::max()) {
399  << "ProductResolverIndexHelper::setFrozen - Process not found in processNames_.\n";
400  }
401  indexAndNames_.emplace_back(item.index(), previousCharacterCount, processStart);
402 
403  iFirstThisType = false;
404  previousTypeID = item.typeID();
405  previousKindOfType = item.kindOfType();
406  previousModuleLabel = item.moduleLabel();
407  previousInstance = item.instance();
408  }
409  ranges_.push_back(Range(iBeginning, iCount));
410  }
411 
412  // Some sanity checks to protect against out of bounds vector accesses
413  // These should only fail if there is a bug. If profiling ever shows
414  // them to be expensive one might delete them.
415  sanityCheck();
416 
417  // Cleanup, do not need the temporary containers anymore
418  // propagate_const<T> has no reset() function
419  items_ = nullptr;
420  processItems_ = nullptr;
421  }
const edm::EventSetup & c
PixelRecoRange< float > Range
unsigned int processIndex(char const *process) const
edm::propagate_const< std::unique_ptr< std::set< std::string > > > processItems_
std::vector< IndexAndNames > indexAndNames_
std::vector< std::string > lookupProcessNames_
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_
std::vector<TypeID> const& edm::ProductResolverIndexHelper::sortedTypeIDs ( ) const
inline

Definition at line 225 of file ProductResolverIndexHelper.h.

References sortedTypeIDs_.

225 { return sortedTypeIDs_; }

Member Data Documentation

unsigned int edm::ProductResolverIndexHelper::beginElements_
private
std::vector<char> edm::ProductResolverIndexHelper::bigNamesContainer_
private
std::vector<IndexAndNames> edm::ProductResolverIndexHelper::indexAndNames_
private
edm::propagate_const<std::unique_ptr<std::set<Item> > > edm::ProductResolverIndexHelper::items_
private

Definition at line 342 of file ProductResolverIndexHelper.h.

Referenced by insert(), lookupProcessNames(), print(), and setFrozen().

std::vector<std::string> edm::ProductResolverIndexHelper::lookupProcessNames_
private

Definition at line 308 of file ProductResolverIndexHelper.h.

Referenced by lookupProcessNames(), and setFrozen().

ProductResolverIndex edm::ProductResolverIndexHelper::nextIndexValue_
private

Definition at line 260 of file ProductResolverIndexHelper.h.

Referenced by insert(), nextIndexValue(), print(), and sanityCheck().

edm::propagate_const<std::unique_ptr<std::set<std::string> > > edm::ProductResolverIndexHelper::processItems_
private

Definition at line 344 of file ProductResolverIndexHelper.h.

Referenced by print(), and setFrozen().

std::vector<char> edm::ProductResolverIndexHelper::processNames_
private
std::vector<Range> edm::ProductResolverIndexHelper::ranges_
private
std::vector<TypeID> edm::ProductResolverIndexHelper::sortedTypeIDs_
private