Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:42

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWProxyBuilderConfiguration
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:
0010 //         Created:  Wed Jul 27 00:58:43 CEST 2011
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include <iostream>
0017 #include <stdexcept>
0018 #include <functional>
0019 
0020 #include "TGFrame.h"
0021 
0022 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0023 #include "Fireworks/Core/interface/FWEventItem.h"
0024 #include "Fireworks/Core/interface/fwLog.h"
0025 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0026 #include "Fireworks/Core/interface/FWItemChangeSignal.h"
0027 #include "Fireworks/Core/interface/FWConfiguration.h"
0028 #include "Fireworks/Core/interface/FWParameterBase.h"
0029 #include "Fireworks/Core/interface/FWGenericParameter.h"
0030 #include "Fireworks/Core/interface/FWEnumParameter.h"
0031 
0032 FWProxyBuilderConfiguration::FWProxyBuilderConfiguration(const FWConfiguration* c, const FWEventItem* item)
0033     : m_txtConfig(c), m_item(item), m_keepEntries(false) {}
0034 
0035 FWProxyBuilderConfiguration::~FWProxyBuilderConfiguration() { delete m_txtConfig; }
0036 
0037 //______________________________________________________________________________
0038 
0039 void FWProxyBuilderConfiguration::addTo(FWConfiguration& iTo) const {
0040   if (begin() != end()) {
0041     FWConfiguration vTmp;
0042     FWConfigurableParameterizable::addTo(vTmp);
0043     iTo.addKeyValue("Var", vTmp, true);
0044   }
0045 }
0046 
0047 void FWProxyBuilderConfiguration::setFrom(const FWConfiguration& iFrom) {
0048   /*
0049      for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it!= keyVals->end(); ++it)
0050      std::cout << it->first << "FWProxyBuilderConfiguration::setFrom  " << std::endl;
0051      }*/
0052 }
0053 
0054 //______________________________________________________________________________
0055 
0056 void FWProxyBuilderConfiguration::makeSetter(TGCompositeFrame* frame, FWParameterBase* pb) {
0057   //  std::cout << "make setter " << pb->name() << std::endl;
0058 
0059   std::shared_ptr<FWParameterSetterBase> ptr(FWParameterSetterBase::makeSetterFor(pb));
0060   ptr->attach(pb, this);
0061   TGFrame* tmpFrame = ptr->build(frame, false);
0062   frame->AddFrame(tmpFrame, new TGLayoutHints(kLHintsExpandX));
0063   m_setters.push_back(ptr);
0064 }
0065 
0066 void FWProxyBuilderConfiguration::populateFrame(TGCompositeFrame* settersFrame) {
0067   //  std::cout << "populate \n";
0068 
0069   TGCompositeFrame* frame = new TGVerticalFrame(settersFrame);
0070   settersFrame->AddFrame(frame, new TGLayoutHints(kLHintsExpandX));  //|kLHintsExpandY
0071 
0072   for (const_iterator it = begin(); it != end(); ++it)
0073     makeSetter(frame, *it);
0074 
0075   settersFrame->MapSubwindows();
0076 }
0077 
0078 void FWProxyBuilderConfiguration::keepEntries(bool b) { m_keepEntries = b; }
0079 
0080 //______________________________________________________________________________
0081 
0082 template <class T>
0083 FWGenericParameter<T>* FWProxyBuilderConfiguration::assertParam(const std::string& name, T def) {
0084   for (const_iterator i = begin(); i != end(); ++i) {
0085     if ((*i)->name() == name) {
0086       return nullptr;
0087     }
0088   }
0089 
0090   FWGenericParameter<T>* mode = new FWGenericParameter<T>(this, name, def);
0091 
0092   //   std::cout << "FWProxyBuilderConfiguration::getVarParameter(). No parameter with name " << name << std::endl;
0093   if (m_txtConfig) {
0094     const FWConfiguration* varConfig = m_txtConfig->keyValues() ? m_txtConfig->valueForKey("Var") : nullptr;
0095     if (varConfig)
0096       mode->setFrom(*varConfig);
0097   }
0098   mode->changed_.connect(std::bind(&FWEventItem::proxyConfigChanged, (FWEventItem*)m_item, m_keepEntries));
0099   return mode;
0100 }
0101 
0102 template <class T>
0103 FWGenericParameterWithRange<T>* FWProxyBuilderConfiguration::assertParam(const std::string& name, T def, T min, T max) {
0104   for (const_iterator i = begin(); i != end(); ++i) {
0105     if ((*i)->name() == name) {
0106       return nullptr;
0107     }
0108   }
0109 
0110   FWGenericParameterWithRange<T>* mode = new FWGenericParameterWithRange<T>(this, name, def, min, max);
0111 
0112   //   std::cout << "FWProxyBuilderConfiguration::getVarParameter(). No parameter with name " << name << std::endl;
0113   const FWConfiguration* varConfig =
0114       m_txtConfig && m_txtConfig->keyValues() ? m_txtConfig->valueForKey("Var") : nullptr;
0115   if (varConfig)
0116     mode->setFrom(*varConfig);
0117 
0118   mode->changed_.connect(std::bind(&FWEventItem::proxyConfigChanged, (FWEventItem*)m_item, m_keepEntries));
0119   return mode;
0120 }
0121 
0122 template <class T>
0123 T FWProxyBuilderConfiguration::value(const std::string& pname) {
0124   FWGenericParameter<T>* param = nullptr;
0125 
0126   for (FWConfigurableParameterizable::const_iterator i = begin(); i != end(); ++i) {
0127     if ((*i)->name() == pname) {
0128       param = (FWGenericParameter<T>*)(*i);
0129       break;
0130     }
0131   }
0132 
0133   if (param)
0134     return param->value();
0135   else
0136     throw std::runtime_error("Invalid parameter request.");
0137 }
0138 
0139 // explicit template instantiation
0140 
0141 template bool FWProxyBuilderConfiguration::value<bool>(const std::string& name);
0142 template long FWProxyBuilderConfiguration::value<long>(const std::string& name);
0143 template double FWProxyBuilderConfiguration::value<double>(const std::string& name);
0144 
0145 template FWGenericParameter<bool>* FWProxyBuilderConfiguration::assertParam(const std::string& name, bool def);
0146 template FWGenericParameterWithRange<long>* FWProxyBuilderConfiguration::assertParam(const std::string& name,
0147                                                                                      long def,
0148                                                                                      long min,
0149                                                                                      long max);
0150 template FWGenericParameterWithRange<double>* FWProxyBuilderConfiguration::assertParam(const std::string& name,
0151                                                                                        double def,
0152                                                                                        double min,
0153                                                                                        double max);