#include #include #include #include #include #include #include "ISlowControlDatabase.hxx" void help(char *exename){ std::cout << "Usage:"<]"<< std::endl; std::cout << " -s specify year month day minute and second of start period"<< std::endl; std::cout << " -e specify year month day minute and second of start period"<< std::endl; std::cout << " -l dump current values from last date saved to offline db"<< std::endl; std::cout << " -o "<< std::endl; return; } std::string exec(std::string cmd) { FILE* pipe = popen(cmd.c_str(), "r"); if (!pipe) return "ERROR"; char buffer[128]; std::string result = ""; while(!feof(pipe)) { if(fgets(buffer, 128, pipe) != NULL) result += buffer; } pclose(pipe); return result; } std::string makeCommand() { TString url = getenv("ENV_TSQL_URL"); TObjArray* Strings = url.Tokenize("//"); const char* server = ((TObjString*)Strings->At(1))->GetString().Data(); const char* db = ((TObjString*)Strings->At(2))->GetString().Data(); const char* user = getenv("ENV_TSQL_USER"); const char* pwd = getenv("ENV_TSQL_PSWD"); std::string cmd = Form("mysql -s -h %s -u %s --password=%s -D %s -A -e \"select max(i_time) from MAGNETCURRENT_DB_TABLE;\" | tail -1",server,user,pwd,db); return cmd; } int main(int argc,char **argv){ UInt_t syear=0; UInt_t smonth=0; UInt_t sday=0; UInt_t shour=0; UInt_t smin=0; UInt_t ssec=0; UInt_t eyear=0; UInt_t emonth=0; UInt_t eday=0; UInt_t ehour=0; UInt_t emin=0; UInt_t esec=0; char* fname = NULL; // ***** process command line arguments ... Int_t i=1; while ( i < argc ) { if ( strcmp(argv[i],"-h") == 0 // || argc < 14 ) { help(argv[0]); exit(1); } else if ( strcmp(argv[i],"-e") == 0 ) { eyear = atoi( argv[++i] ); emonth = atoi( argv[++i] ); eday = atoi( argv[++i] ); ehour = atoi( argv[++i] ); emin = atoi( argv[++i] ); esec = atoi( argv[++i] ); } else if ( strcmp(argv[i],"-s") == 0 ) { syear = atoi( argv[++i] ); smonth = atoi( argv[++i] ); sday = atoi( argv[++i] ); shour = atoi( argv[++i] ); smin = atoi( argv[++i] ); ssec = atoi( argv[++i] ); } else if ( strcmp(argv[i],"-l") == 0 ) { std::string cmd = makeCommand(); std::string output = exec(cmd); UInt_t last_time = atol(output.c_str()); TTimeStamp start(last_time); start.GetDate(kTRUE,0,&syear,&smonth,&sday); start.GetTime(kTRUE,0,&shour,&smin,&ssec); TTimeStamp end; end.GetDate(kTRUE,0,&eyear,&emonth,&eday); end.GetTime(kTRUE,0,&ehour,&emin,&esec); } else if ( strcmp(argv[i],"-o") == 0 ) { fname = argv[++i]; } i++; } if ( syear==0 || eyear==0 ){ std::cout<<"ERROR. One of date parameters missing."< table_fields; // Add variables from table. table_fields.push_back("_t_time"); table_fields.push_back("_i_time"); table_fields.push_back("curr_65_enabled"); table_fields.push_back("curr_65_value"); table_fields.push_back("curr_65_timestamp"); int aggregate = 500; int task =0; char table_name[256]; sprintf(table_name,"magnet_curr_65"); // Now execute database query. std::vector > > returned_values = ISlowControlDatabase::Get().QueryGetFieldStartEndTime(table_name, table_fields, start_time, end_time); // Now let's look at what we got back. int nvalues = returned_values.size(); if(nvalues==0) return 0; std::cout<<"Dumping "< variables = returned_values[row].second; // Now retrieve the individual measurements we asked for: // int _t_time = variables[0]; // int _i_time = variables[1]; //=row_time int curr_65_enabled = variables[2]; double curr_65_value = variables[3]; // int curr_65_timestamp = variables[4]; if(curr_65_enabled != 1) continue; if(row_time