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());
86 unsigned int iToIndexAndNames =
indexToIndexAndNames(kindOfType, typeID, moduleLabel, instance, process);
95 unsigned int startInIndexAndNames,
96 unsigned int numberOfMatches)
97 : productResolverIndexHelper_(productResolverIndexHelper),
98 startInIndexAndNames_(startInIndexAndNames),
99 numberOfMatches_(numberOfMatches) {
100 if (numberOfMatches != 0 &&
103 <<
"ProductResolverIndexHelper::Matches::Matches - Arguments exceed vector bounds.\n";
117 <<
"ProductResolverIndexHelper::Matches::isFullyResolved - Argument is out of range.\n";
125 <<
"ProductResolverIndexHelper::Matches::processName - Argument is out of range.\n";
127 unsigned int startInProcessNames =
135 <<
"ProductResolverIndexHelper::Matches::moduleLabel - Argument is out of range.\n";
146 unsigned int startInIndexAndNames =
indexToIndexAndNames(kindOfType, typeID, moduleLabel, instance,
nullptr);
153 for (
unsigned int j = startInIndexAndNames + 1
U;
j < vSize && (
indexAndNames_[
j].startInProcessNames() != 0
U);
158 return Matches(
this, startInIndexAndNames, numberOfMatches);
162 TypeID const& typeID)
const {
172 startInIndexAndNames = range.
begin();
173 numberOfMatches = range.
end() - range.
begin();
175 return Matches(
this, startInIndexAndNames, numberOfMatches);
182 TypeID const& containedTypeID,
183 std::vector<TypeWithDict>* baseTypesOfContainedType) {
186 <<
"ProductResolverIndexHelper::insert - Attempt to insert more elements after frozen.\n";
189 if (process ==
nullptr || *process ==
'\0') {
195 std::set<Item>::iterator iter =
items_->find(item);
196 if (iter !=
items_->end()) {
198 <<
"ProductResolverIndexHelper::insert - Attempt to insert duplicate entry.\n";
210 iter =
items_->find(item);
211 if (iter ==
items_->end()) {
219 if (containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID()) {
222 Item containedItem(
ELEMENT_TYPE, containedTypeID, moduleLabel, instance, process, savedProductIndex);
223 iter =
items_->find(containedItem);
224 if (iter !=
items_->end()) {
228 items_->insert(containedItem);
230 containedItem.clearProcess();
231 iter =
items_->find(containedItem);
232 if (iter ==
items_->end()) {
235 items_->insert(containedItem);
239 if (baseTypesOfContainedType) {
240 for (
TypeWithDict const& baseType : *baseTypesOfContainedType) {
241 TypeID baseTypeID(baseType.typeInfo());
242 Item baseItem(
ELEMENT_TYPE, baseTypeID, moduleLabel, instance, process, savedProductIndex);
243 iter =
items_->find(baseItem);
244 if (iter !=
items_->end()) {
250 baseItem.clearProcess();
251 iter =
items_->find(baseItem);
252 if (iter ==
items_->end()) {
260 return savedProductIndex;
268 bool hasContainedType = (containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID());
269 std::vector<TypeWithDict> baseTypes;
270 std::vector<TypeWithDict>* baseTypesOfContainedType = &baseTypes;
271 if (hasContainedType) {
272 std::vector<std::string> missingDictionaries;
275 return insert(typeID, moduleLabel, instance, process, containedTypeID, baseTypesOfContainedType);
285 bool iFirstThisType =
true;
286 bool beginElementsWasSet =
false;
291 unsigned int iCountTypes = 0;
292 unsigned int iCountCharacters = 0;
294 if (iFirstThisType ||
item.typeID() != previousTypeID ||
item.kindOfType() != previousKindOfType) {
296 iFirstThisType =
true;
298 if (!beginElementsWasSet) {
300 beginElementsWasSet =
true;
309 if (iFirstThisType ||
item.moduleLabel() != previousModuleLabel ||
item.instance() != previousInstance) {
310 iCountCharacters +=
item.moduleLabel().size();
311 iCountCharacters +=
item.instance().size();
312 iCountCharacters += 2;
315 iFirstThisType =
false;
316 previousTypeID =
item.typeID();
317 previousKindOfType =
item.kindOfType();
318 previousModuleLabel =
item.moduleLabel();
319 previousInstance =
item.instance();
323 unsigned int processNamesSize = 0;
325 processNamesSize += processItem.size();
329 for (
auto const& processItem : *processItems_) {
330 for (
auto const&
c : processItem) {
344 bool iFirstType =
true;
345 iFirstThisType =
true;
346 previousTypeID =
TypeID();
347 unsigned int iCount = 0;
348 unsigned int iBeginning = 0;
349 iCountCharacters = 0;
350 unsigned int previousCharacterCount = 0;
351 if (!items_->empty()) {
352 for (
auto const&
item : *items_) {
353 if (iFirstThisType ||
item.typeID() != previousTypeID ||
item.kindOfType() != previousKindOfType) {
354 iFirstThisType =
true;
365 if (iFirstThisType ||
item.moduleLabel() != previousModuleLabel ||
item.instance() != previousInstance) {
366 unsigned int labelSize =
item.moduleLabel().size();
367 for (
unsigned int j = 0;
j < labelSize; ++
j) {
372 unsigned int instanceSize =
item.instance().size();
373 for (
unsigned int j = 0;
j < instanceSize; ++
j) {
378 previousCharacterCount = iCountCharacters;
380 iCountCharacters += labelSize;
381 iCountCharacters += instanceSize;
382 iCountCharacters += 2;
388 <<
"ProductResolverIndexHelper::setFrozen - Process not found in processNames_.\n";
392 iFirstThisType =
false;
393 previousTypeID =
item.typeID();
394 previousKindOfType =
item.kindOfType();
395 previousModuleLabel =
item.moduleLabel();
396 previousInstance =
item.instance();
409 processItems_ =
nullptr;
415 <<
"ProductResolverIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
428 unsigned startProcess = 0;
438 unsigned int end = range.
end();
440 while (begin < end) {
441 unsigned int midpoint = begin + ((end -
begin) / 2);
446 while (*namePtr && (*namePtr == *label)) {
450 if (*namePtr == *label) {
455 while (*namePtr && (*namePtr == *instanceName)) {
459 if (*namePtr == *instanceName) {
461 if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
464 if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
467 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
470 if (indexAndNames_[midpoint].startInProcessNames() == 0)
476 if (midpoint == indexAndNames_.size())
478 if (indexAndNames_[midpoint].startInProcessNames() == 0)
480 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
487 }
else if (*namePtr < *instanceName) {
488 if (begin == midpoint)
494 }
else if (*namePtr < *label) {
495 if (begin == midpoint)
507 unsigned int beginType = 0;
514 while (beginType < endType) {
515 unsigned int midpointType = beginType + ((endType - beginType) / 2);
519 if (beginType == midpointType)
521 beginType = midpointType;
523 endType = midpointType;
531 char const*
begin = ptr;
534 char const* beginName = ptr;
535 while (*ptr && (*ptr == *p)) {
540 return beginName -
begin;
546 if (static_cast<unsigned>(ptr - begin) >=
processNames_.size()) {
563 auto l = strlen(pModLabel);
564 auto pInstance = pModLabel +
l + 1;
573 bool sanityChecksPass =
true;
575 sanityChecksPass =
false;
577 unsigned int previousEnd = 0;
579 if (
range.begin() != previousEnd)
580 sanityChecksPass =
false;
582 sanityChecksPass =
false;
583 previousEnd =
range.end();
586 sanityChecksPass =
false;
588 unsigned maxStart = 0;
589 unsigned maxStartProcess = 0;
592 sanityChecksPass =
false;
595 sanityChecksPass =
false;
596 if (indexAndName.startInProcessNames() >=
processNames_.size())
597 sanityChecksPass =
false;
599 if (indexAndName.startInBigNamesContainer() > maxStart)
600 maxStart = indexAndName.startInBigNamesContainer();
601 if (indexAndName.startInProcessNames() > maxStartProcess)
602 maxStartProcess = indexAndName.startInProcessNames();
605 if (!indexAndNames_.empty()) {
607 sanityChecksPass =
false;
609 sanityChecksPass =
false;
611 sanityChecksPass =
false;
612 unsigned int countZeroes = 0;
618 if (countZeroes != 2)
619 sanityChecksPass =
false;
621 sanityChecksPass =
false;
628 if (countZeroes != 1)
629 sanityChecksPass =
false;
632 if (!sanityChecksPass) {
643 : kindOfType_(kindOfType),
645 moduleLabel_(moduleLabel),
671 os <<
"\n******* Dump ProductResolverIndexHelper *************************\n";
676 os <<
"\n******* sortedTypeIDs_ \n";
680 os <<
"******* ranges_ \n";
682 os <<
i.begin() <<
" " <<
i.end() <<
"\n";
684 os <<
"******* indexAndNames_ \n";
686 os <<
i.index() <<
" " <<
i.startInBigNamesContainer() <<
" ";
698 os <<
" " <<
i.startInProcessNames() <<
" ";
706 os <<
"******* bigNamesContainer_ \n";
713 if (!bigNamesContainer_.empty())
715 os <<
"******* processNames_ \n";
722 if (!processNames_.empty())
725 os <<
"******* items_ \n";
728 <<
" " <<
item.index() <<
" " <<
item.typeID() <<
"\n";
732 os <<
"******* processItems_ \n";
737 os <<
"sortedTypeIDs_.size() = " << sortedTypeIDs_.size() <<
"\n";
738 os <<
"indexAndNames_.size() = " << indexAndNames_.size() <<
"\n";
739 os <<
"bigNamesContainer_.size() = " << bigNamesContainer_.size() <<
"\n";
740 os <<
"processNames_.size() = " << processNames_.size() <<
"\n";
ProductResolverIndex index(unsigned int i) const
char const * processName(unsigned int i) const
ProductResolverIndexHelper()
char const * moduleLabel(unsigned int i) const
TypeID getContainedType(TypeID const &typeID)
void setIndex(ProductResolverIndex v)
unsigned int indexToType(KindOfType kindOfType, TypeID const &typeID) const
std::vector< TypeID > sortedTypeIDs_
unsigned int ProductResolverIndex
Item(KindOfType kindOfType, TypeID const &typeID, std::string const &moduleLabel, std::string const &instance, std::string const &process, ProductResolverIndex index)
TypeID getContainedTypeFromWrapper(TypeID const &wrappedtypeID, std::string const &className)
static PFTauRenderPlugin instance
PixelRecoRange< float > Range
std::vector< char > processNames_
bool public_base_classes(std::vector< std::string > &missingDictionaries, TypeID const &typeID, std::vector< TypeWithDict > &baseTypes)
ModulesToIndiciesMap indiciesForModulesInProcess(const std::string &iProcessName) const
ProductResolverIndex insert(TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process, TypeID const &containedTypeID, std::vector< TypeWithDict > *baseTypesOfContainedType)
bool isFullyResolved(unsigned int i) const
std::unordered_multimap< std::string, std::tuple< TypeID const *, const char *, ProductResolverIndex >> ModulesToIndiciesMap
const std::type_info & typeInfo() const
unsigned int processIndex(char const *process) const
unsigned int startInIndexAndNames_
static TypeWithDict byName(std::string const &name)
Matches(ProductResolverIndexHelper const *productResolverIndexHelper, unsigned int startInIndexAndNames, unsigned int numberOfMatches)
edm::propagate_const< std::unique_ptr< std::set< std::string > > > processItems_
std::vector< IndexAndNames > const & indexAndNames() const
unsigned int numberOfMatches() const
Matches relatedIndexes(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance) const
unsigned int indexToIndexAndNames(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process) const
std::type_info const & typeInfo() const
std::vector< Range > ranges_
void print(std::ostream &os) const
ProductResolverIndex nextIndexValue_
std::vector< IndexAndNames > indexAndNames_
std::vector< std::string > lookupProcessNames_
std::string wrappedClassName(std::string const &iFullName)
unsigned int numberOfMatches_
std::string const & className() const
ProductResolverIndexHelper const * productResolverIndexHelper_
unsigned int begin() const
unsigned int beginElements_
bool operator<(Item const &right) const
ProductResolverIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=nullptr) const
edm::propagate_const< std::unique_ptr< std::set< Item > > > items_
std::vector< std::string > const & lookupProcessNames() const
std::string className(const T &t)
std::vector< char > bigNamesContainer_