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 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  }
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 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 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 419 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().

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

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

Referenced by indexToIndexAndNames(), and relatedIndexes().

504  {
505 
506  unsigned int beginType = 0;
507  unsigned int endType = beginElements_;
508  if (kindOfType == ELEMENT_TYPE) {
509  beginType = beginElements_;
510  endType = sortedTypeIDs_.size();
511  }
512 
513  while (beginType < endType) {
514  unsigned int midpointType = beginType + ((endType - beginType) / 2);
515  if (sortedTypeIDs_[midpointType] == typeID) {
516  return midpointType; // Found it
517  } else if (sortedTypeIDs_[midpointType] < typeID) {
518  if (beginType == midpointType) break;
519  beginType = midpointType;
520  } else {
521  endType = midpointType;
522  }
523  }
524  return std::numeric_limits<unsigned int>::max(); // Failed to find it
525  }
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, edm::hlt::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)
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 410 of file ProductHolderIndexHelper.cc.

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

410  {
411  if (items_) {
413  << "ProductHolderIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
414  }
415  return lookupProcessNames_;
416  }
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 630 of file ProductHolderIndexHelper.cc.

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

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

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

Referenced by indexToIndexAndNames(), and setFrozen().

527  {
528 
529  char const* ptr = &processNames_[0];
530  char const* begin = ptr;
531  while (true) {
532  char const* p = process;
533  char const* beginName = ptr;
534  while (*ptr && (*ptr == *p)) {
535  ++ptr; ++p;
536  }
537  if (*ptr == *p) {
538  return beginName - begin;
539  }
540  while (*ptr) {
541  ++ptr;
542  }
543  ++ptr;
544  if (static_cast<unsigned>(ptr - begin) >= processNames_.size()) {
546  }
547  }
548  return 0;
549  }
#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 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  }
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const
PixelRecoRange< float > Range
void edm::ProductHolderIndexHelper::sanityCheck ( ) const

Definition at line 551 of file ProductHolderIndexHelper.cc.

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

Referenced by setFrozen().

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

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  items_.reset();
407  processItems_.reset();
408  }
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().