CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/Fireworks/FWInterface/src/FWPSetCellEditor.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     FWInterface
00004 // Class  :     FWPSetCellEditor
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  
00010 //         Created:  Mon Feb 28 20:44:59 CET 2011
00011 // $Id: FWPSetCellEditor.cc,v 1.2 2011/03/04 20:06:57 amraktad Exp $
00012 //
00013 
00014 #include <sstream>
00015 #include "KeySymbols.h"
00016 
00017 // user include files
00018 #include "Fireworks/FWInterface/src/FWPSetCellEditor.h"
00019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020 #include "Fireworks/Core/interface/fwLog.h"
00021 
00022 #include "FWCore/Utilities/interface/Parse.h"
00023 
00024 //______________________________________________________________________________
00025 
00026 template <class T>
00027 bool editNumericParameter(edm::ParameterSet &ps, bool tracked, 
00028                           const std::string &label, 
00029                           const std::string &value) 
00030 {
00031    std::stringstream  str(value);
00032    T v;
00033    str >> v;
00034    bool fail = str.fail();
00035    if (tracked)
00036       ps.addParameter(label, v);
00037    else
00038       ps.addUntrackedParameter(label, v);
00039          
00040    return fail;
00041 }
00042 //______________________________________________________________________________
00043 
00044 void editStringParameter(edm::ParameterSet &ps, bool tracked,
00045                          const std::string &label,
00046                          const std::string &value)
00047 {
00048    if (tracked)
00049       ps.addParameter(label, value);
00050    else
00051       ps.addUntrackedParameter(label, value);
00052 }
00053 
00054 
00055 //______________________________________________________________________________
00056 void editFileInPath(edm::ParameterSet &ps, bool tracked,
00057                     const std::string &label,
00058                     const std::string &value)
00059 {
00060    if (tracked)
00061       ps.addParameter(label, edm::FileInPath(value));
00062    else
00063       ps.addUntrackedParameter(label, edm::FileInPath(value));
00064 }
00065 
00066 //______________________________________________________________________________
00067 
00068 bool editVInputTag(edm::ParameterSet &ps, bool tracked,
00069                    const std::string &label,
00070                    const std::string &value)
00071 { 
00072    std::vector<edm::InputTag> inputTags;
00073    std::stringstream iss(value);
00074    std::string vitem;
00075    bool fail = false;
00076    size_t fst, lst;
00077 
00078    while (getline(iss, vitem, ','))
00079    {
00080       fst = vitem.find("[");
00081       lst = vitem.find("]");
00082         
00083       if ( fst != std::string::npos )
00084          vitem.erase(fst,1);
00085       if ( lst != std::string::npos )
00086          vitem.erase(lst,1);
00087         
00088       std::vector<std::string> tokens = edm::tokenize(vitem, ":");
00089       size_t nwords = tokens.size();
00090         
00091       if ( nwords > 3 )
00092       {
00093          fail = true;
00094          return fail;
00095       }
00096       else 
00097       {
00098          std::string it_label("");
00099          std::string it_instance("");
00100          std::string it_process("");
00101 
00102          if ( nwords > 0 ) 
00103             it_label = tokens[0];
00104          if ( nwords > 1 ) 
00105             it_instance = tokens[1];
00106          if ( nwords > 2 ) 
00107             it_process  = tokens[2];
00108         
00109          inputTags.push_back(edm::InputTag(it_label, it_instance, it_process));
00110       }
00111    }
00112      
00113    if (tracked)
00114       ps.addParameter(label, inputTags);
00115    else
00116       ps.addUntrackedParameter(label, inputTags);
00117 
00118    return fail;
00119 }
00120 
00121 //______________________________________________________________________________
00122 
00123 bool editInputTag(edm::ParameterSet &ps, bool tracked,
00124                   const std::string &label,
00125                   const std::string &value)
00126 {
00127    std::vector<std::string> tokens = edm::tokenize(value, ":");
00128    size_t nwords = tokens.size();
00129      
00130    bool fail;
00131 
00132    if ( nwords > 3 ) 
00133    {
00134       fail = true;
00135    }
00136    else
00137    {           
00138       std::string it_label("");
00139       std::string it_instance("");
00140       std::string it_process("");
00141 
00142       if ( nwords > 0 ) 
00143          it_label = tokens[0];
00144       if ( nwords > 1 ) 
00145          it_instance = tokens[1];
00146       if ( nwords > 2 ) 
00147          it_process  = tokens[2];
00148 
00149       if ( tracked )
00150          ps.addParameter(label, edm::InputTag(it_label, it_instance, it_process));
00151       else
00152          ps.addUntrackedParameter(label, edm::InputTag(it_label, it_instance, it_process));
00153             
00154       fail = false;
00155    }
00156            
00157    return fail;
00158 }
00159 
00160 //______________________________________________________________________________
00161 
00162 bool editESInputTag(edm::ParameterSet &ps, bool tracked,
00163                     const std::string &label,
00164                     const std::string &value)
00165 {
00166    std::vector<std::string> tokens = edm::tokenize(value, ":");
00167    size_t nwords = tokens.size();
00168       
00169    bool fail;
00170   
00171    if ( nwords > 2 )
00172    {
00173       fail = true;    
00174    }
00175    else
00176    {             
00177       std::string it_module("");
00178       std::string it_data("");
00179 
00180       if ( nwords > 0 ) 
00181          it_module = tokens[0];
00182       if ( nwords > 1 ) 
00183          it_data = tokens[1];
00184 
00185       if ( tracked )
00186          ps.addParameter(label, edm::ESInputTag(it_module, it_data));
00187       else
00188          ps.addUntrackedParameter(label, edm::ESInputTag(it_module, it_data));
00189         
00190       fail = false;
00191    }
00192 
00193    return fail;
00194 }
00195   
00196 //______________________________________________________________________________
00197 template <typename T>
00198 void editVectorParameter(edm::ParameterSet &ps, bool tracked,
00199                          const std::string &label,
00200                          const std::string &value)
00201 {
00202    std::vector<T> valueVector;
00203       
00204    std::stringstream iss(value);
00205    std::string vitem;
00206       
00207    size_t fst, lst;
00208 
00209    while (getline(iss, vitem, ','))
00210    {
00211       fst = vitem.find("[");
00212       lst = vitem.find("]");
00213         
00214       if ( fst != std::string::npos )
00215          vitem.erase(fst,1);
00216       if ( lst != std::string::npos )
00217          vitem.erase(lst,1);
00218         
00219       std::stringstream oss(vitem);
00220       T on;
00221       oss >> on;
00222 
00223       valueVector.push_back(on);
00224    }
00225      
00226    if (tracked)
00227       ps.addParameter(label, valueVector);
00228    else
00229       ps.addUntrackedParameter(label, valueVector);
00230 }
00231 
00232 //______________________________________________________________________________
00233 
00234 bool FWPSetCellEditor::apply(FWPSetTableManager::PSetData &data, FWPSetTableManager::PSetData &parent)
00235 {
00236    switch (data.type)
00237    {
00238       case 'I':
00239          editNumericParameter<int32_t>(parent.pset, data.tracked, data.label, GetText());
00240          break;
00241       case 'U':
00242          editNumericParameter<uint32_t>(parent.pset, data.tracked, data.label, GetText());
00243          break;
00244       case 'D':
00245          editNumericParameter<double>(parent.pset, data.tracked, data.label, GetText());
00246          break;
00247       case 'L':
00248          editNumericParameter<long long>(parent.pset, data.tracked, data.label, GetText());
00249          break;
00250       case 'X':
00251          editNumericParameter<unsigned long long>(parent.pset, data.tracked, data.label, GetText());
00252          break;
00253       case 'S':
00254          editStringParameter(parent.pset, data.tracked, data.label, GetText());
00255          break;
00256       case 'i':
00257          editVectorParameter<int32_t>(parent.pset, data.tracked, data.label, GetText());
00258          break;
00259       case 'u':
00260          editVectorParameter<uint32_t>(parent.pset, data.tracked, data.label, GetText());
00261          break;
00262       case 'l':
00263          editVectorParameter<long long>(parent.pset, data.tracked, data.label, GetText());
00264          break;
00265       case 'x':
00266          editVectorParameter<unsigned long long>(parent.pset, data.tracked, data.label, GetText());
00267          break;
00268       case 'd':
00269          editVectorParameter<double>(parent.pset, data.tracked, data.label, GetText());
00270          break;
00271       case 's':
00272          editVectorParameter<std::string>(parent.pset, data.tracked, data.label, GetText());
00273          break; 
00274       case 't':
00275          editInputTag(parent.pset, data.tracked, data.label, GetText());
00276          break;
00277       case 'g':
00278          editESInputTag(parent.pset, data.tracked, data.label, GetText());
00279          break;
00280       case 'v':
00281          editVInputTag(parent.pset, data.tracked, data.label, GetText());
00282          break;
00283       case 'F':
00284          editFileInPath(parent.pset, data.tracked, data.label, GetText());
00285          break;
00286       default:
00287          fwLog(fwlog::kError) << "unsupported parameter" << std::endl;
00288          UnmapWindow();
00289          return false;
00290    }
00291    return true;
00292 }
00293 
00294 //______________________________________________________________________________
00295 
00296 bool FWPSetCellEditor::HandleKey(Event_t*event)
00297 {
00298    UInt_t keysym = event->fCode;
00299 
00300    if (keysym == (UInt_t) gVirtualX->KeysymToKeycode(kKey_Escape))
00301    {
00302       TGFrame *p = dynamic_cast<TGFrame*>(const_cast<TGWindow*>(GetParent()));
00303       while (p)
00304       {
00305          TGMainFrame *mp = dynamic_cast<TGMainFrame*>(p);
00306          //   printf("editor find parent %p, %s, %p\n", p, p->ClassName(), mp);
00307          if (mp)
00308          {
00309             return mp->HandleKey(event);
00310          }
00311          p = dynamic_cast<TGFrame*>(const_cast<TGWindow*>(p->GetParent()));
00312       }
00313    }
00314 
00315    return TGTextEntry::HandleKey(event);
00316 }