00001 // BLTune.hh 00002 /* 00003 This source file is part of G4beamline, http://g4beamline.muonsinc.com 00004 Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved. 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 http://www.gnu.org/copyleft/gpl.html 00017 */ 00018 00019 #ifndef BLTUNE_HH 00020 #define BLTUNE_HH 00021 00022 #include <map> 00023 #include "globals.hh" 00024 #include "BLEvaluator.hh" 00025 00026 00027 /** class BLTune contains the general interface to tuning arguments. 00028 * 00029 * The tune command (class BLCMDtune) will tune arguments to commands 00030 * with the goal of achieving some specified measure of performance. 00031 * Tuning occurs when the Tune Particle is tracked, and only those 00032 * aspects of performance that can be achieved during that tracking 00033 * can be tuned. The example used here is to tune the current in a 00034 * genericbend so the reference particle had dxdz=0 after the magnet. 00035 * 00036 * Tunable arguments to a command must: 00037 * a) be declared with argTunable() in defineArgs() 00038 * b) be referenced indirectly by each placement class of the element; 00039 * that is, the placement object cannot keep a local copy, but 00040 * must always reference the actual parameter variable of the Element. 00041 * c) be copied using BLTune::copyTunableArg() in the element's copy 00042 * constructor 00043 * 00044 * Tunable arguments are set on either the element or place command 00045 * using the usual name=expression syntax. The expression can contain 00046 * the name of any enclosing tune command as a variable, and the value 00047 * of the variable will always be the current value during tuning, and 00048 * will be the final result after tuning is complete. 00049 **/ 00050 class BLTune { 00051 static BLEvaluator eval; 00052 static std::map<G4double*,G4String> tuneExpr; 00053 static std::map<G4double*,G4double> tuneUnits; 00054 public: 00055 /// Constructor 00056 BLTune() { } 00057 00058 /// Destructor 00059 virtual ~BLTune() { } 00060 00061 /// defineTunableArg() will define a tunable argument. 00062 static void defineTunableArg(G4double& arg, G4double units, G4String expr); 00063 00064 /// copyTunableArg() will copy a tunable argument; for use in the copy 00065 /// constructor of Element classes. 00066 static void copyTunableArg(G4double *newArg, const G4double *oldArg); 00067 00068 /// isSet() returns true if the varaible name is set. 00069 static bool isSet(G4String name); 00070 00071 /// set() will set the value of a tune variable, and update all 00072 /// arguments that use it. 00073 static void set(G4String& name, G4double value); 00074 00075 /// unset() will remove a tune variable. 00076 static void unset(G4String& name); 00077 00078 /// update() will update all tunable args with their current values. 00079 static void update(); 00080 }; 00081 00082 #endif // BLTUNE_HH