18 namespace productholderindexhelper {
20 static int const vtcOffset =
21 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 std::string const vectorUniquePtr(
"std::vector<std::unique_ptr<");
28 static std::string const associationMap(
"edm::AssociationMap<");
29 static std::string const newDetSetVector(
"edmNew::DetSetVector<");
30 static size_t const rvsize = refVector.size();
31 static size_t const rtbvsize = refToBaseVector.size();
32 static size_t const pvsize = ptrVector.size();
33 static size_t const vpsize = vectorPtr.size();
34 static size_t const vupsize = vectorUniquePtr.size();
35 static size_t const amsize = associationMap.size();
36 static size_t const ndsize = newDetSetVector.size();
37 bool mayBeRefVector = (
className.substr(0, rvsize) == refVector) ||
38 (
className.substr(0, rtbvsize) == refToBaseVector) ||
39 (
className.substr(0, pvsize) == ptrVector) || (
className.substr(0, vpsize) == vectorPtr) ||
40 (
className.substr(0, vupsize) == vectorUniquePtr);
48 if (
className.substr(0, amsize) == associationMap ||
className.substr(0, ndsize) == newDetSetVector) {
49 return TypeID(
typeid(
void));
51 TClass*
cl = TClass::GetClass(wrappedTypeID.
className().c_str());
53 return TypeID(
typeid(
void));
56 int offset =
cl->GetBaseClassOffset(wbClass) + vtcOffset;
57 std::unique_ptr<ViewTypeChecker> checker = getAnyPtr<ViewTypeChecker>(
p,
offset);
59 std::type_info
const& ti = checker->memberTypeInfo();
60 if (ti !=
typeid(
void)) {
64 return TypeID(checker->valueTypeInfo());
95 unsigned int startInIndexAndNames,
96 unsigned int numberOfMatches)
97 : productResolverIndexHelper_(productResolverIndexHelper),
98 startInIndexAndNames_(startInIndexAndNames),
99 numberOfMatches_(numberOfMatches) {
103 <<
"ProductResolverIndexHelper::Matches::Matches - Arguments exceed vector bounds.\n";
108 if (
i >= numberOfMatches_) {
111 return productResolverIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].index();
115 if (
i >= numberOfMatches_) {
117 <<
"ProductResolverIndexHelper::Matches::isFullyResolved - Argument is out of range.\n";
119 return (productResolverIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].startInProcessNames() != 0
U);
123 if (
i >= numberOfMatches_) {
125 <<
"ProductResolverIndexHelper::Matches::processName - Argument is out of range.\n";
127 unsigned int startInProcessNames =
128 productResolverIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].startInProcessNames();
129 return &productResolverIndexHelper_->processNames_[startInProcessNames];
133 if (
i >= numberOfMatches_) {
135 <<
"ProductResolverIndexHelper::Matches::productInstanceName - Argument is out of range.\n";
138 productResolverIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].startInBigNamesContainer();
139 auto moduleLabelSize = strlen(&productResolverIndexHelper_->bigNamesContainer_[
start]);
140 return &productResolverIndexHelper_->bigNamesContainer_[
start + moduleLabelSize + 1];
144 if (
i >= numberOfMatches_) {
146 <<
"ProductResolverIndexHelper::Matches::moduleLabel - Argument is out of range.\n";
149 productResolverIndexHelper_->indexAndNames_[startInIndexAndNames_ +
i].startInBigNamesContainer();
150 return &productResolverIndexHelper_->bigNamesContainer_[
start];
158 unsigned int numberOfMatches = 1;
164 for (
unsigned int j = startInIndexAndNames + 1
U;
j < vSize && (
indexAndNames_[
j].startInProcessNames() != 0
U);
169 return Matches(
this, startInIndexAndNames, numberOfMatches);
173 TypeID const& typeID)
const {
175 unsigned int numberOfMatches = 0;
183 startInIndexAndNames =
range.begin();
184 numberOfMatches =
range.end() -
range.begin();
186 return Matches(
this, startInIndexAndNames, numberOfMatches);
193 TypeID const& containedTypeID,
194 std::vector<TypeWithDict>* baseTypesOfContainedType) {
197 <<
"ProductResolverIndexHelper::insert - Attempt to insert more elements after frozen.\n";
206 std::set<Item>::iterator iter =
items_->find(
item);
207 if (iter !=
items_->end()) {
209 <<
"ProductResolverIndexHelper::insert - Attempt to insert duplicate entry.\n";
222 if (iter ==
items_->end()) {
230 if (containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID()) {
234 iter =
items_->find(containedItem);
235 if (iter !=
items_->end()) {
239 items_->insert(containedItem);
241 containedItem.clearProcess();
242 iter =
items_->find(containedItem);
243 if (iter ==
items_->end()) {
246 items_->insert(containedItem);
250 if (baseTypesOfContainedType) {
251 for (
TypeWithDict const& baseType : *baseTypesOfContainedType) {
252 TypeID baseTypeID(baseType.typeInfo());
254 iter =
items_->find(baseItem);
255 if (iter !=
items_->end()) {
261 baseItem.clearProcess();
262 iter =
items_->find(baseItem);
263 if (iter ==
items_->end()) {
271 return savedProductIndex;
279 bool hasContainedType = (containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID());
280 std::vector<TypeWithDict> baseTypes;
281 std::vector<TypeWithDict>* baseTypesOfContainedType = &baseTypes;
282 if (hasContainedType) {
283 std::vector<std::string> missingDictionaries;
296 bool iFirstThisType =
true;
297 bool beginElementsWasSet =
false;
302 unsigned int iCountTypes = 0;
303 unsigned int iCountCharacters = 0;
305 if (iFirstThisType ||
item.typeID() != previousTypeID ||
item.kindOfType() != previousKindOfType) {
307 iFirstThisType =
true;
309 if (!beginElementsWasSet) {
311 beginElementsWasSet =
true;
320 if (iFirstThisType ||
item.moduleLabel() != previousModuleLabel ||
item.instance() != previousInstance) {
321 iCountCharacters +=
item.moduleLabel().size();
322 iCountCharacters +=
item.instance().size();
323 iCountCharacters += 2;
326 iFirstThisType =
false;
327 previousTypeID =
item.typeID();
328 previousKindOfType =
item.kindOfType();
329 previousModuleLabel =
item.moduleLabel();
330 previousInstance =
item.instance();
334 unsigned int processNamesSize = 0;
336 processNamesSize += processItem.size();
341 for (
auto const&
c : processItem) {
355 bool iFirstType =
true;
356 iFirstThisType =
true;
357 previousTypeID =
TypeID();
358 unsigned int iCount = 0;
359 unsigned int iBeginning = 0;
360 iCountCharacters = 0;
361 unsigned int previousCharacterCount = 0;
364 if (iFirstThisType ||
item.typeID() != previousTypeID ||
item.kindOfType() != previousKindOfType) {
365 iFirstThisType =
true;
376 if (iFirstThisType ||
item.moduleLabel() != previousModuleLabel ||
item.instance() != previousInstance) {
377 unsigned int labelSize =
item.moduleLabel().size();
378 for (
unsigned int j = 0;
j < labelSize; ++
j) {
383 unsigned int instanceSize =
item.instance().size();
384 for (
unsigned int j = 0;
j < instanceSize; ++
j) {
389 previousCharacterCount = iCountCharacters;
391 iCountCharacters += labelSize;
392 iCountCharacters += instanceSize;
393 iCountCharacters += 2;
399 <<
"ProductResolverIndexHelper::setFrozen - Process not found in processNames_.\n";
403 iFirstThisType =
false;
404 previousTypeID =
item.typeID();
405 previousKindOfType =
item.kindOfType();
406 previousModuleLabel =
item.moduleLabel();
407 previousInstance =
item.instance();
426 <<
"ProductResolverIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
439 unsigned startProcess = 0;
448 unsigned int begin =
range.begin();
451 while (begin <
end) {
452 unsigned int midpoint = begin + ((
end - begin) / 2);
457 while (*namePtr && (*namePtr == *
label)) {
461 if (*namePtr == *
label) {
472 if (startProcess ==
indexAndNames_[midpoint].startInProcessNames()) {
475 if (
indexAndNames_[midpoint].startInProcessNames() > startProcess) {
478 if (
indexAndNames_[midpoint].startInProcessNames() == startProcess) {
491 if (
indexAndNames_[midpoint].startInProcessNames() == startProcess) {
499 if (begin == midpoint)
505 }
else if (*namePtr < *
label) {
506 if (begin == midpoint)
518 unsigned int beginType = 0;
525 while (beginType < endType) {
526 unsigned int midpointType = beginType + ((endType - beginType) / 2);
530 if (beginType == midpointType)
532 beginType = midpointType;
534 endType = midpointType;
542 char const* begin = ptr;
545 char const* beginName = ptr;
546 while (*ptr && (*ptr == *
p)) {
551 return beginName - begin;
557 if (static_cast<unsigned>(ptr - begin) >=
processNames_.size()) {
574 auto l = strlen(pModLabel);
575 auto pInstance = pModLabel +
l + 1;
584 bool sanityChecksPass =
true;
586 sanityChecksPass =
false;
588 unsigned int previousEnd = 0;
590 if (
range.begin() != previousEnd)
591 sanityChecksPass =
false;
593 sanityChecksPass =
false;
594 previousEnd =
range.end();
597 sanityChecksPass =
false;
599 unsigned maxStart = 0;
600 unsigned maxStartProcess = 0;
603 sanityChecksPass =
false;
606 sanityChecksPass =
false;
607 if (indexAndName.startInProcessNames() >=
processNames_.size())
608 sanityChecksPass =
false;
610 if (indexAndName.startInBigNamesContainer() > maxStart)
611 maxStart = indexAndName.startInBigNamesContainer();
612 if (indexAndName.startInProcessNames() > maxStartProcess)
613 maxStartProcess = indexAndName.startInProcessNames();
618 sanityChecksPass =
false;
620 sanityChecksPass =
false;
622 sanityChecksPass =
false;
623 unsigned int countZeroes = 0;
629 if (countZeroes != 2)
630 sanityChecksPass =
false;
632 sanityChecksPass =
false;
639 if (countZeroes != 1)
640 sanityChecksPass =
false;
643 if (!sanityChecksPass) {
654 : kindOfType_(kindOfType),
682 os <<
"\n******* Dump ProductResolverIndexHelper *************************\n";
687 os <<
"\n******* sortedTypeIDs_ \n";
691 os <<
"******* ranges_ \n";
693 os <<
i.begin() <<
" " <<
i.end() <<
"\n";
695 os <<
"******* indexAndNames_ \n";
697 os <<
i.index() <<
" " <<
i.startInBigNamesContainer() <<
" ";
709 os <<
" " <<
i.startInProcessNames() <<
" ";
717 os <<
"******* bigNamesContainer_ \n";
726 os <<
"******* processNames_ \n";
736 os <<
"******* items_ \n";
739 <<
" " <<
item.index() <<
" " <<
item.typeID() <<
"\n";
743 os <<
"******* processItems_ \n";
748 os <<
"sortedTypeIDs_.size() = " <<
sortedTypeIDs_.size() <<
"\n";
749 os <<
"indexAndNames_.size() = " <<
indexAndNames_.size() <<
"\n";
751 os <<
"processNames_.size() = " <<
processNames_.size() <<
"\n";