Changeset 19069 for trunk/FACT++/src


Ignore:
Timestamp:
07/21/18 15:30:20 (6 years ago)
Author:
tbretz
Message:
Improved help text.
File:
1 edited

Legend:

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

    r19068 r19069  
    1 #include <boost/algorithm/string/join.hpp>
    2 
    31#include "Database.h"
    42
     
    97
    108#include <TROOT.h>
    11 #include <TSystem.h>
    12 #include <TFile.h>
    13 #include <TTree.h>
    14 #include <TLeaf.h>
    15 #include <TError.h>
    169#include <TVector3.h>
    1710#include <TRotation.h>
     
    2114// ------------------------------------------------------------------------
    2215
    23 struct Map : pair<string, string>
    24 {
    25     Map() { }
    26 };
    27 
    28 std::istream &operator>>(std::istream &in, Map &m)
    29 {
    30     string txt;
    31     in >> txt;
    32 
    33     const auto p = txt.find_first_of('/');
    34     if (p==string::npos)
    35         throw runtime_error("Missing / in map argument.");
    36     if (p!=txt.find_last_of('/'))
    37         throw runtime_error("Only one / allowed in map argument.");
    38 
    39     m.first  = txt.substr(0, p);
    40     m.second = txt.substr(p+1);
    41 
    42     return in;
    43 }
    44 
    45 
    4616void SetupConfiguration(Configuration &conf)
    4717{
    48     po::options_description control("Root to Database");
     18    po::options_description control("Calcsource options");
    4919    control.add_options()
    50         ("uri,u",          var<string>()->required(), "Database link as in\n\tuser:password@server[:port]/database.")
     20        ("uri,u",          var<string>()
     21#if BOOST_VERSION >= 104200
     22         ->required()
     23#endif
     24         , "Database link as in\n\tuser:password@server[:port]/database.")
    5125        //("source-key",     var<uint32_t>(5),                "")
    5226        //("source-name",    var<string>(""),               "")
     
    8155    cout <<
    8256        "calcsource - Fill a table with source positions\n"
    83 //        "\n"
    84 //        "Usage: rootifysql [rootify.sql [rootify.root]] [-u URI] [-q query|-f file] [-i] [-o out] [-f] [-cN] [-t tree] [-vN]\n"
     57        "\n"
     58        "This tool is to calculate the source position in the camera and fill "
     59        "it into a database table for all events which come from a single run. "
     60        "The run is idetified by its FileId (YYMMDDXXX), where YYMMDD is "
     61        "its date and XXX is the run-number. For this run the corresponding "
     62        "source key `fSourceKey` is obtained from the RunInfo table "
     63        "(--table.runinfo) and the corresponding fRightAscension and fDeclination "
     64        "from the Source table (--table.source). If --ra and --dec was specified "
     65        "by the user, this step is skipped and these two values are used instead."
     66        "\n\n"
     67        "Then for each event with the given FileId, its pointing position "
     68        "(`Ra`, `Dec`), its time (`MJD`, `MilliSec`) and its event number "
     69        "(`EvtNumber`) are requested from the table given by --table.events. "
     70        "Based on this information and the focal distance (--focal-distance) the "
     71        "`X` and `Y` coordinate of the source in the camera plane is calculated. "
     72        "The result can then be filled into a database."
     73        "\n\n"
     74        "The table to be filled or updated should contain the following columns:\n"
     75        "   - FileId INT UNSIGNED NOT NULL\n"
     76        "   - EvtNumber INT UNSIGNED NOT NULL\n"
     77        "   - X FLOAT NOT NULL\n"
     78        "   - Y FLOAT NOT NULL\n"
     79        "\n"
     80        "If the table does not exist, it can be created automatically specifying "
     81        "the --crate option. If a table already exists and it should be dropped "
     82        "before creation, the --drop option can be used:\n"
     83        "\n"
     84        "   calcsource 170909009 --create\n"
     85        "\n"
     86        "Process the data from the run 009 from 09/09/2017. If no table exists "
     87        "a table with the name given by --table.position is created.\n"
     88        "\n"
     89        "   calcsource 170909009 --create --drop\n"
     90        "\n"
     91        "Same as before, but if a table with the name given by --table.position "
     92        "exists, it is dropped before.\n"
     93        "\n"
     94        "For each event, a new row is inserted. If existing rows should be updated, "
     95        "use:\n"
     96        "\n"
     97        "   calcsource 170909009 --updated\n"
     98        "\n"
     99        "The --create option is compatible with that. The --drop option is ignored.\n"
     100        "\n"
     101        "For debugging purposes several print options and options to avoid irreversible "
     102        "changes to the database exist."
     103        "\n\n"
     104        "Usage: calcsource YYMMDDXXX [-u URI] [options]\n"
    85105        "\n"
    86106        ;
    87107    cout << endl;
    88108}
    89 
    90 enum BasicType_t
    91 {
    92     kNone = 0,
    93     kFloat,
    94     kDouble,
    95     kInt16,
    96     kUInt16,
    97     kInt32,
    98     kUInt32,
    99     kInt64,
    100     kUInt64,
    101 };
    102 
    103 static const map<string, pair<BasicType_t, string>> ConvRoot =
    104 {
    105     { "Float_t",   { kFloat,  "FLOAT"             } },
    106     { "Double_t",  { kDouble, "DOUBLE"            } },
    107     { "ULong64_t", { kUInt64, "BIGINT UNSIGNED"   } },
    108     { "Long64_t",  { kInt64,  "BIGINT"            } },
    109     { "UInt_t",    { kUInt32, "INT UNSIGNED"      } },
    110     { "Int_t",     { kInt32,  "INT"               } },
    111     { "UShort_t",  { kUInt16, "SMALLINT UNSIGNED" } },
    112     { "Short_t",   { kInt16,  "SMALLINT"          } },
    113 };
    114 
    115 struct Container
    116 {
    117     string branch; // branch name
    118     string column; // column name
    119     BasicType_t type;
    120     void *ptr;
    121 
    122     Container(const string &b, const string &c, const BasicType_t &t) : branch(b), column(c), type(t), ptr(0)
    123     {
    124         switch (t)
    125         {
    126         case kFloat:  ptr = new Float_t;   break;
    127         case kDouble: ptr = new Double_t;  break;
    128         case kInt16:  ptr = new Short_t;   break;
    129         case kUInt16: ptr = new UShort_t;  break;
    130         case kInt32:  ptr = new Int_t;     break;
    131         case kUInt32: ptr = new UInt_t;    break;
    132         case kInt64:  ptr = new Long64_t;  break;
    133         case kUInt64: ptr = new ULong64_t; break;
    134         case kNone:
    135             break;
    136         }
    137     }
    138     ~Container()
    139     {
    140         //::operator delete(ptr); // It seems root is deleting it already
    141     }
    142 
    143     string fmt() const
    144     {
    145         ostringstream str;
    146 
    147         switch (type)
    148         {
    149         case kFloat:   str << setprecision(8) << *reinterpret_cast<Float_t*>(ptr); break;
    150         case kDouble:  str << setprecision(16) << *reinterpret_cast<Double_t*>(ptr); break;
    151         case kInt16:   str << *reinterpret_cast<Short_t*>(ptr); break;
    152         case kUInt16:  str << *reinterpret_cast<UShort_t*>(ptr); break;
    153         case kInt32:   str << *reinterpret_cast<Int_t*>(ptr); break;
    154         case kUInt32:  str << *reinterpret_cast<UInt_t*>(ptr); break;
    155         case kInt64:   str << *reinterpret_cast<Long64_t*>(ptr); break;
    156         case kUInt64:  str << *reinterpret_cast<ULong64_t*>(ptr); break;
    157         case kNone:
    158             break;
    159         }
    160 
    161         return str.str();
    162     }
    163 };
    164109
    165110class MRotation : public TRotation
     
    172117
    173118
    174 void ErrorHandlerAll(Int_t level, Bool_t abort, const char *location, const char *msg)
    175 {
    176     if (string(msg).substr(0,24)=="no dictionary for class ")
    177         return;
    178 
    179     DefaultErrorHandler(level, abort, location, msg);
    180 }
    181 
    182119int main(int argc, const char* argv[])
    183120{
     
    185122
    186123    gROOT->SetBatch();
    187     SetErrorHandler(ErrorHandlerAll);
    188124
    189125    Configuration conf(argv[0]);
Note: See TracChangeset for help on using the changeset viewer.