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 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::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 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 456 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().

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

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

Referenced by indexToIndexAndNames(), and relatedIndexes().

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

◆ indiciesForModulesInProcess()

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

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

590  {
592  for (unsigned int i = 0; i < beginElements_; ++i) {
593  auto const& range = ranges_[i];
594  for (unsigned int j = range.begin(); j < range.end(); ++j) {
595  auto const& indexAndNames = indexAndNames_[j];
596  if (0 == strcmp(&processNames_[indexAndNames.startInProcessNames()], iProcessName.c_str())) {
597  //The first null terminated string is the module label
598  auto pModLabel = &bigNamesContainer_[indexAndNames.startInBigNamesContainer()];
599  auto l = strlen(pModLabel);
600  auto pInstance = pModLabel + l + 1;
601  result.emplace(pModLabel, std::make_tuple(&sortedTypeIDs_[i], pInstance, indexAndNames.index()));
602  }
603  }
604  }
605  return result;
606  }
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 215 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().

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 (TypeID const& baseTypeID : *baseTypesOfContainedType) {
278  Item baseItem(ELEMENT_TYPE, baseTypeID, moduleLabel, instance, process, savedProductIndex);
279  iter = items_->find(baseItem);
280  if (iter != items_->end()) {
281  baseItem.setIndex(ProductResolverIndexAmbiguous);
282  items_->erase(iter);
283  }
284  items_->insert(baseItem);
285 
286  baseItem.clearProcess();
287  iter = items_->find(baseItem);
288  if (iter == items_->end()) {
289  baseItem.setIndex(nextIndexValue_);
290  ++nextIndexValue_;
291  items_->insert(baseItem);
292  }
293  }
294  }
295  }
296  return savedProductIndex;
297  }
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 299 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().

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

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

448  {
449  if (items_) {
451  << "ProductResolverIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
452  }
453  return lookupProcessNames_;
454  }
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 706 of file ProductResolverIndexHelper.cc.

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

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

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

Referenced by indexToIndexAndNames(), and setFrozen().

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

◆ 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 608 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().

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

◆ setFrozen()

void edm::ProductResolverIndexHelper::setFrozen ( )

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

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