From de1b0a3e35a2e6e98c1aaaffe81c1835df716a76 Mon Sep 17 00:00:00 2001 From: wmtan Date: Thu, 27 Feb 2014 22:13:11 +0100 Subject: [PATCH 1/4] Should be no space before square bracket in C array type name --- FWCore/Utilities/src/TypeDemangler.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/FWCore/Utilities/src/TypeDemangler.cc b/FWCore/Utilities/src/TypeDemangler.cc index ee1676897645c..43de8f64cb4f7 100644 --- a/FWCore/Utilities/src/TypeDemangler.cc +++ b/FWCore/Utilities/src/TypeDemangler.cc @@ -118,10 +118,12 @@ namespace edm { } std::string demangledName(demangled); free(demangled); - // We must use the same conventions used by REFLEX. + // We must use the same conventions previously used by REFLEX. // The order of these is important. // No space after comma replaceString(demangledName, ", ", ","); + // No space before opening square bracket + replaceString(demangledName, " [", "["); // Strip default allocator std::string const allocator(",std::allocator<"); removeParameter(demangledName, allocator); From 30c3313fc05a6f2a530064c9bbea330bc88d82ab Mon Sep 17 00:00:00 2001 From: wmtan Date: Thu, 27 Feb 2014 22:14:25 +0100 Subject: [PATCH 2/4] MemberWitDict::typeOf() must not remove C array info --- FWCore/Utilities/interface/MemberWithDict.h | 1 + FWCore/Utilities/src/MemberWithDict.cc | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/FWCore/Utilities/interface/MemberWithDict.h b/FWCore/Utilities/interface/MemberWithDict.h index db38f1188d8a1..8969aa3ed8ac2 100644 --- a/FWCore/Utilities/interface/MemberWithDict.h +++ b/FWCore/Utilities/interface/MemberWithDict.h @@ -25,6 +25,7 @@ class MemberWithDict { explicit MemberWithDict(TDataMember*); explicit operator bool() const; std::string name() const; + bool isArray() const; bool isConst() const; bool isPublic() const; bool isStatic() const; diff --git a/FWCore/Utilities/src/MemberWithDict.cc b/FWCore/Utilities/src/MemberWithDict.cc index f8ca5eb21f77c..9587ad4ec028b 100644 --- a/FWCore/Utilities/src/MemberWithDict.cc +++ b/FWCore/Utilities/src/MemberWithDict.cc @@ -2,6 +2,8 @@ #include "FWCore/Utilities/interface/ObjectWithDict.h" #include "FWCore/Utilities/interface/TypeWithDict.h" +#include +#include namespace edm { @@ -22,6 +24,16 @@ namespace edm { TypeWithDict MemberWithDict::typeOf() const { + if(isArray()) { + std::ostringstream name; + name << dataMember_->GetTypeName(); + for(int i = 0; i < dataMember_->GetArrayDim(); ++i) { + name << '['; + name << dataMember_->GetMaxIndex(i); + name << ']'; + return TypeWithDict::byName(name.str(), dataMember_->Property()); + } + } return TypeWithDict::byName(dataMember_->GetTypeName(), dataMember_->Property()); } @@ -30,6 +42,11 @@ namespace edm { return TypeWithDict(dataMember_->GetClass(), dataMember_->Property()); } + bool + MemberWithDict::isArray() const { + return dataMember_->Property() & kIsArray; + } + bool MemberWithDict::isConst() const { return dataMember_->Property() & kIsConstant; From aa1856bd7a91b60bc351da1c49c50357c1826284 Mon Sep 17 00:00:00 2001 From: wmtan Date: Thu, 27 Feb 2014 22:15:43 +0100 Subject: [PATCH 3/4] Enhance unit tests --- DataFormats/Common/test/DictionaryTools_t.cpp | 1 + .../TestObjects/interface/ToyProducts.h | 5 ++++ DataFormats/TestObjects/src/classes_def.xml | 3 +++ DataFormats/TestObjects/test/Enum_t.cpp | 26 +++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/DataFormats/Common/test/DictionaryTools_t.cpp b/DataFormats/Common/test/DictionaryTools_t.cpp index 5ec91bd3015c7..fc4ab0808e444 100644 --- a/DataFormats/Common/test/DictionaryTools_t.cpp +++ b/DataFormats/Common/test/DictionaryTools_t.cpp @@ -150,6 +150,7 @@ namespace { checkIt >(); checkIt > >(); checkIt(); + checkIt(); } } diff --git a/DataFormats/TestObjects/interface/ToyProducts.h b/DataFormats/TestObjects/interface/ToyProducts.h index 3a708b7df8f52..c5d3f5f73417b 100644 --- a/DataFormats/TestObjects/interface/ToyProducts.h +++ b/DataFormats/TestObjects/interface/ToyProducts.h @@ -28,6 +28,11 @@ namespace edmtest { struct DummyProduct { }; + struct ArrayProduct { + explicit ArrayProduct(int i = 0) : value{i} {} + int value[1]; + }; + struct EnumProduct { enum TheEnumProduct { TheZero = 0, diff --git a/DataFormats/TestObjects/src/classes_def.xml b/DataFormats/TestObjects/src/classes_def.xml index 0c39be61a377c..844fb18fd51f5 100644 --- a/DataFormats/TestObjects/src/classes_def.xml +++ b/DataFormats/TestObjects/src/classes_def.xml @@ -9,6 +9,9 @@ + + + diff --git a/DataFormats/TestObjects/test/Enum_t.cpp b/DataFormats/TestObjects/test/Enum_t.cpp index 2810e80e14c3e..b30a621988c50 100644 --- a/DataFormats/TestObjects/test/Enum_t.cpp +++ b/DataFormats/TestObjects/test/Enum_t.cpp @@ -16,6 +16,8 @@ class TestDictionaries: public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(TestDictionaries); CPPUNIT_TEST(enum_is_valid); CPPUNIT_TEST(enum_by_name_is_valid); + CPPUNIT_TEST(enum_member_is_valid); + CPPUNIT_TEST(array_member_is_valid); CPPUNIT_TEST(demangling); CPPUNIT_TEST_SUITE_END(); @@ -27,6 +29,8 @@ class TestDictionaries: public CppUnit::TestFixture { void enum_is_valid(); void enum_by_name_is_valid(); + void enum_member_is_valid(); + void array_member_is_valid(); void demangling(); private: @@ -44,6 +48,28 @@ void TestDictionaries::enum_by_name_is_valid() { CPPUNIT_ASSERT(t); } +void TestDictionaries::enum_member_is_valid() { + edm::TypeWithDict t = edm::TypeWithDict::byName("edmtest::EnumProduct"); + edm::MemberWithDict m = t.dataMemberByName("value"); + edm::TypeWithDict t2 = m.typeOf(); + edm::TypeWithDict t3 = edm::TypeWithDict::byName("edmtest::EnumProduct::TheEnumProduct"); + CPPUNIT_ASSERT(t2); + CPPUNIT_ASSERT(t3); + CPPUNIT_ASSERT(t2 == t3); +} + +void TestDictionaries::array_member_is_valid() { + edm::TypeWithDict t = edm::TypeWithDict::byName("edmtest::ArrayProduct"); + edm::MemberWithDict m = t.dataMemberByName("value"); + CPPUNIT_ASSERT(m.isArray()); + edm::TypeWithDict t2 = m.typeOf(); + edm::TypeWithDict t3 = edm::TypeWithDict::byName("int[1]"); + CPPUNIT_ASSERT(t2); + CPPUNIT_ASSERT(t3); + CPPUNIT_ASSERT(t2.qualifiedName() == "int[1]"); + CPPUNIT_ASSERT(t2 == t3); +} + namespace { template void checkIt() { From e17ad264c7ac5643fb1023031cffa2956461b501 Mon Sep 17 00:00:00 2001 From: wmtan Date: Thu, 27 Feb 2014 22:17:08 +0100 Subject: [PATCH 4/4] Strip C array from type when necessary --- CondCore/ORA/src/ClassUtils.cc | 3 ++- CondCore/ORA/src/InlineCArrayStreamer.cc | 2 +- CondCore/ORA/src/ObjectStreamer.cc | 2 +- CondCore/ORA/src/RelationalMapping.cc | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CondCore/ORA/src/ClassUtils.cc b/CondCore/ORA/src/ClassUtils.cc index a97f18b35ed8b..dc875170f07e5 100644 --- a/CondCore/ORA/src/ClassUtils.cc +++ b/CondCore/ORA/src/ClassUtils.cc @@ -436,7 +436,8 @@ edm::TypeWithDict ora::ClassUtils::containerSubType(const edm::TypeWithDict& typ edm::TypeWithDict ora::ClassUtils::resolvedType(const edm::TypeWithDict& typ){ if (typ.isTypedef()){ - return typ.finalType(); + return typ.finalType().toType(); } return typ; } + diff --git a/CondCore/ORA/src/InlineCArrayStreamer.cc b/CondCore/ORA/src/InlineCArrayStreamer.cc index 431f46edda951..8f05e4d0edbe3 100644 --- a/CondCore/ORA/src/InlineCArrayStreamer.cc +++ b/CondCore/ORA/src/InlineCArrayStreamer.cc @@ -25,7 +25,7 @@ ora::InlineCArrayStreamerBase::~InlineCArrayStreamerBase(){ bool ora::InlineCArrayStreamerBase::buildDataElement(DataElement& dataElement, IRelationalData& relationalData, RelationalBuffer* operationBuffer){ - m_arrayType = ClassUtils::resolvedType( m_objectType ); + m_arrayType = ClassUtils::resolvedType( m_objectType.toType() ); if ( ! m_arrayType ) { throwException( "Missing dictionary information for the element of array \"" + m_objectType.qualifiedName() + "\"", diff --git a/CondCore/ORA/src/ObjectStreamer.cc b/CondCore/ORA/src/ObjectStreamer.cc index 5cae0cf7cc450..5fb2988d2886a 100644 --- a/CondCore/ORA/src/ObjectStreamer.cc +++ b/CondCore/ORA/src/ObjectStreamer.cc @@ -42,7 +42,7 @@ void ora::ObjectStreamerBase::buildBaseDataMembers( DataElement& dataElement, for ( unsigned int i=0;i