16 processItems_(new std::set<std::
string>) {
22 char const* moduleLabel,
39 unsigned int startInIndexAndNames,
40 unsigned int numberOfMatches) :
41 productHolderIndexHelper_(productHolderIndexHelper),
42 startInIndexAndNames_(startInIndexAndNames),
43 numberOfMatches_(numberOfMatches) {
46 <<
"ProductHolderIndexHelper::Matches::Matches - Arguments exceed vector bounds.\n";
52 if (i >= numberOfMatches_) {
54 <<
"ProductHolderIndexHelper::Matches::index - Argument is out of range.\n";
56 return productHolderIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].index();
61 if (i >= numberOfMatches_) {
63 <<
"ProductHolderIndexHelper::Matches::isFullyResolved - Argument is out of range.\n";
65 return (productHolderIndexHelper_->indexAndNames_[startInIndexAndNames_ + i].startInProcessNames() != 0U);
71 char const* moduleLabel,
79 unsigned int numberOfMatches = 1;
85 for (
unsigned int j = startInIndexAndNames + 1U;
91 return Matches(
this, startInIndexAndNames, numberOfMatches);
96 TypeID const& typeID)
const {
99 unsigned int numberOfMatches = 0;
108 startInIndexAndNames = range.
begin();
109 numberOfMatches = range.
end() - range.
begin();
111 return Matches(
this, startInIndexAndNames, numberOfMatches);
116 char const* moduleLabel,
121 <<
"ProductHolderIndexHelper::insert - Attempt to insert more elements after frozen.\n";
124 if (process == 0 || *process ==
'\0') {
126 <<
"ProductHolderIndexHelper::insert - Empty process.\n";
133 std::set<Item>::iterator
iter =
items_->find(item);
134 if (iter !=
items_->end()) {
136 <<
"ProductHolderIndexHelper::insert - Attempt to insert duplicate entry.\n";
148 iter =
items_->find(item);
149 if (iter ==
items_->end()) {
162 &&
bool(containedType)) {
165 Item containedItem(
ELEMENT_TYPE, containedTypeID, moduleLabel, instance, process, savedProductIndex);
166 iter =
items_->find(containedItem);
167 if (iter !=
items_->end()) {
171 items_->insert(containedItem);
173 containedItem.clearProcess();
174 iter =
items_->find(containedItem);
175 if (iter ==
items_->end()) {
178 items_->insert(containedItem);
182 std::vector<TypeWithDict> baseTypes;
187 TypeID baseTypeID(baseType.typeInfo());
188 Item baseItem(
ELEMENT_TYPE, baseTypeID, moduleLabel, instance, process, savedProductIndex);
189 iter =
items_->find(baseItem);
190 if (iter !=
items_->end()) {
196 baseItem.clearProcess();
197 iter =
items_->find(baseItem);
198 if (iter ==
items_->end()) {
205 return savedProductIndex;
215 bool iFirstThisType =
true;
216 bool beginElementsWasSet =
false;
221 unsigned int iCountTypes = 0;
222 unsigned int iCountCharacters = 0;
223 for (
auto const& item : *
items_) {
225 if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
227 iFirstThisType =
true;
229 if (!beginElementsWasSet) {
231 beginElementsWasSet =
true;
240 if (iFirstThisType ||
241 item.moduleLabel() != previousModuleLabel ||
242 item.instance() != previousInstance) {
243 iCountCharacters += item.moduleLabel().size();
244 iCountCharacters += item.instance().size();
245 iCountCharacters += 2;
248 iFirstThisType =
false;
249 previousTypeID = item.typeID();
250 previousKindOfType = item.kindOfType();
251 previousModuleLabel = item.moduleLabel();
252 previousInstance = item.instance();
256 unsigned int processNamesSize = 0;
258 processNamesSize += processItem.size();
262 for (
auto const& processItem : *processItems_) {
263 for (
auto const&
c : processItem) {
277 bool iFirstType =
true;
278 iFirstThisType =
true;
279 previousTypeID =
TypeID();
280 unsigned int iCount = 0;
281 unsigned int iBeginning = 0;
282 iCountCharacters = 0;
283 unsigned int previousCharacterCount = 0;
284 if (!items_->empty()) {
285 for (
auto const& item : *items_) {
287 if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
288 iFirstThisType =
true;
299 if (iFirstThisType ||
300 item.moduleLabel() != previousModuleLabel ||
301 item.instance() != previousInstance) {
303 unsigned int labelSize = item.moduleLabel().size();
304 for (
unsigned int j = 0;
j < labelSize; ++
j) {
309 unsigned int instanceSize = item.instance().size();
310 for (
unsigned int j = 0;
j < instanceSize; ++
j) {
315 previousCharacterCount = iCountCharacters;
317 iCountCharacters += labelSize;
318 iCountCharacters += instanceSize;
319 iCountCharacters += 2;
322 unsigned int processStart =
processIndex(item.process().c_str());
325 <<
"ProductHolderIndexHelper::setFrozen - Process not found in processNames_.\n";
327 indexAndNames_.emplace_back(item.index(), previousCharacterCount, processStart);
329 iFirstThisType =
false;
330 previousTypeID = item.typeID();
331 previousKindOfType = item.kindOfType();
332 previousModuleLabel = item.moduleLabel();
333 previousInstance = item.instance();
345 processItems_.reset();
351 <<
"ProductHolderIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
359 char const* moduleLabel,
367 unsigned startProcess = 0;
377 unsigned int end = range.
end();
379 while (begin < end) {
381 unsigned int midpoint = begin + ((end -
begin) / 2);
385 char const*
label = moduleLabel;
386 while (*namePtr && (*namePtr == *label)) {
389 if (*namePtr == *label) {
393 char const* instanceName =
instance;
394 while (*namePtr && (*namePtr == *instanceName)) {
395 ++namePtr; ++instanceName;
397 if (*namePtr == *instanceName) {
400 if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
403 if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
406 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
409 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
414 if (midpoint == indexAndNames_.size())
break;
415 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
416 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
423 }
else if (*namePtr < *instanceName) {
424 if (begin == midpoint)
break;
429 }
else if (*namePtr < *label) {
430 if (begin == midpoint)
break;
442 TypeID const& typeID)
const {
444 unsigned int beginType = 0;
451 while (beginType < endType) {
452 unsigned int midpointType = beginType + ((endType - beginType) / 2);
456 if (beginType == midpointType)
break;
457 beginType = midpointType;
459 endType = midpointType;
468 char const*
begin = ptr;
471 char const* beginName = ptr;
472 while (*ptr && (*ptr == *p)) {
476 return beginName -
begin;
482 if (static_cast<unsigned>(ptr - begin) >=
processNames_.size()) {
490 bool sanityChecksPass =
true;
493 unsigned int previousEnd = 0;
494 for (
auto const& range :
ranges_) {
495 if (range.begin() != previousEnd) sanityChecksPass =
false;
496 if (range.begin() >= range.end()) sanityChecksPass =
false;
497 previousEnd = range.end();
499 if (previousEnd !=
indexAndNames_.size()) sanityChecksPass =
false;
502 unsigned maxStart = 0;
503 unsigned maxStartProcess = 0;
507 if (indexAndName.startInBigNamesContainer() >=
bigNamesContainer_.size()) sanityChecksPass =
false;
508 if (indexAndName.startInProcessNames() >=
processNames_.size()) sanityChecksPass =
false;
510 if (indexAndName.startInBigNamesContainer() > maxStart) maxStart = indexAndName.startInBigNamesContainer();
511 if (indexAndName.startInProcessNames() > maxStartProcess) maxStartProcess = indexAndName.startInProcessNames();
514 if (!indexAndNames_.empty()) {
518 unsigned int countZeroes = 0;
524 if (countZeroes != 2) sanityChecksPass =
false;
525 if (maxStartProcess >=
processNames_.size()) sanityChecksPass =
false;
532 if (countZeroes != 1) sanityChecksPass =
false;
535 if (!sanityChecksPass) {
537 <<
"ProductHolderIndexHelper::setFrozen - Detected illegal state.\n";
547 kindOfType_(kindOfType),
559 if (typeID_ < right.
typeID_)
return true;
560 if (typeID_ > right.
typeID_)
return false;
563 if (instance_ < right.
instance_)
return true;
564 if (instance_ > right.
instance_)
return false;
570 os <<
"\n******* Dump ProductHolderIndexHelper *************************\n";
575 os <<
"\n******* sortedTypeIDs_ \n";
579 os <<
"******* ranges_ \n";
581 os <<
i.begin() <<
" " <<
i.end() <<
"\n";
583 os <<
"******* indexAndNames_ \n";
585 os <<
i.index() <<
" " <<
i.startInBigNamesContainer() <<
" ";
597 os <<
" " <<
i.startInProcessNames() <<
" ";
605 os <<
"******* bigNamesContainer_ \n";
607 if (
i ==
'\0') os <<
'\\' <<
'0';
610 if (!bigNamesContainer_.empty()) os <<
"\n";
611 os <<
"******* processNames_ \n";
613 if (
i ==
'\0') os <<
'\\' <<
'0';
616 if (!processNames_.empty()) os <<
"\n";
618 os <<
"******* items_ \n";
619 for (
auto const& item : *
items_) {
620 std:: cout << item.kindOfType() <<
" " << item.moduleLabel() <<
" " << item.instance() <<
" " << item.process() <<
" " << item.index() <<
" " << item.typeID() <<
"\n";
624 os <<
"******* processItems_ \n";
629 os <<
"sortedTypeIDs_.size() = " << sortedTypeIDs_.size() <<
"\n";
630 os <<
"indexAndNames_.size() = " << indexAndNames_.size() <<
"\n";
631 os <<
"bigNamesContainer_.size() = " << bigNamesContainer_.size() <<
"\n";
632 os <<
"processNames_.size() = " << processNames_.size() <<
"\n";
Matches relatedIndexes(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance) const
bool is_RefToBaseVector(TypeWithDict const &possible_ref_vector, TypeWithDict &value_type)
std::vector< char > bigNamesContainer_
std::vector< TypeID > sortedTypeIDs_
std::vector< Range > ranges_
std::unique_ptr< std::set< std::string > > processItems_
static PFTauRenderPlugin instance
ProductHolderIndexHelper const * productHolderIndexHelper_
ProductHolderIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=0) const
std::vector< IndexAndNames > indexAndNames_
unsigned int startInIndexAndNames_
ProductHolderIndex insert(TypeWithDict const &typeWithDict, char const *moduleLabel, char const *instance, char const *process)
void print(std::ostream &os) const
unsigned int ProductHolderIndex
std::vector< std::string > lookupProcessNames_
unsigned int numberOfMatches_
ProductHolderIndex nextIndexValue_
unsigned int beginElements_
void public_base_classes(TypeWithDict const &type, std::vector< TypeWithDict > &baseTypes)
bool is_RefVector(TypeWithDict const &possible_ref_vector, TypeWithDict &value_type)
Matches(ProductHolderIndexHelper const *productHolderIndexHelper, unsigned int startInIndexAndNames, unsigned int numberOfMatches)
std::unique_ptr< std::set< Item > > items_
ProductHolderIndexHelper()
bool operator<(Item const &right) const
bool isFullyResolved(unsigned int i) const
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const
unsigned int begin() const
ProductHolderIndex index(unsigned int i) const
std::type_info const & typeInfo() const
unsigned int processIndex(char const *process) const
PixelRecoRange< float > Range
std::vector< std::string > const & lookupProcessNames() const
std::vector< char > processNames_
Item(KindOfType kindOfType, TypeID const &typeID, std::string const &moduleLabel, std::string const &instance, std::string const &process, ProductHolderIndex index)
bool is_PtrVector(TypeWithDict const &possible_ref_vector, TypeWithDict &value_type)
unsigned int indexToIndexAndNames(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process) const
bool value_type_of(TypeWithDict const &t, TypeWithDict &found_type)