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_
 
edm::propagate_const
< std::unique_ptr< std::set
< Item > > > 
items_
 
std::vector< std::string > lookupProcessNames_
 
ProductHolderIndex 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 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 85 of file ProductHolderIndexHelper.h.

Constructor & Destructor Documentation

edm::ProductHolderIndexHelper::ProductHolderIndexHelper ( )

Definition at line 60 of file ProductHolderIndexHelper.cc.

60  :
61  nextIndexValue_(0),
62  beginElements_(0),
63  items_(new std::set<ProductHolderIndexHelper::Item>),
64  processItems_(new std::set<std::string>) {
65  }
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_
edm::propagate_const< std::unique_ptr< std::set< std::string > > > processItems_

Member Function Documentation

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

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

72  {
73 
74  unsigned int iToIndexAndNames = indexToIndexAndNames(kindOfType,
75  typeID,
76  moduleLabel,
77  instance,
78  process);
79 
80  if (iToIndexAndNames == std::numeric_limits<unsigned int>::max()) {
82  }
83  return indexAndNames_[iToIndexAndNames].index();
84  }
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 222 of file ProductHolderIndexHelper.h.

References indexAndNames_.

222 { 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 420 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().

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

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

Referenced by indexToIndexAndNames(), and relatedIndexes().

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

Definition at line 183 of file ProductHolderIndexHelper.cc.

References edm::ProductHolderIndexHelper::Item::clearProcess(), edm::ELEMENT_TYPE, Exception, items_, 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().

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

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

Referenced by BeautifulSoup.PageElement::_invert().

185  {
186  return insert(typeID, moduleLabel, instance, process, productholderindexhelper::getContainedType(typeID));
187  }
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 411 of file ProductHolderIndexHelper.cc.

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

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

Definition at line 247 of file ProductHolderIndexHelper.h.

References nextIndexValue_.

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

Definition at line 631 of file ProductHolderIndexHelper.cc.

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

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

Definition at line 528 of file ProductHolderIndexHelper.cc.

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

Referenced by indexToIndexAndNames(), and setFrozen().

528  {
529 
530  char const* ptr = &processNames_[0];
531  char const* begin = ptr;
532  while (true) {
533  char const* p = process;
534  char const* beginName = ptr;
535  while (*ptr && (*ptr == *p)) {
536  ++ptr; ++p;
537  }
538  if (*ptr == *p) {
539  return beginName - begin;
540  }
541  while (*ptr) {
542  ++ptr;
543  }
544  ++ptr;
545  if (static_cast<unsigned>(ptr - begin) >= processNames_.size()) {
547  }
548  }
549  return 0;
550  }
#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 223 of file ProductHolderIndexHelper.h.

References processNames_.

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

Definition at line 221 of file ProductHolderIndexHelper.h.

References ranges_.

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

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

140  {
141 
142  unsigned int startInIndexAndNames = indexToIndexAndNames(kindOfType,
143  typeID,
144  moduleLabel,
145  instance,
146  0);
147  unsigned int numberOfMatches = 1;
148 
149  if (startInIndexAndNames == std::numeric_limits<unsigned int>::max()) {
150  numberOfMatches = 0;
151  } else {
152  auto vSize = indexAndNames_.size();
153  for (unsigned int j = startInIndexAndNames + 1U;
154  j < vSize && (indexAndNames_[j].startInProcessNames() != 0U);
155  ++j) {
156  ++numberOfMatches;
157  }
158  }
159  return Matches(this, startInIndexAndNames, numberOfMatches);
160  }
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 163 of file ProductHolderIndexHelper.cc.

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

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

Definition at line 552 of file ProductHolderIndexHelper.cc.

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

Referenced by setFrozen().

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

Definition at line 270 of file ProductHolderIndexHelper.cc.

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

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

Definition at line 220 of file ProductHolderIndexHelper.h.

References sortedTypeIDs_.

220 { return sortedTypeIDs_; }

Member Data Documentation

unsigned int edm::ProductHolderIndexHelper::beginElements_
private

Definition at line 261 of file ProductHolderIndexHelper.h.

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

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

Definition at line 299 of file ProductHolderIndexHelper.h.

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

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

Definition at line 338 of file ProductHolderIndexHelper.h.

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

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

Definition at line 304 of file ProductHolderIndexHelper.h.

Referenced by lookupProcessNames(), and setFrozen().

ProductHolderIndex edm::ProductHolderIndexHelper::nextIndexValue_
private

Definition at line 256 of file ProductHolderIndexHelper.h.

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

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

Definition at line 340 of file ProductHolderIndexHelper.h.

Referenced by print(), and setFrozen().

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

Definition at line 300 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 268 of file ProductHolderIndexHelper.h.

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