test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 boost::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 boost::shared_ptr<FWItemAccessorBase>(
108  boost::shared_ptr<TVirtualCollectionProxy>(iClass->GetCollectionProxy()->Generate())));
109  }
110 
111  // Iterate on the available plugins and use the one which handles
112  // the iClass type.
113  // NOTE: This is done only a few times, not really performance critical.
114  // If you want this to be fast, the loop can be moved in the
115  // constructor. Notice that this will require constructing FWEventItemsManager
116  // after the plugin manager (i.e. invoking FWLiteEnabler::enable()) is configured
117  // (i.e. invoking FWLiteEnabler::enable()) in CmsShowMain.
118  std::string accessorName;
119  if (hasAccessor(iClass, accessorName))
120  {
121  if (debug)
122  fwLog(fwlog::kDebug) << "class " << iClass->GetName() << " uses "
123  << accessorName << "." << std::endl;
124  return boost::shared_ptr<FWItemAccessorBase>(FWItemAccessorRegistry::get()->create(accessorName, iClass));
125  }
126 
127  if (hasMemberTVirtualCollectionProxy(iClass, member,offset))
128  {
129  if (debug)
130  fwLog(fwlog::kDebug) << "class "<< iClass->GetName()
131  << " only contains data member " << member->GetName()
132  << " which uses FWItemTVirtualCollectionProxyAccessor."
133  << std::endl;
134 
135  return boost::shared_ptr<FWItemAccessorBase>(
137  boost::shared_ptr<TVirtualCollectionProxy>(member->GetCollectionProxy()->Generate()),
138  offset));
139  }
140 
141  return boost::shared_ptr<FWItemAccessorBase>(new FWItemSingleAccessor(iClass));
142 }
143 
147 bool
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 }
157 
169 bool
171  TClass *&oMember,
172  size_t& oOffset)
173 {
174  assert(iClass->GetTypeInfo());
175  edm::TypeWithDict dataType(*(iClass->GetTypeInfo()));
176  assert(bool(dataType));
177 
178  // If the object has more than one data member, we avoid guessing.
179  edm::TypeDataMembers members(dataType);
180  if (members.size() != 1)
181  return false;
182 
183  edm::MemberWithDict member(*members.begin());
184  edm::TypeWithDict memType(member.typeOf());
185  assert(bool(memType));
186  oMember = TClass::GetClass(memType.typeInfo());
187  oOffset = member.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 }
197 
205 bool
207 {
208  const std::vector<edmplugin::PluginInfo> &available
209  = edmplugin::PluginManager::get()->categoryToInfos().find("cmsShow FWItemAccessorBase")->second;
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 }
223 
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 }
240 
241 //
242 // static member functions
243 //
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
IterWithDict< TDataMember > begin() const
static bool classAccessedAsCollection(const TClass *)
assert(m_qm.get())
size_t size() const
tuple result
Definition: mps_fire.py:84
#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()
boost::shared_ptr< FWItemAccessorBase > accessorFor(const TClass *) const
T get(const Candidate &c)
Definition: component.h:55