24 {
"help", 0, NULL,
'h' },
25 {
"verbose", 0, NULL,
'v' },
26 {
"debug", 0, NULL,
'D' },
27 {
"dry-run", 0, NULL,
'n' },
28 {
"startrun", 1, NULL,
's' },
29 {
"endrun", 1, NULL,
'e' },
30 {
"running", 0, NULL,
'r' },
31 {
"lastrun", 0, NULL,
'l' },
32 {
"config", 1, NULL,
'c' },
33 {
"generate",2,NULL,
'g' },
34 {
"runquality",1,NULL,
'Q' },
46 printf(
"Usage: %s -c cfgfile [OPTIONS] [ACTION] ...\n",
ProgramName->Data());
47 printf(
" Where options :\n\n"
48 " -h, --help\t print this text and exit\n"
49 " -v, --verbose\t increase verbosity level, can be repeated several times\n"
50 " -D, --debug\t increase debug level can repeat several times\n"
51 " -n, --dry-run\t perform a trial run with no changes made\n"
52 " -c file , --config\t use file us config file (defult harpodbrc.xml)\n"
54 " -sNNNN , --startrun\t create new run record in DB and mark the run us running\n"
55 " -eNNNN , --endrun\t mark run us finished and update run duration\n"
56 " -r, --running\t show runs marked us running in DB\n"
57 " -l, --lastrun\t show the last run number in DB\n"
58 " -g[NNNN] , --generate\t crete configuration file using information from run NNNN\n"
59 " -QNNNN str(12) , --runquality\t set RunQuality for run NNNN to str\n"
69 if (
Debug > 0 ) std::cout << __FUNCTION__ << std::endl;
75 if (db->
ExecQuery(
"SELECT `run` FROM `runconfig` WHERE `RunQuality` LIKE 'Running%';",&run_list) ) {
76 if (
Debug > 0)std::cout <<
"Ok, size of result " << run_list.size() << std::endl;
78 std::cout <<
"Bad SELET QUERY" << std::endl;
82 return run_list.size();
88 if (
Debug > 0 ) std::cout << __FUNCTION__ << std::endl;
89 if ( gSystem->AccessPathName(
CfgFileName->Data(),kReadPermission) ) {
90 std::cout <<
"File not exist " << *
CfgFileName<< std::endl;
94 TFile * rcfile = TXMLFile::Open(
CfgFileName->Data());
95 if (
Debug > 0 ) rcfile->ls();
96 rcfile->GetObject(
"HarpoDBrunconfig",entry);
110 if (
Debug > 0 ) std::cout << __FUNCTION__ << std::endl;
114 std::cout <<
"Warning : " << nrun <<
" runs marked as running Harpo DB" << std::endl;
119 if ( ! db->
Open() )
return;
129 std::cout <<
"Error : Run " << r <<
" exist in Harpo DB" << std::endl;
134 runinfo.
SetVal(
"RunQuality",TString(
"Running"));
136 runinfo.
SetVal(
"date",TString(
"NOW()"));
137 runinfo.
SetVal(
"Duration",TString());
138 runinfo.
SetVal(
"nevt",0L);
141 std::cout <<
"----------------------------------------" << std::endl;
144 TString opt = ((
Debug > 0) ?
"verbose" :
"" );
146 if (
Verbose > 1 ) std::cout <<
"Run " << r <<
" Started." << std::endl;
155 if (
Debug > 0 ) std::cout << __FUNCTION__ << std::endl;
166 for (dbFields::iterator it=fields.begin(); it!=fields.end(); ++it) {
167 if (!( it->first.Contains(
"run") || it->first.Contains(
"RunQuality")
168 || it->first.Contains(
"Duration") ))
179 runinfo.
SetVal(
"RunQuality",TString(
"Done"));
181 runinfo.
SetVal(
"Duration",TString(
"TIMEDIFF(NOW(),`date`)"));
183 TString opt = ((
Debug > 0) ?
"verbose" :
"" );
186 std::cout <<
"Error : Run " << r <<
" not in Harpo DB" << std::endl;
196 if (
Debug > 0 ) std::cout << __FUNCTION__ << std::endl;
200 for(dbResults::iterator il=run_list.begin();il !=run_list.end();++il){
201 for(dbFields::iterator im=il->begin();im != il->end();++im){
202 if (im->first.EqualTo(
"run") && ( im->second.Atoll() == r)) {
203 std::cout <<
"Ending run " << im->second << std::endl;
210 std::cout <<
"No Runs running" << std::endl;
212 std::cout <<
"Run " << r <<
" not running" << std::endl;
218 if (
Debug > 0 ) std::cout << __FUNCTION__ << std::endl;
222 for(dbResults::iterator il=run_list.begin();il !=run_list.end();++il){
223 if (
Verbose > 0) std::cout <<
" ======================" << std::endl;
224 for(dbFields::iterator im=il->begin();im != il->end();++im){
226 std::cout << im->first <<
" = " << im->second << std::endl;
228 std::cout << im->second << std::endl;
233 std::cout <<
"No Runs running" << std::endl;
240 if (
Debug > 0 ) std::cout << __FUNCTION__ << std::endl;
248 if (db->
ExecQuery(
"SELECT MAX(`run`) FROM `runconfig`;",&run_list) ) {
249 if (
Debug > 0)std::cout <<
"Ok, size of result " << run_list.size() << std::endl;
251 std::cout <<
"Bad SELET QUERY" << std::endl;
253 for(dbResults::iterator il=run_list.begin();il !=run_list.end();++il){
254 if (
Verbose > 0) std::cout <<
" ======================" << std::endl;
255 for(dbFields::iterator im=il->begin();im != il->end();++im){
257 std::cout << im->first <<
" = " << im->second << std::endl;
259 std::cout << im->second << std::endl;
270 if (
Debug > 0 ) std::cout << __FUNCTION__ << std::endl;
278 if (
Debug > 0 ) std::cout << __FUNCTION__ << std::endl;
306 rcfile = TXMLFile::Open(
CfgFileName->Data(),
"RECREATE",
"Harpo DB rc file",0);
319 if (
Debug > 0 ) std::cout << __FUNCTION__ << std::endl;
330 for (dbFields::iterator it=fields.begin(); it!=fields.end(); ++it) {
331 if (!( it->first.Contains(
"run") || it->first.Contains(
"RunQuality")))
342 runinfo.
SetVal(
"RunQuality",TString(qstr));
344 TString opt = ((
Debug > 0) ?
"verbose" :
"" );
347 std::cout <<
"Error : Run " << r <<
" not in Harpo DB" << std::endl;
356 int main(
int argc,
char **argv)
361 Bool_t doUpdates =
true;
367 int option_index = 0;
378 printf(
" with arg %s", optarg);
400 run = strtol(optarg,NULL,0);
405 if ( optarg != NULL ) {
406 run = strtol(optarg,NULL,0);
409 if (
Debug>0) std::cout <<
"'e' without arg" << std::endl;
427 if ( optarg != NULL ) {
428 run = strtol(optarg,NULL,0);
431 if (
Debug>0) std::cout <<
"'g' without arg" << std::endl;
437 run = strtol(optarg,NULL,0);
442 printf(
"UNKNOWN option\n");
447 printf(
"?? getopt returned character code 0%o ??\n", c);
477 if ( optind < argc ) {
void help()
Print Usage and exit.
static TString * ProgramName
Bool_t UpdateRunRow(HarpoDBRow row, const TString option="")
Bool_t GetRunRow(Long_t nrun, HarpoDBRow &row)
Query Table for given run information.
void EndRun(long int r)
Mark run us finished and update Duration.
void GetRunning()
Get list of runs marked us Running in DB.
void Export(HarpoDBRow &row)
static void SetUser(TString u, TString p)
dbResSize RunningList(dbResults &run_list)
Get list of runs marked us Running in DB.
void SetRunQuality(long int r, const char *qstr)
Set Run Quqlity String.
Bool_t Open(const TString *DbUrl=NULL)
std::list< dbFields > dbResults
Bool_t GetTable(const TString name, HarpoDBTable *table)
Bool_t InsertRunRow(HarpoDBRow row, const TString option="")
void ReadConfig(HarpoDBRow &rinfo)
Bool_t SetVal(const TString field, TString val)
void StartRun(long int r)
Mark Run us running @ date and Fill other fiels from configuration files.
static const char *const short_options
void Import(HarpoDBRow &row)
Bool_t TypeExpression(const TString field)
Mark filed as expression for insert and update.
dbResults::size_type dbResSize
void GetLastRun()
Query Max Run Number in DB table.
dbFields & GetFiledsTypes()
Harpo Database access class. The class query MySQL database. Deal with (single !) Harpo Database and ...
Bool_t ExecQuery(const TString sql, dbResults *list=NULL)
void Erase(const TString &field)
enum DBACTIONS_ DBACTIONS
static TString * CfgFileName
int main(int argc, char **argv)
Program start.
static const struct option long_options[]
void SetConfig(const char *file)
Set Configuration File Name.
void GenConfig(long int r)
Genarate Configuration File ( run template )
void list()
list all fields with values
std::map< TString, TString > dbFields
void SetFields(dbFields f)