00001
00004 #include "ODBCheck.hh"
00005
00006 #include <iostream>
00007 #include <sstream>
00008
00009 #include "TROOT.h"
00010 #include "TPluginManager.h"
00011
00012 extern TROOT* gROOT;
00013
00015 void usage() {
00016 using namespace std;
00017 cout << "usage: odb_check [-h | --help] [--usage] -d data_dir [-c corr_dir] [-r first_run last_run] [run1 [run2...]]" << endl;
00018 }
00019
00022 void help() {
00023 using namespace std;
00024 usage();
00025 cout <<
00026 "odb_check: Read in shapes histogram from alcapana output files," << endl <<
00027 " estimate certain values, and then output to corrections file." << endl <<
00028 " -d : Followed by place where hist directory and corr directory are." << endl <<
00029 " The corrections files are saved to data_dir/corr/ if" << endl <<
00030 " -c flag is no specified." << endl <<
00031 " -c : The directory where the correction files are stored. If not specified," << endl <<
00032 " data_dir/corr/ is assumed." << endl <<
00033 " -r : Followed by two numbers indicating a range of runs to process." << endl <<
00034 " run1... : Any arguments not associated with a flag are assumed to be run" << endl <<
00035 " numbers to process." << endl;
00036 }
00037
00039 bool parse_args(int argc, char* argv[], std::vector<int>& runs, std::string& data_dir, std::string& corr_dir) {
00040 if (argc == 1) {
00041 help();
00042 return false;
00043 }
00044 for (int i = 1; i < argc; ++i) {
00045 std::string iarg(argv[i]);
00046 if (iarg == "-h" || iarg == "--help") {
00047 help();
00048 return false;
00049 } else if (iarg == "--usage") {
00050 usage();
00051 return false;
00052 } else if (iarg == "-d") {
00053 if (++i != argc) {
00054 data_dir = std::string(argv[i]);
00055 if (data_dir[data_dir.size() - 1] != '/')
00056 data_dir += '/';
00057 continue;
00058 } else {
00059 std::cout << "ERROR: Nothing following -d flag!" << std::endl;
00060 return false;
00061 }
00062 } else if (iarg == "-c") {
00063 if (++i != argc) {
00064 corr_dir = std::string(argv[i]);
00065 if (corr_dir[corr_dir.size() - 1] != '/')
00066 corr_dir += '/';
00067 continue;
00068 } else {
00069 std::cout << "ERROR: Nothing following -c flag!" << std::endl;
00070 }
00071 } else if (iarg == "-r") {
00072 std::stringstream ss;
00073 int rlow, rhigh;
00074 if (i + 2 >= argc) {
00075 std::cout << "ERROR: Not enough arguments following -r flag!" << std::endl;
00076 return false;
00077 }
00078 ss << argv[i + 1] << " " << argv[i + 2];
00079 ss >> rlow >> rhigh;
00080 i += 2;
00081 if (rlow == 0 || rhigh == 0) {
00082 std::cout <<
00083 "ERROR: Either 0 or a non-numerical value was passed as a run number." << std::endl <<
00084 " Neither can be processed." << std::endl;
00085 return false;
00086 } else if (rlow >= rhigh) {
00087 std::cout << "ERROR: The first run following the -r option must be smaller than the second!" << std::endl;
00088 return false;
00089 } else if (rlow < 0) {
00090 std::cout << "ERROR: Cannot process negative run number!" << std::endl;
00091 return false;
00092 }
00093 for (int r = rlow; r <= rhigh; ++r)
00094 runs.push_back(r);
00095 } else {
00096 std::stringstream ss;
00097 int r;
00098 ss << iarg;
00099 ss >> r;
00100 if (r == 0) {
00101 std::cout <<
00102 "ERROR: Either 0 or a non-numerical value was passed as a run number." << std::endl <<
00103 " Neither can be processed." << std::endl;
00104 return false;
00105 } else if (r < 0) {
00106 std::cout << "ERROR: Cannot process negative run number!" << std::endl;
00107 return false;
00108 }
00109 runs.push_back(r);
00110 }
00111 }
00112 if (runs.size() == 0) {
00113 std::cout << "ERROR: No runs to process!" << std::endl;
00114 return false;
00115 } else if (data_dir.size() == 0) {
00116 std::cout << "ERROR: No data directory indicated!" << std::endl;
00117 return false;
00118 }
00119 if (corr_dir.size() == 0)
00120 corr_dir = data_dir + "corr/";
00121 return true;
00122 }
00123
00135 int main(int argc, char* argv[]) {
00136
00137 if(gROOT->GetPluginManager()->FindHandler("TVirtualStreamerInfo") == NULL)
00138 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo","*","TStreamerInfo","RIO","TStreamerInfo()");
00139
00140
00141 std::vector<int> runs;
00142 std::string data_dir;
00143 std::string corr_dir;
00144
00145 if (!parse_args(argc, argv, runs, data_dir, corr_dir))
00146 return 1;
00147
00148 ODBCheck x;
00149 std::string raw_dir = data_dir + "raw/";
00150 std::string odb_dir = data_dir + "odb/";
00151 std::string hist_dir = data_dir + "hist/";
00152 x.SetDirs(raw_dir, odb_dir, hist_dir, corr_dir);
00153 for (int r = 0; r < (int)runs.size(); ++r) {
00154 std::cout << "Checking run " << runs[r] << "..." << std::endl;
00155 x.Check(runs[r]);
00156 }
00157 }