Changeset 11483


Ignore:
Timestamp:
07/20/11 10:27:17 (13 years ago)
Author:
tbretz
Message:
Added a registry for wildcarded options to detect unaccessed options; for this EvalConfiguration(const Configuration&) has been changed to EvalOptions(Configuration&)
Location:
trunk/FACT++/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Configuration.cc

    r11481 r11483  
    528528        ("print-unknown",       "Print unrecognized options.")
    529529        ("print-options",       "Print options as passed to program.")
     530        ("print-wildcards",     "Print all options registered with wildcards.")
    530531        ("dont-check",          "Do not check validity of options from files and database.")
    531532        ("dont-check-files",    "Do not check validity of options from files.")
     
    591592        //for (int j=0; j<options[i].value.size(); j++)
    592593        //    cout << "\t = " << options[i].value[j];
    593 
    594         //cout << "/" << options[i].position_key;
    595594        //cout << "/" << options[i].original_tokens[0];
    596         //cout << "/" << options[i].unregistered << endl;
     595
     596        ostringstream com;
     597
     598        if (opt.position_key>=0)
     599            com << " [position=" << opt.position_key << "]";
    597600        if (opt.unregistered)
    598             cout << "   # option unknown";
     601            com << " [unregistered]";
     602
     603        if (!com.str().empty())
     604            cout << "  # " << com.str();
     605
    599606        cout << endl;
    600607    }
     
    963970//!         options from the default configuration-file and options
    964971//!         from the environment.
    965 //!  - (15) Finally all options which were found and flagged as unrecognized,
     972//!  - (15) Find all options which were found and flagged as unrecognized,
    966973//!         because they are not in the user-defined list of described
    967974//!         options, are collected and stored in the corresponding
    968975//!         data-members.
    969 //!  - (16) Before the function returns it check for \b --print-options
     976//!  - (16) Find all options which where registered with wildcards and
     977//!         store the list in fWildcardOptions.
     978//!  - (17) Before the function returns it check for \b --print-options
    970979//!         and \b --print-unknown and performs the corresponding actions.
    971980//!
     
    10581067    const string globalfile = path.parent_path().string()+"/fact++.rc";
    10591068
    1060     cerr << "Reading options from '" << globalfile << "'." << endl;
     1069    cerr << "Reading global  options from '" << globalfile << "'." << endl;
    10611070
    10621071    ifstream gfile(globalfile.c_str());
     
    10731082    {
    10741083        fDefaultFile = getfiles["default"].as<string>();
    1075         cerr << "Reading options from '" << fDefaultFile << "'." << endl;
     1084        cerr << "Reading default options from '" << fDefaultFile << "'." << endl;
    10761085    }
    10771086
     
    11091118    {
    11101119        fPriorityFile = getfiles["config"].as<string>();
    1111         cerr << "Reading options from '" << fPriorityFile << "'." << endl;
     1120        cerr << "Reading config options from '" << fPriorityFile << "'." << endl;
    11121121    }
    11131122
     
    12081217    // ------------------------ (16) -------------------------
    12091218
     1219    CreateWildcardOptions();
     1220
     1221    // ------------------------ (17) -------------------------
     1222
    12101223    if (result.count("print-options"))
    12111224        PrintOptions();
    12121225
     1226    if (result.count("print-wildcards"))
     1227        PrintWildcardOptions();
     1228
    12131229    if (result.count("print-unknown"))
    12141230        PrintUnknown();
    12151231
    12161232    return fVariables;
     1233}
     1234
     1235// --------------------------------------------------------------------------
     1236//
     1237//! Create a list of all options which were registered using wildcards
     1238//!
     1239void Configuration::CreateWildcardOptions()
     1240{
     1241    po::options_description opts;
     1242
     1243    for (int i=0; i<2; i++)
     1244    {
     1245        opts.add(fOptionsCommandline[i]);
     1246        opts.add(fOptionsConfigfile[i]);
     1247        opts.add(fOptionsEnvironment[i]);
     1248        opts.add(fOptionsDatabase[i]);
     1249    }
     1250
     1251    fWildcardOptions.clear();
     1252
     1253    typedef map<string,po::variable_value> Vars;
     1254    typedef vector<boost::shared_ptr<po::option_description>> Descs;
     1255
     1256    const Descs &desc = opts.options();
     1257
     1258    for (Vars::const_iterator io=fVariables.begin(); io!=fVariables.end(); io++)
     1259    {
     1260        for (Descs::const_iterator id=desc.begin(); id!=desc.end(); id++)
     1261            if ((*id)->match(io->first, false, false, false)==po::option_description::approximate_match)
     1262                fWildcardOptions[io->first] = (*id)->long_name();
     1263    }
     1264}
     1265
     1266// --------------------------------------------------------------------------
     1267//
     1268//! Print a list of all options which were registered using wildcards and
     1269//! have not be registered subsequently by access.
     1270//!
     1271void Configuration::PrintWildcardOptions() const
     1272{
     1273    cout << "Options registered with wildcards and not yet accessed:" << endl;
     1274
     1275    size_t max = 0;
     1276    for (map<string,string>::const_iterator it=fWildcardOptions.begin(); it!=fWildcardOptions.end(); it++)
     1277        if (it->second.length()>max)
     1278            max = it->second.length();
     1279
     1280    cout.setf(ios_base::left);
     1281    for (map<string,string>::const_iterator it=fWildcardOptions.begin(); it!=fWildcardOptions.end(); it++)
     1282        cout << setw(max+1) << it->second << " : " << it->first <<endl;
    12171283}
    12181284
  • trunk/FACT++/src/Configuration.h

    r11481 r11483  
    3333    std::vector<std::string> fUnknownDatabase;      /// Storage container for unrecognized options retrieved from the database
    3434
     35    std::map<std::string, std::string> fWildcardOptions;  /// Options which were registered using wildcards
     36
    3537    std::string fPriorityFile;  /// File name of the priority configuration file (overwrites option from the databse)
    3638    std::string fDefaultFile;   /// File name of the default configuration file (usually {program}.rc)
     
    5658            val=comp;
    5759    }
     60
     61    /// Helper for Parse to create list of used wildcard options
     62    void CreateWildcardOptions();
    5863
    5964    // Helper functions for PrintOptions and GetOptions
     
    112117    void PrintOptions() const;
    113118    void PrintUnknown() const;
     119    void PrintWildcardOptions() const;
     120
     121    const std::map<std::string,std::string> &GetWildcardOptions() const { return fWildcardOptions; }
    114122
    115123    std::multimap<std::string, std::string> GetOptions() const;
     
    118126    const po::variables_map &Parse(int argc, const char **argv);
    119127
    120     bool HasVersion() const
     128    bool HasVersion()
    121129    {
    122130        return Has("version");
    123131    }
    124132
    125     bool HasHelp() const
     133    bool HasHelp()
    126134    {
    127135        return Has("help") || Has("help-config") || Has("help-env") || Has("help-database");
    128136    }
    129137
    130     bool HasPrint() const
     138    bool HasPrint()
    131139    {
    132140        return Has("print-all") || Has("print") || Has("print-default") ||
    133141            Has("print-database") || Has("print-config") ||
    134142            Has("print-environment") || Has("print-unknown") ||
    135             Has("print-options");
     143            Has("print-options") || Has("print-wildcards");
    136144    }
    137145
    138146    // Simplified access to the parsed options
    139147    template<class T>
    140         T Get(const std::string &var) const { return fVariables[var].as<T>(); }
    141     template<class T>
    142         std::vector<T> Vec(const std::string &var) const { return Has(var) ? fVariables[var].as<std::vector<T>>() : std::vector<T>(); }
    143     bool Has(const std::string &var) const { return fVariables.count(var)>0; }
     148        T Get(const std::string &var) { fWildcardOptions.erase(var); return fVariables[var].as<T>(); }
     149    bool Has(const std::string &var) { fWildcardOptions.erase(var); return fVariables.count(var)>0; }
     150
     151    template<class T>
     152        std::vector<T> Vec(const std::string &var) { return Has(var) ? fVariables[var].as<std::vector<T>>() : std::vector<T>(); }
    144153
    145154    template<class T, class S>
    146     T Get(const std::string &var, const S &val) const
     155    T Get(const std::string &var, const S &val)
    147156    {
    148157        std::ostringstream str;
     
    152161
    153162    template<class T>
    154     bool Has(const std::string &var, const T &val) const
     163    bool Has(const std::string &var, const T &val)
    155164    {
    156165        std::ostringstream str;
     
    160169
    161170    template<class T, class S>
    162     T GetDef(const std::string &var, const S &val) const
     171    T GetDef(const std::string &var, const S &val)
    163172    {
    164173        return Has(var, val) ? Get<T>(var, val) : Get<T>(var+"default");
     
    166175
    167176    template<class T>
    168     bool HasDef(const std::string &var, const T &val) const
     177    bool HasDef(const std::string &var, const T &val)
    169178    {
    170179        return Has(var, val) ? true : Has(var+"default");
    171180    }
    172 
    173     template<class T>
    174     std::map<std::string, T> GetMap(const std::string &var) const
     181/*
     182    template<class T>
     183    std::map<std::string, T> GetMap(const std::string &var)
    175184    {
    176185        const size_t len = var.length();
     
    186195
    187196    template<class T>
    188     std::vector<std::string> GetKeys(const std::string &var) const
     197    std::vector<std::string> GetKeys(const std::string &var)
    189198    {
    190199        const size_t len = var.length();
     
    198207        return rc;
    199208    }
    200 
     209*/
    201210    const std::string &GetName() const { return fName; }
    202211};
  • trunk/FACT++/src/Main.h

    r11481 r11483  
    22#define FACT_MAIN
    33
     4#include <map>
    45#include <thread>
    56#include <functional>
     
    4142
    4243template<class T, class S>
    43 int Main(const Configuration &conf, bool dummy=false)
     44int Main(Configuration &conf, bool dummy=false)
    4445{
    4546    static T shell(conf.GetName().c_str(),
     
    7071    io_service.Write(now, "| Start:    "+now.GetAsStr("%c"));
    7172    io_service.Write(now, "\\----------------------- Options ------------------------");
    72     const multimap<string,string> map = conf.GetOptions();
    73     for (multimap<string,string>::const_iterator it=map.begin(); it!=map.end(); it++)
     73    const multimap<string,string> mmap = conf.GetOptions();
     74    for (multimap<string,string>::const_iterator it=mmap.begin(); it!=mmap.end(); it++)
    7475        io_service.Write(now, ": "+it->first+(it->second.empty()?"":" = ")+it->second);
    7576    io_service.Write(now, "\\------------------- Evaluating options -----------------");
     77    const int rc = io_service.EvalOptions(conf);
    7678
    77     const int rc = io_service.EvalConfiguration(conf);
     79    const map<string,string> &wco = conf.GetWildcardOptions();
     80    if (wco.size()>0)
     81    {
     82        io_service.Write(now, "------------- Unrecognized wildcard options -------------", MessageImp::kWarn);
     83
     84        size_t max = 0;
     85        for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++)
     86            if (it->second.length()>max)
     87                max = it->second.length();
     88
     89        for (map<string,string>::const_iterator it=wco.begin(); it!=wco.end(); it++)
     90        {
     91            ostringstream str;
     92            str.setf(ios_base::left);
     93            str << setw(max+1) << it->second << " : " << it->first;
     94            io_service.Write(now, str.str(), MessageImp::kWarn);
     95        }
     96        return 127;
     97    }
     98
    7899    io_service.Message("==================== Starting main loop =================");
    79100    if (rc>=0)
  • trunk/FACT++/src/biasctrl.cc

    r11481 r11483  
    537537    }
    538538
    539     int EvalConfiguration(const Configuration &conf)
     539    int EvalOptions(Configuration &conf)
    540540    {
    541541        SetEndpoint(conf.Get<string>("addr"));
  • trunk/FACT++/src/datalogger.cc

    r11481 r11483  
    23362336//! @param conf the configuration object that should be used
    23372337//!
    2338 int DataLogger::EvalConfiguration(const Configuration& conf)
     2338int DataLogger::EvalOptions(Configuration& conf)
    23392339{
    23402340    fDebugIsOn = conf.Get<bool>("debug");
  • trunk/FACT++/src/drivectrl.cc

    r11481 r11483  
     1#include <boost/bind.hpp>
     2
    13#include "FACT.h"
    24#include "Dim.h"
     
    410412    {
    411413        boost::asio::async_read_until(*this, fBuffer, '\n',
    412                                       bind(&ConnectionDrive::HandleReceivedReport, this,
     414                                      boost::bind(&ConnectionDrive::HandleReceivedReport, this,
    413415                                                  dummy::error, dummy::bytes_transferred));
    414416    }
     
    421423
    422424        fKeepAlive.expires_from_now(boost::posix_time::seconds(10));
    423         fKeepAlive.async_wait(bind(&ConnectionDrive::HandleKeepAlive,
     425        fKeepAlive.async_wait(boost::bind(&ConnectionDrive::HandleKeepAlive,
    424426                                          this, dummy::error));
    425427    }
     
    834836    }
    835837
    836     int EvalConfiguration(const Configuration &conf)
     838    int EvalOptions(Configuration &conf)
    837839    {
    838840        SetEndpoint(conf.Get<string>("addr"));
  • trunk/FACT++/src/fadctrl.cc

    r11481 r11483  
    17901790
    17911791    template<class V>
    1792     bool CheckConfigVal(const Configuration &conf, V max, const string &name, const string &sub)
     1792    bool CheckConfigVal(Configuration &conf, V max, const string &name, const string &sub)
    17931793    {
    17941794        if (!conf.HasDef(name, sub))
     
    18101810    }
    18111811
    1812     int EvalConfiguration(const Configuration &conf)
     1812    int EvalOptions(Configuration &conf)
    18131813    {
    18141814        // ---------- General setup ---------
  • trunk/FACT++/src/fscctrl.cc

    r11481 r11483  
    506506    }
    507507
    508     int EvalConfiguration(const Configuration &conf)
     508    int EvalOptions(Configuration &conf)
    509509    {
    510510        SetEndpoint(conf.Get<string>("addr"));
  • trunk/FACT++/src/ftmctrl.cc

    r11481 r11483  
    19711971
    19721972    template<class V>
    1973     bool CheckConfigVal(const Configuration &conf, V max, const string &name, const string &sub)
     1973    bool CheckConfigVal(Configuration &conf, V max, const string &name, const string &sub)
    19741974    {
    19751975        if (!conf.HasDef(name, sub))
     
    19911991    }
    19921992
    1993     int EvalConfiguration(const Configuration &conf)
     1993    int EvalOptions(Configuration &conf)
    19941994    {
    19951995        // ---------- General setup ----------
  • trunk/FACT++/src/mcp.cc

    r11481 r11483  
    179179    int Reset(const EventImp &evt)
    180180    {
     181        fRunType = "";
    181182        return kStateIdle;
    182183        /*
     
    200201    }
    201202
     203    string fRunType;
     204
    202205    int StartRun(const EventImp &evt)
    203206    {
     207        Message("Starting configuration '"+evt.GetString()+"' for new run.");
     208        fRunType = evt.GetString();
    204209        return kStateConfiguring1;
    205210    }
     
    225230                if (fStatusLog.second!=30/*kSM_WaitForRun*/)
    226231                    Dim::SendCommand("DATA_LOGGER/WAIT_FOR_RUN_NUMBER");
    227                 Dim::SendCommand("FTM_CONTROL/CONFIGURE", "data");
     232                Dim::SendCommand("FTM_CONTROL/CONFIGURE", fRunType);
    228233                return kStateConfiguring2;
    229234            }
     
    236241                    return GetCurrentState();
    237242
    238                 Dim::SendCommand("FAD_CONTROL/CONFIGURE", "data");
     243                Dim::SendCommand("FAD_CONTROL/CONFIGURE", fRunType);
    239244                return kStateConfiguring3;
    240245            }
     
    248253                Message("START DATA TAKING");
    249254                Fatal("Distribute run-number to start datalogger!");
    250                 Fatal("fadctrl should go out of Configured after first event received!");
    251                 Fatal("Must configure if FTM should be started or not?");
     255                //Fatal("Must configure if FTM should be started or not?");
    252256                Dim::SendCommand("FTM_CONTROL/START_RUN");
    253257                return kStateConfigured;
     
    329333
    330334
    331         AddEvent("START", kStateIdle)
     335        AddEvent("START", "C", kStateIdle)
    332336            (bind(&StateMachineMCP::StartRun, this, placeholders::_1))
    333337            ("");
     
    352356    }
    353357
    354     int EvalConfiguration(const Configuration &conf)
     358    int EvalOptions(Configuration &conf)
    355359    {
    356360        //SetEndpoint(conf.Get<string>("addr"));
     
    401405
    402406template<class T>
    403 int RunShell(const Configuration &conf)
     407int RunShell(Configuration &conf)
    404408{
    405409    return Main<T, StateMachineMCP>(conf);
  • trunk/FACT++/src/scheduler.cc

    r11481 r11483  
    691691    }
    692692
    693     int EvalConfiguration(const Configuration &conf)
     693    int EvalOptions(Configuration &conf)
    694694    {
    695695        fDatabase       = conf.Get<string>("schedule-database");
Note: See TracChangeset for help on using the changeset viewer.