//============================================================================== //============================================================================== uint32_t getfilesize(vector pFileNameList) { // // get the total number of lines in the files // char buffer[8192]; uint32_t retval = 0; for ( uint32_t file = 0; file < arguments.pFileNameList.size(); 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; } while ( ifs.getline(buffer, 8192) && !ifs.eof() ) retval++; ifs.close(); } cout << "*Found " << retval << " values to be updated in the file(s)!" << 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 *outFile = new ofstream(); outFile->open("TableExists.sql"); *outFile << dbq->getSqlQueryTableExists(tableName) << endl; outFile->close(); delete outFile; outFile = 0; return true; } else { try { Statement st(con); st.Execute(dbq->getSqlQueryTableExists(tableName)); Resultset rs = st.GetResultset(); while (rs.Next()) { exists = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; } catch(exception &ex) { cout << ex.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 *outFile = new ofstream(); outFile->open("TableEmpty.sql"); *outFile << dbq->getSqlQueryTableEmpty(tableName) << endl; outFile->close(); delete outFile; outFile = 0; return true; } else { try { Statement st(con); st.Execute(dbq->getSqlQueryTableEmpty(tableName)); Resultset rs = st.GetResultset(); while (rs.Next()) { entries = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; } catch(exception &ex) { cout << ex.what() << endl; return false; } } if ( entries > 0 ) return false; else return true; } // ============================================================================= // ============================================================================= int32_t findmaxids() { // // Find max ids in tables // pedestalMaxId = -1; zsthrMaxId = -1; onchannelMaxId = -1; cmcorrMaxId = -1; itcorr1MaxId = -1; itcorr2MaxId = -1; cruMaxId = -1; fecMaxId = -1; partitionMaxId = -1; sectorMaxId = -1; tpcMaxId = -1; if ( arguments.pTest ) { ofstream *outFile = new ofstream(); outFile->open("FindMaxIDs.sql"); *outFile << dbq->getSqlMaxId("PEDESTAL") << endl; *outFile << dbq->getSqlMaxId("ZSTHR") << endl; *outFile << dbq->getSqlMaxId("ON_CHANNEL") << endl; *outFile << dbq->getSqlMaxId("CMCORR") << endl; *outFile << dbq->getSqlMaxId("ITCORR1") << endl; *outFile << dbq->getSqlMaxId("ITCORR2") << endl; *outFile << dbq->getSqlMaxId("CRU") << endl; *outFile << dbq->getSqlMaxId("FEC") << endl; *outFile << dbq->getSqlMaxId("PARTITION") << endl; *outFile << dbq->getSqlMaxId("SECTOR") << endl; outFile->close(); delete outFile; outFile = 0; return true; } else { try { Statement st(con); st.Execute(dbq->getSqlMaxId("PEDESTAL")); Resultset rs = st.GetResultset(); while (rs.Next()) { pedestalMaxId = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; st.Execute(dbq->getSqlMaxId("ZSTHR")); rs = st.GetResultset(); while (rs.Next()) { zsthrMaxId = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; st.Execute(dbq->getSqlMaxId("CMCORR")); rs = st.GetResultset(); while (rs.Next()) { cmcorrMaxId = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; st.Execute(dbq->getSqlMaxId("ITCORR1")); rs = st.GetResultset(); while (rs.Next()) { itcorr1MaxId = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; st.Execute(dbq->getSqlMaxId("ITCORR2")); rs = st.GetResultset(); while (rs.Next()) { itcorr2MaxId = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; st.Execute(dbq->getSqlMaxId("ON_CHANNEL")); rs = st.GetResultset(); while (rs.Next()) { onchannelMaxId = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; st.Execute(dbq->getSqlMaxId("CRU")); rs = st.GetResultset(); while (rs.Next()) { cruMaxId = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; st.Execute(dbq->getSqlMaxId("FEC")); rs = st.GetResultset(); while (rs.Next()) { fecMaxId = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; st.Execute(dbq->getSqlMaxId("PARTITION")); rs = st.GetResultset(); while (rs.Next()) { partitionMaxId = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; st.Execute(dbq->getSqlMaxId("SECTOR")); rs = st.GetResultset(); while (rs.Next()) { sectorMaxId = rs.Get(1); } //cout << "Total fetched rows : " << rs.GetCount() << endl; } catch(exception &ex) { cout << ex.what() << endl; return false; } } if (pedestalMaxId < 0) pedestalMaxId = 0; if (zsthrMaxId < 0) zsthrMaxId = 0; if (onchannelMaxId < 0) onchannelMaxId = 0; if (cmcorrMaxId < 0) cmcorrMaxId = 0; if (itcorr1MaxId < 0) itcorr1MaxId = 0; if (itcorr2MaxId < 0) itcorr2MaxId = 0; if (cruMaxId < 0) cruMaxId = 0; if (fecMaxId < 0) fecMaxId = 0; if (partitionMaxId < 0) partitionMaxId = 0; if (sectorMaxId < 0) sectorMaxId = 0; cout << "pedestalMaxId : " << pedestalMaxId << " (" << pedestalMaxId/ciLinks << " configs) "; if (pedestalMaxId%ciLinks) cout << "WEIRD NUMBER! SOMETHING WRONG?" << endl; else cout << endl; cout << "zsthrMaxId : " << zsthrMaxId << " (" << zsthrMaxId/ciLinks << " configs) "; if (zsthrMaxId%ciLinks) cout << "WEIRD NUMBER! SOMETHING WRONG?" << endl; else cout << endl; cout << "onchannelMaxId : " << onchannelMaxId << " (" << onchannelMaxId/ciLinks << " configs) "; if (onchannelMaxId%ciLinks) cout << "WEIRD NUMBER! SOMETHING WRONG?" << endl; else cout << endl; cout << "cmcorrMaxId : " << cmcorrMaxId << " (" << cmcorrMaxId/ciLinks << " configs) "; if (cmcorrMaxId%ciLinks) cout << "WEIRD NUMBER! SOMETHING WRONG?" << endl; else cout << endl; cout << "itcorr1MaxId : " << itcorr1MaxId << " (" << itcorr1MaxId/ciLinks << " configs) "; if (itcorr1MaxId%ciLinks) cout << "WEIRD NUMBER! SOMETHING WRONG?" << endl; else cout << endl; cout << "itcorr2MaxId : " << itcorr2MaxId << " (" << itcorr2MaxId/ciLinks << " configs) "; if (itcorr2MaxId%ciLinks) cout << "WEIRD NUMBER! SOMETHING WRONG?" << endl; else cout << endl; if ( (pedestalMaxId != zsthrMaxId) || (pedestalMaxId != onchannelMaxId) || (pedestalMaxId != cmcorrMaxId) || (pedestalMaxId != itcorr1MaxId) || (pedestalMaxId != itcorr2MaxId) ) cout << "Error! All 5 values above should be the same!" << endl; cout << "cruMaxId : " << cruMaxId << " (" << cruMaxId/ciCrus << " configs) "; if (cruMaxId%ciCrus) cout << "WEIRD NUMBER! SOMETHING WRONG?" << endl; else cout << endl; cout << "fecMaxId : " << fecMaxId << " (" << fecMaxId/ciFecs << " configs) "; if (fecMaxId%ciFecs) cout << "WEIRD NUMBER! SOMETHING WRONG?" << endl; else cout << endl; cout << "partitionMaxId : " << partitionMaxId << " (" << partitionMaxId/180 << " configs) "; if (partitionMaxId%180) cout << "WEIRD NUMBER! SOMETHING WRONG?" << endl; else cout << endl; cout << "sectorMaxId : " << sectorMaxId << " (" << sectorMaxId/36 << " configs) "; if (sectorMaxId%36) cout << "WEIRD NUMBER! SOMETHING WRONG?" << endl; else cout << endl; pedestalIndex = pedestalMaxId + 1; cruIndex = cruMaxId + 1; fecIndex = fecMaxId + 1; partitionIndex = partitionMaxId + 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 >= tpcconf.getNumConfigs() ) { cerr << "*ConfigID (tag) " << tag << " is unknown." << endl; return 1; } int32_t nrows = 0; if ( arguments.pTest ) { ofstream *outFile = new ofstream(); outFile->open("CheckConfigExist.sql"); *outFile << dbq->getSqlSelectTpcRow(tag) << endl; outFile->close(); delete outFile; outFile = 0; return 0; } else { try { Statement st(con); st.Execute(dbq->getSqlSelectTpcRow(tag)); Resultset rs = st.GetResultset(); while (rs.Next()) { } nrows = rs.GetCount(); } catch(exception &ex) { cout << ex.what() << endl; return 1; } } if ( nrows == 0 ) { cout << "*Config with ID (tag) " << tag << " is not yet in DB." << endl; return 0; } cout << "*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++ ) { if ( !configexists(arguments.pSelectTagList.at(tagCounter)) ) { tmp.push_back(arguments.pSelectTagList.at(tagCounter)); } } arguments.pSelectTagList = tmp; if ( arguments.pSelectTagList.size() == 0 ) return 0; return 1; } // ============================================================================= // ============================================================================= bool checkULtableContainsFloats(string tablename) { // // Check if this is a table that has float values. Return true in case // return false; }