Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:42

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWSimpleRepresentationChecker
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Nov 25 10:54:28 EST 2008
0011 //
0012 
0013 // system include files
0014 #include <iostream>
0015 #include "TClass.h"
0016 #include "FWCore/Reflection/interface/BaseWithDict.h"
0017 
0018 // user include files
0019 #include "Fireworks/Core/interface/FWSimpleRepresentationChecker.h"
0020 
0021 #include "Fireworks/Core/interface/FWRepresentationInfo.h"
0022 
0023 #include "Fireworks/Core/interface/FWItemAccessorFactory.h"
0024 #include "Fireworks/Core/interface/FWItemAccessorBase.h"
0025 
0026 //
0027 // constants, enums and typedefs
0028 //
0029 
0030 //
0031 // static data member definitions
0032 //
0033 
0034 //
0035 // constructors and destructor
0036 //
0037 FWSimpleRepresentationChecker::FWSimpleRepresentationChecker(const std::string& iTypeName,
0038                                                              const std::string& iPurpose,
0039                                                              unsigned int iBitPackedViews,
0040                                                              bool iRepresentsSubPart,
0041                                                              bool iRequiresFF)
0042     : FWRepresentationCheckerBase(iPurpose, iBitPackedViews, iRepresentsSubPart, iRequiresFF),
0043       m_typeidName(iTypeName) {}
0044 
0045 // FWSimpleRepresentationChecker::FWSimpleRepresentationChecker(const FWSimpleRepresentationChecker& rhs)
0046 // {
0047 //    // do actual copying here;
0048 // }
0049 
0050 FWSimpleRepresentationChecker::~FWSimpleRepresentationChecker() {}
0051 
0052 //
0053 // assignment operators
0054 //
0055 // const FWSimpleRepresentationChecker& FWSimpleRepresentationChecker::operator=(const FWSimpleRepresentationChecker& rhs)
0056 // {
0057 //   //An exception safe implementation is
0058 //   FWSimpleRepresentationChecker temp(rhs);
0059 //   swap(rhs);
0060 //
0061 //   return *this;
0062 // }
0063 
0064 //
0065 // member functions
0066 //
0067 
0068 //
0069 // const member functions
0070 //
0071 bool FWSimpleRepresentationChecker::inheritsFrom(const edm::TypeWithDict& iChild,
0072                                                  const std::string& iParentTypeName,
0073                                                  unsigned int& distance) {
0074   if (iChild.getClass()) {
0075     if (iChild.getClass()->GetTypeInfo() == nullptr) {
0076       return false;
0077     }
0078   }
0079 
0080   if (iChild.typeInfo().name() == iParentTypeName) {
0081     return true;
0082   }
0083   edm::TypeBases bases(iChild);
0084   if (bases.size() == 0) {
0085     return false;
0086   }
0087   ++distance;
0088   for (auto const& base : bases) {
0089     if (inheritsFrom(edm::BaseWithDict(base).typeOf(), iParentTypeName, distance)) {
0090       return true;
0091     }
0092   }
0093   --distance;
0094   return false;
0095 }
0096 
0097 FWRepresentationInfo FWSimpleRepresentationChecker::infoFor(const std::string& iTypeName) const {
0098   unsigned int distance = 1;
0099 
0100   FWItemAccessorFactory factory;
0101   //std::cout<<"checker infoFor"<<iTypeName<<std::endl;
0102   TClass* clss = TClass::GetClass(iTypeName.c_str());
0103   //Class could be unknown if the dictionary for it has not been loaded
0104   if (nullptr == clss || nullptr == clss->GetTypeInfo()) {
0105     return FWRepresentationInfo();
0106   }
0107   std::shared_ptr<FWItemAccessorBase> accessor = factory.accessorFor(clss);
0108 
0109   const TClass* modelClass = accessor->modelType();
0110   //std::cout <<"   "<<modelClass->GetName()<<" "<< bool(modelClass == clss)<< std::endl;
0111 
0112   if (nullptr == modelClass || nullptr == modelClass->GetTypeInfo()) {
0113     //some containers e.g. vector<int> do not have known TClasses for their elements
0114     // or the contained type may be unknown to ROOT
0115     return FWRepresentationInfo();
0116   }
0117   edm::TypeWithDict modelType(*(modelClass->GetTypeInfo()));
0118   //see if the modelType inherits from our type
0119 
0120   if (inheritsFrom(modelType, m_typeidName, distance)) {
0121     return FWRepresentationInfo(purpose(), distance, bitPackedViews(), representsSubPart(), requiresFF());
0122   }
0123   return FWRepresentationInfo();
0124 }
0125 
0126 //
0127 // static member functions
0128 //