CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions
FWItemAccessorFactory Class Reference

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

Public Member Functions

boost::shared_ptr
< FWItemAccessorBase
accessorFor (const TClass *) const
 
 FWItemAccessorFactory ()
 
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)
 

Private Member Functions

 FWItemAccessorFactory (const FWItemAccessorFactory &)
 
const FWItemAccessorFactoryoperator= (const FWItemAccessorFactory &)
 

Detailed Description

Description: Factory for constructing FWItemAccessorBases appropriate to a certain type

Usage: <usage>

Definition at line 32 of file FWItemAccessorFactory.h.

Constructor & Destructor Documentation

FWItemAccessorFactory::FWItemAccessorFactory ( )

Definition at line 39 of file FWItemAccessorFactory.cc.

40 {
41 }
FWItemAccessorFactory::~FWItemAccessorFactory ( )
virtual

Definition at line 48 of file FWItemAccessorFactory.cc.

49 {
50 }
FWItemAccessorFactory::FWItemAccessorFactory ( const FWItemAccessorFactory )
private

Member Function Documentation

boost::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 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.

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

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 95 of file FWItemAccessorFactory.cc.

References debug, fwLog, reco::get(), hasAccessor(), hasMemberTVirtualCollectionProxy(), hasTVirtualCollectionProxy(), fwlog::kDebug, and evf::evtn::offset().

Referenced by FWSimpleRepresentationChecker::infoFor().

96 {
97  static const bool debug = false;
98 
99  TClass *member = 0;
100  size_t offset=0;
101 
102  if(hasTVirtualCollectionProxy(iClass))
103  {
104  if (debug)
105  fwLog(fwlog::kDebug) << "class " << iClass->GetName()
106  << " uses FWItemTVirtualCollectionProxyAccessor." << std::endl;
107  return boost::shared_ptr<FWItemAccessorBase>(
109  boost::shared_ptr<TVirtualCollectionProxy>(iClass->GetCollectionProxy()->Generate())));
110  }
111  else if (hasMemberTVirtualCollectionProxy(iClass, member,offset))
112  {
113  if (debug)
114  fwLog(fwlog::kDebug) << "class "<< iClass->GetName()
115  << " only contains data member " << member->GetName()
116  << " which uses FWItemTVirtualCollectionProxyAccessor."
117  << std::endl;
118 
119  return boost::shared_ptr<FWItemAccessorBase>(
121  boost::shared_ptr<TVirtualCollectionProxy>(member->GetCollectionProxy()->Generate()),
122  offset));
123  }
124 
125  // Iterate on the available plugins and use the one which handles
126  // the iClass type.
127  // NOTE: This is done only a few times, not really performance critical.
128  // If you want this to be fast, the loop can be moved in the
129  // constructor. Notice that this will require constructing FWEventItemsManager
130  // after the plugin manager (i.e. invoking AutoLibraryLoader::enable()) is configured
131  // (i.e. invoking AutoLibraryLoader::enable()) in CmsShowMain.
132  std::string accessorName;
133  if (hasAccessor(iClass, accessorName))
134  {
135  if (debug)
136  fwLog(fwlog::kDebug) << "class " << iClass->GetName() << " uses "
137  << accessorName << "." << std::endl;
138  return boost::shared_ptr<FWItemAccessorBase>(FWItemAccessorRegistry::get()->create(accessorName, iClass));
139  }
140 
141  return boost::shared_ptr<FWItemAccessorBase>(new FWItemSingleAccessor(iClass));
142 }
unsigned int offset(bool)
#define fwLog(_level_)
Definition: fwLog.h:51
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 debug
Definition: MEtoEDMFormat.h:34
T get(const Candidate &c)
Definition: component.h:56
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 229 of file FWItemAccessorFactory.cc.

References hasAccessor(), hasMemberTVirtualCollectionProxy(), hasTVirtualCollectionProxy(), and evf::evtn::offset().

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

230 {
231  std::string accessorName;
232  TClass *member = 0;
233  size_t offset=0;
234 
235  // This is pretty much the same thing that happens
238  || FWItemAccessorFactory::hasAccessor(iClass, accessorName));
239 }
unsigned int offset(bool)
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)
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 206 of file FWItemAccessorFactory.cc.

References reco::get(), i, and mergeVDriftHistosByStation::name.

Referenced by accessorFor(), and classAccessedAsCollection().

207 {
208  const std::vector<edmplugin::PluginInfo> &available
209  = FWItemAccessorRegistry::get()->available();
210 
211  for (size_t i = 0, e = available.size(); i != e; ++i)
212  {
213  std::string name = available[i].name_;
214  std::string type = name.substr(0, name.find_first_of('@'));
215  if (iClass->GetTypeInfo()->name() == type)
216  {
217  result.swap(name);
218  return true;
219  }
220  }
221  return false;
222 }
type
Definition: HCALResponse.h:22
int i
Definition: DBlmapReader.cc:9
tuple result
Definition: query.py:137
T get(const Candidate &c)
Definition: component.h:56
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 170 of file FWItemAccessorFactory.cc.

References dtT0WireCalibration_cfg::dataType, and hasTVirtualCollectionProxy().

Referenced by accessorFor(), and classAccessedAsCollection().

173 {
174  assert(iClass->GetTypeInfo());
175  ROOT::Reflex::Type dataType(ROOT::Reflex::Type::ByTypeInfo(*(iClass->GetTypeInfo())));
176  assert(dataType != ROOT::Reflex::Type());
177 
178  // If the object has more than one data member, we avoid guessing.
179  if (dataType.DataMemberSize() != 1)
180  return false;
181 
182  ROOT::Reflex::Type memType(dataType.DataMemberAt(0).TypeOf());
183  assert(memType != ROOT::Reflex::Type());
184  //make sure this is the real type and not a typedef
185  memType = memType.FinalType();
186  oMember = TClass::GetClass(memType.TypeInfo());
187  oOffset = dataType.DataMemberAt(0).Offset();
188 
189  // Check if this is a collection known by ROOT but also that the item held by
190  // the colletion actually has a dictionary
191 
192  if (!hasTVirtualCollectionProxy(oMember))
193  return false;
194 
195  return true;
196 }
static bool hasTVirtualCollectionProxy(const TClass *iClass)
bool FWItemAccessorFactory::hasTVirtualCollectionProxy ( const TClass *  iClass)
static

Helper method which

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

Definition at line 148 of file FWItemAccessorFactory.cc.

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

149 {
150  // Check if this is a collection known by ROOT but also that the item held by
151  // the colletion actually has a dictionary
152  return iClass &&
153  iClass->GetCollectionProxy() &&
154  iClass->GetCollectionProxy()->GetValueClass() &&
155  iClass->GetCollectionProxy()->GetValueClass()->IsLoaded();
156 }
const FWItemAccessorFactory& FWItemAccessorFactory::operator= ( const FWItemAccessorFactory )
private