CMS 3D CMS Logo

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 == "FWGenericParameter<std::string>")
104  name = "FWStringParameterSetter";
105  else if (name == "FWGenericParameter<std::basic_string<char> >")
106  name = "FWStringParameterSetter";
107  else if (name == "FWGenericParameterWithRange<double>")
108  name = "FWDoubleParameterSetter";
109  else if (name == "FWGenericParameterWithRange<long int>")
110  name = "FWLongParameterSetter";
111  else if (name == "FWGenericParameterWithRange<long>")
112  name = "FWLongParameterSetter";
113  else
114  name += "Setter";
115 
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.*/
FWParameterSetterBase::setEnabled
virtual void setEnabled(bool)
Definition: FWParameterSetterBase.cc:139
edm::TypeWithDict::byName
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
FWParameterSetterEditorBase
Definition: FWParameterSetterEditorBase.h:27
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
edm::TypeWithDict::destruct
void destruct(void *address, bool dealloc=true) const
Definition: TypeWithDict.cc:798
edm::ObjectWithDict::address
void * address() const
Definition: ObjectWithDict.cc:27
FWParameterSetterBase
Definition: FWParameterSetterBase.h:31
edm::ObjectWithDict
Definition: ObjectWithDict.h:17
FWParameterSetterBase::attach
void attach(FWParameterBase *, FWParameterSetterEditorBase *)
Definition: FWParameterSetterBase.cc:65
FWParameterBase
Definition: FWParameterBase.h:31
cms::cuda::assert
assert(be >=bs)
TypeID.h
TypeWithDict.h
FWParameterSetterBase::FWParameterSetterBase
FWParameterSetterBase()
Definition: FWParameterSetterBase.cc:40
FWParameterSetterEditorBase.h
ObjectWithDict.h
FWParameterBase.h
FWParameterSetterBase::~FWParameterSetterBase
virtual ~FWParameterSetterBase()
Definition: FWParameterSetterBase.cc:47
FWParameterSetterBase::update
void update() const
Definition: FWParameterSetterBase.cc:74
edm::TypeWithDict
Definition: TypeWithDict.h:38
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
FWParameterSetterEditorBase::updateEditor
virtual void updateEditor()
Definition: FWParameterSetterEditorBase.cc:55
FWParameterSetterBase.h
fwLog.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FWParameterSetterBase::makeSetterFor
static std::shared_ptr< FWParameterSetterBase > makeSetterFor(FWParameterBase *)
Definition: FWParameterSetterBase.cc:83
FWParameterSetterBase::m_frame
FWParameterSetterEditorBase * m_frame
Definition: FWParameterSetterBase.h:61
edm::TypeID
Definition: TypeID.h:22
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
fwlog::kError
Definition: fwLog.h:35
edm::TypeWithDict::name
std::string name() const
Definition: TypeWithDict.cc:456