Changeset 18929 for trunk


Ignore:
Timestamp:
11/12/17 20:02:22 (7 years ago)
Author:
tbretz
Message:
Allow to skip filling the tree to debug speed of reading the database. Skip columns starting with @. Add more output for the user. Implement a way to skip columns.
File:
1 edited

Legend:

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

    r18927 r18929  
    11#include "Database.h"
     2
     3#include <regex>
    24
    35#include "Time.h"
     
    2628        ("compression,c", var<uint16_t>(1),            "zlib compression level for the root file")
    2729        ("tree,t",        var<string>("Result"),       "Name of the root tree")
     30        ("ignore",        vars<string>(),              "Ignore the given columns")
    2831        ("display,d",     po_switch(),                 "Displays contents on the screen (most usefull in combination with mysql statements as SHOW or EXPLAIN)")
    29         ("null,n",        po_switch(),                 "Redirect the output file to /dev/null")
     32        ("null,n",        po_switch(),                 "Redirect the output file to /dev/null (mainly for debugging purposes, e.g. performance studies)")
     33        ("no-fill",       po_switch(),                 "Do not fill events into the root file (mainly for debugging purposes, e.g. performance studies)")
    3034        ("delimiter",     var<string>(""),             "The delimiter used if contents are displayed with --display (default=\\t)")
    3135        ("verbose,v",     var<uint16_t>(1),            "Verbosity (0: quiet, 1: default, 2: more, 3, ...)")
     
    6468        "filename is specified by the --file option or a query is given with --query.\n"
    6569        "\n"
     70        "As a trick, the rootify.sql file can be made excutable (chmod u+x rootify.sql). "
     71        "If the first line contains '#!rootifysql', the script can be executed directly.\n"
     72        "\n"
    6673        "Comments in the query-file can be placed according to the SQL standard inline "
    67         "/*comment*/ or on individual lines introduces with # or --.\n"
     74        "/*comment*/ or introduced with # (shell script style) or -- (SQL style).\n"
    6875        "\n"
    6976        "In case of succes, 0 is returned, a value>0 otherwise.\n"
     
    94101    const string   tree        = conf.Get<string>("tree");
    95102    const bool     force       = conf.Get<bool>("force");
    96     const bool     ignore      = conf.Get<bool>("ignore-null");
     103    const bool     ignorenull  = conf.Get<bool>("ignore-null");
    97104    const bool     update      = conf.Get<bool>("update");
    98105    const bool     display     = conf.Get<bool>("display");
    99106    const bool     noout       = conf.Get<bool>("null");
     107    const bool     nofill      = conf.Get<bool>("no-fill");
    100108    const uint16_t verbose     = conf.Get<uint16_t>("verbose");
    101109    const uint16_t compression = conf.Get<uint16_t>("compression");
    102110    const string   delimiter   = conf.Get<string>("delimiter");
     111    const vector<string> ignore = conf.Vec<string>("ignore");
    103112    // -------------------------------------------------------------------------
    104113
     
    202211
    203212    vector<double>  buf(l.size());
    204     vector<uint8_t> typ(l.size(),'n');
     213    vector<uint8_t> typ(l.size(),'n'); // n=number [double], d is used for DateTime
    205214
    206215    UInt_t cols = 0;
     216
    207217
    208218    // -------------------- Configure branches of TTree ------------------------
    209219    TTree *ttree = new TTree(tree.c_str(), query.c_str());
     220
     221    size_t skipat  = 0;
     222    size_t skipreg = 0;
    210223    for (size_t i=0; i<l.size(); i++)
    211224    {
     
    227240                            typ[i] = 'C';
    228241
    229         const bool use = typ[i]!='V' && typ[i]!='C';
     242        bool found = false;
     243        for (const auto &pattern: ignore)
     244        {
     245            if (regex_match(l[i], regex(pattern)))
     246            {
     247                found = true;
     248                typ[i] = '-';
     249                skipreg++;
     250                break;
     251            }
     252        }
     253
     254        if (l[i][0]=='@')
     255        {
     256            typ[i] = '@';
     257            skipat++;
     258        }
     259
     260        const bool use = l[i][0]!='@' && typ[i]!='V' && typ[i]!='C' && !found;
    230261
    231262        if (verbose>1)
     
    243274        cout << endl;
    244275    if (verbose>0)
     276    {
     277        if (skipreg)
     278            cout << skipreg << " branches skipped due to ignore list." << endl;
     279        if (skipat)
     280            cout << skipat  << " branches skipped due to name starting with @." << endl;
    245281        cout << "Configured " << cols << " branches.\nFilling branches..." << endl;
     282    }
    246283
    247284    if (display)
     
    273310            }
    274311
    275             if (!ignore && col->is_null())
     312            if (!ignorenull && col->is_null())
    276313            {
    277314                skip++;
     
    295332            case 'V':
    296333            case 'C':
     334            case '-':
     335            case '@':
    297336                break;
    298337
     
    304343        if (idx==row.size())
    305344        {
    306             ttree->Fill();
     345            if (!nofill)
     346                ttree->Fill();
     347
    307348            if (display)
    308349                cout << sout.str() << endl;
     
    310351
    311352        row = res.fetch_row();
     353
    312354
    313355    } while (row);
Note: See TracChangeset for help on using the changeset viewer.