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 == 0 || *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) {
603 bool sanityChecksPass =
true;
606 unsigned int previousEnd = 0;
607 for (
auto const& range :
ranges_) {
608 if (range.begin() != previousEnd) sanityChecksPass =
false;
609 if (range.begin() >= range.end()) sanityChecksPass =
false;
610 previousEnd = range.end();
612 if (previousEnd !=
indexAndNames_.size()) sanityChecksPass =
false;
615 unsigned maxStart = 0;
616 unsigned maxStartProcess = 0;
620 if (indexAndName.startInBigNamesContainer() >=
bigNamesContainer_.size()) sanityChecksPass =
false;
621 if (indexAndName.startInProcessNames() >=
processNames_.size()) sanityChecksPass =
false;
623 if (indexAndName.startInBigNamesContainer() > maxStart) maxStart = indexAndName.startInBigNamesContainer();
624 if (indexAndName.startInProcessNames() > maxStartProcess) maxStartProcess = indexAndName.startInProcessNames();
627 if (!indexAndNames_.empty()) {
631 unsigned int countZeroes = 0;
637 if (countZeroes != 2) sanityChecksPass =
false;
638 if (maxStartProcess >=
processNames_.size()) sanityChecksPass =
false;
640 for (
unsigned j = maxStartProcess; j <
processNames_.size(); ++j) {
645 if (countZeroes != 1) sanityChecksPass =
false;
648 if (!sanityChecksPass) {
650 <<
"ProductResolverIndexHelper::setFrozen - Detected illegal state.\n";
660 kindOfType_(kindOfType),
662 moduleLabel_(moduleLabel),
683 os <<
"\n******* Dump ProductResolverIndexHelper *************************\n";
688 os <<
"\n******* sortedTypeIDs_ \n";
692 os <<
"******* ranges_ \n";
694 os <<
i.begin() <<
" " <<
i.end() <<
"\n";
696 os <<
"******* indexAndNames_ \n";
698 os <<
i.index() <<
" " <<
i.startInBigNamesContainer() <<
" ";
710 os <<
" " <<
i.startInProcessNames() <<
" ";
718 os <<
"******* bigNamesContainer_ \n";
720 if (
i ==
'\0') os <<
'\\' <<
'0';
723 if (!bigNamesContainer_.empty()) os <<
"\n";
724 os <<
"******* processNames_ \n";
726 if (
i ==
'\0') os <<
'\\' <<
'0';
729 if (!processNames_.empty()) os <<
"\n";
731 os <<
"******* items_ \n";
732 for (
auto const& item : *
items_) {
733 std:: cout << item.kindOfType() <<
" " << item.moduleLabel() <<
" " << item.instance() <<
" " << item.process() <<
" " << item.index() <<
" " << item.typeID() <<
"\n";
737 os <<
"******* processItems_ \n";
742 os <<
"sortedTypeIDs_.size() = " << sortedTypeIDs_.size() <<
"\n";
743 os <<
"indexAndNames_.size() = " << indexAndNames_.size() <<
"\n";
744 os <<
"bigNamesContainer_.size() = " << bigNamesContainer_.size() <<
"\n";
745 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_
std::unordered_multimap< std::string, ProductResolverIndex > ModulesToIndiciesMap
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
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
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_
PixelRecoRange< float > Range
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_
ProductResolverIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=0) const
std::string const & className() const
ProductResolverIndexHelper const * productResolverIndexHelper_
unsigned int begin() const
unsigned int beginElements_
bool operator<(Item const &right) 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_