Changeset 18497 for trunk


Ignore:
Timestamp:
05/08/16 18:47:22 (9 years ago)
Author:
tbretz
Message:
Added an option to redirect the output file to null.
File:
1 edited

Legend:

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

    r18491 r18497  
    2727        ("tree,t",        var<string>("Result"),       "Name of the root tree")
    2828        ("display,d",     po_switch(),                 "Displays contents on the screen (most usefull in combination with mysql statements as SHOW or EXPLAIN)")
     29        ("no-out,n",      po_switch(),                 "Redirect the output file to /dev/null")
    2930        ("delimiter",     var<string>(""),             "The delimiter used if contents are displayed with --display (default=\\t)")
    3031        ("verbose,v",     var<uint16_t>(1),            "Verbosity (0: quiet, 1: default, 2: more, 3, ...)")
     
    4344    cout <<
    4445        "rootifysql - Converts the result of a mysql query into a root file\n"
     46        "\n"
     47        "For convenience, this documentation uses the extended version of the options, "
     48        "refer to the output below to get the abbreviations.\n"
    4549        "\n"
    4650        "Writes the result of a mysql query into a root file. For each column, a branch is "
     
    5559        "This can be useful to create an ascii file or to show results as 'SHOW DATABASES' "
    5660        "or 'EXPLAIN table'. To redirect the contents into an ascii file, the option -v0 "
    57         "is useful.\n"
     61        "is useful. To suppredd writing to an output file --no-out can be used.\n"
    5862        "\n"
    5963        "The default is to read the query from a file called rootify.sql. Except if a different "
     
    9397    const bool     update      = conf.Get<bool>("update");
    9498    const bool     display     = conf.Get<bool>("display");
     99    const bool     noout       = conf.Get<bool>("no-out");
    95100    const uint16_t verbose     = conf.Get<uint16_t>("verbose");
    96101    const uint16_t compression = conf.Get<uint16_t>("compression");
     
    129134    // I am using root here instead of boost to be
    130135    // consistent with the access pattern by TFile
    131     TString path(out.c_str());
     136    TString path(noout?"/dev/null":out.c_str());
    132137    gSystem->ExpandPathName(path);
    133138
    134     FileStat_t stat;
    135     const Int_t  exist = !gSystem->GetPathInfo(path, stat);
    136     const Bool_t write = !gSystem->AccessPathName(path,  kWritePermission) && R_ISREG(stat.fMode);
    137 
    138     if ((update && !exist) || (update && exist && !write) || (force && exist && !write))
    139     {
    140         cerr << "File '" << path << "' is not writable." << endl;
    141         return 3;
    142     }
    143 
    144     if (!update && !force && exist)
    145     {
    146         cerr << "File '" << path << "' already exists." << endl;
    147         return 4;
     139    if (!noout)
     140    {
     141        FileStat_t stat;
     142        const Int_t  exist = !gSystem->GetPathInfo(path, stat);
     143        const Bool_t write = !gSystem->AccessPathName(path,  kWritePermission) && R_ISREG(stat.fMode);
     144
     145        if ((update && !exist) || (update && exist && !write) || (force && exist && !write))
     146        {
     147            cerr << "File '" << path << "' is not writable." << endl;
     148            return 3;
     149        }
     150
     151        if (!update && !force && exist)
     152        {
     153            cerr << "File '" << path << "' already exists." << endl;
     154            return 4;
     155        }
    148156    }
    149157    // -------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.