Changeset 19069 for trunk/FACT++/src
- Timestamp:
- 07/21/18 15:30:20 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/calcsource.cc
r19068 r19069 1 #include <boost/algorithm/string/join.hpp>2 3 1 #include "Database.h" 4 2 … … 9 7 10 8 #include <TROOT.h> 11 #include <TSystem.h>12 #include <TFile.h>13 #include <TTree.h>14 #include <TLeaf.h>15 #include <TError.h>16 9 #include <TVector3.h> 17 10 #include <TRotation.h> … … 21 14 // ------------------------------------------------------------------------ 22 15 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 46 16 void SetupConfiguration(Configuration &conf) 47 17 { 48 po::options_description control(" Root to Database");18 po::options_description control("Calcsource options"); 49 19 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.") 51 25 //("source-key", var<uint32_t>(5), "") 52 26 //("source-name", var<string>(""), "") … … 81 55 cout << 82 56 "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" 85 105 "\n" 86 106 ; 87 107 cout << endl; 88 108 } 89 90 enum BasicType_t91 {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 Container116 {117 string branch; // branch name118 string column; // column name119 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 already141 }142 143 string fmt() const144 {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 };164 109 165 110 class MRotation : public TRotation … … 172 117 173 118 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 182 119 int main(int argc, const char* argv[]) 183 120 { … … 185 122 186 123 gROOT->SetBatch(); 187 SetErrorHandler(ErrorHandlerAll);188 124 189 125 Configuration conf(argv[0]);
Note:
See TracChangeset
for help on using the changeset viewer.