CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Fireworks/Core/src/FWSimpleRepresentationChecker.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWSimpleRepresentationChecker
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Tue Nov 25 10:54:28 EST 2008
00011 // $Id: FWSimpleRepresentationChecker.cc,v 1.9 2013/02/10 22:12:04 wmtan Exp $
00012 //
00013 
00014 // system include files
00015 #include <iostream>
00016 #include "TClass.h"
00017 #include "FWCore/Utilities/interface/BaseWithDict.h"
00018 
00019 // user include files
00020 #include "Fireworks/Core/interface/FWSimpleRepresentationChecker.h"
00021 
00022 #include "Fireworks/Core/interface/FWRepresentationInfo.h"
00023 
00024 #include "Fireworks/Core/interface/FWItemAccessorFactory.h"
00025 #include "Fireworks/Core/interface/FWItemAccessorBase.h"
00026 
00027 //
00028 // constants, enums and typedefs
00029 //
00030 
00031 //
00032 // static data member definitions
00033 //
00034 
00035 //
00036 // constructors and destructor
00037 //
00038 FWSimpleRepresentationChecker::FWSimpleRepresentationChecker(const std::string& iTypeName,
00039                                                              const std::string& iPurpose,
00040                                                              unsigned int iBitPackedViews,
00041                                                              bool iRepresentsSubPart) :
00042    FWRepresentationCheckerBase(iPurpose,iBitPackedViews,iRepresentsSubPart),
00043    m_typeidName(iTypeName)
00044 {
00045 }
00046 
00047 // FWSimpleRepresentationChecker::FWSimpleRepresentationChecker(const FWSimpleRepresentationChecker& rhs)
00048 // {
00049 //    // do actual copying here;
00050 // }
00051 
00052 FWSimpleRepresentationChecker::~FWSimpleRepresentationChecker()
00053 {
00054 }
00055 
00056 //
00057 // assignment operators
00058 //
00059 // const FWSimpleRepresentationChecker& FWSimpleRepresentationChecker::operator=(const FWSimpleRepresentationChecker& rhs)
00060 // {
00061 //   //An exception safe implementation is
00062 //   FWSimpleRepresentationChecker temp(rhs);
00063 //   swap(rhs);
00064 //
00065 //   return *this;
00066 // }
00067 
00068 //
00069 // member functions
00070 //
00071 
00072 //
00073 // const member functions
00074 //
00075 static bool inheritsFrom(const edm::TypeWithDict& iChild,
00076                          const std::string& iParentTypeName,
00077                          unsigned int& distance) {
00078    if(iChild.typeInfo().name() == iParentTypeName) {
00079       return true;
00080    }
00081    edm::TypeBases bases(iChild);
00082    if(bases.size() == 0) {
00083       return false;
00084    }
00085    ++distance;
00086    for(auto const& base : bases) {
00087       if(inheritsFrom(edm::BaseWithDict(base).typeOf(),iParentTypeName,distance)) {
00088          return true;
00089       }
00090    }
00091    --distance;
00092    return false;
00093 }
00094 
00095 FWRepresentationInfo
00096 FWSimpleRepresentationChecker::infoFor(const std::string& iTypeName) const
00097 {
00098    unsigned int distance=1;
00099 
00100    FWItemAccessorFactory factory;
00101    //std::cout<<"checker infoFor"<<iTypeName<<std::endl;
00102    TClass* clss = TClass::GetClass(iTypeName.c_str());
00103    //Class could be unknown if the dictionary for it has not been loaded
00104    if(0==clss || 0==clss->GetTypeInfo()) {
00105       return FWRepresentationInfo();
00106    }
00107    boost::shared_ptr<FWItemAccessorBase> accessor = factory.accessorFor(clss);
00108 
00109    const TClass* modelClass = accessor->modelType();
00110    //std::cout <<"   "<<modelClass->GetName()<<" "<< bool(modelClass == clss)<< std::endl;
00111 
00112    if(0==modelClass || 0 == modelClass->GetTypeInfo()) {
00113       //some containers e.g. vector<int> do not have known TClasses for their elements
00114       // or the contained type may be unknown to ROOT
00115       return FWRepresentationInfo();
00116    }
00117    edm::TypeWithDict modelType( *(modelClass->GetTypeInfo()));
00118    //see if the modelType inherits from our type
00119 
00120    if(inheritsFrom(modelType,m_typeidName,distance) ) {
00121       return FWRepresentationInfo(purpose(),distance,bitPackedViews(), representsSubPart());
00122    }
00123    return FWRepresentationInfo();
00124 }
00125 
00126 //
00127 // static member functions
00128 //