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, ProductResolverIndex >
 

Public Member Functions

unsigned int beginElements () const
 
ProductResolverIndex index (KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=0) 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 88 of file ProductResolverIndexHelper.h.

Member Typedef Documentation

Definition at line 123 of file ProductResolverIndexHelper.h.

Constructor & Destructor Documentation

edm::ProductResolverIndexHelper::ProductResolverIndexHelper ( )

Definition at line 75 of file ProductResolverIndexHelper.cc.

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

Member Function Documentation

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

Definition at line 224 of file ProductResolverIndexHelper.h.

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

Definition at line 83 of file ProductResolverIndexHelper.cc.

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

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

87  {
88 
89  unsigned int iToIndexAndNames = indexToIndexAndNames(kindOfType,
90  typeID,
91  moduleLabel,
92  instance,
93  process);
94 
95  if (iToIndexAndNames == std::numeric_limits<unsigned int>::max()) {
97  }
98  return indexAndNames_[iToIndexAndNames].index();
99  }
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_
std::vector<IndexAndNames> const& edm::ProductResolverIndexHelper::indexAndNames ( ) const
inline

Definition at line 227 of file ProductResolverIndexHelper.h.

Referenced by indiciesForModulesInProcess().

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

Definition at line 452 of file ProductResolverIndexHelper.cc.

References begin, edm::ProductResolverIndexHelper::Range::begin(), bigNamesContainer_, end, edm::ProductResolverIndexHelper::Range::end(), indexAndNames_, indexToType(), instance, MuonErrorMatrixAdjuster_cfi::instanceName, diffTwoXMLs::label, hpstanc_transforms::max, edm::ProductResolverIndexHelper::Matches::moduleLabel(), processIndex(), and ranges_.

Referenced by index(), and relatedIndexes().

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

Definition at line 536 of file ProductResolverIndexHelper.cc.

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

Referenced by indexToIndexAndNames(), and relatedIndexes().

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

Definition at line 585 of file ProductResolverIndexHelper.cc.

References beginElements_, bigNamesContainer_, mps_fire::i, indexAndNames(), indexAndNames_, processNames_, ranges_, and mps_fire::result.

585  {
586 
588  for(unsigned int i=0; i<beginElements_; ++i) {
589  auto const& range= ranges_[i];
590  for(unsigned int j=range.begin(); j<range.end();++j) {
591  auto const& indexAndNames = indexAndNames_[j];
592  if(0 == strcmp(&processNames_[indexAndNames.startInProcessNames()], iProcessName.c_str())) {
593  //The first null terminated string is the module label
594  result.emplace(&bigNamesContainer_[indexAndNames.startInBigNamesContainer()],indexAndNames.index());
595  }
596  }
597  }
598  return result;
599  }
std::unordered_multimap< std::string, ProductResolverIndex > ModulesToIndiciesMap
std::vector< IndexAndNames > const & indexAndNames() const
std::vector< IndexAndNames > indexAndNames_
ProductResolverIndex edm::ProductResolverIndexHelper::insert ( TypeID const &  typeID,
char const *  moduleLabel,
char const *  instance,
char const *  process,
TypeID const &  containedTypeID,
std::vector< TypeWithDict > *  baseTypesOfContainedType 
)

Definition at line 198 of file ProductResolverIndexHelper.cc.

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

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

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

Definition at line 286 of file ProductResolverIndexHelper.cc.

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

Referenced by BeautifulSoup.PageElement::append().

289  {
290 
291  TypeID containedTypeID = productholderindexhelper::getContainedType(typeID);
292  bool hasContainedType = (containedTypeID != TypeID(typeid(void)) && containedTypeID != TypeID());
293  std::vector<TypeWithDict> baseTypes;
294  std::vector<TypeWithDict>* baseTypesOfContainedType = &baseTypes;
295  if (hasContainedType) {
296  std::vector<std::string> missingDictionaries;
297  public_base_classes(missingDictionaries, containedTypeID, baseTypes);
298  }
299  return insert(typeID, moduleLabel, instance, process, containedTypeID, baseTypesOfContainedType);
300  }
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)
std::vector< std::string > const & edm::ProductResolverIndexHelper::lookupProcessNames ( ) const

Definition at line 443 of file ProductResolverIndexHelper.cc.

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

443  {
444  if (items_) {
446  << "ProductResolverIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
447  }
448  return lookupProcessNames_;
449  }
std::vector< std::string > lookupProcessNames_
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_
ProductResolverIndex edm::ProductResolverIndexHelper::nextIndexValue ( ) const
inline

Definition at line 252 of file ProductResolverIndexHelper.h.

References edm::print().

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

Definition at line 681 of file ProductResolverIndexHelper.cc.

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

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

Definition at line 560 of file ProductResolverIndexHelper.cc.

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

Referenced by indexToIndexAndNames(), and setFrozen().

560  {
561 
562  char const* ptr = &processNames_[0];
563  char const* begin = ptr;
564  while (true) {
565  char const* p = process;
566  char const* beginName = ptr;
567  while (*ptr && (*ptr == *p)) {
568  ++ptr; ++p;
569  }
570  if (*ptr == *p) {
571  return beginName - begin;
572  }
573  while (*ptr) {
574  ++ptr;
575  }
576  ++ptr;
577  if (static_cast<unsigned>(ptr - begin) >= processNames_.size()) {
579  }
580  }
581  return 0;
582  }
#define begin
Definition: vmac.h:30
std::vector<char> const& edm::ProductResolverIndexHelper::processNames ( ) const
inline

Definition at line 228 of file ProductResolverIndexHelper.h.

References LaserDQM_cfg::process.

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

Definition at line 226 of file ProductResolverIndexHelper.h.

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

Definition at line 152 of file ProductResolverIndexHelper.cc.

References indexAndNames_, indexToIndexAndNames(), edm::ProductResolverIndexHelper::Matches::Matches(), hpstanc_transforms::max, edm::ProductResolverIndexHelper::Matches::numberOfMatches(), and mitigatedMETSequence_cff::U.

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

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

Definition at line 178 of file ProductResolverIndexHelper.cc.

References edm::ProductResolverIndexHelper::Range::begin(), edm::ProductResolverIndexHelper::Range::end(), indexToType(), edm::ProductResolverIndexHelper::Matches::Matches(), hpstanc_transforms::max, edm::ProductResolverIndexHelper::Matches::numberOfMatches(), and ranges_.

179  {
180 
181  unsigned int startInIndexAndNames = std::numeric_limits<unsigned int>::max();
182  unsigned int numberOfMatches = 0;
183 
184  // Look for the type and check to see if it found it
185  unsigned iType = indexToType(kindOfType, typeID);
187 
188  // Get the range of entries with a matching TypeID
189  Range const& range = ranges_[iType];
190 
191  startInIndexAndNames = range.begin();
192  numberOfMatches = range.end() - range.begin();
193  }
194  return Matches(this, startInIndexAndNames, numberOfMatches);
195  }
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const
PixelRecoRange< float > Range
void edm::ProductResolverIndexHelper::sanityCheck ( ) const

Definition at line 602 of file ProductResolverIndexHelper.cc.

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

Referenced by setFrozen().

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

Definition at line 302 of file ProductResolverIndexHelper.cc.

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

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

Definition at line 225 of file ProductResolverIndexHelper.h.

225 { return sortedTypeIDs_; }

Member Data Documentation

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

Definition at line 343 of file ProductResolverIndexHelper.h.

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

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

Definition at line 309 of file ProductResolverIndexHelper.h.

Referenced by lookupProcessNames(), and setFrozen().

ProductResolverIndex edm::ProductResolverIndexHelper::nextIndexValue_
private

Definition at line 261 of file ProductResolverIndexHelper.h.

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

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

Definition at line 345 of file ProductResolverIndexHelper.h.

Referenced by print(), and setFrozen().

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

Definition at line 273 of file ProductResolverIndexHelper.h.

Referenced by indexToType(), print(), sanityCheck(), and setFrozen().