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< TypeID > *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 227 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::TransformerBase::extendUpdateLookup(), edm::Principal::findProductByLabel(), edm::PrincipalGetAdapter::getBranchDescription(), 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 230 of file ProductResolverIndexHelper.h.

References indexAndNames_.

Referenced by indiciesForModulesInProcess().

230 { 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 448 of file ProductResolverIndexHelper.cc.

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

Referenced by index(), and relatedIndexes().

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

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

Referenced by indexToIndexAndNames(), and relatedIndexes().

534  {
535  unsigned int beginType = 0;
536  unsigned int endType = beginElements_;
537  if (kindOfType == ELEMENT_TYPE) {
538  beginType = beginElements_;
539  endType = sortedTypeIDs_.size();
540  }
541 
542  while (beginType < endType) {
543  unsigned int midpointType = beginType + ((endType - beginType) / 2);
544  if (sortedTypeIDs_[midpointType] == typeID) {
545  return midpointType; // Found it
546  } else if (sortedTypeIDs_[midpointType] < typeID) {
547  if (beginType == midpointType)
548  break;
549  beginType = midpointType;
550  } else {
551  endType = midpointType;
552  }
553  }
554  return std::numeric_limits<unsigned int>::max(); // Failed to find it
555  }

◆ indiciesForModulesInProcess()

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

Definition at line 581 of file ProductResolverIndexHelper.cc.

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

582  {
584  for (unsigned int i = 0; i < beginElements_; ++i) {
585  auto const& range = ranges_[i];
586  for (unsigned int j = range.begin(); j < range.end(); ++j) {
587  auto const& indexAndNames = indexAndNames_[j];
588  if (0 == strcmp(&processNames_[indexAndNames.startInProcessNames()], iProcessName.c_str())) {
589  //The first null terminated string is the module label
590  auto pModLabel = &bigNamesContainer_[indexAndNames.startInBigNamesContainer()];
591  auto l = strlen(pModLabel);
592  auto pInstance = pModLabel + l + 1;
593  result.emplace(pModLabel, std::make_tuple(&sortedTypeIDs_[i], pInstance, indexAndNames.index()));
594  }
595  }
596  }
597  return result;
598  }
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< TypeID > *  baseTypesOfContainedType 
)

Definition at line 207 of file ProductResolverIndexHelper.cc.

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

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

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

294  {
295  TypeID containedTypeID = productholderindexhelper::getContainedType(typeID);
296  bool hasContainedType = (containedTypeID != TypeID(typeid(void)) && containedTypeID != TypeID());
297  std::vector<TypeID> baseTypes;
298  std::vector<TypeID>* baseTypesOfContainedType = &baseTypes;
299  if (hasContainedType) {
300  std::vector<std::string> missingDictionaries;
301  public_base_classes(missingDictionaries, containedTypeID, baseTypes);
302  }
303  return insert(typeID, moduleLabel, instance, process, containedTypeID, baseTypesOfContainedType);
304  }
TypeID getContainedType(TypeID const &typeID)
bool public_base_classes(std::vector< std::string > &missingDictionaries, TypeID const &typeID, std::vector< TypeID > &baseTypes)
static PFTauRenderPlugin instance
ProductResolverIndex insert(TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process, TypeID const &containedTypeID, std::vector< TypeID > *baseTypesOfContainedType)

◆ lookupProcessNames()

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

Definition at line 440 of file ProductResolverIndexHelper.cc.

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

440  {
441  if (items_) {
443  << "ProductResolverIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
444  }
445  return lookupProcessNames_;
446  }
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 255 of file ProductResolverIndexHelper.h.

References nextIndexValue_.

255 { return nextIndexValue_; }

◆ print()

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

Definition at line 698 of file ProductResolverIndexHelper.cc.

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

698  {
699  os << "\n******* Dump ProductResolverIndexHelper *************************\n";
700 
701  os << "\nnextIndexValue_ = " << nextIndexValue_ << "\n";
702  os << "beginElements_ = " << beginElements_ << "\n";
703 
704  os << "\n******* sortedTypeIDs_ \n";
705  for (auto const& i : sortedTypeIDs_) {
706  os << i << "\n";
707  }
708  os << "******* ranges_ \n";
709  for (auto const& i : ranges_) {
710  os << i.begin() << " " << i.end() << "\n";
711  }
712  os << "******* indexAndNames_ \n";
713  for (auto const& i : indexAndNames_) {
714  os << i.index() << " " << i.startInBigNamesContainer() << " ";
715  char const* ptr = &bigNamesContainer_[i.startInBigNamesContainer()];
716  while (*ptr) {
717  os << *ptr;
718  ++ptr;
719  }
720  ++ptr;
721  os << " ";
722  while (*ptr) {
723  os << *ptr;
724  ++ptr;
725  }
726  os << " " << i.startInProcessNames() << " ";
727  ptr = &processNames_[i.startInProcessNames()];
728  while (*ptr) {
729  os << *ptr;
730  ++ptr;
731  }
732  os << "\n";
733  }
734  os << "******* bigNamesContainer_ \n";
735  for (auto i : bigNamesContainer_) {
736  if (i == '\0')
737  os << '\\' << '0';
738  else
739  os << i;
740  }
741  if (!bigNamesContainer_.empty())
742  os << "\n";
743  os << "******* processNames_ \n";
744  for (auto i : processNames_) {
745  if (i == '\0')
746  os << '\\' << '0';
747  else
748  os << i;
749  }
750  if (!processNames_.empty())
751  os << "\n";
752  if (items_) {
753  os << "******* items_ \n";
754  for (auto const& item : *items_) {
755  std::cout << item.kindOfType() << " " << item.moduleLabel() << " " << item.instance() << " " << item.process()
756  << " " << item.index() << " " << item.typeID() << "\n";
757  }
758  }
759  if (processItems_) {
760  os << "******* processItems_ \n";
761  for (auto const& item : *processItems_) {
762  os << item << "\n";
763  }
764  }
765  os << "sortedTypeIDs_.size() = " << sortedTypeIDs_.size() << "\n";
766  os << "indexAndNames_.size() = " << indexAndNames_.size() << "\n";
767  os << "bigNamesContainer_.size() = " << bigNamesContainer_.size() << "\n";
768  os << "processNames_.size() = " << processNames_.size() << "\n";
769  os << "\n";
770  }
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 557 of file ProductResolverIndexHelper.cc.

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

Referenced by indexToIndexAndNames(), and setFrozen().

557  {
558  char const* ptr = &processNames_[0];
559  char const* begin = ptr;
560  while (true) {
561  char const* p = process;
562  char const* beginName = ptr;
563  while (*ptr && (*ptr == *p)) {
564  ++ptr;
565  ++p;
566  }
567  if (*ptr == *p) {
568  return beginName - begin;
569  }
570  while (*ptr) {
571  ++ptr;
572  }
573  ++ptr;
574  if (static_cast<unsigned>(ptr - begin) >= processNames_.size()) {
576  }
577  }
578  return 0;
579  }

◆ processNames()

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

Definition at line 231 of file ProductResolverIndexHelper.h.

References processNames_.

231 { return processNames_; }

◆ ranges()

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

Definition at line 229 of file ProductResolverIndexHelper.h.

References ranges_.

229 { 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 171 of file ProductResolverIndexHelper.cc.

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

174  {
175  unsigned int startInIndexAndNames = indexToIndexAndNames(kindOfType, typeID, moduleLabel, instance, nullptr);
176  unsigned int numberOfMatches = 1;
177 
178  if (startInIndexAndNames == std::numeric_limits<unsigned int>::max()) {
179  numberOfMatches = 0;
180  } else {
181  auto vSize = indexAndNames_.size();
182  for (unsigned int j = startInIndexAndNames + 1U; j < vSize && (indexAndNames_[j].startInProcessNames() != 0U);
183  ++j) {
184  ++numberOfMatches;
185  }
186  }
187  return Matches(this, startInIndexAndNames, numberOfMatches);
188  }
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 190 of file ProductResolverIndexHelper.cc.

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

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

◆ sanityCheck()

void edm::ProductResolverIndexHelper::sanityCheck ( ) const

Definition at line 600 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().

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

◆ setFrozen()

void edm::ProductResolverIndexHelper::setFrozen ( )

Definition at line 306 of file ProductResolverIndexHelper.cc.

References beginElements_, bigNamesContainer_, HltBtagPostValidation_cff::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.

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

References sortedTypeIDs_.

228 { 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 345 of file ProductResolverIndexHelper.h.

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

◆ lookupProcessNames_

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

Definition at line 311 of file ProductResolverIndexHelper.h.

Referenced by lookupProcessNames(), and setFrozen().

◆ nextIndexValue_

ProductResolverIndex edm::ProductResolverIndexHelper::nextIndexValue_
private

Definition at line 263 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 347 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