#include // std::string //#include #include // std::cout #include // std::stringstream #include #include #include #include #include #include //#include #include #include #include #include "../Utilities/Stopwatch.h" #include "../Utilities/ProgressBar.h" struct LinkData { int cru; int link; int val[80]; }; struct arguments { //string pSelectField, pUpdateString, pdbUser, pdbPassword, pdbConnectId; //vector pSelectSectorList, pSelectSideList, pSelectTagList; }; struct arguments arguments; using namespace std; //using namespace oracle::occi; const char *argp_program_version = "filepush"; const char *argp_program_bug_address = ""; static const char doc[]= "Program to do something.\ \v============================================================================== \ \nExample: \ \n=============================================================================="; #define OPT_X 1 // possible up to 31 static const struct argp_option options[]={ //{"test", OPT_TEST, 0, 0, "Test only. No DB activity. SQL Commands are written to files." , 0}, { 0 } }; static error_t parse_opt(int32_t key, char *arg, struct argp_state *state) { struct arguments *arguments = (struct arguments*)state->input; char *arg_copy; char *token; switch (key) { case OPT_X: break; default: return ARGP_ERR_UNKNOWN; } return 0; } static struct argp argp={options,parse_opt,0,doc}; // ============================================================================= // ============================================================================= int32_t check_args(int32_t argc, char** argv ) { // // Check all arguments given // // Default arguments //arguments.pdbUserSet = false; argp_parse(&argp, argc, argv, 0, 0, &arguments); /* if ( arguments.pdbUserSet == false ) { arguments.pdbUser = "tpcfero"; arguments.pdbUserSet = true; if (arguments.pTest == false) cout << "*No db Username set. Using default: " << arguments.pdbUser << endl; } */ return 1; } // ============================================================================= // ============================================================================= int main(int argc, char** argv ) { if (!check_args(argc, argv)) { return 1; } // open file ifstream ifs("pedestal_values.txt", ifstream::in); if ( !ifs.good() ) { cerr << endl << "*File can not be opened!" << endl; return 0; } ofstream ofs("pedestal_values.dat", ios::out | ios::binary); if ( !ofs ) { cerr << "Cannot open output file!" << endl; return 0; } string sline; uint32_t cru, side, sector, partition, ep, link; vector val; val.resize(80); LinkData lData; int32_t rec_size = sizeof(lData); cout << "Size of record is: " << rec_size << endl; // Loop over file content while ( getline(ifs, sline) ) { // Get each line // // Read data and extract coordinates // stringstream sdata(sline); string ss; int ctr = 0; getline(sdata, ss, ' '); // get first value: CRU number (0..359) cru = atoi(ss.c_str()); lData.cru = cru; if ( (cru < 0) || (cru>=360) ) { cerr << "*Error in function updateULfromfile(). Strange CRU number (0..359): " << cru << endl; /* delete fp; fp = 0; delete pb; pb = 0; return 0; */ return 0; } side = (cru>=180) ? 1 : 0; sector = cru%180/10; partition = cru%10/2; cru = cru%10%2; getline(sdata, ss, ' '); // get second value: link number (0..9, 12..21) link = atoi(ss.c_str()); lData.link = link; ep = link/12; if ( (link < 0) || (link>=24) ) { cerr << "*Error in function updateULfromfile(). Strange link number (0..23): " << link << endl; /* delete fp; fp = 0; delete pb; pb = 0; return 0; */ } link = link%12; /* cout << "Side " << side << ", sector " << sector << ", partition " << partition << ", cru " << cru << ", EP " << ep << ", link " << link << endl; */ while ( getline(sdata, ss, ',') ) { val[ctr] = atoi(ss.c_str()); lData.val[ctr] = val[ctr]; //cout << val[ctr] << " "; ctr++; } //cout << endl; ofs.write((char *) &lData, rec_size); } // Loop over lines in input file ifs.close(); ofs.close(); if(!ofs.good()) { cout << "Error occurred at writing output time!" << endl; return 1; } return 1; } // EOF