CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FWParameterSetterBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWParameterSetterBase
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Fri Mar 7 14:16:20 EST 2008
11 //
12 
13 // system include files
16 
17 #include <cassert>
18 #include <iostream>
19 #include <functional>
20 
21 // user include files
23 
28 
29 //
30 // constants, enums and typedefs
31 //
32 
33 //
34 // static data member definitions
35 //
36 
37 //
38 // constructors and destructor
39 //
41 
42 // FWParameterSetterBase::FWParameterSetterBase(const FWParameterSetterBase& rhs)
43 // {
44 // // do actual copying here;
45 // }
46 
48 
49 //
50 // assignment operators
51 //
52 // const FWParameterSetterBase& FWParameterSetterBase::operator=(const FWParameterSetterBase& rhs)
53 // {
54 // //An exception safe implementation is
55 // FWParameterSetterBase temp(rhs);
56 // swap(rhs);
57 //
58 // return *this;
59 // }
60 
61 //
62 // member functions
63 //
64 
66  m_frame = iFrame;
67  attach(iBase);
68 }
69 
70 //
71 // const member functions
72 //
73 
75  if (m_frame != nullptr)
77 }
78 
79 //
80 // static member functions
81 //
82 
83 std::shared_ptr<FWParameterSetterBase> FWParameterSetterBase::makeSetterFor(FWParameterBase* iParam) {
84  static std::map<edm::TypeID, edm::TypeWithDict> s_paramToSetterMap;
85  edm::TypeID paramType(typeid(*iParam));
86  std::map<edm::TypeID, edm::TypeWithDict>::iterator itFind = s_paramToSetterMap.find(paramType);
87  if (itFind == s_paramToSetterMap.end()) {
88  edm::TypeWithDict paramClass(typeid(*iParam));
89  if (paramClass == edm::TypeWithDict()) {
90  fwLog(fwlog::kError) << " the type " << typeid(*iParam).name() << " is not known to Root" << std::endl;
91  }
92  assert(paramClass != edm::TypeWithDict());
93 
94  //the corresponding setter has the same name but with 'Setter' at the end
95  std::string name = paramClass.name();
96  // FIXME: there was a convention between parameter class names and associated
97  // setters. The following works around the problem introduced by
98  // the generic parameter class but it is clear that a better
99  // way of doing the binding is required. Notice that there are only 5
100  // different type of FW*Parameter.
101  if (name == "FWGenericParameter<bool>")
102  name = "FWBoolParameterSetter";
103  else if (name == "FWGenericParameterWithRange<double>")
104  name = "FWDoubleParameterSetter";
105  else if (name == "FWGenericParameterWithRange<long int>")
106  name = "FWLongParameterSetter";
107  else if (name == "FWGenericParameterWithRange<long>")
108  name = "FWLongParameterSetter";
109  else if (paramClass.friendlyClassName() == "StringFWGenericParameter")
110  name = "FWStringParameterSetter";
111  else {
112  name += "Setter";
113  fwLog(fwlog::kWarning) << "can't find setter type for "<< iParam->name() << ", guessing to " << name << "\n";
114  }
115  edm::TypeWithDict setterClass(edm::TypeWithDict::byName(name));
116 
117  if (setterClass == edm::TypeWithDict()) {
118  fwLog(fwlog::kError) << " the type " << name << " has no dictionary" << std::endl;
119  }
120  assert(setterClass != edm::TypeWithDict());
121 
122  s_paramToSetterMap[paramType] = setterClass;
123  itFind = s_paramToSetterMap.find(paramType);
124  }
125  //create the instance we want
126  //NOTE: 'construct' will use 'malloc' to allocate the memory if the object is not of class type.
127  // This means the object cannot be deleted using 'delete'! So we must call destruct on the object.
128  edm::ObjectWithDict setterObj = itFind->second.construct();
129 
130  //make it into the base class
131  FWParameterSetterBase* p = static_cast<FWParameterSetterBase*>(setterObj.address());
132  //Make a shared pointer to the base class that uses a destructor for the derived class, in order to match the above construct call.
133  std::shared_ptr<FWParameterSetterBase> ptr(
134  p, std::bind(&edm::TypeWithDict::destruct, itFind->second, setterObj.address(), true));
135  return ptr;
136 }
137 
138 /* Virtual function which sets widgets enabled state.*/
void * address() const
void attach(FWParameterBase *, FWParameterSetterEditorBase *)
virtual void setEnabled(bool)
assert(be >=bs)
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
std::string name() const
std::string friendlyClassName() const
FWParameterSetterEditorBase * m_frame
#define fwLog(_level_)
Definition: fwLog.h:45
void destruct(void *address, bool dealloc=true) const
static std::shared_ptr< FWParameterSetterBase > makeSetterFor(FWParameterBase *)
const std::string & name() const