CMS 3D CMS Logo

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 93 of file ProductResolverIndexHelper.h.

Member Typedef Documentation

◆ ModulesToIndiciesMap

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

Definition at line 128 of file ProductResolverIndexHelper.h.

Constructor & Destructor Documentation

◆ ProductResolverIndexHelper()

edm::ProductResolverIndexHelper::ProductResolverIndexHelper ( )

Definition at line 101 of file ProductResolverIndexHelper.cc.

102  : nextIndexValue_(0),
103  beginElements_(0),
104  items_(new std::set<ProductResolverIndexHelper::Item>),
105  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

◆ beginElements()

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

Definition at line 228 of file ProductResolverIndexHelper.h.

References beginElements_.

◆ index()

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

Definition at line 107 of file ProductResolverIndexHelper.cc.

References indexAndNames_, indexToIndexAndNames(), instance, SiStripPI::max, HerwigMaxPtPartonFilter_cfi::moduleLabel, LaserDQM_cfg::process, and edm::ProductResolverIndexInvalid.

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

111  {
112  unsigned int iToIndexAndNames = indexToIndexAndNames(kindOfType, typeID, moduleLabel, instance, process);
113 
114  if (iToIndexAndNames == std::numeric_limits<unsigned int>::max()) {
116  }
117  return indexAndNames_[iToIndexAndNames].index();
118  }
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_

◆ indexAndNames()

std::vector<IndexAndNames> const& edm::ProductResolverIndexHelper::indexAndNames ( ) const
inline

Definition at line 231 of file ProductResolverIndexHelper.h.

References indexAndNames_.

Referenced by indiciesForModulesInProcess().

231 { return indexAndNames_; }
std::vector< IndexAndNames > indexAndNames_

◆ indexToIndexAndNames()

unsigned int edm::ProductResolverIndexHelper::indexToIndexAndNames ( KindOfType  kindOfType,
TypeID const &  typeID,
char const *  moduleLabel,
char const *  instance,
char const *  process 
) const

Definition at line 457 of file ProductResolverIndexHelper.cc.

References bigNamesContainer_, mps_fire::end, indexAndNames_, indexToType(), instance, MuonErrorMatrixAdjuster_cfi::instanceName, label, SiStripPI::max, HerwigMaxPtPartonFilter_cfi::moduleLabel, LaserDQM_cfg::process, processIndex(), FastTimerService_cff::range, and ranges_.

Referenced by index(), and relatedIndexes().

461  {
462  // Look for the type and check to see if it found it
463  unsigned iType = indexToType(kindOfType, typeID);
465  unsigned startProcess = 0;
466  if (process) {
467  startProcess = processIndex(process);
468  if (startProcess == std::numeric_limits<unsigned int>::max()) {
470  }
471  }
472 
474  unsigned int begin = range.begin();
475  unsigned int end = range.end();
476 
477  while (begin < end) {
478  unsigned int midpoint = begin + ((end - begin) / 2);
479  char const* namePtr = &bigNamesContainer_[indexAndNames_[midpoint].startInBigNamesContainer()];
480 
481  // Compare the module label
482  char const* label = moduleLabel;
483  while (*namePtr && (*namePtr == *label)) {
484  ++namePtr;
485  ++label;
486  }
487  if (*namePtr == *label) { // true only if both are at the '\0' at the end of the C string
488  ++namePtr; // move to the next C string
489 
490  // Compare the instance name
491  char const* instanceName = instance;
492  while (*namePtr && (*namePtr == *instanceName)) {
493  ++namePtr;
494  ++instanceName;
495  }
496  if (*namePtr == *instanceName) {
497  // Compare the process name
498  if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
499  return midpoint;
500  } else {
501  if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
502  while (true) {
503  --midpoint;
504  if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
505  return midpoint;
506  }
507  if (indexAndNames_[midpoint].startInProcessNames() == 0)
508  break;
509  }
510  } else {
511  while (true) {
512  ++midpoint;
513  if (midpoint == indexAndNames_.size())
514  break;
515  if (indexAndNames_[midpoint].startInProcessNames() == 0)
516  break;
517  if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
518  return midpoint;
519  }
520  }
521  }
522  break;
523  }
524  } else if (*namePtr < *instanceName) {
525  if (begin == midpoint)
526  break;
527  begin = midpoint;
528  } else {
529  end = midpoint;
530  }
531  } else if (*namePtr < *label) {
532  if (begin == midpoint)
533  break;
534  begin = midpoint;
535  } else {
536  end = midpoint;
537  }
538  } // end while (begin < end)
539  }
541  }
unsigned int processIndex(char const *process) const
static PFTauRenderPlugin instance
PixelRecoRange< float > Range
char const * label
std::vector< IndexAndNames > indexAndNames_
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const

◆ indexToType()

unsigned int edm::ProductResolverIndexHelper::indexToType ( KindOfType  kindOfType,
TypeID const &  typeID 
) const

Definition at line 543 of file ProductResolverIndexHelper.cc.

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

Referenced by indexToIndexAndNames(), and relatedIndexes().

543  {
544  unsigned int beginType = 0;
545  unsigned int endType = beginElements_;
546  if (kindOfType == ELEMENT_TYPE) {
547  beginType = beginElements_;
548  endType = sortedTypeIDs_.size();
549  }
550 
551  while (beginType < endType) {
552  unsigned int midpointType = beginType + ((endType - beginType) / 2);
553  if (sortedTypeIDs_[midpointType] == typeID) {
554  return midpointType; // Found it
555  } else if (sortedTypeIDs_[midpointType] < typeID) {
556  if (beginType == midpointType)
557  break;
558  beginType = midpointType;
559  } else {
560  endType = midpointType;
561  }
562  }
563  return std::numeric_limits<unsigned int>::max(); // Failed to find it
564  }

◆ indiciesForModulesInProcess()

ProductResolverIndexHelper::ModulesToIndiciesMap edm::ProductResolverIndexHelper::indiciesForModulesInProcess ( const std::string &  iProcessName) const

Definition at line 590 of file ProductResolverIndexHelper.cc.

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

591  {
593  for (unsigned int i = 0; i < beginElements_; ++i) {
594  auto const& range = ranges_[i];
595  for (unsigned int j = range.begin(); j < range.end(); ++j) {
596  auto const& indexAndNames = indexAndNames_[j];
597  if (0 == strcmp(&processNames_[indexAndNames.startInProcessNames()], iProcessName.c_str())) {
598  //The first null terminated string is the module label
599  auto pModLabel = &bigNamesContainer_[indexAndNames.startInBigNamesContainer()];
600  auto l = strlen(pModLabel);
601  auto pInstance = pModLabel + l + 1;
602  result.emplace(pModLabel, std::make_tuple(&sortedTypeIDs_[i], pInstance, indexAndNames.index()));
603  }
604  }
605  }
606  return result;
607  }
std::vector< IndexAndNames > indexAndNames_
std::vector< IndexAndNames > const & indexAndNames() const
std::unordered_multimap< std::string, std::tuple< TypeID const *, const char *, ProductResolverIndex > > ModulesToIndiciesMap

◆ insert() [1/2]

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 215 of file ProductResolverIndexHelper.cc.

References edm::ELEMENT_TYPE, Exception, instance, B2GTnPMonitor_cfi::item, items_, edm::errors::LogicError, HerwigMaxPtPartonFilter_cfi::moduleLabel, nextIndexValue_, LaserDQM_cfg::process, edm::PRODUCT_TYPE, edm::ProductResolverIndexAmbiguous, and edm::TypeID::typeInfo().

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

220  {
221  if (!items_) {
223  << "ProductResolverIndexHelper::insert - Attempt to insert more elements after frozen.\n";
224  }
225 
226  if (process == nullptr || *process == '\0') {
227  throw Exception(errors::LogicError) << "ProductResolverIndexHelper::insert - Empty process.\n";
228  }
229 
230  // Throw if this has already been inserted
231  Item item(PRODUCT_TYPE, typeID, moduleLabel, instance, process, 0);
232  std::set<Item>::iterator iter = items_->find(item);
233  if (iter != items_->end()) {
235  << "ProductResolverIndexHelper::insert - Attempt to insert duplicate entry.\n";
236  }
237 
238  // Put in an entry for the product
239  item.setIndex(nextIndexValue_);
240  unsigned int savedProductIndex = nextIndexValue_;
241  ++nextIndexValue_;
242  items_->insert(item);
243 
244  // Put in an entry for the product with an empty process name
245  // if it is not already there
246  item.clearProcess();
247  iter = items_->find(item);
248  if (iter == items_->end()) {
249  item.setIndex(nextIndexValue_);
250  ++nextIndexValue_;
251  items_->insert(item);
252  }
253 
254  // Now put in entries for a contained class if this is a
255  // recognized container.
256  if (containedTypeID != TypeID(typeid(void)) && containedTypeID != TypeID()) {
257  TypeWithDict containedType(containedTypeID.typeInfo());
258 
259  Item containedItem(ELEMENT_TYPE, containedTypeID, moduleLabel, instance, process, savedProductIndex);
260  iter = items_->find(containedItem);
261  if (iter != items_->end()) {
262  containedItem.setIndex(ProductResolverIndexAmbiguous);
263  items_->erase(iter);
264  }
265  items_->insert(containedItem);
266 
267  containedItem.clearProcess();
268  iter = items_->find(containedItem);
269  if (iter == items_->end()) {
270  containedItem.setIndex(nextIndexValue_);
271  ++nextIndexValue_;
272  items_->insert(containedItem);
273  }
274 
275  // Repeat this for all public base classes of the contained type
276  if (baseTypesOfContainedType) {
277  for (TypeWithDict const& baseType : *baseTypesOfContainedType) {
278  TypeID baseTypeID(baseType.typeInfo());
279  Item baseItem(ELEMENT_TYPE, baseTypeID, moduleLabel, instance, process, savedProductIndex);
280  iter = items_->find(baseItem);
281  if (iter != items_->end()) {
282  baseItem.setIndex(ProductResolverIndexAmbiguous);
283  items_->erase(iter);
284  }
285  items_->insert(baseItem);
286 
287  baseItem.clearProcess();
288  iter = items_->find(baseItem);
289  if (iter == items_->end()) {
290  baseItem.setIndex(nextIndexValue_);
291  ++nextIndexValue_;
292  items_->insert(baseItem);
293  }
294  }
295  }
296  }
297  return savedProductIndex;
298  }
static PFTauRenderPlugin instance
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_

◆ insert() [2/2]

ProductResolverIndex edm::ProductResolverIndexHelper::insert ( TypeID const &  typeID,
char const *  moduleLabel,
char const *  instance,
char const *  process 
)

Definition at line 300 of file ProductResolverIndexHelper.cc.

References edm::productholderindexhelper::getContainedType(), insert(), instance, HerwigMaxPtPartonFilter_cfi::moduleLabel, LaserDQM_cfg::process, and edm::public_base_classes().

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

303  {
304  TypeID containedTypeID = productholderindexhelper::getContainedType(typeID);
305  bool hasContainedType = (containedTypeID != TypeID(typeid(void)) && containedTypeID != TypeID());
306  std::vector<TypeWithDict> baseTypes;
307  std::vector<TypeWithDict>* baseTypesOfContainedType = &baseTypes;
308  if (hasContainedType) {
309  std::vector<std::string> missingDictionaries;
310  public_base_classes(missingDictionaries, containedTypeID, baseTypes);
311  }
312  return insert(typeID, moduleLabel, instance, process, containedTypeID, baseTypesOfContainedType);
313  }
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)

◆ lookupProcessNames()

std::vector< std::string > const & edm::ProductResolverIndexHelper::lookupProcessNames ( ) const

Definition at line 449 of file ProductResolverIndexHelper.cc.

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

449  {
450  if (items_) {
452  << "ProductResolverIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
453  }
454  return lookupProcessNames_;
455  }
std::vector< std::string > lookupProcessNames_
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_

◆ nextIndexValue()

ProductResolverIndex edm::ProductResolverIndexHelper::nextIndexValue ( ) const
inline

Definition at line 256 of file ProductResolverIndexHelper.h.

References nextIndexValue_.

256 { return nextIndexValue_; }

◆ print()

void edm::ProductResolverIndexHelper::print ( std::ostream &  os) const

Definition at line 707 of file ProductResolverIndexHelper.cc.

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

707  {
708  os << "\n******* Dump ProductResolverIndexHelper *************************\n";
709 
710  os << "\nnextIndexValue_ = " << nextIndexValue_ << "\n";
711  os << "beginElements_ = " << beginElements_ << "\n";
712 
713  os << "\n******* sortedTypeIDs_ \n";
714  for (auto const& i : sortedTypeIDs_) {
715  os << i << "\n";
716  }
717  os << "******* ranges_ \n";
718  for (auto const& i : ranges_) {
719  os << i.begin() << " " << i.end() << "\n";
720  }
721  os << "******* indexAndNames_ \n";
722  for (auto const& i : indexAndNames_) {
723  os << i.index() << " " << i.startInBigNamesContainer() << " ";
724  char const* ptr = &bigNamesContainer_[i.startInBigNamesContainer()];
725  while (*ptr) {
726  os << *ptr;
727  ++ptr;
728  }
729  ++ptr;
730  os << " ";
731  while (*ptr) {
732  os << *ptr;
733  ++ptr;
734  }
735  os << " " << i.startInProcessNames() << " ";
736  ptr = &processNames_[i.startInProcessNames()];
737  while (*ptr) {
738  os << *ptr;
739  ++ptr;
740  }
741  os << "\n";
742  }
743  os << "******* bigNamesContainer_ \n";
744  for (auto i : bigNamesContainer_) {
745  if (i == '\0')
746  os << '\\' << '0';
747  else
748  os << i;
749  }
750  if (!bigNamesContainer_.empty())
751  os << "\n";
752  os << "******* processNames_ \n";
753  for (auto i : processNames_) {
754  if (i == '\0')
755  os << '\\' << '0';
756  else
757  os << i;
758  }
759  if (!processNames_.empty())
760  os << "\n";
761  if (items_) {
762  os << "******* items_ \n";
763  for (auto const& item : *items_) {
764  std::cout << item.kindOfType() << " " << item.moduleLabel() << " " << item.instance() << " " << item.process()
765  << " " << item.index() << " " << item.typeID() << "\n";
766  }
767  }
768  if (processItems_) {
769  os << "******* processItems_ \n";
770  for (auto const& item : *processItems_) {
771  os << item << "\n";
772  }
773  }
774  os << "sortedTypeIDs_.size() = " << sortedTypeIDs_.size() << "\n";
775  os << "indexAndNames_.size() = " << indexAndNames_.size() << "\n";
776  os << "bigNamesContainer_.size() = " << bigNamesContainer_.size() << "\n";
777  os << "processNames_.size() = " << processNames_.size() << "\n";
778  os << "\n";
779  }
edm::propagate_const< std::unique_ptr< std::set< std::string > > > processItems_
std::vector< IndexAndNames > indexAndNames_
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_

◆ processIndex()

unsigned int edm::ProductResolverIndexHelper::processIndex ( char const *  process) const

Definition at line 566 of file ProductResolverIndexHelper.cc.

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

Referenced by indexToIndexAndNames(), and setFrozen().

566  {
567  char const* ptr = &processNames_[0];
568  char const* begin = ptr;
569  while (true) {
570  char const* p = process;
571  char const* beginName = ptr;
572  while (*ptr && (*ptr == *p)) {
573  ++ptr;
574  ++p;
575  }
576  if (*ptr == *p) {
577  return beginName - begin;
578  }
579  while (*ptr) {
580  ++ptr;
581  }
582  ++ptr;
583  if (static_cast<unsigned>(ptr - begin) >= processNames_.size()) {
585  }
586  }
587  return 0;
588  }

◆ processNames()

std::vector<char> const& edm::ProductResolverIndexHelper::processNames ( ) const
inline

Definition at line 232 of file ProductResolverIndexHelper.h.

References processNames_.

232 { return processNames_; }

◆ ranges()

std::vector<Range> const& edm::ProductResolverIndexHelper::ranges ( ) const
inline

Definition at line 230 of file ProductResolverIndexHelper.h.

References ranges_.

230 { return ranges_; }

◆ relatedIndexes() [1/2]

ProductResolverIndexHelper::Matches edm::ProductResolverIndexHelper::relatedIndexes ( KindOfType  kindOfType,
TypeID const &  typeID,
char const *  moduleLabel,
char const *  instance 
) const

Definition at line 179 of file ProductResolverIndexHelper.cc.

References indexAndNames_, indexToIndexAndNames(), instance, dqmiolumiharvest::j, SiStripPI::max, HerwigMaxPtPartonFilter_cfi::moduleLabel, and mitigatedMETSequence_cff::U.

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

182  {
183  unsigned int startInIndexAndNames = indexToIndexAndNames(kindOfType, typeID, moduleLabel, instance, nullptr);
184  unsigned int numberOfMatches = 1;
185 
186  if (startInIndexAndNames == std::numeric_limits<unsigned int>::max()) {
187  numberOfMatches = 0;
188  } else {
189  auto vSize = indexAndNames_.size();
190  for (unsigned int j = startInIndexAndNames + 1U; j < vSize && (indexAndNames_[j].startInProcessNames() != 0U);
191  ++j) {
192  ++numberOfMatches;
193  }
194  }
195  return Matches(this, startInIndexAndNames, numberOfMatches);
196  }
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_

◆ relatedIndexes() [2/2]

ProductResolverIndexHelper::Matches edm::ProductResolverIndexHelper::relatedIndexes ( KindOfType  kindOfType,
TypeID const &  typeID 
) const

Definition at line 198 of file ProductResolverIndexHelper.cc.

References indexToType(), SiStripPI::max, FastTimerService_cff::range, and ranges_.

199  {
200  unsigned int startInIndexAndNames = std::numeric_limits<unsigned int>::max();
201  unsigned int numberOfMatches = 0;
202 
203  // Look for the type and check to see if it found it
204  unsigned iType = indexToType(kindOfType, typeID);
206  // Get the range of entries with a matching TypeID
207  Range const& range = ranges_[iType];
208 
209  startInIndexAndNames = range.begin();
210  numberOfMatches = range.end() - range.begin();
211  }
212  return Matches(this, startInIndexAndNames, numberOfMatches);
213  }
PixelRecoRange< float > Range
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const

◆ sanityCheck()

void edm::ProductResolverIndexHelper::sanityCheck ( ) const

Definition at line 609 of file ProductResolverIndexHelper.cc.

References bigNamesContainer_, Exception, indexAndNames_, dqmiolumiharvest::j, edm::errors::LogicError, nextIndexValue_, processNames_, edm::ProductResolverIndexAmbiguous, FastTimerService_cff::range, ranges_, and sortedTypeIDs_.

Referenced by setFrozen().

609  {
610  bool sanityChecksPass = true;
611  if (sortedTypeIDs_.size() != ranges_.size())
612  sanityChecksPass = false;
613 
614  unsigned int previousEnd = 0;
615  for (auto const& range : ranges_) {
616  if (range.begin() != previousEnd)
617  sanityChecksPass = false;
618  if (range.begin() >= range.end())
619  sanityChecksPass = false;
620  previousEnd = range.end();
621  }
622  if (previousEnd != indexAndNames_.size())
623  sanityChecksPass = false;
624 
625  unsigned maxStart = 0;
626  unsigned maxStartProcess = 0;
627  for (auto const& indexAndName : indexAndNames_) {
628  if (indexAndName.index() >= nextIndexValue_ && indexAndName.index() != ProductResolverIndexAmbiguous)
629  sanityChecksPass = false;
630 
631  if (indexAndName.startInBigNamesContainer() >= bigNamesContainer_.size())
632  sanityChecksPass = false;
633  if (indexAndName.startInProcessNames() >= processNames_.size())
634  sanityChecksPass = false;
635 
636  if (indexAndName.startInBigNamesContainer() > maxStart)
637  maxStart = indexAndName.startInBigNamesContainer();
638  if (indexAndName.startInProcessNames() > maxStartProcess)
639  maxStartProcess = indexAndName.startInProcessNames();
640  }
641 
642  if (!indexAndNames_.empty()) {
643  if (bigNamesContainer_.back() != '\0')
644  sanityChecksPass = false;
645  if (processNames_.back() != '\0')
646  sanityChecksPass = false;
647  if (maxStart >= bigNamesContainer_.size())
648  sanityChecksPass = false;
649  unsigned int countZeroes = 0;
650  for (unsigned j = maxStart; j < bigNamesContainer_.size(); ++j) {
651  if (bigNamesContainer_[j] == '\0') {
652  ++countZeroes;
653  }
654  }
655  if (countZeroes != 2)
656  sanityChecksPass = false;
657  if (maxStartProcess >= processNames_.size())
658  sanityChecksPass = false;
659  countZeroes = 0;
660  for (unsigned j = maxStartProcess; j < processNames_.size(); ++j) {
661  if (processNames_[j] == '\0') {
662  ++countZeroes;
663  }
664  }
665  if (countZeroes != 1)
666  sanityChecksPass = false;
667  }
668 
669  if (!sanityChecksPass) {
670  throw Exception(errors::LogicError) << "ProductResolverIndexHelper::setFrozen - Detected illegal state.\n";
671  }
672  }
std::vector< IndexAndNames > indexAndNames_

◆ setFrozen()

void edm::ProductResolverIndexHelper::setFrozen ( )

Definition at line 315 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.

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

◆ sortedTypeIDs()

std::vector<TypeID> const& edm::ProductResolverIndexHelper::sortedTypeIDs ( ) const
inline

Definition at line 229 of file ProductResolverIndexHelper.h.

References sortedTypeIDs_.

229 { return sortedTypeIDs_; }

Member Data Documentation

◆ beginElements_

unsigned int edm::ProductResolverIndexHelper::beginElements_
private

◆ bigNamesContainer_

std::vector<char> edm::ProductResolverIndexHelper::bigNamesContainer_
private

◆ indexAndNames_

std::vector<IndexAndNames> edm::ProductResolverIndexHelper::indexAndNames_
private

◆ items_

edm::propagate_const<std::unique_ptr<std::set<Item> > > edm::ProductResolverIndexHelper::items_
private

Definition at line 346 of file ProductResolverIndexHelper.h.

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

◆ lookupProcessNames_

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

Definition at line 312 of file ProductResolverIndexHelper.h.

Referenced by lookupProcessNames(), and setFrozen().

◆ nextIndexValue_

ProductResolverIndex edm::ProductResolverIndexHelper::nextIndexValue_
private

Definition at line 264 of file ProductResolverIndexHelper.h.

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

◆ processItems_

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

Definition at line 348 of file ProductResolverIndexHelper.h.

Referenced by print(), and setFrozen().

◆ processNames_

std::vector<char> edm::ProductResolverIndexHelper::processNames_
private

◆ ranges_

std::vector<Range> edm::ProductResolverIndexHelper::ranges_
private

◆ sortedTypeIDs_

std::vector<TypeID> edm::ProductResolverIndexHelper::sortedTypeIDs_
private