18 namespace productholderindexhelper {
21 static int const vtcOffset = TClass::GetClass(
"edm::WrapperBase")->GetBaseClassOffset(TClass::GetClass(
"edm::ViewTypeChecker"));
22 static TClass
const*
const wbClass = TClass::GetClass(
"edm::WrapperBase");
23 static std::string const refVector(
"edm::RefVector<");
24 static std::string const refToBaseVector(
"edm::RefToBaseVector<");
25 static std::string const ptrVector(
"edm::PtrVector<");
26 static size_t const rvsize = refVector.size();
27 static size_t const rtbvsize = refToBaseVector.size();
28 static size_t const pvsize = ptrVector.size();
29 bool mayBeRefVector = (className.substr(0, rvsize) == refVector)
30 || (className.substr(0, rtbvsize) == refToBaseVector)
31 || (className.substr(0, pvsize) == ptrVector);
32 TClass*
cl = TClass::GetClass(wrappedTypeID.
className().c_str());
34 return TypeID(
typeid(
void));
37 int offset = cl->GetBaseClassOffset(wbClass) + vtcOffset;;
38 std::unique_ptr<ViewTypeChecker> checker = getAnyPtr<ViewTypeChecker>(
p,
offset);
40 std::type_info
const& ti = checker->memberTypeInfo();
41 if(ti !=
typeid(
void)) {
45 return TypeID(checker->valueTypeInfo());
61 processItems_(new std::set<std::
string>) {
67 char const* moduleLabel,
84 unsigned int startInIndexAndNames,
85 unsigned int numberOfMatches) :
86 productHolderIndexHelper_(productHolderIndexHelper),
87 startInIndexAndNames_(startInIndexAndNames),
88 numberOfMatches_(numberOfMatches) {
91 <<
"ProductHolderIndexHelper::Matches::Matches - Arguments exceed vector bounds.\n";
97 if (i >= numberOfMatches_) {
99 <<
"ProductHolderIndexHelper::Matches::index - Argument is out of range.\n";
101 return productHolderIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].index();
106 if (i >= numberOfMatches_) {
108 <<
"ProductHolderIndexHelper::Matches::isFullyResolved - Argument is out of range.\n";
110 return (productHolderIndexHelper_->indexAndNames_[startInIndexAndNames_ + i].startInProcessNames() != 0U);
116 char const* moduleLabel,
124 unsigned int numberOfMatches = 1;
130 for (
unsigned int j = startInIndexAndNames + 1U;
136 return Matches(
this, startInIndexAndNames, numberOfMatches);
141 TypeID const& typeID)
const {
144 unsigned int numberOfMatches = 0;
153 startInIndexAndNames = range.
begin();
154 numberOfMatches = range.
end() - range.
begin();
156 return Matches(
this, startInIndexAndNames, numberOfMatches);
161 char const* moduleLabel,
164 TypeID const& containedTypeID) {
167 <<
"ProductHolderIndexHelper::insert - Attempt to insert more elements after frozen.\n";
170 if (process == 0 || *process ==
'\0') {
172 <<
"ProductHolderIndexHelper::insert - Empty process.\n";
177 std::set<Item>::iterator
iter =
items_->find(item);
178 if (iter !=
items_->end()) {
180 <<
"ProductHolderIndexHelper::insert - Attempt to insert duplicate entry.\n";
192 iter =
items_->find(item);
193 if (iter ==
items_->end()) {
201 if(containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID()) {
204 Item containedItem(
ELEMENT_TYPE, containedTypeID, moduleLabel, instance, process, savedProductIndex);
205 iter =
items_->find(containedItem);
206 if (iter !=
items_->end()) {
210 items_->insert(containedItem);
212 containedItem.clearProcess();
213 iter =
items_->find(containedItem);
214 if (iter ==
items_->end()) {
217 items_->insert(containedItem);
221 std::vector<TypeWithDict> baseTypes;
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()) {
235 baseItem.clearProcess();
236 iter =
items_->find(baseItem);
237 if (iter ==
items_->end()) {
244 return savedProductIndex;
254 bool iFirstThisType =
true;
255 bool beginElementsWasSet =
false;
260 unsigned int iCountTypes = 0;
261 unsigned int iCountCharacters = 0;
262 for (
auto const& item : *
items_) {
264 if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
266 iFirstThisType =
true;
268 if (!beginElementsWasSet) {
270 beginElementsWasSet =
true;
279 if (iFirstThisType ||
280 item.moduleLabel() != previousModuleLabel ||
281 item.instance() != previousInstance) {
282 iCountCharacters += item.moduleLabel().size();
283 iCountCharacters += item.instance().size();
284 iCountCharacters += 2;
287 iFirstThisType =
false;
288 previousTypeID = item.typeID();
289 previousKindOfType = item.kindOfType();
290 previousModuleLabel = item.moduleLabel();
291 previousInstance = item.instance();
295 unsigned int processNamesSize = 0;
297 processNamesSize += processItem.size();
301 for (
auto const& processItem : *processItems_) {
302 for (
auto const&
c : processItem) {
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_) {
326 if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
327 iFirstThisType =
true;
338 if (iFirstThisType ||
339 item.moduleLabel() != previousModuleLabel ||
340 item.instance() != previousInstance) {
342 unsigned int labelSize = item.moduleLabel().size();
343 for (
unsigned int j = 0;
j < labelSize; ++
j) {
348 unsigned int instanceSize = item.instance().size();
349 for (
unsigned int j = 0;
j < instanceSize; ++
j) {
354 previousCharacterCount = iCountCharacters;
356 iCountCharacters += labelSize;
357 iCountCharacters += instanceSize;
358 iCountCharacters += 2;
361 unsigned int processStart =
processIndex(item.process().c_str());
364 <<
"ProductHolderIndexHelper::setFrozen - Process not found in processNames_.\n";
366 indexAndNames_.emplace_back(item.index(), previousCharacterCount, processStart);
368 iFirstThisType =
false;
369 previousTypeID = item.typeID();
370 previousKindOfType = item.kindOfType();
371 previousModuleLabel = item.moduleLabel();
372 previousInstance = item.instance();
384 processItems_.reset();
390 <<
"ProductHolderIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
398 char const* moduleLabel,
406 unsigned startProcess = 0;
416 unsigned int end = range.
end();
418 while (begin < end) {
420 unsigned int midpoint = begin + ((end -
begin) / 2);
424 char const*
label = moduleLabel;
425 while (*namePtr && (*namePtr == *label)) {
428 if (*namePtr == *label) {
432 char const* instanceName =
instance;
433 while (*namePtr && (*namePtr == *instanceName)) {
434 ++namePtr; ++instanceName;
436 if (*namePtr == *instanceName) {
439 if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
442 if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
445 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
448 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
453 if (midpoint == indexAndNames_.size())
break;
454 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
455 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
462 }
else if (*namePtr < *instanceName) {
463 if (begin == midpoint)
break;
468 }
else if (*namePtr < *label) {
469 if (begin == midpoint)
break;
481 TypeID const& typeID)
const {
483 unsigned int beginType = 0;
490 while (beginType < endType) {
491 unsigned int midpointType = beginType + ((endType - beginType) / 2);
495 if (beginType == midpointType)
break;
496 beginType = midpointType;
498 endType = midpointType;
507 char const*
begin = ptr;
510 char const* beginName = ptr;
511 while (*ptr && (*ptr == *p)) {
515 return beginName -
begin;
521 if (static_cast<unsigned>(ptr - begin) >=
processNames_.size()) {
529 bool sanityChecksPass =
true;
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();
538 if (previousEnd !=
indexAndNames_.size()) sanityChecksPass =
false;
541 unsigned maxStart = 0;
542 unsigned maxStartProcess = 0;
546 if (indexAndName.startInBigNamesContainer() >=
bigNamesContainer_.size()) sanityChecksPass =
false;
547 if (indexAndName.startInProcessNames() >=
processNames_.size()) sanityChecksPass =
false;
549 if (indexAndName.startInBigNamesContainer() > maxStart) maxStart = indexAndName.startInBigNamesContainer();
550 if (indexAndName.startInProcessNames() > maxStartProcess) maxStartProcess = indexAndName.startInProcessNames();
553 if (!indexAndNames_.empty()) {
557 unsigned int countZeroes = 0;
563 if (countZeroes != 2) sanityChecksPass =
false;
564 if (maxStartProcess >=
processNames_.size()) sanityChecksPass =
false;
571 if (countZeroes != 1) sanityChecksPass =
false;
574 if (!sanityChecksPass) {
576 <<
"ProductHolderIndexHelper::setFrozen - Detected illegal state.\n";
586 kindOfType_(kindOfType),
598 if (typeID_ < right.
typeID_)
return true;
599 if (typeID_ > right.
typeID_)
return false;
602 if (instance_ < right.
instance_)
return true;
603 if (instance_ > right.
instance_)
return false;
609 os <<
"\n******* Dump ProductHolderIndexHelper *************************\n";
614 os <<
"\n******* sortedTypeIDs_ \n";
618 os <<
"******* ranges_ \n";
620 os <<
i.begin() <<
" " <<
i.end() <<
"\n";
622 os <<
"******* indexAndNames_ \n";
624 os <<
i.index() <<
" " <<
i.startInBigNamesContainer() <<
" ";
636 os <<
" " <<
i.startInProcessNames() <<
" ";
644 os <<
"******* bigNamesContainer_ \n";
646 if (
i ==
'\0') os <<
'\\' <<
'0';
649 if (!bigNamesContainer_.empty()) os <<
"\n";
650 os <<
"******* processNames_ \n";
652 if (
i ==
'\0') os <<
'\\' <<
'0';
655 if (!processNames_.empty()) os <<
"\n";
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";
663 os <<
"******* processItems_ \n";
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";
Matches relatedIndexes(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance) const
TypeID getContainedType(TypeID const &typeID)
std::vector< char > bigNamesContainer_
std::vector< TypeID > sortedTypeIDs_
static TypeWithDict byName(std::string const &className)
std::vector< Range > ranges_
std::unique_ptr< std::set< std::string > > processItems_
TypeID getContainedTypeFromWrapper(TypeID const &wrappedtypeID, std::string const &className)
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_
void print(std::ostream &os) const
unsigned int ProductHolderIndex
const std::type_info & typeInfo() const
std::vector< std::string > lookupProcessNames_
unsigned int numberOfMatches_
ProductHolderIndex nextIndexValue_
unsigned int beginElements_
void public_base_classes(TypeWithDict const &type, std::vector< TypeWithDict > &baseTypes)
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
unsigned int offset(bool)
PixelRecoRange< float > Range
std::string wrappedClassName(std::string const &iFullName)
ProductHolderIndex insert(TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process, TypeID const &containedTypeID)
std::string const & className() const
std::vector< std::string > const & lookupProcessNames() const
void setIndex(ProductHolderIndex v)
std::vector< char > processNames_
Item(KindOfType kindOfType, TypeID const &typeID, std::string const &moduleLabel, std::string const &instance, std::string const &process, ProductHolderIndex index)
std::string className(const T &t)
unsigned int indexToIndexAndNames(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process) const