CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: FWSimpleRepresentationChecker.cc,v 1.7 2012/06/26 22:13:04 wmtan Exp $
12 //
13 
14 // system include files
15 #include <iostream>
16 #include "TClass.h"
17 #include "Reflex/Base.h"
18 
19 // user include files
21 
23 
26 
27 //
28 // constants, enums and typedefs
29 //
30 
31 //
32 // static data member definitions
33 //
34 
35 //
36 // constructors and destructor
37 //
39  const std::string& iPurpose,
40  unsigned int iBitPackedViews,
41  bool iRepresentsSubPart) :
42  FWRepresentationCheckerBase(iPurpose,iBitPackedViews,iRepresentsSubPart),
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 //
75 static bool inheritsFrom(const Reflex::Type& iChild,
76  const std::string& iParentTypeName,
77  unsigned int& distance) {
78  if(iChild.TypeInfo().name() == iParentTypeName) {
79  return true;
80  }
81  if(iChild.BaseSize() == 0) {
82  return false;
83  }
84  ++distance;
85  for(Reflex::Base_Iterator it = iChild.Base_Begin(),
86  itEnd = iChild.Base_End();
87  it != itEnd;
88  ++it) {
89  if(inheritsFrom(it->ToType(),iParentTypeName,distance)) {
90  return true;
91  }
92  }
93  --distance;
94  return false;
95 }
96 
98 FWSimpleRepresentationChecker::infoFor(const std::string& iTypeName) const
99 {
100  unsigned int distance=1;
101 
102  FWItemAccessorFactory factory;
103  //std::cout<<"checker infoFor"<<iTypeName<<std::endl;
104  TClass* clss = TClass::GetClass(iTypeName.c_str());
105  //Class could be unknown if the dictionary for it has not been loaded
106  if(0==clss || 0==clss->GetTypeInfo()) {
107  return FWRepresentationInfo();
108  }
109  boost::shared_ptr<FWItemAccessorBase> accessor = factory.accessorFor(clss);
110 
111  const TClass* modelClass = accessor->modelType();
112  //std::cout <<" "<<modelClass->GetName()<<" "<< bool(modelClass == clss)<< std::endl;
113 
114  if(0==modelClass || 0 == modelClass->GetTypeInfo()) {
115  //some containers e.g. vector<int> do not have known TClasses for their elements
116  // or the contained type may be unknown to ROOT
117  return FWRepresentationInfo();
118  }
119  Reflex::Type modelType =
120  Reflex::Type::ByTypeInfo( *(modelClass->GetTypeInfo()));
121  //see if the modelType inherits from our type
122 
123  if(inheritsFrom(modelType,m_typeidName,distance) ) {
125  }
126  return FWRepresentationInfo();
127 }
128 
129 //
130 // static member functions
131 //
virtual FWRepresentationInfo infoFor(const std::string &iTypeName) const
FWSimpleRepresentationChecker(const std::string &iTypeidName, const std::string &iPurpose, unsigned int iBitPackedViews, bool iRepresentsSubPart)
const std::string & purpose() const
static bool inheritsFrom(const Reflex::Type &iChild, const std::string &iParentTypeName, unsigned int &distance)
boost::shared_ptr< FWItemAccessorBase > accessorFor(const TClass *) const