CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions
FWItemAccessorFactory Class Reference

#include <Fireworks/Core/interface/FWItemAccessorFactory.h>

Public Member Functions

std::shared_ptr< FWItemAccessorBaseaccessorFor (const TClass *) const
 
 FWItemAccessorFactory ()
 
 FWItemAccessorFactory (const FWItemAccessorFactory &)=delete
 
const FWItemAccessorFactoryoperator= (const FWItemAccessorFactory &)=delete
 
virtual ~FWItemAccessorFactory ()
 

Static Public Member Functions

static bool classAccessedAsCollection (const TClass *)
 
static bool hasAccessor (const TClass *iClass, std::string &result)
 
static bool hasMemberTVirtualCollectionProxy (const TClass *iClass, TClass *&oMember, size_t &oOffset)
 
static bool hasTVirtualCollectionProxy (const TClass *iClass)
 

Detailed Description

Description: Factory for constructing FWItemAccessorBases appropriate to a certain type

Usage: <usage>

Definition at line 31 of file FWItemAccessorFactory.h.

Constructor & Destructor Documentation

◆ FWItemAccessorFactory() [1/2]

FWItemAccessorFactory::FWItemAccessorFactory ( )

Definition at line 38 of file FWItemAccessorFactory.cc.

38 {}

◆ ~FWItemAccessorFactory()

FWItemAccessorFactory::~FWItemAccessorFactory ( )
virtual

Definition at line 45 of file FWItemAccessorFactory.cc.

45 {}

◆ FWItemAccessorFactory() [2/2]

FWItemAccessorFactory::FWItemAccessorFactory ( const FWItemAccessorFactory )
delete

Member Function Documentation

◆ accessorFor()

std::shared_ptr< FWItemAccessorBase > FWItemAccessorFactory::accessorFor ( const TClass *  iClass) const

Create an accessor for a given type iClass.

iClass the type for which we need an accessor.

If the type is known to ROOT to be some sort of collection, we return the a FWItemTVirtualCollectionProxyAccessor constructed using the associated TVirtualCollectionProxy.

If above is not true, we lookup the plugin based FWItemAccessorRegistry for a plugin that can handle the given type.

If the type is not a collection but it contains only one element which is a collection, we return a FWItemTVirtualCollectionProxyAccessor using the TVirtualCollectionProxy of that element.

Failing that, we return a FWItemSingleAccessor which threats the object as if it was not a collection. Notice that this also will mean that the product associated to iClass will not show up in the "Add Collection" table.

Definition at line 89 of file FWItemAccessorFactory.cc.

References debug, fwLog, get, hasAccessor(), hasMemberTVirtualCollectionProxy(), hasTVirtualCollectionProxy(), fwlog::kDebug, HLT_IsoTrack_cff::offset, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by FWSimpleRepresentationChecker::infoFor().

89  {
90  static const bool debug = false;
91 
92  TClass *member = nullptr;
93  size_t offset = 0;
94 
95  if (hasTVirtualCollectionProxy(iClass)) {
96  if (debug)
97  fwLog(fwlog::kDebug) << "class " << iClass->GetName() << " uses FWItemTVirtualCollectionProxyAccessor."
98  << std::endl;
99  return std::make_shared<FWItemTVirtualCollectionProxyAccessor>(
100  iClass, std::shared_ptr<TVirtualCollectionProxy>(iClass->GetCollectionProxy()->Generate()));
101  }
102 
103  // Iterate on the available plugins and use the one which handles
104  // the iClass type.
105  // NOTE: This is done only a few times, not really performance critical.
106  // If you want this to be fast, the loop can be moved in the
107  // constructor. Notice that this will require constructing FWEventItemsManager
108  // after the plugin manager (i.e. invoking FWLiteEnabler::enable()) is configured
109  // (i.e. invoking FWLiteEnabler::enable()) in CmsShowMain.
110  std::string accessorName;
111  if (hasAccessor(iClass, accessorName)) {
112  if (debug)
113  fwLog(fwlog::kDebug) << "class " << iClass->GetName() << " uses " << accessorName << "." << std::endl;
114  return std::shared_ptr<FWItemAccessorBase>(FWItemAccessorRegistry::get()->create(accessorName, iClass));
115  }
116 
117  if (hasMemberTVirtualCollectionProxy(iClass, member, offset)) {
118  if (debug)
119  fwLog(fwlog::kDebug) << "class " << iClass->GetName() << " only contains data member " << member->GetName()
120  << " which uses FWItemTVirtualCollectionProxyAccessor." << std::endl;
121 
122  return std::make_shared<FWItemTVirtualCollectionProxyAccessor>(
123  iClass, std::shared_ptr<TVirtualCollectionProxy>(member->GetCollectionProxy()->Generate()), offset);
124  }
125 
126  return std::make_shared<FWItemSingleAccessor>(iClass);
127 }
#define debug
Definition: HDRShower.cc:19
#define fwLog(_level_)
Definition: fwLog.h:45
static bool hasTVirtualCollectionProxy(const TClass *iClass)
static bool hasMemberTVirtualCollectionProxy(const TClass *iClass, TClass *&oMember, size_t &oOffset)
static bool hasAccessor(const TClass *iClass, std::string &result)
#define get

◆ classAccessedAsCollection()

bool FWItemAccessorFactory::classAccessedAsCollection ( const TClass *  iClass)
static

Helper method which checks if the object will be treated as a collection.

Returns
true if this is the case, false otherwise.

Definition at line 202 of file FWItemAccessorFactory.cc.

References hasAccessor(), hasMemberTVirtualCollectionProxy(), hasTVirtualCollectionProxy(), HLT_IsoTrack_cff::offset, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by FWLiteJobMetadataManager::doUpdate(), and FWFFMetadataManager::doUpdate().

202  {
203  std::string accessorName;
204  TClass *member = nullptr;
205  size_t offset = 0;
206 
207  // This is pretty much the same thing that happens
210  FWItemAccessorFactory::hasAccessor(iClass, accessorName));
211 }
static bool hasTVirtualCollectionProxy(const TClass *iClass)
static bool hasMemberTVirtualCollectionProxy(const TClass *iClass, TClass *&oMember, size_t &oOffset)
static bool hasAccessor(const TClass *iClass, std::string &result)

◆ hasAccessor()

bool FWItemAccessorFactory::hasAccessor ( const TClass *  iClass,
std::string &  result 
)
static

Helper method which can be used to retrieve the name of the accessor plugin which has to be created for a object of type iClass.

The result is stored in the passed reference result.

Returns
true if the plugin coul be found, false otherwise.

Definition at line 182 of file FWItemAccessorFactory.cc.

References edmplugin::PluginManager::categoryToInfos(), MillePedeFileConverter_cfg::e, edmplugin::PluginManager::get(), mps_fire::i, mergeVDriftHistosByStation::name, mps_fire::result, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by accessorFor(), and classAccessedAsCollection().

182  {
183  const std::vector<edmplugin::PluginInfo> &available =
184  edmplugin::PluginManager::get()->categoryToInfos().find("cmsShow FWItemAccessorBase")->second;
185 
186  for (size_t i = 0, e = available.size(); i != e; ++i) {
187  std::string name = available[i].name_;
188  std::string type = name.substr(0, name.find_first_of('@'));
189  if (iClass->GetTypeInfo()->name() == type) {
190  result.swap(name);
191  return true;
192  }
193  }
194  return false;
195 }
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
static PluginManager * get()

◆ hasMemberTVirtualCollectionProxy()

bool FWItemAccessorFactory::hasMemberTVirtualCollectionProxy ( const TClass *  iClass,
TClass *&  oMember,
size_t &  oOffset 
)
static

Helper method which checks if the object has only one data member and if that data memeber can be accessed via a TVirtualCollectionProxy.

oMember a reference to the pointer which will hold the actual TClass of the datamember to be used to build the TVirtualCollectionProxy.

a reference which will hold the offset of the member relative to the beginning address of a class instance.

Returns
true if this is the case, false otherwise.

Definition at line 150 of file FWItemAccessorFactory.cc.

References cms::cuda::assert(), edm::TypeDataMembers::begin(), dtTPAnalyzer_cfg::dataType, hasTVirtualCollectionProxy(), and edm::TypeDataMembers::size().

Referenced by accessorFor(), and classAccessedAsCollection().

150  {
151  assert(iClass->GetTypeInfo());
152  edm::TypeWithDict dataType(*(iClass->GetTypeInfo()));
153  assert(bool(dataType));
154 
155  // If the object has more than one data member, we avoid guessing.
157  if (members.size() != 1)
158  return false;
159 
160  edm::MemberWithDict member(*members.begin());
161  edm::TypeWithDict memType(member.typeOf());
162  assert(bool(memType));
163  oMember = TClass::GetClass(memType.typeInfo());
164  oOffset = member.offset();
165 
166  // Check if this is a collection known by ROOT but also that the item held by
167  // the colletion actually has a dictionary
168 
169  if (!hasTVirtualCollectionProxy(oMember))
170  return false;
171 
172  return true;
173 }
assert(be >=bs)
static bool hasTVirtualCollectionProxy(const TClass *iClass)

◆ hasTVirtualCollectionProxy()

bool FWItemAccessorFactory::hasTVirtualCollectionProxy ( const TClass *  iClass)
static

Helper method which

Returns
true if the passes iClass can be accessed via TVirtualCollectionProxy.

Definition at line 132 of file FWItemAccessorFactory.cc.

Referenced by accessorFor(), classAccessedAsCollection(), and hasMemberTVirtualCollectionProxy().

132  {
133  // Check if this is a collection known by ROOT but also that the item held by
134  // the colletion actually has a dictionary
135  return iClass && iClass->GetCollectionProxy() && iClass->GetCollectionProxy()->GetValueClass() &&
136  iClass->GetCollectionProxy()->GetValueClass()->IsLoaded();
137 }

◆ operator=()

const FWItemAccessorFactory& FWItemAccessorFactory::operator= ( const FWItemAccessorFactory )
delete