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());
79 processItems_(new std::set<std::
string>) {}
83 char const* moduleLabel,
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";
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() != 0U);
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];
155 char const* moduleLabel,
157 unsigned int startInIndexAndNames =
indexToIndexAndNames(kindOfType, typeID, moduleLabel, instance,
nullptr);
158 unsigned int numberOfMatches = 1;
164 for (
unsigned int j = startInIndexAndNames + 1U;
j < vSize && (
indexAndNames_[
j].startInProcessNames() != 0U);
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);
190 char const* moduleLabel,
193 TypeID const& containedTypeID,
194 std::vector<TypeWithDict>* baseTypesOfContainedType) {
197 <<
"ProductResolverIndexHelper::insert - Attempt to insert more elements after frozen.\n";
200 if (process ==
nullptr || *process ==
'\0') {
206 std::set<Item>::iterator iter =
items_->find(item);
207 if (iter !=
items_->end()) {
209 <<
"ProductResolverIndexHelper::insert - Attempt to insert duplicate entry.\n";
221 iter =
items_->find(item);
222 if (iter ==
items_->end()) {
230 if (containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID()) {
233 Item containedItem(
ELEMENT_TYPE, containedTypeID, moduleLabel, instance, process, savedProductIndex);
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());
253 Item baseItem(
ELEMENT_TYPE, baseTypeID, moduleLabel, instance, process, savedProductIndex);
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;
275 char const* moduleLabel,
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;
286 return insert(typeID, moduleLabel, instance, process, containedTypeID, baseTypesOfContainedType);
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();
340 for (
auto const& processItem : *processItems_) {
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;
362 if (!items_->empty()) {
363 for (
auto const&
item : *items_) {
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();
420 processItems_ =
nullptr;
426 <<
"ProductResolverIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
433 char const* moduleLabel,
439 unsigned startProcess = 0;
449 unsigned int end = range.
end();
451 while (begin < end) {
452 unsigned int midpoint = begin + ((end -
begin) / 2);
456 char const*
label = moduleLabel;
457 while (*namePtr && (*namePtr == *label)) {
461 if (*namePtr == *label) {
465 char const* instanceName =
instance;
466 while (*namePtr && (*namePtr == *instanceName)) {
470 if (*namePtr == *instanceName) {
472 if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
475 if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
478 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
481 if (indexAndNames_[midpoint].startInProcessNames() == 0)
487 if (midpoint == indexAndNames_.size())
489 if (indexAndNames_[midpoint].startInProcessNames() == 0)
491 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
498 }
else if (*namePtr < *instanceName) {
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();
616 if (!indexAndNames_.empty()) {
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";
724 if (!bigNamesContainer_.empty())
726 os <<
"******* processNames_ \n";
733 if (!processNames_.empty())
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";
750 os <<
"bigNamesContainer_.size() = " << bigNamesContainer_.size() <<
"\n";
751 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_
const edm::EventSetup & c
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)
constexpr const std::type_info & typeInfo() const
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
unsigned int processIndex(char const *process) const
unsigned int startInIndexAndNames_
const uint16_t range(const Frame &aFrame)
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
char const * productInstanceName(unsigned int i) 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_