Changeset 19987 for trunk/FACT++/src


Ignore:
Timestamp:
08/17/20 15:19:11 (4 years ago)
Author:
tbretz
Message:
Cleanup of commandline options, files are not obverwritten anymore per default.
File:
1 edited

Legend:

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

    r19986 r19987  
    133133         , "Database link as in\n\tuser:password@server[:port]/database[?compress=0|1].")
    134134        ("out,o", var<string>(conf.GetName()), "Defines the prefix (with path) of the output files.")
    135         ("confidence-level,c", var<double>(0.99), "Confidence level for the calculation of the upper limits.")
    136         ("feldman-cousins", po_bool(), "Calculate Feldman-Cousins ULs (slow and only minor difference to Rolke).")
    137         ;
    138 
    139     po::options_description binnings("Binnings");
    140     binnings.add_options()
    141         ("theta",             var<Binning>(Binning(90, 0, 90)),  "Add equidistant bins in theta (degrees). Syntax: N,lo,hi (Number N of equidistant bins between lo and hi)")
    142         ("theta-bin",         vars<double>(),                    "Add a bin-edge to the theta binning (degree)")
    143         ("energy-dense",      var<Binning>(Binning(30, 2, 5)),   "Add equidistant bins in log10 simulated energy. Syntax: N,lo,hi (Number N of equidistant bins between lo and hi)")
    144         ("energy-dense-bin",  vars<double>(),                    "Add a bin-edge to the binnnig in log10 simulated enegry")
    145         ("energy-sparse",     var<Binning>(Binning(15, 2, 5)),   "Add equidistant bins in log10 estimated energy. Syntax: N,lo,hi (Number N of equidistant bins between lo and hi)")
    146         ("energy-sparse-bin", vars<double>(),                    "Add a bin-edge to the binning in log10 estimated enegry")
    147         ("impact",            var<Binning>(Binning(28, 0, 280)), "Add equidistant bins in impact in meter. Syntax: N,lo,hi (Number N of equidistant bins between lo and hi)")
    148         ("impact-bin",        vars<double>(),                    "Add a bin-edge to the binning in impact in meter")
    149         ;
    150 
    151     po::options_description analysis("Analysis Setup");
    152     analysis.add_options()
    153         ("analysis",    var<string>("analysis.sql"),   "File with the analysis query. A default file is created automatically in the <prefix> directory it does not exist.")
    154         ("source-key", var<uint16_t>(5),          "Source key to be used in data file selection.")
    155         ("selector",   vars<string>()->required(),"WHERE clause to be used in data file selection.")
    156         ("selsim",     vars<string>(),            "WHERE clause to be used in monte carlo file selection.")
    157         ("estimator",  var<string>()->required(), "Energy estimator to be used.")
    158         ("spectrum",   var<string>()->required(), "Spectral shape for re-weighting of simulated 'Energy'")
    159         ("env.*",      var<string>(),             "Define a variable that is replaced in all queries automatically.")
    160         ;
     135        ("force,f", po_bool(), "Force overwriting output files.");
    161136
    162137    po::options_description debug("Debug options");
     
    173148        ;
    174149
     150
     151    po::options_description binnings("Binnings");
     152    binnings.add_options()
     153        ("theta",             var<Binning>(Binning(90, 0, 90)),  "Add equidistant bins in theta (degrees). Syntax: N,lo,hi (Number N of equidistant bins between lo and hi)")
     154        ("theta-bin",         vars<double>(),                    "Add a bin-edge to the theta binning (degree)")
     155        ("energy-dense",      var<Binning>(Binning(30, 2, 5)),   "Add equidistant bins in log10 simulated energy. Syntax: N,lo,hi (Number N of equidistant bins between lo and hi)")
     156        ("energy-dense-bin",  vars<double>(),                    "Add a bin-edge to the binnnig in log10 simulated enegry")
     157        ("energy-sparse",     var<Binning>(Binning(15, 2, 5)),   "Add equidistant bins in log10 estimated energy. Syntax: N,lo,hi (Number N of equidistant bins between lo and hi)")
     158        ("energy-sparse-bin", vars<double>(),                    "Add a bin-edge to the binning in log10 estimated enegry")
     159        ("impact",            var<Binning>(Binning(28, 0, 280)), "Add equidistant bins in impact in meter. Syntax: N,lo,hi (Number N of equidistant bins between lo and hi)")
     160        ("impact-bin",        vars<double>(),                    "Add a bin-edge to the binning in impact in meter")
     161        ;
     162
     163    po::options_description analysis("Analysis Setup");
     164    analysis.add_options()
     165        ("analysis",    var<string>("analysis.sql"),   "File with the analysis query. A default file is created automatically in the <prefix> directory it does not exist.")
     166        ("source-key", var<uint16_t>(5),          "Source key to be used in data file selection (Default=Crab).")
     167        ("selector",   vars<string>()->required(),"WHERE clause to be used in data file selection, selectors are concatenated by AND.")
     168        ("selsim",     vars<string>(),            "WHERE clause to be used in monte carlo file selection, selsims are concatenated by AND.")
     169        ("estimator",  var<string>()->required(), "Energy estimator to be used (units must be consistent with energy binnings).")
     170        ("spectrum",   var<string>()->required(), "Spectral shape for re-weighting of simulated 'Energy'")
     171//        ("env.*",      var<string>(),             "Define a variable that is replaced in all queries automatically.")
     172        ;
     173
     174    po::options_description physics("Physics");
     175    physics.add_options()
     176        ("confidence-level,c", var<double>(0.99), "Confidence level for the calculation of the upper limits.")
     177        ("feldman-cousins", po_bool(), "Calculate Feldman-Cousins ULs (slow and only minor difference to Rolke).")
     178        ;
     179
    175180    //po::positional_options_description p;
    176181    //p.add("file", 1); // The 1st positional options (n=1)
    177182
    178183    conf.AddOptions(control);
     184    conf.AddOptions(debug);
    179185    conf.AddOptions(binnings);
    180186    conf.AddOptions(analysis);
    181     conf.AddOptions(debug);
     187    conf.AddOptions(physics);
    182188    //conf.SetArgumentPositions(p);
    183189}
     
    627633    const string   uri        = conf.Get<bool>("dry-run") ? "" : conf.Get<string>("uri");
    628634    const string   out        = conf.Get<string>("out");
     635    const bool     force      = conf.Get<bool>("force");
    629636    const uint16_t verbose    = conf.Get<uint16_t>("verbose");
    630637    const double   confidence = conf.Get<double>("confidence-level");
     
    652659    const string   estimator  = conf.Get<string>("estimator");
    653660    const string   spectrum   = conf.Get<string>("spectrum");
    654     const auto     env        = conf.GetOptions<string>("env.");
     661//    const auto     env        = conf.GetOptions<string>("env.");
    655662
    656663    cout << "\n";
     
    719726    // Create log streams
    720727
     728    cout << "\n";
     729    cout << "Queries    will be logged  to " << out << ".query.sql\n";
     730    if (connection.connected())
     731    {
     732        cout << "Tables     will be dumped  to " << out << ".dump.sql\n";
     733        cout << "ROOT macro will be written to " << out << ".C\n";
     734    }
     735
     736#ifdef HAVE_ROOT
     737    TFile root(connection.connected() ? (out+".hist.root").c_str() : "", force ? "RECREATE" : "CREATE");
     738    if (connection.connected())
     739    {
     740        if (root.IsZombie())
     741            return 10;
     742        cout << "Histograms will be written to " << out << ".hist.root\n";
     743    }
     744    if (verbose>0)
     745        cout << "\nCalculating upper limits for a confidence interval of " << confidence << endl;
     746#endif
     747
     748    cout << endl;
     749
     750    if (!force)
     751    {
     752        if (fs::exists(out+".query.sql"))
     753        {
     754            cerr << "File '" << out <<  ".query.sql' already exists!" << endl;
     755            return 11;
     756        }
     757        if (connection.connected())
     758        {
     759            if (fs::exists(out+".dump.sql"))
     760            {
     761                cerr << "File '" << out <<  ".dump.sql' already exists!" << endl;
     762                return 12;
     763            }
     764            if (fs::exists(out+".C"))
     765            {
     766                cerr << "File '" << out <<  ".C' already exists!" << endl;
     767                return 13;
     768            }
     769        }
     770    }
     771
    721772    ofstream qlog(out+".query.sql");
    722773    ofstream flog(connection.connected() ? out+".dump.sql" : "");
    723774    ofstream mlog(connection.connected() ? out+".C" : "");
    724 
    725     cout << "\n";
    726     cout << "Queries    will be logged  to " << out << ".query.sql\n";
    727     if (connection.connected())
    728     {
    729         cout << "Tables     will be dumped  to " << out << ".dump.sql\n";
    730         cout << "ROOT macro will be written to " << out << ".C\n";
    731     }
    732 
    733 #ifdef HAVE_ROOT
    734     TFile root(connection.connected() ? (out+".hist.root").c_str() : "", "RECREATE");
    735     if (connection.connected())
    736     {
    737         if (root.IsZombie())
    738             return 10;
    739         cout << "Histograms will be written to " << out << ".hist.root\n";
    740     }
    741     if (verbose>0)
    742         cout << "\nCalculating upper limits for a confidence interval of " << confidence << endl;
    743 #endif
    744 
    745     cout << endl;
    746775
    747776    // FIMXE: Implement SYNTAX check on spectrum, estimator and selector
     
    13301359
    13311360    query8.parse();
    1332     for (auto it=env.cbegin(); it!=env.cend(); it++)
    1333         query8.template_defaults[it->first.c_str()] = it->second.c_str();
     1361//    for (auto it=env.cbegin(); it!=env.cend(); it++)
     1362//        query8.template_defaults[it->first.c_str()] = it->second.c_str();
    13341363
    13351364    //query6.template_defaults["columns"]   = "FileId, EvtNumber, CorsikaNumReuse,";
     
    19982027
    19992028    query12.parse();
    2000     for (auto it=env.cbegin(); it!=env.cend(); it++)
    2001         query12.template_defaults[it->first.c_str()] = it->second.c_str();
     2029//    for (auto it=env.cbegin(); it!=env.cend(); it++)
     2030//        query12.template_defaults[it->first.c_str()] = it->second.c_str();
    20022031
    20032032    //query5.template_defaults["columns"]   = "FileId, EvtNumber,";
Note: See TracChangeset for help on using the changeset viewer.