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);
115 if (i >= numberOfMatches_) {
117 <<
"ProductHolderIndexHelper::Matches::processName - Argument is out of range.\n";
119 unsigned int startInProcessNames = productHolderIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].startInProcessNames();
120 return &productHolderIndexHelper_->processNames_[startInProcessNames];
125 if (i >= numberOfMatches_) {
127 <<
"ProductHolderIndexHelper::Matches::moduleLabel - Argument is out of range.\n";
129 unsigned int start = productHolderIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].startInBigNamesContainer();
130 return &productHolderIndexHelper_->bigNamesContainer_[
start];
136 char const* moduleLabel,
144 unsigned int numberOfMatches = 1;
150 for (
unsigned int j = startInIndexAndNames + 1U;
156 return Matches(
this, startInIndexAndNames, numberOfMatches);
161 TypeID const& typeID)
const {
164 unsigned int numberOfMatches = 0;
173 startInIndexAndNames = range.
begin();
174 numberOfMatches = range.
end() - range.
begin();
176 return Matches(
this, startInIndexAndNames, numberOfMatches);
181 char const* moduleLabel,
184 TypeID const& containedTypeID) {
187 <<
"ProductHolderIndexHelper::insert - Attempt to insert more elements after frozen.\n";
190 if (process == 0 || *process ==
'\0') {
192 <<
"ProductHolderIndexHelper::insert - Empty process.\n";
197 std::set<Item>::iterator
iter =
items_->find(item);
198 if (iter !=
items_->end()) {
200 <<
"ProductHolderIndexHelper::insert - Attempt to insert duplicate entry.\n";
212 iter =
items_->find(item);
213 if (iter ==
items_->end()) {
221 if(containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID()) {
224 Item containedItem(
ELEMENT_TYPE, containedTypeID, moduleLabel, instance, process, savedProductIndex);
225 iter =
items_->find(containedItem);
226 if (iter !=
items_->end()) {
230 items_->insert(containedItem);
232 containedItem.clearProcess();
233 iter =
items_->find(containedItem);
234 if (iter ==
items_->end()) {
237 items_->insert(containedItem);
241 std::vector<TypeWithDict> baseTypes;
246 TypeID baseTypeID(baseType.typeInfo());
247 Item baseItem(
ELEMENT_TYPE, baseTypeID, moduleLabel, instance, process, savedProductIndex);
248 iter =
items_->find(baseItem);
249 if (iter !=
items_->end()) {
255 baseItem.clearProcess();
256 iter =
items_->find(baseItem);
257 if (iter ==
items_->end()) {
264 return savedProductIndex;
274 bool iFirstThisType =
true;
275 bool beginElementsWasSet =
false;
280 unsigned int iCountTypes = 0;
281 unsigned int iCountCharacters = 0;
282 for (
auto const& item : *
items_) {
284 if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
286 iFirstThisType =
true;
288 if (!beginElementsWasSet) {
290 beginElementsWasSet =
true;
299 if (iFirstThisType ||
300 item.moduleLabel() != previousModuleLabel ||
301 item.instance() != previousInstance) {
302 iCountCharacters += item.moduleLabel().size();
303 iCountCharacters += item.instance().size();
304 iCountCharacters += 2;
307 iFirstThisType =
false;
308 previousTypeID = item.typeID();
309 previousKindOfType = item.kindOfType();
310 previousModuleLabel = item.moduleLabel();
311 previousInstance = item.instance();
315 unsigned int processNamesSize = 0;
317 processNamesSize += processItem.size();
321 for (
auto const& processItem : *processItems_) {
322 for (
auto const&
c : processItem) {
336 bool iFirstType =
true;
337 iFirstThisType =
true;
338 previousTypeID =
TypeID();
339 unsigned int iCount = 0;
340 unsigned int iBeginning = 0;
341 iCountCharacters = 0;
342 unsigned int previousCharacterCount = 0;
343 if (!items_->empty()) {
344 for (
auto const& item : *items_) {
346 if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
347 iFirstThisType =
true;
358 if (iFirstThisType ||
359 item.moduleLabel() != previousModuleLabel ||
360 item.instance() != previousInstance) {
362 unsigned int labelSize = item.moduleLabel().size();
363 for (
unsigned int j = 0;
j < labelSize; ++
j) {
368 unsigned int instanceSize = item.instance().size();
369 for (
unsigned int j = 0;
j < instanceSize; ++
j) {
374 previousCharacterCount = iCountCharacters;
376 iCountCharacters += labelSize;
377 iCountCharacters += instanceSize;
378 iCountCharacters += 2;
381 unsigned int processStart =
processIndex(item.process().c_str());
384 <<
"ProductHolderIndexHelper::setFrozen - Process not found in processNames_.\n";
386 indexAndNames_.emplace_back(item.index(), previousCharacterCount, processStart);
388 iFirstThisType =
false;
389 previousTypeID = item.typeID();
390 previousKindOfType = item.kindOfType();
391 previousModuleLabel = item.moduleLabel();
392 previousInstance = item.instance();
404 processItems_.reset();
410 <<
"ProductHolderIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
418 char const* moduleLabel,
426 unsigned startProcess = 0;
436 unsigned int end = range.
end();
438 while (begin < end) {
440 unsigned int midpoint = begin + ((end -
begin) / 2);
444 char const*
label = moduleLabel;
445 while (*namePtr && (*namePtr == *label)) {
448 if (*namePtr == *label) {
452 char const* instanceName =
instance;
453 while (*namePtr && (*namePtr == *instanceName)) {
454 ++namePtr; ++instanceName;
456 if (*namePtr == *instanceName) {
459 if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
462 if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
465 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
468 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
473 if (midpoint == indexAndNames_.size())
break;
474 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
475 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
482 }
else if (*namePtr < *instanceName) {
483 if (begin == midpoint)
break;
488 }
else if (*namePtr < *label) {
489 if (begin == midpoint)
break;
501 TypeID const& typeID)
const {
503 unsigned int beginType = 0;
510 while (beginType < endType) {
511 unsigned int midpointType = beginType + ((endType - beginType) / 2);
515 if (beginType == midpointType)
break;
516 beginType = midpointType;
518 endType = midpointType;
527 char const*
begin = ptr;
530 char const* beginName = ptr;
531 while (*ptr && (*ptr == *p)) {
535 return beginName -
begin;
541 if (static_cast<unsigned>(ptr - begin) >=
processNames_.size()) {
549 bool sanityChecksPass =
true;
552 unsigned int previousEnd = 0;
553 for (
auto const& range :
ranges_) {
554 if (range.begin() != previousEnd) sanityChecksPass =
false;
555 if (range.begin() >= range.end()) sanityChecksPass =
false;
556 previousEnd = range.end();
558 if (previousEnd !=
indexAndNames_.size()) sanityChecksPass =
false;
561 unsigned maxStart = 0;
562 unsigned maxStartProcess = 0;
566 if (indexAndName.startInBigNamesContainer() >=
bigNamesContainer_.size()) sanityChecksPass =
false;
567 if (indexAndName.startInProcessNames() >=
processNames_.size()) sanityChecksPass =
false;
569 if (indexAndName.startInBigNamesContainer() > maxStart) maxStart = indexAndName.startInBigNamesContainer();
570 if (indexAndName.startInProcessNames() > maxStartProcess) maxStartProcess = indexAndName.startInProcessNames();
573 if (!indexAndNames_.empty()) {
577 unsigned int countZeroes = 0;
583 if (countZeroes != 2) sanityChecksPass =
false;
584 if (maxStartProcess >=
processNames_.size()) sanityChecksPass =
false;
591 if (countZeroes != 1) sanityChecksPass =
false;
594 if (!sanityChecksPass) {
596 <<
"ProductHolderIndexHelper::setFrozen - Detected illegal state.\n";
606 kindOfType_(kindOfType),
618 if (typeID_ < right.
typeID_)
return true;
619 if (typeID_ > right.
typeID_)
return false;
622 if (instance_ < right.
instance_)
return true;
623 if (instance_ > right.
instance_)
return false;
629 os <<
"\n******* Dump ProductHolderIndexHelper *************************\n";
634 os <<
"\n******* sortedTypeIDs_ \n";
638 os <<
"******* ranges_ \n";
640 os <<
i.begin() <<
" " <<
i.end() <<
"\n";
642 os <<
"******* indexAndNames_ \n";
644 os <<
i.index() <<
" " <<
i.startInBigNamesContainer() <<
" ";
656 os <<
" " <<
i.startInProcessNames() <<
" ";
664 os <<
"******* bigNamesContainer_ \n";
666 if (
i ==
'\0') os <<
'\\' <<
'0';
669 if (!bigNamesContainer_.empty()) os <<
"\n";
670 os <<
"******* processNames_ \n";
672 if (
i ==
'\0') os <<
'\\' <<
'0';
675 if (!processNames_.empty()) os <<
"\n";
677 os <<
"******* items_ \n";
678 for (
auto const& item : *
items_) {
679 std:: cout << item.kindOfType() <<
" " << item.moduleLabel() <<
" " << item.instance() <<
" " << item.process() <<
" " << item.index() <<
" " << item.typeID() <<
"\n";
683 os <<
"******* processItems_ \n";
688 os <<
"sortedTypeIDs_.size() = " << sortedTypeIDs_.size() <<
"\n";
689 os <<
"indexAndNames_.size() = " << indexAndNames_.size() <<
"\n";
690 os <<
"bigNamesContainer_.size() = " << bigNamesContainer_.size() <<
"\n";
691 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)
tuple start
Check for commandline option errors.
std::vector< char > bigNamesContainer_
std::vector< TypeID > sortedTypeIDs_
std::vector< Range > ranges_
std::unique_ptr< std::set< std::string > > processItems_
TypeID getContainedTypeFromWrapper(TypeID const &wrappedtypeID, std::string const &className)
char const * moduleLabel(unsigned int i) const
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_
char const * processName(unsigned int i) const
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_
static TypeWithDict byName(std::string const &name)
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
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