CMS 3D CMS Logo

FWSimpleRepresentationChecker.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWSimpleRepresentationChecker
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Tue Nov 25 10:54:28 EST 2008
11 //
12 
13 // system include files
14 #include <iostream>
15 #include "TClass.h"
17 
18 // user include files
20 
22 
25 
26 //
27 // constants, enums and typedefs
28 //
29 
30 //
31 // static data member definitions
32 //
33 
34 //
35 // constructors and destructor
36 //
38  const std::string& iPurpose,
39  unsigned int iBitPackedViews,
40  bool iRepresentsSubPart,
41  bool iRequiresFF) :
42  FWRepresentationCheckerBase(iPurpose,iBitPackedViews,iRepresentsSubPart, iRequiresFF),
43  m_typeidName(iTypeName)
44 {
45 }
46 
47 // FWSimpleRepresentationChecker::FWSimpleRepresentationChecker(const FWSimpleRepresentationChecker& rhs)
48 // {
49 // // do actual copying here;
50 // }
51 
53 {
54 }
55 
56 //
57 // assignment operators
58 //
59 // const FWSimpleRepresentationChecker& FWSimpleRepresentationChecker::operator=(const FWSimpleRepresentationChecker& rhs)
60 // {
61 // //An exception safe implementation is
62 // FWSimpleRepresentationChecker temp(rhs);
63 // swap(rhs);
64 //
65 // return *this;
66 // }
67 
68 //
69 // member functions
70 //
71 
72 //
73 // const member functions
74 //
76  const std::string& iParentTypeName,
77  unsigned int& distance) {
78 
79  if (iChild.getClass()) {
80  if (iChild.getClass()->GetTypeInfo() == nullptr) {
81  return false;
82  }
83  }
84 
85  if(iChild.typeInfo().name() == iParentTypeName) {
86  return true;
87  }
88  edm::TypeBases bases(iChild);
89  if(bases.size() == 0) {
90  return false;
91  }
92  ++distance;
93  for(auto const& base : bases) {
94  if(inheritsFrom(edm::BaseWithDict(base).typeOf(),iParentTypeName,distance)) {
95  return true;
96  }
97  }
98  --distance;
99  return false;
100 }
101 
104 {
105  unsigned int distance=1;
106 
107  FWItemAccessorFactory factory;
108  //std::cout<<"checker infoFor"<<iTypeName<<std::endl;
109  TClass* clss = TClass::GetClass(iTypeName.c_str());
110  //Class could be unknown if the dictionary for it has not been loaded
111  if(nullptr==clss || nullptr==clss->GetTypeInfo()) {
112  return FWRepresentationInfo();
113  }
114  std::shared_ptr<FWItemAccessorBase> accessor = factory.accessorFor(clss);
115 
116  const TClass* modelClass = accessor->modelType();
117  //std::cout <<" "<<modelClass->GetName()<<" "<< bool(modelClass == clss)<< std::endl;
118 
119  if(nullptr==modelClass || nullptr == modelClass->GetTypeInfo()) {
120  //some containers e.g. vector<int> do not have known TClasses for their elements
121  // or the contained type may be unknown to ROOT
122  return FWRepresentationInfo();
123  }
124  edm::TypeWithDict modelType( *(modelClass->GetTypeInfo()));
125  //see if the modelType inherits from our type
126 
127  if(inheritsFrom(modelType,m_typeidName,distance) ) {
129  }
130  return FWRepresentationInfo();
131 }
132 
133 //
134 // static member functions
135 //
const std::string & purpose() const
std::shared_ptr< FWItemAccessorBase > accessorFor(const TClass *) const
FWSimpleRepresentationChecker(const std::string &iTypeidName, const std::string &iPurpose, unsigned int iBitPackedViews, bool iRepresentsSubPart, bool iRequiresFF=false)
size_t size() const
static bool inheritsFrom(const edm::TypeWithDict &iChild, const std::string &iParentTypeName, unsigned int &distance)
TClass * getClass() const
std::type_info const & typeInfo() const
base
Make Sure CMSSW is Setup ##.
FWRepresentationInfo infoFor(const std::string &iTypeName) const override