File indexing completed on 2024-04-06 12:11:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "FWCore/Reflection/interface/TypeWithDict.h"
0015 #include "FWCore/Reflection/interface/ObjectWithDict.h"
0016
0017 #include <cassert>
0018 #include <iostream>
0019 #include <functional>
0020
0021
0022 #include "FWCore/Utilities/interface/TypeID.h"
0023
0024 #include "Fireworks/Core/interface/FWParameterSetterBase.h"
0025 #include "Fireworks/Core/interface/FWParameterBase.h"
0026 #include "Fireworks/Core/interface/FWParameterSetterEditorBase.h"
0027 #include "Fireworks/Core/interface/fwLog.h"
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 FWParameterSetterBase::FWParameterSetterBase() : m_frame(nullptr) {}
0041
0042
0043
0044
0045
0046
0047 FWParameterSetterBase::~FWParameterSetterBase() {}
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 void FWParameterSetterBase::attach(FWParameterBase* iBase, FWParameterSetterEditorBase* iFrame) {
0066 m_frame = iFrame;
0067 attach(iBase);
0068 }
0069
0070
0071
0072
0073
0074 void FWParameterSetterBase::update() const {
0075 if (m_frame != nullptr)
0076 m_frame->updateEditor();
0077 }
0078
0079
0080
0081
0082
0083 std::shared_ptr<FWParameterSetterBase> FWParameterSetterBase::makeSetterFor(FWParameterBase* iParam) {
0084 static std::map<edm::TypeID, edm::TypeWithDict> s_paramToSetterMap;
0085 edm::TypeID paramType(typeid(*iParam));
0086 std::map<edm::TypeID, edm::TypeWithDict>::iterator itFind = s_paramToSetterMap.find(paramType);
0087 if (itFind == s_paramToSetterMap.end()) {
0088 edm::TypeWithDict paramClass(typeid(*iParam));
0089 if (paramClass == edm::TypeWithDict()) {
0090 fwLog(fwlog::kError) << " the type " << typeid(*iParam).name() << " is not known to Root" << std::endl;
0091 }
0092 assert(paramClass != edm::TypeWithDict());
0093
0094
0095 std::string name = paramClass.name();
0096
0097
0098
0099
0100
0101 if (name == "FWGenericParameter<bool>")
0102 name = "FWBoolParameterSetter";
0103 else if (name == "FWGenericParameterWithRange<double>")
0104 name = "FWDoubleParameterSetter";
0105 else if (name == "FWGenericParameterWithRange<long int>")
0106 name = "FWLongParameterSetter";
0107 else if (name == "FWGenericParameterWithRange<long>")
0108 name = "FWLongParameterSetter";
0109 else if (paramClass.friendlyClassName() == "StringFWGenericParameter")
0110 name = "FWStringParameterSetter";
0111 else {
0112 name += "Setter";
0113 fwLog(fwlog::kWarning) << "can't find setter type for " << iParam->name() << ", guessing to " << name << "\n";
0114 }
0115 edm::TypeWithDict setterClass(edm::TypeWithDict::byName(name));
0116
0117 if (setterClass == edm::TypeWithDict()) {
0118 fwLog(fwlog::kError) << " the type " << name << " has no dictionary" << std::endl;
0119 }
0120 assert(setterClass != edm::TypeWithDict());
0121
0122 s_paramToSetterMap[paramType] = setterClass;
0123 itFind = s_paramToSetterMap.find(paramType);
0124 }
0125
0126
0127
0128 edm::ObjectWithDict setterObj = itFind->second.construct();
0129
0130
0131 FWParameterSetterBase* p = static_cast<FWParameterSetterBase*>(setterObj.address());
0132
0133 std::shared_ptr<FWParameterSetterBase> ptr(
0134 p, std::bind(&edm::TypeWithDict::destruct, itFind->second, setterObj.address(), true));
0135 return ptr;
0136 }
0137
0138
0139 void FWParameterSetterBase::setEnabled(bool) {}