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 std::string const vectorPtr(
"std::vector<edm::Ptr<");
27 static size_t const rvsize = refVector.size();
28 static size_t const rtbvsize = refToBaseVector.size();
29 static size_t const pvsize = ptrVector.size();
30 static size_t const vpsize = vectorPtr.size();
31 bool mayBeRefVector = (className.substr(0, rvsize) == refVector)
32 || (className.substr(0, rtbvsize) == refToBaseVector)
33 || (className.substr(0, pvsize) == ptrVector)
34 || (className.substr(0, vpsize) == vectorPtr);
35 TClass*
cl = TClass::GetClass(wrappedTypeID.
className().c_str());
37 return TypeID(
typeid(
void));
40 int offset = cl->GetBaseClassOffset(wbClass) + vtcOffset;;
41 std::unique_ptr<ViewTypeChecker> checker = getAnyPtr<ViewTypeChecker>(
p,
offset);
43 std::type_info
const& ti = checker->memberTypeInfo();
44 if(ti !=
typeid(
void)) {
48 return TypeID(checker->valueTypeInfo());
64 processItems_(new std::set<std::
string>) {
70 char const* moduleLabel,
87 unsigned int startInIndexAndNames,
88 unsigned int numberOfMatches) :
89 productHolderIndexHelper_(productHolderIndexHelper),
90 startInIndexAndNames_(startInIndexAndNames),
91 numberOfMatches_(numberOfMatches) {
94 <<
"ProductHolderIndexHelper::Matches::Matches - Arguments exceed vector bounds.\n";
100 if (i >= numberOfMatches_) {
102 <<
"ProductHolderIndexHelper::Matches::index - Argument is out of range.\n";
104 return productHolderIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].index();
109 if (i >= numberOfMatches_) {
111 <<
"ProductHolderIndexHelper::Matches::isFullyResolved - Argument is out of range.\n";
113 return (productHolderIndexHelper_->indexAndNames_[startInIndexAndNames_ + i].startInProcessNames() != 0U);
118 if (i >= numberOfMatches_) {
120 <<
"ProductHolderIndexHelper::Matches::processName - Argument is out of range.\n";
122 unsigned int startInProcessNames = productHolderIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].startInProcessNames();
123 return &productHolderIndexHelper_->processNames_[startInProcessNames];
128 if (i >= numberOfMatches_) {
130 <<
"ProductHolderIndexHelper::Matches::moduleLabel - Argument is out of range.\n";
132 unsigned int start = productHolderIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].startInBigNamesContainer();
133 return &productHolderIndexHelper_->bigNamesContainer_[
start];
139 char const* moduleLabel,
147 unsigned int numberOfMatches = 1;
153 for (
unsigned int j = startInIndexAndNames + 1U;
159 return Matches(
this, startInIndexAndNames, numberOfMatches);
164 TypeID const& typeID)
const {
167 unsigned int numberOfMatches = 0;
176 startInIndexAndNames = range.
begin();
177 numberOfMatches = range.
end() - range.
begin();
179 return Matches(
this, startInIndexAndNames, numberOfMatches);
184 char const* moduleLabel,
187 TypeID const& containedTypeID) {
190 <<
"ProductHolderIndexHelper::insert - Attempt to insert more elements after frozen.\n";
193 if (process == 0 || *process ==
'\0') {
195 <<
"ProductHolderIndexHelper::insert - Empty process.\n";
200 std::set<Item>::iterator iter =
items_->find(item);
201 if (iter !=
items_->end()) {
203 <<
"ProductHolderIndexHelper::insert - Attempt to insert duplicate entry.\n";
215 iter =
items_->find(item);
216 if (iter ==
items_->end()) {
224 if(containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID()) {
227 Item containedItem(
ELEMENT_TYPE, containedTypeID, moduleLabel, instance, process, savedProductIndex);
228 iter =
items_->find(containedItem);
229 if (iter !=
items_->end()) {
233 items_->insert(containedItem);
235 containedItem.clearProcess();
236 iter =
items_->find(containedItem);
237 if (iter ==
items_->end()) {
240 items_->insert(containedItem);
244 std::vector<TypeWithDict> baseTypes;
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()) {
258 baseItem.clearProcess();
259 iter =
items_->find(baseItem);
260 if (iter ==
items_->end()) {
267 return savedProductIndex;
277 bool iFirstThisType =
true;
278 bool beginElementsWasSet =
false;
283 unsigned int iCountTypes = 0;
284 unsigned int iCountCharacters = 0;
285 for (
auto const& item : *
items_) {
287 if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
289 iFirstThisType =
true;
291 if (!beginElementsWasSet) {
293 beginElementsWasSet =
true;
302 if (iFirstThisType ||
303 item.moduleLabel() != previousModuleLabel ||
304 item.instance() != previousInstance) {
305 iCountCharacters += item.moduleLabel().size();
306 iCountCharacters += item.instance().size();
307 iCountCharacters += 2;
310 iFirstThisType =
false;
311 previousTypeID = item.typeID();
312 previousKindOfType = item.kindOfType();
313 previousModuleLabel = item.moduleLabel();
314 previousInstance = item.instance();
318 unsigned int processNamesSize = 0;
320 processNamesSize += processItem.size();
324 for (
auto const& processItem : *processItems_) {
325 for (
auto const&
c : processItem) {
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_) {
349 if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
350 iFirstThisType =
true;
361 if (iFirstThisType ||
362 item.moduleLabel() != previousModuleLabel ||
363 item.instance() != previousInstance) {
365 unsigned int labelSize = item.moduleLabel().size();
366 for (
unsigned int j = 0;
j < labelSize; ++
j) {
371 unsigned int instanceSize = item.instance().size();
372 for (
unsigned int j = 0;
j < instanceSize; ++
j) {
377 previousCharacterCount = iCountCharacters;
379 iCountCharacters += labelSize;
380 iCountCharacters += instanceSize;
381 iCountCharacters += 2;
384 unsigned int processStart =
processIndex(item.process().c_str());
387 <<
"ProductHolderIndexHelper::setFrozen - Process not found in processNames_.\n";
389 indexAndNames_.emplace_back(item.index(), previousCharacterCount, processStart);
391 iFirstThisType =
false;
392 previousTypeID = item.typeID();
393 previousKindOfType = item.kindOfType();
394 previousModuleLabel = item.moduleLabel();
395 previousInstance = item.instance();
407 processItems_.reset();
413 <<
"ProductHolderIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
421 char const* moduleLabel,
429 unsigned startProcess = 0;
439 unsigned int end = range.
end();
441 while (begin < end) {
443 unsigned int midpoint = begin + ((end -
begin) / 2);
447 char const*
label = moduleLabel;
448 while (*namePtr && (*namePtr == *label)) {
451 if (*namePtr == *label) {
455 char const* instanceName =
instance;
456 while (*namePtr && (*namePtr == *instanceName)) {
457 ++namePtr; ++instanceName;
459 if (*namePtr == *instanceName) {
462 if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
465 if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
468 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
471 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
476 if (midpoint == indexAndNames_.size())
break;
477 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
478 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
485 }
else if (*namePtr < *instanceName) {
486 if (begin == midpoint)
break;
491 }
else if (*namePtr < *label) {
492 if (begin == midpoint)
break;
504 TypeID const& typeID)
const {
506 unsigned int beginType = 0;
513 while (beginType < endType) {
514 unsigned int midpointType = beginType + ((endType - beginType) / 2);
518 if (beginType == midpointType)
break;
519 beginType = midpointType;
521 endType = midpointType;
530 char const*
begin = ptr;
533 char const* beginName = ptr;
534 while (*ptr && (*ptr == *p)) {
538 return beginName -
begin;
544 if (static_cast<unsigned>(ptr - begin) >=
processNames_.size()) {
552 bool sanityChecksPass =
true;
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();
561 if (previousEnd !=
indexAndNames_.size()) sanityChecksPass =
false;
564 unsigned maxStart = 0;
565 unsigned maxStartProcess = 0;
569 if (indexAndName.startInBigNamesContainer() >=
bigNamesContainer_.size()) sanityChecksPass =
false;
570 if (indexAndName.startInProcessNames() >=
processNames_.size()) sanityChecksPass =
false;
572 if (indexAndName.startInBigNamesContainer() > maxStart) maxStart = indexAndName.startInBigNamesContainer();
573 if (indexAndName.startInProcessNames() > maxStartProcess) maxStartProcess = indexAndName.startInProcessNames();
576 if (!indexAndNames_.empty()) {
580 unsigned int countZeroes = 0;
586 if (countZeroes != 2) sanityChecksPass =
false;
587 if (maxStartProcess >=
processNames_.size()) sanityChecksPass =
false;
594 if (countZeroes != 1) sanityChecksPass =
false;
597 if (!sanityChecksPass) {
599 <<
"ProductHolderIndexHelper::setFrozen - Detected illegal state.\n";
609 kindOfType_(kindOfType),
621 if (typeID_ < right.
typeID_)
return true;
622 if (typeID_ > right.
typeID_)
return false;
625 if (instance_ < right.
instance_)
return true;
626 if (instance_ > right.
instance_)
return false;
632 os <<
"\n******* Dump ProductHolderIndexHelper *************************\n";
637 os <<
"\n******* sortedTypeIDs_ \n";
641 os <<
"******* ranges_ \n";
643 os <<
i.begin() <<
" " <<
i.end() <<
"\n";
645 os <<
"******* indexAndNames_ \n";
647 os <<
i.index() <<
" " <<
i.startInBigNamesContainer() <<
" ";
659 os <<
" " <<
i.startInProcessNames() <<
" ";
667 os <<
"******* bigNamesContainer_ \n";
669 if (
i ==
'\0') os <<
'\\' <<
'0';
672 if (!bigNamesContainer_.empty()) os <<
"\n";
673 os <<
"******* processNames_ \n";
675 if (
i ==
'\0') os <<
'\\' <<
'0';
678 if (!processNames_.empty()) os <<
"\n";
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";
686 os <<
"******* processItems_ \n";
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";
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