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 std::string const associationMap(
"edm::AssociationMap<");
28 static std::string const newDetSetVector(
"edmNew::DetSetVector<");
29 static size_t const rvsize = refVector.size();
30 static size_t const rtbvsize = refToBaseVector.size();
31 static size_t const pvsize = ptrVector.size();
32 static size_t const vpsize = vectorPtr.size();
33 static size_t const amsize = associationMap.size();
34 static size_t const ndsize = newDetSetVector.size();
35 bool mayBeRefVector = (className.substr(0, rvsize) == refVector)
36 || (className.substr(0, rtbvsize) == refToBaseVector)
37 || (className.substr(0, pvsize) == ptrVector)
38 || (className.substr(0, vpsize) == vectorPtr);
46 if (className.substr(0, amsize) == associationMap ||
47 className.substr(0, ndsize) == newDetSetVector) {
48 return TypeID(
typeid(
void));
50 TClass*
cl = TClass::GetClass(wrappedTypeID.
className().c_str());
52 return TypeID(
typeid(
void));
55 int offset = cl->GetBaseClassOffset(wbClass) + vtcOffset;
56 std::unique_ptr<ViewTypeChecker> checker = getAnyPtr<ViewTypeChecker>(
p,
offset);
58 std::type_info
const& ti = checker->memberTypeInfo();
59 if(ti !=
typeid(
void)) {
63 return TypeID(checker->valueTypeInfo());
85 char const* moduleLabel,
102 unsigned int startInIndexAndNames,
103 unsigned int numberOfMatches) :
104 productResolverIndexHelper_(productResolverIndexHelper),
105 startInIndexAndNames_(startInIndexAndNames),
106 numberOfMatches_(numberOfMatches) {
109 <<
"ProductResolverIndexHelper::Matches::Matches - Arguments exceed vector bounds.\n";
117 <<
"ProductResolverIndexHelper::Matches::index - Argument is out of range.\n";
126 <<
"ProductResolverIndexHelper::Matches::isFullyResolved - Argument is out of range.\n";
135 <<
"ProductResolverIndexHelper::Matches::processName - Argument is out of range.\n";
145 <<
"ProductResolverIndexHelper::Matches::moduleLabel - Argument is out of range.\n";
168 for (
unsigned int j = startInIndexAndNames + 1
U;
174 return Matches(
this, startInIndexAndNames, numberOfMatches);
179 TypeID const& typeID)
const {
191 startInIndexAndNames = range.
begin();
192 numberOfMatches = range.
end() - range.
begin();
194 return Matches(
this, startInIndexAndNames, numberOfMatches);
202 TypeID const& containedTypeID,
203 std::vector<TypeWithDict>* baseTypesOfContainedType) {
206 <<
"ProductResolverIndexHelper::insert - Attempt to insert more elements after frozen.\n";
209 if (process ==
nullptr || *process ==
'\0') {
211 <<
"ProductResolverIndexHelper::insert - Empty process.\n";
216 std::set<Item>::iterator iter =
items_->find(item);
217 if (iter !=
items_->end()) {
219 <<
"ProductResolverIndexHelper::insert - Attempt to insert duplicate entry.\n";
231 iter =
items_->find(item);
232 if (iter ==
items_->end()) {
240 if(containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID()) {
243 Item containedItem(
ELEMENT_TYPE, containedTypeID, moduleLabel, instance, process, savedProductIndex);
244 iter =
items_->find(containedItem);
245 if (iter !=
items_->end()) {
249 items_->insert(containedItem);
251 containedItem.clearProcess();
252 iter =
items_->find(containedItem);
253 if (iter ==
items_->end()) {
256 items_->insert(containedItem);
260 if (baseTypesOfContainedType) {
262 for(
TypeWithDict const& baseType : *baseTypesOfContainedType) {
263 TypeID baseTypeID(baseType.typeInfo());
264 Item baseItem(
ELEMENT_TYPE, baseTypeID, moduleLabel, instance, process, savedProductIndex);
265 iter =
items_->find(baseItem);
266 if (iter !=
items_->end()) {
272 baseItem.clearProcess();
273 iter =
items_->find(baseItem);
274 if (iter ==
items_->end()) {
282 return savedProductIndex;
292 bool hasContainedType = (containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID());
293 std::vector<TypeWithDict> baseTypes;
294 std::vector<TypeWithDict>* baseTypesOfContainedType = &baseTypes;
295 if (hasContainedType) {
296 std::vector<std::string> missingDictionaries;
299 return insert(typeID, moduleLabel, instance, process, containedTypeID, baseTypesOfContainedType);
309 bool iFirstThisType =
true;
310 bool beginElementsWasSet =
false;
315 unsigned int iCountTypes = 0;
316 unsigned int iCountCharacters = 0;
317 for (
auto const& item : *
items_) {
319 if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
321 iFirstThisType =
true;
323 if (!beginElementsWasSet) {
325 beginElementsWasSet =
true;
334 if (iFirstThisType ||
335 item.moduleLabel() != previousModuleLabel ||
336 item.instance() != previousInstance) {
337 iCountCharacters += item.moduleLabel().size();
338 iCountCharacters += item.instance().size();
339 iCountCharacters += 2;
342 iFirstThisType =
false;
343 previousTypeID = item.typeID();
344 previousKindOfType = item.kindOfType();
345 previousModuleLabel = item.moduleLabel();
346 previousInstance = item.instance();
350 unsigned int processNamesSize = 0;
352 processNamesSize += processItem.size();
356 for (
auto const& processItem : *processItems_) {
357 for (
auto const&
c : processItem) {
371 bool iFirstType =
true;
372 iFirstThisType =
true;
373 previousTypeID =
TypeID();
374 unsigned int iCount = 0;
375 unsigned int iBeginning = 0;
376 iCountCharacters = 0;
377 unsigned int previousCharacterCount = 0;
378 if (!items_->empty()) {
379 for (
auto const& item : *items_) {
381 if (iFirstThisType || item.typeID() != previousTypeID || item.kindOfType() != previousKindOfType) {
382 iFirstThisType =
true;
393 if (iFirstThisType ||
394 item.moduleLabel() != previousModuleLabel ||
395 item.instance() != previousInstance) {
397 unsigned int labelSize = item.moduleLabel().size();
398 for (
unsigned int j = 0; j < labelSize; ++j) {
403 unsigned int instanceSize = item.instance().size();
404 for (
unsigned int j = 0; j < instanceSize; ++j) {
409 previousCharacterCount = iCountCharacters;
411 iCountCharacters += labelSize;
412 iCountCharacters += instanceSize;
413 iCountCharacters += 2;
416 unsigned int processStart =
processIndex(item.process().c_str());
419 <<
"ProductResolverIndexHelper::setFrozen - Process not found in processNames_.\n";
421 indexAndNames_.emplace_back(item.index(), previousCharacterCount, processStart);
423 iFirstThisType =
false;
424 previousTypeID = item.typeID();
425 previousKindOfType = item.kindOfType();
426 previousModuleLabel = item.moduleLabel();
427 previousInstance = item.instance();
440 processItems_ =
nullptr;
446 <<
"ProductResolverIndexHelper::lookupProcessNames - Attempt to access names before frozen.\n";
462 unsigned startProcess = 0;
472 unsigned int end = range.
end();
474 while (begin < end) {
476 unsigned int midpoint = begin + ((end -
begin) / 2);
481 while (*namePtr && (*namePtr == *label)) {
484 if (*namePtr == *label) {
489 while (*namePtr && (*namePtr == *instanceName)) {
492 if (*namePtr == *instanceName) {
495 if (startProcess == indexAndNames_[midpoint].startInProcessNames()) {
498 if (indexAndNames_[midpoint].startInProcessNames() > startProcess) {
501 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
504 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
509 if (midpoint == indexAndNames_.size())
break;
510 if (indexAndNames_[midpoint].startInProcessNames() == 0)
break;
511 if (indexAndNames_[midpoint].startInProcessNames() == startProcess) {
518 }
else if (*namePtr < *instanceName) {
519 if (begin == midpoint)
break;
524 }
else if (*namePtr < *label) {
525 if (begin == midpoint)
break;
537 TypeID const& typeID)
const {
539 unsigned int beginType = 0;
546 while (beginType < endType) {
547 unsigned int midpointType = beginType + ((endType - beginType) / 2);
551 if (beginType == midpointType)
break;
552 beginType = midpointType;
554 endType = midpointType;
563 char const*
begin = ptr;
566 char const* beginName = ptr;
567 while (*ptr && (*ptr == *p)) {
571 return beginName -
begin;
577 if (static_cast<unsigned>(ptr - begin) >=
processNames_.size()) {
590 for(
unsigned int j=range.begin(); j<range.end();++j) {
595 auto l = strlen(pModLabel);
596 auto pInstance = pModLabel+
l+1;
597 result.emplace(pModLabel,
609 bool sanityChecksPass =
true;
612 unsigned int previousEnd = 0;
613 for (
auto const& range :
ranges_) {
614 if (range.begin() != previousEnd) sanityChecksPass =
false;
615 if (range.begin() >= range.end()) sanityChecksPass =
false;
616 previousEnd = range.end();
618 if (previousEnd !=
indexAndNames_.size()) sanityChecksPass =
false;
621 unsigned maxStart = 0;
622 unsigned maxStartProcess = 0;
626 if (indexAndName.startInBigNamesContainer() >=
bigNamesContainer_.size()) sanityChecksPass =
false;
627 if (indexAndName.startInProcessNames() >=
processNames_.size()) sanityChecksPass =
false;
629 if (indexAndName.startInBigNamesContainer() > maxStart) maxStart = indexAndName.startInBigNamesContainer();
630 if (indexAndName.startInProcessNames() > maxStartProcess) maxStartProcess = indexAndName.startInProcessNames();
633 if (!indexAndNames_.empty()) {
637 unsigned int countZeroes = 0;
643 if (countZeroes != 2) sanityChecksPass =
false;
644 if (maxStartProcess >=
processNames_.size()) sanityChecksPass =
false;
646 for (
unsigned j = maxStartProcess; j <
processNames_.size(); ++j) {
651 if (countZeroes != 1) sanityChecksPass =
false;
654 if (!sanityChecksPass) {
656 <<
"ProductResolverIndexHelper::setFrozen - Detected illegal state.\n";
666 kindOfType_(kindOfType),
668 moduleLabel_(moduleLabel),
689 os <<
"\n******* Dump ProductResolverIndexHelper *************************\n";
694 os <<
"\n******* sortedTypeIDs_ \n";
698 os <<
"******* ranges_ \n";
700 os <<
i.begin() <<
" " <<
i.end() <<
"\n";
702 os <<
"******* indexAndNames_ \n";
704 os <<
i.index() <<
" " <<
i.startInBigNamesContainer() <<
" ";
716 os <<
" " <<
i.startInProcessNames() <<
" ";
724 os <<
"******* bigNamesContainer_ \n";
726 if (
i ==
'\0') os <<
'\\' <<
'0';
729 if (!bigNamesContainer_.empty()) os <<
"\n";
730 os <<
"******* processNames_ \n";
732 if (
i ==
'\0') os <<
'\\' <<
'0';
735 if (!processNames_.empty()) os <<
"\n";
737 os <<
"******* items_ \n";
738 for (
auto const& item : *
items_) {
739 std:: cout << item.kindOfType() <<
" " << item.moduleLabel() <<
" " << item.instance() <<
" " << item.process() <<
" " << 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_
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
std::unordered_multimap< std::string, std::tuple< TypeID const *, const char *, ProductResolverIndex >> ModulesToIndiciesMap
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
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_