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 //
FWItemSingleAccessor.h
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
mps_fire.i
i
Definition: mps_fire.py:428
FWItemTVirtualCollectionProxyAccessor.h
FWItemAccessorFactory::accessorFor
std::shared_ptr< FWItemAccessorBase > accessorFor(const TClass *) const
Definition: FWItemAccessorFactory.cc:89
cms::cuda::assert
assert(be >=bs)
FWItemAccessorFactory.h
TypeWithDict.h
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
FWItemAccessorFactory::hasTVirtualCollectionProxy
static bool hasTVirtualCollectionProxy(const TClass *iClass)
Definition: FWItemAccessorFactory.cc:132
DTskim_cfg.dataType
dataType
Definition: DTskim_cfg.py:56
edmplugin::PluginManager::get
static PluginManager * get()
Definition: PluginManager.cc:306
edmplugin::PluginManager::categoryToInfos
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
FWItemAccessorFactory::classAccessedAsCollection
static bool classAccessedAsCollection(const TClass *)
Definition: FWItemAccessorFactory.cc:202
debug
#define debug
Definition: HDRShower.cc:19
edm::TypeDataMembers::size
size_t size() const
Definition: TypeWithDict.cc:869
edm::TypeWithDict
Definition: TypeWithDict.h:38
edm::TypeDataMembers::begin
IterWithDict< TDataMember > begin() const
Definition: TypeWithDict.cc:860
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
edm::TypeDataMembers
Definition: TypeWithDict.h:164
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
edm::MemberWithDict
Definition: MemberWithDict.h:19
fwLog.h
get
#define get
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FWItemAccessorFactory::~FWItemAccessorFactory
virtual ~FWItemAccessorFactory()
Definition: FWItemAccessorFactory.cc:45
fwlog::kDebug
Definition: fwLog.h:35
FWItemAccessorFactory::hasMemberTVirtualCollectionProxy
static bool hasMemberTVirtualCollectionProxy(const TClass *iClass, TClass *&oMember, size_t &oOffset)
Definition: FWItemAccessorFactory.cc:150
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
FWItemAccessorRegistry.h
FWItemAccessorFactory::FWItemAccessorFactory
FWItemAccessorFactory()
Definition: FWItemAccessorFactory.cc:38
mps_fire.result
result
Definition: mps_fire.py:311
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
MemberWithDict.h
FWItemAccessorFactory::hasAccessor
static bool hasAccessor(const TClass *iClass, std::string &result)
Definition: FWItemAccessorFactory.cc:182
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37