#include "FeeSampleClient.hpp" #include "../CommandCoder/TPCCommandCoderReadback.h" #include "../DB/DBQueryCreator.h" #include "../DB/OracleDB.h" #include "../DB/FERODBFieldPositions.h" #include #include #include using namespace std; using namespace dcs::fee; void printhelp() { cout << "=========================================================================" << endl; cout << "Use Command Coder and Feeclient lib to get configs data back from RCU." << endl; cout << "Author: Christian Lippmann (Christian.Lippmann@cern.ch)." << endl; cout << "The data can be compared to the data found in the config DB." << endl; cout << "Usage: ./Verify.app -branch -fec -altro [options]" << endl; cout << "=========================================================================" << endl; cout << " Options are:" << endl; cout << " -help : print this help" << endl; cout << " -branch : Specify the branch to read from (mandatory)" << endl; cout << " -fec : Specify the FEC to read from (mandatory)" << endl; cout << " -altro : Specify the ALTRO to read from (mandatory)" << endl; cout << " -server : name of the FeeServer" << endl; cout << " -tag : Configuration tag to retrieve from DB (mandatory)" << endl; cout << "=========================================================================" << endl; } /** * send a command block to a FeeServer and write result to std output or a file stream * The command buffer is transferred to the FeeServer command channel as it is. * The target FeeServer must be specified by its name and a FeeClient has to be stated * for the server. NB: one FeeClient can handle more than one FeeServer. * * @param pFeeClient instance of the FeeClient * @param pServerName name of the FeeServer to send the command to * @param buffer [in] buffer with the command block
* [out] data received from the FeeServer * @return length of received data in bytes, neg. error code if failed */ int32_t SendFeeServerCmd(FeeSampleClient* pFeeClient, const char* pServerName, FeeSampleClient::DataArray& buffer) { int32_t iResult = 0; if (pFeeClient && pServerName) { /* those variables are used to pass arguments to and fetch results from the * specific function of the client */ uint16_t flags = 0; int16_t errorCode = 0; int16_t status = 0; uint32_t size = buffer.size()*sizeof(FeeSampleClient::DataArray::value_type); string serverName(pServerName); iResult = pFeeClient->writeReadData(serverName, size, buffer, flags, errorCode, status); if (iResult) { cerr << "info: command result size " << size << endl; iResult=size; } else { cerr << "error: readWriteData errorCode = " << errorCode << endl;; iResult=-EIO; } } else { iResult=-EINVAL; } return iResult; } //=========================================================================== int32_t strtonum(string number) { // convert string to number char * strolConversionCheck; return strtol(number.c_str(),&strolConversionCheck,0); } // =========================================================================================== // =========================================================================================== // =========================================================================================== // =========================================================================================== int main( int argc, char** argv ) { // // ... // int32_t branch = -1; int32_t fec = -1; int32_t altro = -1; int32_t tag = -1; bool toserver = 0; string node("TPC-FEE_1_12_1"); for (int32_t i = 1; i < argc; i++) { if (argv[i][0] == '-') { if (argv[i][1] == 'h') { printhelp(); return 0; } else if (argv[i][1] == 's') { toserver = true; if (++i < argc) node = argv[i]; } else if (argv[i][1] == 'b') { if (++i < argc) branch = atoi(argv[i]); } else if (argv[i][1] == 'f') { if (++i < argc) fec = atoi(argv[i]); } else if (argv[i][1] == 'a') { if (++i < argc) altro = atoi(argv[i]); } else if (argv[i][1] == 't') { if (++i < argc) tag = atoi(argv[i]); } } else { cout << "Not a valid option: " << argv[i] << endl; return 0; } } if ( branch < 0 ) { cerr << "No branch specified!" << endl; return -1; } if ( fec < 0 ) { cerr << "No fec specified!" << endl; return -1; } if ( altro < 0 ) { cerr << "No altro specified!" << endl; return -1; } if ( tag < 0 ) { cerr << "No tag specified!" << endl; return -1; } // Get side, sector and partition from target name (e.g. TPC-FEE_1_12_1) uint32_t pos1_ = node.find( "_", 0 ); uint32_t pos2_ = node.find( "_", (pos1_+1) ); uint32_t pos3_ = node.find( "_", (pos2_+2) ); uint32_t side = strtonum(node.substr((pos1_+1), (pos2_-pos1_-1 ))); uint32_t sector = strtonum(node.substr((pos2_+1), (pos3_-pos2_-1 ))); uint32_t rcu = strtonum(node.substr((pos3_+1), (node.size()-pos3_-1))); // The Command Coder creates the data block to be sent to RCU. This will // cause the Rcu to read back configuration data into the result mem. TPCCommandCoderReadback *CoCo = new TPCCommandCoderReadback(); CoCo->setBranch(branch); CoCo->setFec(fec); CoCo->setAltro(altro); uint32_t length = CoCo->createDataBlock((char*)node.c_str(), 0); uint32_t *instrmem = CoCo->getDataBlock(); int32_t iResult = 0; if ( !toserver ) { // Print this configuration cout << "TPCCommandCoderMain: No server selected. Printing instruction code:" << endl; cout.setf(ios::hex, ios::basefield); for(uint32_t i = 0; i < length/4; i++){ cout << setw(3) << i << " | 0x"; cout << instrmem[i] << endl; } delete CoCo; return 1; } // Write this configuration to the server FeeSampleClient* feeClient = new FeeSampleClient(); if ( node.c_str() ) { if ( feeClient->registerFeeServerName(node.c_str()) ) { if ( feeClient->startFeeClient() ) { int32_t iArraySize=length/sizeof(FeeSampleClient::DataArray::value_type); FeeSampleClient::DataArray buffer(iArraySize); memcpy(&(buffer[0]), instrmem, length); // Send and get data: iResult = SendFeeServerCmd(feeClient, node.c_str(), buffer); if (iResult>0) { cout << "TPCCommandCoderMain: Received " << iResult << " bytes from " << node << endl; } cout << "TPCCommandCoderMain: No output file selected. Printing output:" << endl; cout.setf(ios::hex, ios::basefield); for(int32_t i = 0; i < iResult/4; i++){ cout << setw(3) << i << " | "; cout << buffer[i] << endl; } feeClient->stopFeeClient(); delete feeClient; feeClient = NULL; } } } delete CoCo; // Now connect to DB OracleDB *db = new OracleDB(); if ( 0 ) db->connect("tpccfg", "tpc", "aldcs031"); else db->connect("tpcfero", "tpc1234", "alice_fero"); DBQueryCreator *dbq = new DBQueryCreator(); db->calcRowCount(dbq->getSqlSelectAltroRow(tag, side, sector, rcu, branch, fec, altro)); db->executeQuery(dbq->getSqlSelectAltroRow(tag, side, sector, rcu, branch, fec, altro)); cout << "*Found " << db->getRowCount() << " Row!" << endl; db->disconnect(); return 1; }