#include "TPCCommandCoderDBcache.h" #include #include //============================================================================ // Stuff for ARGP const char *argp_program_version = "TPCCommandCoderDBcache.app"; const char *argp_program_bug_address = ""; static char doc[] = "This program can be used to dump config data from the DB in ascii format."; static char args_doc[] = " SERVERNAME (e.g. TPC-FEE_1_11_1)"; //============================================================================ // The options ARGP understands static struct argp_option options[] = { {"verbose", 'v', "VERBOSITY", 0, "Produce verbose output" }, {"quiet", 'q', 0, 0, "Don't produce any output" }, {"binary", 'b', 0, 0, "Dump binary result to screen" }, {"file", 'f', 0, 0, "Dump binary result to file out.bin" }, {"error", 'e', 0, 0, "Dump all errors from CommandCoder" }, {"tag", 't', "TAG", 0, "Specify the configuration tag [1...]" }, { 0 } }; //============================================================================ // Used by main to communicate with ARGP parse_opt struct arguments { bool silent, binary, file, error; int verbose; int tag; string server; }; //============================================================================ //Get the input argument from argp_parse, which is a pointer to the ARGP arguments structure. static error_t parse_opt (int key, char *arg, struct argp_state *state) { struct arguments *arguments = (struct arguments*)state->input; switch (key) { // Parse a single option case 'q': arguments->silent = true; break; case 'v': arguments->verbose = atoi(arg); break; case 'b': arguments->binary = true; break; case 'f': arguments->file = true; break; case 'e': arguments->error = true; break; case 't': arguments->tag = atoi(arg); break; case ARGP_KEY_ARG: arguments->server = arg; break; case ARGP_KEY_END: if (state->arg_num < 1) argp_usage(state); // Not enough arguments break; default: return ARGP_ERR_UNKNOWN; } return 0; } //============================================================================ static struct argp argp = { options, parse_opt, args_doc, doc }; //============================================================================ //============================================================================ //============================================================================ int main( int argc, char** argv ) { // // Create TPCCommandCoderDBcache object and read data block for rcu prcu and ID ptag // struct arguments arguments; // Default values arguments.silent = false; arguments.binary = false; arguments.error = false; arguments.file = false; arguments.verbose = 0; arguments.tag = -99999; // Parse arguments; every option seen by parse_opt will be reflected in arguments argp_parse (&argp, argc, argv, 0, 0, &arguments); if ( arguments.tag < -99998 ) { cerr << "*No tag specified!" << endl; return -1; } uint32_t *instrmem; // the intruction memory to be sent to RCU int32_t length = 0; // Will hold the intruction Mem length TPCCommandCoderDBcache *CoCo = new TPCCommandCoderDBcache(); CoCo->setDebugLevel(arguments.verbose); length = CoCo->createDataBlock( const_cast( arguments.server.c_str() ), arguments.tag ); instrmem = CoCo->getDataBlock(); // Dump data to screen (binary format) if ( arguments.binary && instrmem != NULL ) { cout.write( ( char* ) instrmem, length ); } else if (!arguments.silent) { // Dump data to screen (Asci format) for ( int i = 0; i < length / 4; i++ ) { printf("%06d | 0x%08x\n", i, (uint32_t)instrmem[i]); } } // Write to file if (arguments.file) { ofstream *file = new ofstream(); file->open("out.bin"); file->write((char*)instrmem, length*sizeof(long int)); file->close(); delete file; } // Dump errors: if (arguments.error) { vector errors = CoCo->getError(); cout << "Size of error vector: " << errors.size() << endl; for(uint32_t i = 0; i < errors.size(); i++){ cerr << i << "\t" << errors.at(i) << endl << endl; } } return 1; }