CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/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.6 2010/06/02 22:55:42 chrjones Exp $
00012 //
00013 
00014 // system include files
00015 #include <iostream>
00016 #include "TClass.h"
00017 #include "Reflex/Base.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 ROOT::Reflex::Type& iChild,
00076                          const std::string& iParentTypeName,
00077                          unsigned int& distance) {
00078    if(iChild.TypeInfo().name() == iParentTypeName) {
00079       return true;
00080    }
00081    if(iChild.BaseSize() == 0) {
00082       return false;
00083    }
00084    ++distance;
00085    for(ROOT::Reflex::Base_Iterator it = iChild.Base_Begin(),
00086                                    itEnd = iChild.Base_End();
00087        it != itEnd;
00088        ++it) {
00089       if(inheritsFrom(it->ToType(),iParentTypeName,distance)) {
00090          return true;
00091       }
00092    }
00093    --distance;
00094    return false;
00095 }
00096 
00097 FWRepresentationInfo
00098 FWSimpleRepresentationChecker::infoFor(const std::string& iTypeName) const
00099 {
00100    unsigned int distance=1;
00101 
00102    FWItemAccessorFactory factory;
00103    //std::cout<<"checker infoFor"<<iTypeName<<std::endl;
00104    TClass* clss = TClass::GetClass(iTypeName.c_str());
00105    //Class could be unknown if the dictionary for it has not been loaded
00106    if(0==clss || 0==clss->GetTypeInfo()) {
00107       return FWRepresentationInfo();
00108    }
00109    boost::shared_ptr<FWItemAccessorBase> accessor = factory.accessorFor(clss);
00110 
00111    const TClass* modelClass = accessor->modelType();
00112    //std::cout <<"   "<<modelClass->GetName()<<" "<< bool(modelClass == clss)<< std::endl;
00113 
00114    if(0==modelClass || 0 == modelClass->GetTypeInfo()) {
00115       //some containers e.g. vector<int> do not have known TClasses for their elements
00116       // or the contained type may be unknown to ROOT
00117       return FWRepresentationInfo();
00118    }
00119    ROOT::Reflex::Type modelType =
00120       ROOT::Reflex::Type::ByTypeInfo( *(modelClass->GetTypeInfo()));
00121    //see if the modelType inherits from our type
00122 
00123    if(inheritsFrom(modelType,m_typeidName,distance) ) {
00124       return FWRepresentationInfo(purpose(),distance,bitPackedViews(), representsSubPart());
00125    }
00126    return FWRepresentationInfo();
00127 }
00128 
00129 //
00130 // static member functions
00131 //