Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
// -*- C++ -*-
//
// Package:     Core
// Class  :     FWSimpleRepresentationChecker
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:  Chris Jones
//         Created:  Tue Nov 25 10:54:28 EST 2008
//

// system include files
#include <iostream>
#include "TClass.h"
#include "FWCore/Reflection/interface/BaseWithDict.h"

// user include files
#include "Fireworks/Core/interface/FWSimpleRepresentationChecker.h"

#include "Fireworks/Core/interface/FWRepresentationInfo.h"

#include "Fireworks/Core/interface/FWItemAccessorFactory.h"
#include "Fireworks/Core/interface/FWItemAccessorBase.h"

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
FWSimpleRepresentationChecker::FWSimpleRepresentationChecker(const std::string& iTypeName,
                                                             const std::string& iPurpose,
                                                             unsigned int iBitPackedViews,
                                                             bool iRepresentsSubPart,
                                                             bool iRequiresFF)
    : FWRepresentationCheckerBase(iPurpose, iBitPackedViews, iRepresentsSubPart, iRequiresFF),
      m_typeidName(iTypeName) {}

// FWSimpleRepresentationChecker::FWSimpleRepresentationChecker(const FWSimpleRepresentationChecker& rhs)
// {
//    // do actual copying here;
// }

FWSimpleRepresentationChecker::~FWSimpleRepresentationChecker() {}

//
// assignment operators
//
// const FWSimpleRepresentationChecker& FWSimpleRepresentationChecker::operator=(const FWSimpleRepresentationChecker& rhs)
// {
//   //An exception safe implementation is
//   FWSimpleRepresentationChecker temp(rhs);
//   swap(rhs);
//
//   return *this;
// }

//
// member functions
//

//
// const member functions
//
bool FWSimpleRepresentationChecker::inheritsFrom(const edm::TypeWithDict& iChild,
                                                 const std::string& iParentTypeName,
                                                 unsigned int& distance) {
  if (iChild.getClass()) {
    if (iChild.getClass()->GetTypeInfo() == nullptr) {
      return false;
    }
  }

  if (iChild.typeInfo().name() == iParentTypeName) {
    return true;
  }
  edm::TypeBases bases(iChild);
  if (bases.size() == 0) {
    return false;
  }
  ++distance;
  for (auto const& base : bases) {
    if (inheritsFrom(edm::BaseWithDict(base).typeOf(), iParentTypeName, distance)) {
      return true;
    }
  }
  --distance;
  return false;
}

FWRepresentationInfo FWSimpleRepresentationChecker::infoFor(const std::string& iTypeName) const {
  unsigned int distance = 1;

  FWItemAccessorFactory factory;
  //std::cout<<"checker infoFor"<<iTypeName<<std::endl;
  TClass* clss = TClass::GetClass(iTypeName.c_str());
  //Class could be unknown if the dictionary for it has not been loaded
  if (nullptr == clss || nullptr == clss->GetTypeInfo()) {
    return FWRepresentationInfo();
  }
  std::shared_ptr<FWItemAccessorBase> accessor = factory.accessorFor(clss);

  const TClass* modelClass = accessor->modelType();
  //std::cout <<"   "<<modelClass->GetName()<<" "<< bool(modelClass == clss)<< std::endl;

  if (nullptr == modelClass || nullptr == modelClass->GetTypeInfo()) {
    //some containers e.g. vector<int> do not have known TClasses for their elements
    // or the contained type may be unknown to ROOT
    return FWRepresentationInfo();
  }
  edm::TypeWithDict modelType(*(modelClass->GetTypeInfo()));
  //see if the modelType inherits from our type

  if (inheritsFrom(modelType, m_typeidName, distance)) {
    return FWRepresentationInfo(purpose(), distance, bitPackedViews(), representsSubPart(), requiresFF());
  }
  return FWRepresentationInfo();
}

//
// static member functions
//