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();
408 processItems_ =
nullptr;
414 <<
"ProductHolderIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
422 char const* moduleLabel,
430 unsigned startProcess = 0;
440 unsigned int end = range.
end();
442 while (begin < end) {
444 unsigned int midpoint = begin + ((end -
begin) / 2);
448 char const*
label = moduleLabel;
449 while (*namePtr && (*namePtr == *label)) {
452 if (*namePtr == *label) {
456 char const* instanceName =
instance;
457 while (*namePtr && (*namePtr == *instanceName)) {
458 ++namePtr; ++instanceName;
460 if (*namePtr == *instanceName) {
463 if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
466 if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
469 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
472 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
477 if (midpoint == indexAndNames_.size())
break;
478 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
479 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
486 }
else if (*namePtr < *instanceName) {
487 if (begin == midpoint)
break;
492 }
else if (*namePtr < *label) {
493 if (begin == midpoint)
break;
505 TypeID const& typeID)
const {
507 unsigned int beginType = 0;
514 while (beginType < endType) {
515 unsigned int midpointType = beginType + ((endType - beginType) / 2);
519 if (beginType == midpointType)
break;
520 beginType = midpointType;
522 endType = midpointType;
531 char const*
begin = ptr;
534 char const* beginName = ptr;
535 while (*ptr && (*ptr == *p)) {
539 return beginName -
begin;
545 if (static_cast<unsigned>(ptr - begin) >=
processNames_.size()) {
553 bool sanityChecksPass =
true;
556 unsigned int previousEnd = 0;
557 for (
auto const& range :
ranges_) {
558 if (range.begin() != previousEnd) sanityChecksPass =
false;
559 if (range.begin() >= range.end()) sanityChecksPass =
false;
560 previousEnd = range.end();
562 if (previousEnd !=
indexAndNames_.size()) sanityChecksPass =
false;
565 unsigned maxStart = 0;
566 unsigned maxStartProcess = 0;
570 if (indexAndName.startInBigNamesContainer() >=
bigNamesContainer_.size()) sanityChecksPass =
false;
571 if (indexAndName.startInProcessNames() >=
processNames_.size()) sanityChecksPass =
false;
573 if (indexAndName.startInBigNamesContainer() > maxStart) maxStart = indexAndName.startInBigNamesContainer();
574 if (indexAndName.startInProcessNames() > maxStartProcess) maxStartProcess = indexAndName.startInProcessNames();
577 if (!indexAndNames_.empty()) {
581 unsigned int countZeroes = 0;
587 if (countZeroes != 2) sanityChecksPass =
false;
588 if (maxStartProcess >=
processNames_.size()) sanityChecksPass =
false;
595 if (countZeroes != 1) sanityChecksPass =
false;
598 if (!sanityChecksPass) {
600 <<
"ProductHolderIndexHelper::setFrozen - Detected illegal state.\n";
610 kindOfType_(kindOfType),
622 if (typeID_ < right.
typeID_)
return true;
623 if (typeID_ > right.
typeID_)
return false;
626 if (instance_ < right.
instance_)
return true;
627 if (instance_ > right.
instance_)
return false;
633 os <<
"\n******* Dump ProductHolderIndexHelper *************************\n";
638 os <<
"\n******* sortedTypeIDs_ \n";
642 os <<
"******* ranges_ \n";
644 os <<
i.begin() <<
" " <<
i.end() <<
"\n";
646 os <<
"******* indexAndNames_ \n";
648 os <<
i.index() <<
" " <<
i.startInBigNamesContainer() <<
" ";
660 os <<
" " <<
i.startInProcessNames() <<
" ";
668 os <<
"******* bigNamesContainer_ \n";
670 if (
i ==
'\0') os <<
'\\' <<
'0';
673 if (!bigNamesContainer_.empty()) os <<
"\n";
674 os <<
"******* processNames_ \n";
676 if (
i ==
'\0') os <<
'\\' <<
'0';
679 if (!processNames_.empty()) os <<
"\n";
681 os <<
"******* items_ \n";
682 for (
auto const& item : *
items_) {
683 std:: cout << item.kindOfType() <<
" " << item.moduleLabel() <<
" " << item.instance() <<
" " << item.process() <<
" " << item.index() <<
" " << item.typeID() <<
"\n";
687 os <<
"******* processItems_ \n";
692 os <<
"sortedTypeIDs_.size() = " << sortedTypeIDs_.size() <<
"\n";
693 os <<
"indexAndNames_.size() = " << indexAndNames_.size() <<
"\n";
694 os <<
"bigNamesContainer_.size() = " << bigNamesContainer_.size() <<
"\n";
695 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_
TypeID getContainedTypeFromWrapper(TypeID const &wrappedtypeID, std::string const &className)
char const * moduleLabel(unsigned int i) const
static PFTauRenderPlugin instance
ProductHolderIndexHelper const * productHolderIndexHelper_
PixelRecoRange< float > Range
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)
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
std::string wrappedClassName(std::string const &iFullName)
ProductHolderIndex insert(TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process, TypeID const &containedTypeID)
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_
std::string const & className() const
edm::propagate_const< std::unique_ptr< std::set< std::string > > > processItems_
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