CMS 3D CMS Logo

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

#include <ProductHolderIndexHelper.h>

Classes

class  IndexAndNames
 
class  Item
 
class  Matches
 
class  Range
 

Public Member Functions

unsigned int beginElements () const
 
ProductHolderIndex 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
 
ProductHolderIndex insert (TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process, TypeID const &containedTypeID)
 
ProductHolderIndex insert (TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process)
 
std::vector< std::string > const & lookupProcessNames () const
 
ProductHolderIndex nextIndexValue () const
 
void print (std::ostream &os) const
 
unsigned int processIndex (char const *process) const
 
std::vector< char > const & processNames () const
 
 ProductHolderIndexHelper ()
 
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_
 
std::unique_ptr< std::set< Item > > items_
 
std::vector< std::string > lookupProcessNames_
 
ProductHolderIndex nextIndexValue_
 
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 ProductHolderIndex associated with a type, module label, instance, and process. The ProductHolderIndex is used to tell the Principal where to store a ProductHolder and how to find it quickly.

One can also look up the same ProductHolderIndex'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 ProductHolderIndex's generated where the process name is empty. These indexes refer to a special ProductHolders that search for a matching product from the most recent process that has a matching type, label and instance. There is ProductHolderIndex 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 ProductHolders.

The ProductHolderIndex 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 ProductHolderIndexes can be safely cached in InputTags and possibly other places, because they never change within a process. The ProductHolderIndex for a particular product is not intended to be persistent and will be different in different processes.

The ProductHolderIndex is used to order the placement of the ProductHolders in the Principal that are either present in the input or produced in the current process. Be aware that there are other ProductHolders for products that come after ProductHolders 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 ProductHolders 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 84 of file ProductHolderIndexHelper.h.

Constructor & Destructor Documentation

edm::ProductHolderIndexHelper::ProductHolderIndexHelper ( )

Definition at line 57 of file ProductHolderIndexHelper.cc.

57  :
58  nextIndexValue_(0),
59  beginElements_(0),
60  items_(new std::set<ProductHolderIndexHelper::Item>),
61  processItems_(new std::set<std::string>) {
62  }
std::unique_ptr< std::set< std::string > > processItems_
std::unique_ptr< std::set< Item > > items_

Member Function Documentation

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

Definition at line 218 of file ProductHolderIndexHelper.h.

References beginElements_.

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

Definition at line 65 of file ProductHolderIndexHelper.cc.

References indexAndNames_, indexToIndexAndNames(), bookConverter::max, and edm::ProductHolderIndexInvalid.

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

69  {
70 
71  unsigned int iToIndexAndNames = indexToIndexAndNames(kindOfType,
72  typeID,
73  moduleLabel,
74  instance,
75  process);
76 
77  if (iToIndexAndNames == std::numeric_limits<unsigned int>::max()) {
79  }
80  return indexAndNames_[iToIndexAndNames].index();
81  }
static PFTauRenderPlugin instance
std::vector< IndexAndNames > indexAndNames_
tuple process
Definition: LaserDQM_cfg.py:3
unsigned int indexToIndexAndNames(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process) const
std::vector<IndexAndNames> const& edm::ProductHolderIndexHelper::indexAndNames ( ) const
inline

Definition at line 221 of file ProductHolderIndexHelper.h.

References indexAndNames_.

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

Definition at line 416 of file ProductHolderIndexHelper.cc.

References begin, edm::ProductHolderIndexHelper::Range::begin(), bigNamesContainer_, end, edm::ProductHolderIndexHelper::Range::end(), indexAndNames_, indexToType(), instance, diffTwoXMLs::label, bookConverter::max, processIndex(), and ranges_.

Referenced by index(), and relatedIndexes().

420  {
421 
422  // Look for the type and check to see if it found it
423  unsigned iType = indexToType(kindOfType, typeID);
425 
426  unsigned startProcess = 0;
427  if (process) {
428  startProcess = processIndex(process);
429  if (startProcess == std::numeric_limits<unsigned int>::max()) {
431  }
432  }
433 
434  ProductHolderIndexHelper::Range const& range = ranges_[iType];
435  unsigned int begin = range.begin();
436  unsigned int end = range.end();
437 
438  while (begin < end) {
439 
440  unsigned int midpoint = begin + ((end - begin) / 2);
441  char const* namePtr = &bigNamesContainer_[indexAndNames_[midpoint].startInBigNamesContainer()];
442 
443  // Compare the module label
444  char const* label = moduleLabel;
445  while (*namePtr && (*namePtr == *label)) {
446  ++namePtr; ++label;
447  }
448  if (*namePtr == *label) { // true only if both are at the '\0' at the end of the C string
449  ++namePtr; // move to the next C string
450 
451  // Compare the instance name
452  char const* instanceName = instance;
453  while (*namePtr && (*namePtr == *instanceName)) {
454  ++namePtr; ++instanceName;
455  }
456  if (*namePtr == *instanceName) {
457 
458  // Compare the process name
459  if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
460  return midpoint;
461  } else {
462  if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
463  while (true) {
464  --midpoint;
465  if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
466  return midpoint;
467  }
468  if (indexAndNames_[midpoint].startInProcessNames() == 0) break;
469  }
470  } else {
471  while (true) {
472  ++midpoint;
473  if (midpoint == indexAndNames_.size()) break;
474  if (indexAndNames_[midpoint].startInProcessNames() == 0) break;
475  if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
476  return midpoint;
477  }
478  }
479  }
480  break;
481  }
482  } else if (*namePtr < *instanceName) {
483  if (begin == midpoint) break;
484  begin = midpoint;
485  } else {
486  end = midpoint;
487  }
488  } else if (*namePtr < *label) {
489  if (begin == midpoint) break;
490  begin = midpoint;
491  } else {
492  end = midpoint;
493  }
494  } // end while (begin < end)
495  }
497  }
static PFTauRenderPlugin instance
std::vector< IndexAndNames > indexAndNames_
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const
unsigned int processIndex(char const *process) const
#define end
Definition: vmac.h:37
PixelRecoRange< float > Range
#define begin
Definition: vmac.h:30
tuple process
Definition: LaserDQM_cfg.py:3
unsigned int edm::ProductHolderIndexHelper::indexToType ( KindOfType  kindOfType,
TypeID const &  typeID 
) const

Definition at line 500 of file ProductHolderIndexHelper.cc.

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

Referenced by indexToIndexAndNames(), and relatedIndexes().

501  {
502 
503  unsigned int beginType = 0;
504  unsigned int endType = beginElements_;
505  if (kindOfType == ELEMENT_TYPE) {
506  beginType = beginElements_;
507  endType = sortedTypeIDs_.size();
508  }
509 
510  while (beginType < endType) {
511  unsigned int midpointType = beginType + ((endType - beginType) / 2);
512  if (sortedTypeIDs_[midpointType] == typeID) {
513  return midpointType; // Found it
514  } else if (sortedTypeIDs_[midpointType] < typeID) {
515  if (beginType == midpointType) break;
516  beginType = midpointType;
517  } else {
518  endType = midpointType;
519  }
520  }
521  return std::numeric_limits<unsigned int>::max(); // Failed to find it
522  }
ProductHolderIndex edm::ProductHolderIndexHelper::insert ( TypeID const &  typeID,
char const *  moduleLabel,
char const *  instance,
char const *  process,
TypeID const &  containedTypeID 
)

Definition at line 180 of file ProductHolderIndexHelper.cc.

References edm::ProductHolderIndexHelper::Item::clearProcess(), edm::ELEMENT_TYPE, edm::hlt::Exception, items_, getDQMSummary::iter, edm::errors::LogicError, nextIndexValue_, edm::PRODUCT_TYPE, edm::ProductHolderIndexAmbiguous, edm::public_base_classes(), edm::ProductHolderIndexHelper::Item::setIndex(), and edm::TypeIDBase::typeInfo().

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

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

Definition at line 181 of file ProductHolderIndexHelper.h.

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

Referenced by BeautifulSoup.PageElement::_invert().

184  {
185  return insert(typeID, moduleLabel, instance, process, productholderindexhelper::getContainedType(typeID));
186  }
TypeID getContainedType(TypeID const &typeID)
static PFTauRenderPlugin instance
ProductHolderIndex insert(TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process, TypeID const &containedTypeID)
tuple process
Definition: LaserDQM_cfg.py:3
std::vector< std::string > const & edm::ProductHolderIndexHelper::lookupProcessNames ( ) const

Definition at line 407 of file ProductHolderIndexHelper.cc.

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

407  {
408  if (items_) {
410  << "ProductHolderIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
411  }
412  return lookupProcessNames_;
413  }
std::vector< std::string > lookupProcessNames_
std::unique_ptr< std::set< Item > > items_
ProductHolderIndex edm::ProductHolderIndexHelper::nextIndexValue ( ) const
inline

Definition at line 246 of file ProductHolderIndexHelper.h.

References nextIndexValue_.

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

Definition at line 627 of file ProductHolderIndexHelper.cc.

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

627  {
628 
629  os << "\n******* Dump ProductHolderIndexHelper *************************\n";
630 
631  os << "\nnextIndexValue_ = " << nextIndexValue_ << "\n";
632  os << "beginElements_ = " << beginElements_ << "\n";
633 
634  os << "\n******* sortedTypeIDs_ \n";
635  for (auto const& i : sortedTypeIDs_) {
636  os << i << "\n";
637  }
638  os << "******* ranges_ \n";
639  for (auto const& i : ranges_) {
640  os << i.begin() << " " << i.end() << "\n";
641  }
642  os << "******* indexAndNames_ \n";
643  for (auto const& i : indexAndNames_) {
644  os << i.index() << " " << i.startInBigNamesContainer() << " ";
645  char const* ptr = &bigNamesContainer_[i.startInBigNamesContainer()];
646  while (*ptr) {
647  os << *ptr;
648  ++ptr;
649  }
650  ++ptr;
651  os << " ";
652  while (*ptr) {
653  os << *ptr;
654  ++ptr;
655  }
656  os << " " << i.startInProcessNames() << " ";
657  ptr = &processNames_[i.startInProcessNames()];
658  while (*ptr) {
659  os << *ptr;
660  ++ptr;
661  }
662  os << "\n";
663  }
664  os << "******* bigNamesContainer_ \n";
665  for (auto i : bigNamesContainer_) {
666  if (i == '\0') os << '\\' << '0';
667  else os << i;
668  }
669  if (!bigNamesContainer_.empty()) os << "\n";
670  os << "******* processNames_ \n";
671  for (auto i : processNames_) {
672  if (i == '\0') os << '\\' << '0';
673  else os << i;
674  }
675  if (!processNames_.empty()) os << "\n";
676  if (items_) {
677  os << "******* items_ \n";
678  for (auto const& item : *items_) {
679  std:: cout << item.kindOfType() << " " << item.moduleLabel() << " " << item.instance() << " " << item.process() << " " << item.index() << " " << item.typeID() << "\n";
680  }
681  }
682  if (processItems_) {
683  os << "******* processItems_ \n";
684  for (auto const& item : *processItems_) {
685  os << item << "\n";
686  }
687  }
688  os << "sortedTypeIDs_.size() = " << sortedTypeIDs_.size() << "\n";
689  os << "indexAndNames_.size() = " << indexAndNames_.size() << "\n";
690  os << "bigNamesContainer_.size() = " << bigNamesContainer_.size() << "\n";
691  os << "processNames_.size() = " << processNames_.size() << "\n";
692  os << "\n";
693  }
int i
Definition: DBlmapReader.cc:9
std::unique_ptr< std::set< std::string > > processItems_
std::vector< IndexAndNames > indexAndNames_
std::unique_ptr< std::set< Item > > items_
tuple cout
Definition: gather_cfg.py:121
unsigned int edm::ProductHolderIndexHelper::processIndex ( char const *  process) const

Definition at line 524 of file ProductHolderIndexHelper.cc.

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

Referenced by indexToIndexAndNames(), and setFrozen().

524  {
525 
526  char const* ptr = &processNames_[0];
527  char const* begin = ptr;
528  while (true) {
529  char const* p = process;
530  char const* beginName = ptr;
531  while (*ptr && (*ptr == *p)) {
532  ++ptr; ++p;
533  }
534  if (*ptr == *p) {
535  return beginName - begin;
536  }
537  while (*ptr) {
538  ++ptr;
539  }
540  ++ptr;
541  if (static_cast<unsigned>(ptr - begin) >= processNames_.size()) {
543  }
544  }
545  return 0;
546  }
#define begin
Definition: vmac.h:30
tuple process
Definition: LaserDQM_cfg.py:3
std::vector<char> const& edm::ProductHolderIndexHelper::processNames ( ) const
inline

Definition at line 222 of file ProductHolderIndexHelper.h.

References processNames_.

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

Definition at line 220 of file ProductHolderIndexHelper.h.

References ranges_.

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

Definition at line 134 of file ProductHolderIndexHelper.cc.

References indexAndNames_, indexToIndexAndNames(), j, and bookConverter::max.

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

137  {
138 
139  unsigned int startInIndexAndNames = indexToIndexAndNames(kindOfType,
140  typeID,
141  moduleLabel,
142  instance,
143  0);
144  unsigned int numberOfMatches = 1;
145 
146  if (startInIndexAndNames == std::numeric_limits<unsigned int>::max()) {
147  numberOfMatches = 0;
148  } else {
149  auto vSize = indexAndNames_.size();
150  for (unsigned int j = startInIndexAndNames + 1U;
151  j < vSize && (indexAndNames_[j].startInProcessNames() != 0U);
152  ++j) {
153  ++numberOfMatches;
154  }
155  }
156  return Matches(this, startInIndexAndNames, numberOfMatches);
157  }
static PFTauRenderPlugin instance
std::vector< IndexAndNames > indexAndNames_
int j
Definition: DBlmapReader.cc:9
unsigned int indexToIndexAndNames(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process) const
ProductHolderIndexHelper::Matches edm::ProductHolderIndexHelper::relatedIndexes ( KindOfType  kindOfType,
TypeID const &  typeID 
) const

Definition at line 160 of file ProductHolderIndexHelper.cc.

References edm::ProductHolderIndexHelper::Range::begin(), edm::ProductHolderIndexHelper::Range::end(), indexToType(), bookConverter::max, and ranges_.

161  {
162 
163  unsigned int startInIndexAndNames = std::numeric_limits<unsigned int>::max();
164  unsigned int numberOfMatches = 0;
165 
166  // Look for the type and check to see if it found it
167  unsigned iType = indexToType(kindOfType, typeID);
169 
170  // Get the range of entries with a matching TypeID
171  Range const& range = ranges_[iType];
172 
173  startInIndexAndNames = range.begin();
174  numberOfMatches = range.end() - range.begin();
175  }
176  return Matches(this, startInIndexAndNames, numberOfMatches);
177  }
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const
PixelRecoRange< float > Range
void edm::ProductHolderIndexHelper::sanityCheck ( ) const

Definition at line 548 of file ProductHolderIndexHelper.cc.

References bigNamesContainer_, edm::hlt::Exception, indexAndNames_, j, edm::errors::LogicError, nextIndexValue_, processNames_, edm::ProductHolderIndexAmbiguous, ranges_, and sortedTypeIDs_.

Referenced by setFrozen().

548  {
549  bool sanityChecksPass = true;
550  if (sortedTypeIDs_.size() != ranges_.size()) sanityChecksPass = false;
551 
552  unsigned int previousEnd = 0;
553  for ( auto const& range : ranges_) {
554  if (range.begin() != previousEnd) sanityChecksPass = false;
555  if (range.begin() >= range.end()) sanityChecksPass = false;
556  previousEnd = range.end();
557  }
558  if (previousEnd != indexAndNames_.size()) sanityChecksPass = false;
559 
560 
561  unsigned maxStart = 0;
562  unsigned maxStartProcess = 0;
563  for (auto const& indexAndName : indexAndNames_) {
564  if (indexAndName.index() >= nextIndexValue_ && indexAndName.index() != ProductHolderIndexAmbiguous) sanityChecksPass = false;
565 
566  if (indexAndName.startInBigNamesContainer() >= bigNamesContainer_.size()) sanityChecksPass = false;
567  if (indexAndName.startInProcessNames() >= processNames_.size()) sanityChecksPass = false;
568 
569  if (indexAndName.startInBigNamesContainer() > maxStart) maxStart = indexAndName.startInBigNamesContainer();
570  if (indexAndName.startInProcessNames() > maxStartProcess) maxStartProcess = indexAndName.startInProcessNames();
571  }
572 
573  if (!indexAndNames_.empty()) {
574  if (bigNamesContainer_.back() != '\0') sanityChecksPass = false;
575  if (processNames_.back() != '\0') sanityChecksPass = false;
576  if (maxStart >= bigNamesContainer_.size()) sanityChecksPass = false;
577  unsigned int countZeroes = 0;
578  for (unsigned j = maxStart; j < bigNamesContainer_.size(); ++j) {
579  if (bigNamesContainer_[j] == '\0') {
580  ++countZeroes;
581  }
582  }
583  if (countZeroes != 2) sanityChecksPass = false;
584  if (maxStartProcess >= processNames_.size()) sanityChecksPass = false;
585  countZeroes = 0;
586  for (unsigned j = maxStartProcess; j < processNames_.size(); ++j) {
587  if (processNames_[j] == '\0') {
588  ++countZeroes;
589  }
590  }
591  if (countZeroes != 1) sanityChecksPass = false;
592  }
593 
594  if (!sanityChecksPass) {
596  << "ProductHolderIndexHelper::setFrozen - Detected illegal state.\n";
597  }
598  }
std::vector< IndexAndNames > indexAndNames_
int j
Definition: DBlmapReader.cc:9
void edm::ProductHolderIndexHelper::setFrozen ( )

Definition at line 267 of file ProductHolderIndexHelper.cc.

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

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

Definition at line 219 of file ProductHolderIndexHelper.h.

References sortedTypeIDs_.

219 { return sortedTypeIDs_; }

Member Data Documentation

unsigned int edm::ProductHolderIndexHelper::beginElements_
private

Definition at line 260 of file ProductHolderIndexHelper.h.

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

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

Definition at line 298 of file ProductHolderIndexHelper.h.

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

std::vector<IndexAndNames> edm::ProductHolderIndexHelper::indexAndNames_
private
std::unique_ptr<std::set<Item> > edm::ProductHolderIndexHelper::items_
private

Definition at line 337 of file ProductHolderIndexHelper.h.

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

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

Definition at line 303 of file ProductHolderIndexHelper.h.

Referenced by lookupProcessNames(), and setFrozen().

ProductHolderIndex edm::ProductHolderIndexHelper::nextIndexValue_
private

Definition at line 255 of file ProductHolderIndexHelper.h.

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

std::unique_ptr<std::set<std::string> > edm::ProductHolderIndexHelper::processItems_
private

Definition at line 339 of file ProductHolderIndexHelper.h.

Referenced by print(), and setFrozen().

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

Definition at line 299 of file ProductHolderIndexHelper.h.

Referenced by print(), processIndex(), processNames(), sanityCheck(), and setFrozen().

std::vector<Range> edm::ProductHolderIndexHelper::ranges_
private
std::vector<TypeID> edm::ProductHolderIndexHelper::sortedTypeIDs_
private

Definition at line 267 of file ProductHolderIndexHelper.h.

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