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.9 2013/02/10 22:12:04 wmtan Exp $
12 //
13 
14 // system include files
15 #include <iostream>
16 #include "TClass.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 edm::TypeWithDict& iChild,
76  const std::string& iParentTypeName,
77  unsigned int& distance) {
78  if(iChild.typeInfo().name() == iParentTypeName) {
79  return true;
80  }
81  edm::TypeBases bases(iChild);
82  if(bases.size() == 0) {
83  return false;
84  }
85  ++distance;
86  for(auto const& base : bases) {
87  if(inheritsFrom(edm::BaseWithDict(base).typeOf(),iParentTypeName,distance)) {
88  return true;
89  }
90  }
91  --distance;
92  return false;
93 }
94 
97 {
98  unsigned int distance=1;
99 
100  FWItemAccessorFactory factory;
101  //std::cout<<"checker infoFor"<<iTypeName<<std::endl;
102  TClass* clss = TClass::GetClass(iTypeName.c_str());
103  //Class could be unknown if the dictionary for it has not been loaded
104  if(0==clss || 0==clss->GetTypeInfo()) {
105  return FWRepresentationInfo();
106  }
107  boost::shared_ptr<FWItemAccessorBase> accessor = factory.accessorFor(clss);
108 
109  const TClass* modelClass = accessor->modelType();
110  //std::cout <<" "<<modelClass->GetName()<<" "<< bool(modelClass == clss)<< std::endl;
111 
112  if(0==modelClass || 0 == modelClass->GetTypeInfo()) {
113  //some containers e.g. vector<int> do not have known TClasses for their elements
114  // or the contained type may be unknown to ROOT
115  return FWRepresentationInfo();
116  }
117  edm::TypeWithDict modelType( *(modelClass->GetTypeInfo()));
118  //see if the modelType inherits from our type
119 
120  if(inheritsFrom(modelType,m_typeidName,distance) ) {
122  }
123  return FWRepresentationInfo();
124 }
125 
126 //
127 // static member functions
128 //
tuple base
Main Program
Definition: newFWLiteAna.py:92
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
size_t size() const
static bool inheritsFrom(const edm::TypeWithDict &iChild, const std::string &iParentTypeName, unsigned int &distance)
std::type_info const & typeInfo() const
boost::shared_ptr< FWItemAccessorBase > accessorFor(const TClass *) const