//============================================================================== //============================================================================== uint32_t getfilesize(vector pFileNameList) { // // get the number of lines in the file // char buffer[8192]; uint32_t retval = 0; for ( uint32_t file = 0; file < arguments.pFileNameList.size(); file++ ) { // open file ifstream ifs(arguments.pFileNameList.at(file).c_str(), ifstream::in); if ( !ifs.good() ) { cerr << "*File " << arguments.pFileNameList.at(file).c_str() << " can not be opened!" << endl; continue; } // Loop over file content while ( ifs.getline(buffer, 8192) && !ifs.eof() ) { retval++; } ifs.close(); retval -= 1; // first line in files does not count } cout << "*Found " << retval << " values in file(s) to be updated!" << endl; return retval; } //============================================================================== //============================================================================== int32_t roundtoint(float number) { return (int)(floor(number + 0.5)); } // ============================================================================= // ============================================================================= bool tableExists(string tableName) { // // Check if the table exists in the DB // int32_t exists = 0; if ( arguments.pTest ) { ofstream *seperateOutFile = new ofstream(); seperateOutFile->open("TableExists.sql"); *seperateOutFile << dbq->getSqlQueryTableExists(tableName) << endl; seperateOutFile->close(); delete seperateOutFile; seperateOutFile = 0; return true; } else { try { db->executeQuery(dbq->getSqlQueryTableExists(tableName)); db->getRow(); exists = db->getRowValueAsInt(0); db->freeResult(); } catch(SQLException& ea) { cout << ea.what() << endl; return false; } } if ( exists > 0 ) return true; else return false; } // ============================================================================= // ============================================================================= bool tableEmpty(string tableName) { // // Check if a table in the DB is empty // int32_t entries = 0; if ( arguments.pTest ) { ofstream *seperateOutFile = new ofstream(); seperateOutFile->open("TableEmpty.sql"); *seperateOutFile << dbq->getSqlQueryTableEmpty(tableName) << endl; seperateOutFile->close(); delete seperateOutFile; seperateOutFile = 0; return true; } else { try { db->executeQuery(dbq->getSqlQueryTableEmpty(tableName)); db->getRow(); entries = db->getRowValueAsInt(0); db->freeResult(); } catch(SQLException& ea) { cout << ea.what() << endl; return false; } } if ( entries > 0 ) return false; else return true; } // ============================================================================= // ============================================================================= int32_t findmaxids() { // // Find max ids in tables // altroMaxId = -1; fecMaxId = -1; rcuMaxId = -1; sectorMaxId = -1; tpcMaxId = -1; if ( arguments.pTest ) { ofstream *seperateOutFile = new ofstream(); seperateOutFile->open("FindMaxIDs.sql"); *seperateOutFile << dbq->getSqlMaxId("ALTRO") << endl; *seperateOutFile << dbq->getSqlMaxId("FEC") << endl; *seperateOutFile << dbq->getSqlMaxId("RCU") << endl; *seperateOutFile << dbq->getSqlMaxId("SECTOR") << endl; seperateOutFile->close(); delete seperateOutFile; seperateOutFile = 0; return true; } else { try { db->executeQuery(dbq->getSqlMaxId("ALTRO")); db->getRow(); altroMaxId = db->getRowValueAsInt(0); db->freeResult(); db->executeQuery(dbq->getSqlMaxId("FEC")); db->getRow(); fecMaxId = db->getRowValueAsInt(0); db->freeResult(); db->executeQuery(dbq->getSqlMaxId("RCU")); db->getRow(); rcuMaxId = db->getRowValueAsInt(0); db->freeResult(); db->executeQuery(dbq->getSqlMaxId("SECTOR")); db->getRow(); sectorMaxId = db->getRowValueAsInt(0); db->freeResult(); } catch(SQLException& ea) { cout << ea.what() << endl; return 0; } } if (altroMaxId < 0) altroMaxId = 0; if (fecMaxId < 0) fecMaxId = 0; if (rcuMaxId < 0) rcuMaxId = 0; if (sectorMaxId < 0) sectorMaxId = 0; cout << "altroMaxId : " << altroMaxId << endl; cout << "fecMaxId : " << fecMaxId << endl; cout << "rcuMaxId : " << rcuMaxId << endl; cout << "sectorMaxId : " << sectorMaxId << endl; altroIndex = altroMaxId + 1; fecIndex = fecMaxId + 1; rcuIndex = rcuMaxId + 1; sectorIndex = sectorMaxId + 1; return 1; } // ============================================================================= // ============================================================================= int32_t configexists(int32_t tag) { // // Check if configurations with the given IDs already exist. If yes, return 1. // TpcConfig tpcconf; if ( tag < 1 ) { cout << "*ConfigID (tag) must be > 0!" << endl; return 1; } if ( tag > tpcconf.getNumConfigs() ) { cout << "*ConfigID (tag) " << tag << " is not defined in Configs/Config.C!" << endl; return 1; } int32_t nrows = 0; if ( arguments.pTest ) { ofstream *seperateOutFile = new ofstream(); seperateOutFile->open("CheckConfigExist.sql"); *seperateOutFile << dbq->getSqlSelectTpcRow(tag) << endl; seperateOutFile->close(); delete seperateOutFile; seperateOutFile = 0; return 0; } else { // Check if config exists. try { db->calcRowCount(dbq->getSqlSelectTpcRow(tag)); nrows = db->getRowCount(); } catch(SQLException& ea) { cout << ea.what() << endl; return 1; } } //cout << "*Found " << nrows << " Row(s) with config ID (tag) " << tag << " in DB!" << endl; if ( nrows == 0 ) { cerr << "*Config with ID (tag) " << tag << " is not yet in DB." << endl; return 0; } //cout << nrows << endl; cerr << "*Config with ID (tag) " << tag << " was found in DB!" << endl; return 1; } // ============================================================================= // ============================================================================= int32_t checkbeforefillconfigexists() { // // Check if configurations with the given IDs already exist. If yes, delete this one // from list. // vector tmp; TpcConfig tpcconf; for ( uint32_t tagCounter = 0; tagCounter < arguments.pSelectTagList.size(); tagCounter++ ) { // Check if config exists. if ( configexists(arguments.pSelectTagList.at(tagCounter)) ) { /* do nothing */ } else { tmp.push_back(arguments.pSelectTagList.at(tagCounter)); arguments.pFillComment.push_back(tpcconf.ConfigName(arguments.pSelectTagList.at(tagCounter))); } } arguments.pSelectTagList = tmp; if ( arguments.pSelectTagList.size() == 0 ) return 0; return 1; } // ============================================================================= // ============================================================================= int32_t get_eqid(int32_t side, int32_t sector, int32_t rcu) { // // Get the equipment Id from the position of an RCU. // Copied from TPCC code (tpcc_db_gen.c) // int32_t A_INNER = 768; int32_t A_OUTER = 840; int32_t C_INNER = 804; int32_t C_OUTER = 912; int32_t NUM_INNER = 2; int32_t NUM_OUTER = 4; int32_t base = 0; int32_t eid = 0; int32_t magic = 0; if ( side == 0 ) { if ( rcu < NUM_INNER ) { // IROC base = A_INNER; magic = NUM_INNER; } else { // OROC base = A_OUTER; magic = NUM_OUTER; } } else if ( side == 1 ) { if ( rcu < NUM_INNER ) { // IROC base = C_INNER; magic = NUM_INNER; } else { // OROC base = C_OUTER; magic = NUM_OUTER; } } eid = (base + (magic*sector)) + ((rcu+2)-magic); return eid; } // ============================================================================= // ============================================================================= int32_t HwToOffline(int32_t sidePosition, int32_t rcuPosition, int32_t branchPosition, int32_t fecPosition) { // // Convert Fec position in hardware numbering (branch, fec) to the offline numbering // ABranch = 0, 1; fecPosition = 0, .... , 9 (12, 13, 10). // int32_t fecPerRCUBranch[6][2] = {{9, 9}, {13, 12}, {9, 9}, {10, 10}, {10, 10}, {10, 10}}; if ( branchPosition == 0 ) // branch A return (fecPerRCUBranch[rcuPosition][0] - 1 - fecPosition); else // branch B return (fecPosition + fecPerRCUBranch[rcuPosition][0]); }