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 216 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(), 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 219 of file ProductHolderIndexHelper.h.

References indexAndNames_.

219 { 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 396 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().

400  {
401 
402  // Look for the type and check to see if it found it
403  unsigned iType = indexToType(kindOfType, typeID);
405 
406  unsigned startProcess = 0;
407  if (process) {
408  startProcess = processIndex(process);
409  if (startProcess == std::numeric_limits<unsigned int>::max()) {
411  }
412  }
413 
414  ProductHolderIndexHelper::Range const& range = ranges_[iType];
415  unsigned int begin = range.begin();
416  unsigned int end = range.end();
417 
418  while (begin < end) {
419 
420  unsigned int midpoint = begin + ((end - begin) / 2);
421  char const* namePtr = &bigNamesContainer_[indexAndNames_[midpoint].startInBigNamesContainer()];
422 
423  // Compare the module label
424  char const* label = moduleLabel;
425  while (*namePtr && (*namePtr == *label)) {
426  ++namePtr; ++label;
427  }
428  if (*namePtr == *label) { // true only if both are at the '\0' at the end of the C string
429  ++namePtr; // move to the next C string
430 
431  // Compare the instance name
432  char const* instanceName = instance;
433  while (*namePtr && (*namePtr == *instanceName)) {
434  ++namePtr; ++instanceName;
435  }
436  if (*namePtr == *instanceName) {
437 
438  // Compare the process name
439  if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
440  return midpoint;
441  } else {
442  if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
443  while (true) {
444  --midpoint;
445  if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
446  return midpoint;
447  }
448  if (indexAndNames_[midpoint].startInProcessNames() == 0) break;
449  }
450  } else {
451  while (true) {
452  ++midpoint;
453  if (midpoint == indexAndNames_.size()) break;
454  if (indexAndNames_[midpoint].startInProcessNames() == 0) break;
455  if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
456  return midpoint;
457  }
458  }
459  }
460  break;
461  }
462  } else if (*namePtr < *instanceName) {
463  if (begin == midpoint) break;
464  begin = midpoint;
465  } else {
466  end = midpoint;
467  }
468  } else if (*namePtr < *label) {
469  if (begin == midpoint) break;
470  begin = midpoint;
471  } else {
472  end = midpoint;
473  }
474  } // end while (begin < end)
475  }
477  }
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 480 of file ProductHolderIndexHelper.cc.

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

Referenced by indexToIndexAndNames(), and relatedIndexes().

481  {
482 
483  unsigned int beginType = 0;
484  unsigned int endType = beginElements_;
485  if (kindOfType == ELEMENT_TYPE) {
486  beginType = beginElements_;
487  endType = sortedTypeIDs_.size();
488  }
489 
490  while (beginType < endType) {
491  unsigned int midpointType = beginType + ((endType - beginType) / 2);
492  if (sortedTypeIDs_[midpointType] == typeID) {
493  return midpointType; // Found it
494  } else if (sortedTypeIDs_[midpointType] < typeID) {
495  if (beginType == midpointType) break;
496  beginType = midpointType;
497  } else {
498  endType = midpointType;
499  }
500  }
501  return std::numeric_limits<unsigned int>::max(); // Failed to find it
502  }
ProductHolderIndex edm::ProductHolderIndexHelper::insert ( TypeID const &  typeID,
char const *  moduleLabel,
char const *  instance,
char const *  process,
TypeID const &  containedTypeID 
)

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

164  {
165  if (!items_) {
167  << "ProductHolderIndexHelper::insert - Attempt to insert more elements after frozen.\n";
168  }
169 
170  if (process == 0 || *process == '\0') {
172  << "ProductHolderIndexHelper::insert - Empty process.\n";
173  }
174 
175  // Throw if this has already been inserted
176  Item item(PRODUCT_TYPE, typeID, moduleLabel, instance, process, 0);
177  std::set<Item>::iterator iter = items_->find(item);
178  if (iter != items_->end()) {
180  << "ProductHolderIndexHelper::insert - Attempt to insert duplicate entry.\n";
181  }
182 
183  // Put in an entry for the product
184  item.setIndex(nextIndexValue_);
185  unsigned int savedProductIndex = nextIndexValue_;
186  ++nextIndexValue_;
187  items_->insert(item);
188 
189  // Put in an entry for the product with an empty process name
190  // if it is not already there
191  item.clearProcess();
192  iter = items_->find(item);
193  if (iter == items_->end()) {
194  item.setIndex(nextIndexValue_);
195  ++nextIndexValue_;
196  items_->insert(item);
197  }
198 
199  // Now put in entries for a contained class if this is a
200  // recognized container.
201  if(containedTypeID != TypeID(typeid(void)) && containedTypeID != TypeID()) {
202  TypeWithDict containedType(containedTypeID.typeInfo());
203 
204  Item containedItem(ELEMENT_TYPE, containedTypeID, moduleLabel, instance, process, savedProductIndex);
205  iter = items_->find(containedItem);
206  if (iter != items_->end()) {
207  containedItem.setIndex(ProductHolderIndexAmbiguous);
208  items_->erase(iter);
209  }
210  items_->insert(containedItem);
211 
212  containedItem.clearProcess();
213  iter = items_->find(containedItem);
214  if (iter == items_->end()) {
215  containedItem.setIndex(nextIndexValue_);
216  ++nextIndexValue_;
217  items_->insert(containedItem);
218  }
219 
220  // Repeat this for all public base classes of the contained type
221  std::vector<TypeWithDict> baseTypes;
222  public_base_classes(containedType, baseTypes);
223 
224  for(TypeWithDict const& baseType : baseTypes) {
225 
226  TypeID baseTypeID(baseType.typeInfo());
227  Item baseItem(ELEMENT_TYPE, baseTypeID, moduleLabel, instance, process, savedProductIndex);
228  iter = items_->find(baseItem);
229  if (iter != items_->end()) {
230  baseItem.setIndex(ProductHolderIndexAmbiguous);
231  items_->erase(iter);
232  }
233  items_->insert(baseItem);
234 
235  baseItem.clearProcess();
236  iter = items_->find(baseItem);
237  if (iter == items_->end()) {
238  baseItem.setIndex(nextIndexValue_);
239  ++nextIndexValue_;
240  items_->insert(baseItem);
241  }
242  }
243  }
244  return savedProductIndex;
245  }
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 179 of file ProductHolderIndexHelper.h.

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

Referenced by BeautifulSoup.PageElement::_invert().

182  {
183  return insert(typeID, moduleLabel, instance, process, productholderindexhelper::getContainedType(typeID));
184  }
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 387 of file ProductHolderIndexHelper.cc.

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

387  {
388  if (items_) {
390  << "ProductHolderIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
391  }
392  return lookupProcessNames_;
393  }
std::vector< std::string > lookupProcessNames_
std::unique_ptr< std::set< Item > > items_
ProductHolderIndex edm::ProductHolderIndexHelper::nextIndexValue ( ) const
inline

Definition at line 244 of file ProductHolderIndexHelper.h.

References nextIndexValue_.

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

Definition at line 607 of file ProductHolderIndexHelper.cc.

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

607  {
608 
609  os << "\n******* Dump ProductHolderIndexHelper *************************\n";
610 
611  os << "\nnextIndexValue_ = " << nextIndexValue_ << "\n";
612  os << "beginElements_ = " << beginElements_ << "\n";
613 
614  os << "\n******* sortedTypeIDs_ \n";
615  for (auto const& i : sortedTypeIDs_) {
616  os << i << "\n";
617  }
618  os << "******* ranges_ \n";
619  for (auto const& i : ranges_) {
620  os << i.begin() << " " << i.end() << "\n";
621  }
622  os << "******* indexAndNames_ \n";
623  for (auto const& i : indexAndNames_) {
624  os << i.index() << " " << i.startInBigNamesContainer() << " ";
625  char const* ptr = &bigNamesContainer_[i.startInBigNamesContainer()];
626  while (*ptr) {
627  os << *ptr;
628  ++ptr;
629  }
630  ++ptr;
631  os << " ";
632  while (*ptr) {
633  os << *ptr;
634  ++ptr;
635  }
636  os << " " << i.startInProcessNames() << " ";
637  ptr = &processNames_[i.startInProcessNames()];
638  while (*ptr) {
639  os << *ptr;
640  ++ptr;
641  }
642  os << "\n";
643  }
644  os << "******* bigNamesContainer_ \n";
645  for (auto i : bigNamesContainer_) {
646  if (i == '\0') os << '\\' << '0';
647  else os << i;
648  }
649  if (!bigNamesContainer_.empty()) os << "\n";
650  os << "******* processNames_ \n";
651  for (auto i : processNames_) {
652  if (i == '\0') os << '\\' << '0';
653  else os << i;
654  }
655  if (!processNames_.empty()) os << "\n";
656  if (items_) {
657  os << "******* items_ \n";
658  for (auto const& item : *items_) {
659  std:: cout << item.kindOfType() << " " << item.moduleLabel() << " " << item.instance() << " " << item.process() << " " << item.index() << " " << item.typeID() << "\n";
660  }
661  }
662  if (processItems_) {
663  os << "******* processItems_ \n";
664  for (auto const& item : *processItems_) {
665  os << item << "\n";
666  }
667  }
668  os << "sortedTypeIDs_.size() = " << sortedTypeIDs_.size() << "\n";
669  os << "indexAndNames_.size() = " << indexAndNames_.size() << "\n";
670  os << "bigNamesContainer_.size() = " << bigNamesContainer_.size() << "\n";
671  os << "processNames_.size() = " << processNames_.size() << "\n";
672  os << "\n";
673  }
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 504 of file ProductHolderIndexHelper.cc.

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

Referenced by indexToIndexAndNames(), and setFrozen().

504  {
505 
506  char const* ptr = &processNames_[0];
507  char const* begin = ptr;
508  while (true) {
509  char const* p = process;
510  char const* beginName = ptr;
511  while (*ptr && (*ptr == *p)) {
512  ++ptr; ++p;
513  }
514  if (*ptr == *p) {
515  return beginName - begin;
516  }
517  while (*ptr) {
518  ++ptr;
519  }
520  ++ptr;
521  if (static_cast<unsigned>(ptr - begin) >= processNames_.size()) {
523  }
524  }
525  return 0;
526  }
#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 220 of file ProductHolderIndexHelper.h.

References processNames_.

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

Definition at line 218 of file ProductHolderIndexHelper.h.

References ranges_.

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

Definition at line 114 of file ProductHolderIndexHelper.cc.

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

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

117  {
118 
119  unsigned int startInIndexAndNames = indexToIndexAndNames(kindOfType,
120  typeID,
121  moduleLabel,
122  instance,
123  0);
124  unsigned int numberOfMatches = 1;
125 
126  if (startInIndexAndNames == std::numeric_limits<unsigned int>::max()) {
127  numberOfMatches = 0;
128  } else {
129  auto vSize = indexAndNames_.size();
130  for (unsigned int j = startInIndexAndNames + 1U;
131  j < vSize && (indexAndNames_[j].startInProcessNames() != 0U);
132  ++j) {
133  ++numberOfMatches;
134  }
135  }
136  return Matches(this, startInIndexAndNames, numberOfMatches);
137  }
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 140 of file ProductHolderIndexHelper.cc.

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

141  {
142 
143  unsigned int startInIndexAndNames = std::numeric_limits<unsigned int>::max();
144  unsigned int numberOfMatches = 0;
145 
146  // Look for the type and check to see if it found it
147  unsigned iType = indexToType(kindOfType, typeID);
149 
150  // Get the range of entries with a matching TypeID
151  Range const& range = ranges_[iType];
152 
153  startInIndexAndNames = range.begin();
154  numberOfMatches = range.end() - range.begin();
155  }
156  return Matches(this, startInIndexAndNames, numberOfMatches);
157  }
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const
PixelRecoRange< float > Range
void edm::ProductHolderIndexHelper::sanityCheck ( ) const

Definition at line 528 of file ProductHolderIndexHelper.cc.

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

Referenced by setFrozen().

528  {
529  bool sanityChecksPass = true;
530  if (sortedTypeIDs_.size() != ranges_.size()) sanityChecksPass = false;
531 
532  unsigned int previousEnd = 0;
533  for ( auto const& range : ranges_) {
534  if (range.begin() != previousEnd) sanityChecksPass = false;
535  if (range.begin() >= range.end()) sanityChecksPass = false;
536  previousEnd = range.end();
537  }
538  if (previousEnd != indexAndNames_.size()) sanityChecksPass = false;
539 
540 
541  unsigned maxStart = 0;
542  unsigned maxStartProcess = 0;
543  for (auto const& indexAndName : indexAndNames_) {
544  if (indexAndName.index() >= nextIndexValue_ && indexAndName.index() != ProductHolderIndexAmbiguous) sanityChecksPass = false;
545 
546  if (indexAndName.startInBigNamesContainer() >= bigNamesContainer_.size()) sanityChecksPass = false;
547  if (indexAndName.startInProcessNames() >= processNames_.size()) sanityChecksPass = false;
548 
549  if (indexAndName.startInBigNamesContainer() > maxStart) maxStart = indexAndName.startInBigNamesContainer();
550  if (indexAndName.startInProcessNames() > maxStartProcess) maxStartProcess = indexAndName.startInProcessNames();
551  }
552 
553  if (!indexAndNames_.empty()) {
554  if (bigNamesContainer_.back() != '\0') sanityChecksPass = false;
555  if (processNames_.back() != '\0') sanityChecksPass = false;
556  if (maxStart >= bigNamesContainer_.size()) sanityChecksPass = false;
557  unsigned int countZeroes = 0;
558  for (unsigned j = maxStart; j < bigNamesContainer_.size(); ++j) {
559  if (bigNamesContainer_[j] == '\0') {
560  ++countZeroes;
561  }
562  }
563  if (countZeroes != 2) sanityChecksPass = false;
564  if (maxStartProcess >= processNames_.size()) sanityChecksPass = false;
565  countZeroes = 0;
566  for (unsigned j = maxStartProcess; j < processNames_.size(); ++j) {
567  if (processNames_[j] == '\0') {
568  ++countZeroes;
569  }
570  }
571  if (countZeroes != 1) sanityChecksPass = false;
572  }
573 
574  if (!sanityChecksPass) {
576  << "ProductHolderIndexHelper::setFrozen - Detected illegal state.\n";
577  }
578  }
std::vector< IndexAndNames > indexAndNames_
int j
Definition: DBlmapReader.cc:9
void edm::ProductHolderIndexHelper::setFrozen ( )

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

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

References sortedTypeIDs_.

217 { return sortedTypeIDs_; }

Member Data Documentation

unsigned int edm::ProductHolderIndexHelper::beginElements_
private

Definition at line 258 of file ProductHolderIndexHelper.h.

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

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

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

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

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

Definition at line 301 of file ProductHolderIndexHelper.h.

Referenced by lookupProcessNames(), and setFrozen().

ProductHolderIndex edm::ProductHolderIndexHelper::nextIndexValue_
private

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

Referenced by print(), and setFrozen().

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

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

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