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 // FWItemAccessorFactory::FWItemAccessorFactory(const FWItemAccessorFactory& rhs)
41 // {
42 // // do actual copying here;
43 // }
44 
46 
47 //
48 // assignment operators
49 //
50 // const FWItemAccessorFactory& FWItemAccessorFactory::operator=(const FWItemAccessorFactory& rhs)
51 // {
52 // //An exception safe implementation is
53 // FWItemAccessorFactory temp(rhs);
54 // swap(rhs);
55 //
56 // return *this;
57 // }
58 
59 //
60 // member functions
61 //
62 
63 //
64 // const member functions
65 //
66 
89 std::shared_ptr<FWItemAccessorBase> FWItemAccessorFactory::accessorFor(const TClass *iClass) const {
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 }
128 
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 }
138 
150 bool FWItemAccessorFactory::hasMemberTVirtualCollectionProxy(const TClass *iClass, TClass *&oMember, size_t &oOffset) {
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 }
174 
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 }
196 
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 }
212 
213 //
214 // static member functions
215 //
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
static bool classAccessedAsCollection(const TClass *)
IterWithDict< TDataMember > begin() const
std::shared_ptr< FWItemAccessorBase > accessorFor(const TClass *) const
assert(be >=bs)
#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)
size_t size() const
#define get
static PluginManager * get()