CMS 3D CMS Logo

FWItemAccessorFactory.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWItemAccessorFactory
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Sat Oct 18 14:48:14 EDT 2008
11 //
12 
13 // system include files
14 #include <iostream>
15 #include "TClass.h"
16 #include "TVirtualCollectionProxy.h"
19 
20 // user include files
26 
27 //
28 // constants, enums and typedefs
29 //
30 
31 //
32 // static data member definitions
33 //
34 
35 //
36 // constructors and destructor
37 //
39 {
40 }
41 
42 // FWItemAccessorFactory::FWItemAccessorFactory(const FWItemAccessorFactory& rhs)
43 // {
44 // // do actual copying here;
45 // }
46 
48 {
49 }
50 
51 //
52 // assignment operators
53 //
54 // const FWItemAccessorFactory& FWItemAccessorFactory::operator=(const FWItemAccessorFactory& rhs)
55 // {
56 // //An exception safe implementation is
57 // FWItemAccessorFactory temp(rhs);
58 // swap(rhs);
59 //
60 // return *this;
61 // }
62 
63 //
64 // member functions
65 //
66 
67 //
68 // const member functions
69 //
70 
93 std::shared_ptr<FWItemAccessorBase>
94 FWItemAccessorFactory::accessorFor(const TClass* iClass) const
95 {
96  static const bool debug = false;
97 
98  TClass *member = 0;
99  size_t offset=0;
100 
101  if(hasTVirtualCollectionProxy(iClass))
102  {
103  if (debug)
104  fwLog(fwlog::kDebug) << "class " << iClass->GetName()
105  << " uses FWItemTVirtualCollectionProxyAccessor." << std::endl;
106  return std::make_shared<FWItemTVirtualCollectionProxyAccessor>(iClass,
107  std::shared_ptr<TVirtualCollectionProxy>(iClass->GetCollectionProxy()->Generate()));
108  }
109 
110  // Iterate on the available plugins and use the one which handles
111  // the iClass type.
112  // NOTE: This is done only a few times, not really performance critical.
113  // If you want this to be fast, the loop can be moved in the
114  // constructor. Notice that this will require constructing FWEventItemsManager
115  // after the plugin manager (i.e. invoking FWLiteEnabler::enable()) is configured
116  // (i.e. invoking FWLiteEnabler::enable()) in CmsShowMain.
117  std::string accessorName;
118  if (hasAccessor(iClass, accessorName))
119  {
120  if (debug)
121  fwLog(fwlog::kDebug) << "class " << iClass->GetName() << " uses "
122  << accessorName << "." << std::endl;
123  return std::shared_ptr<FWItemAccessorBase>(FWItemAccessorRegistry::get()->create(accessorName, iClass));
124  }
125 
126  if (hasMemberTVirtualCollectionProxy(iClass, member,offset))
127  {
128  if (debug)
129  fwLog(fwlog::kDebug) << "class "<< iClass->GetName()
130  << " only contains data member " << member->GetName()
131  << " which uses FWItemTVirtualCollectionProxyAccessor."
132  << std::endl;
133 
134  return std::make_shared<FWItemTVirtualCollectionProxyAccessor>(iClass,
135  std::shared_ptr<TVirtualCollectionProxy>(member->GetCollectionProxy()->Generate()),
136  offset);
137  }
138 
139  return std::make_shared<FWItemSingleAccessor>(iClass);
140 }
141 
145 bool
147 {
148  // Check if this is a collection known by ROOT but also that the item held by
149  // the colletion actually has a dictionary
150  return iClass &&
151  iClass->GetCollectionProxy() &&
152  iClass->GetCollectionProxy()->GetValueClass() &&
153  iClass->GetCollectionProxy()->GetValueClass()->IsLoaded();
154 }
155 
167 bool
169  TClass *&oMember,
170  size_t& oOffset)
171 {
172  assert(iClass->GetTypeInfo());
173  edm::TypeWithDict dataType(*(iClass->GetTypeInfo()));
174  assert(bool(dataType));
175 
176  // If the object has more than one data member, we avoid guessing.
177  edm::TypeDataMembers members(dataType);
178  if (members.size() != 1)
179  return false;
180 
181  edm::MemberWithDict member(*members.begin());
182  edm::TypeWithDict memType(member.typeOf());
183  assert(bool(memType));
184  oMember = TClass::GetClass(memType.typeInfo());
185  oOffset = member.offset();
186 
187  // Check if this is a collection known by ROOT but also that the item held by
188  // the colletion actually has a dictionary
189 
190  if (!hasTVirtualCollectionProxy(oMember))
191  return false;
192 
193  return true;
194 }
195 
203 bool
205 {
206  const std::vector<edmplugin::PluginInfo> &available
207  = edmplugin::PluginManager::get()->categoryToInfos().find("cmsShow FWItemAccessorBase")->second;
208 
209  for (size_t i = 0, e = available.size(); i != e; ++i)
210  {
211  std::string name = available[i].name_;
212  std::string type = name.substr(0, name.find_first_of('@'));
213  if (iClass->GetTypeInfo()->name() == type)
214  {
215  result.swap(name);
216  return true;
217  }
218  }
219  return false;
220 }
221 
228 {
229  std::string accessorName;
230  TClass *member = 0;
231  size_t offset=0;
232 
233  // This is pretty much the same thing that happens
236  || FWItemAccessorFactory::hasAccessor(iClass, accessorName));
237 }
238 
239 //
240 // static member functions
241 //
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
type
Definition: HCALResponse.h:21
IterWithDict< TDataMember > begin() const
static bool classAccessedAsCollection(const TClass *)
std::shared_ptr< FWItemAccessorBase > accessorFor(const TClass *) const
size_t size() const
#define debug
Definition: HDRShower.cc:19
#define fwLog(_level_)
Definition: fwLog.h:50
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)
static PluginManager * get()
T get(const Candidate &c)
Definition: component.h:55