#include "DBQueryCreator.h" DBQueryCreator::DBQueryCreator() { // // Default Constructor // fRevision = 7; // table revision is 6 at the moment } DBQueryCreator::~DBQueryCreator() { // // Destructor // } string DBQueryCreator::GetSqlDBIntegerString(int32_t length) { // // Return integer data type. The data type specifies what type of data the // column can hold. // char carry[40]; sprintf(carry,"%d",length); string retval = "Number("; retval += carry; retval += ") "; return retval; } string DBQueryCreator::GetSqlCreateVar(string ColumnName, int32_t length, string parameters, bool seperator) { // // Return column name and integer data type (plus parameters and separator (,) if wished) // string retval; retval = " \""; retval += ColumnName; retval += "\" "; retval += GetSqlDBIntegerString(length); retval += parameters; if ( seperator == true ) { retval += ", "; } return retval; } string DBQueryCreator::GetSqlCreateDateTime(string Name, string defaultVal, bool seperator) { // //Return column name and date/time data type (plus separator (,) if wished) // string retval; retval = " \""; retval += Name; retval += "\" timestamp default "; retval += defaultVal; if ( seperator == true ) retval += " ,"; return retval; } string DBQueryCreator::GetSqlCreateText(string Name, bool seperator) { // // Return column name and character data type (plus separator (,) if wished) // string retval; retval = " \""; retval += Name; retval += "\" VARCHAR2(2000 CHAR)"; if ( seperator == true ) retval += " ,"; return retval; } string DBQueryCreator::GetSqlCreateBlob(string ColumnName, string parameters, bool seperator) { // // Return column name and integer data type (plus parameters and separator (,) if wished) // string retval; retval = " \""; retval += ColumnName; retval += "\" BLOB"; retval += parameters; if ( seperator == true ) { retval += ","; } return retval; } string DBQueryCreator::GetSqlCreateConstraint(string KeyName, string LinkName, string LinkTableName, string LinkTableID, bool seperator) { // // Create a constraint. The CONSTRAINT32_T clause is used to maintain data integrity by providing // limits on the values that can be inserted into a column or table. We use a relationship with // a field in a foreign table (LinkTableName) by using REFERENCES and naming that foreign table // and the field (LinkTableID). // string retval; retval = "CONSTRAINT32_T \""; retval += KeyName; retval += "\" FOREIGN KEY (\""; retval += LinkName; retval += "\") REFERENCES \""; retval += LinkTableName; retval += "\" (\""; retval += LinkTableID; retval += "\")"; if ( seperator == true ) retval += " ,"; return retval; } string DBQueryCreator::GetSqlCreateDefineKey(string Name, bool seperator) { // // Primary key is to be used to uniquely identify each row in a // table (E.g.: You can not have twice the same ID). // string retval = GetSqlCreateVar(Name, 11, "Primary Key", seperator); return retval; } string DBQueryCreator::GetSqlCreateTable(string Name) { // // Creates the following sql statement: CREATE TABLE "tablename" ( // string retval; retval = "CREATE TABLE \""; retval += Name; retval += "\" ("; return retval; } string DBQueryCreator::GetSqlCreateTableEnd() { // // Creates the closing bracket ")" // string retval = " )"; return retval; } //---- TPC Create Table Querys -------------------------------------------------------------------- string DBQueryCreator::getSqlCreateTableALTRO() { // // Creates an sql statement which creates the ALTRO table // The table consist of 150 columns // There are 8 ALTROs per FEC // id=unique id of one ALTRO configuration // Position=position of the ALTRO on the FEC(in readout order) // ON_ALTRO=switch to define the state of the chip // ON_CHANNEL[0...15]=switch to define the state of the channel // [K/L/VFPED]_CHANNEL[0...15]=channel configuration parameters // ZSTHR/.../DPCF2=global configuration parameters // string retval; char carry[40]; retval = GetSqlCreateTable("ALTRO"); // ALTRO Id retval += GetSqlCreateDefineKey("id", true); // ALTRO Position retval += GetSqlCreateVar("Position", 1, "default NULL", true); // ON_ALTRO retval += GetSqlCreateVar("ON_ALTRO", 1, "default NULL", true); for(int32_t i = 0; i< 16; i++) { sprintf(carry,"ON_CHANNEL%02d",i); retval += GetSqlCreateVar(carry, 1, "default NULL", true); } // ALTRO Configuration Registers for(int32_t i = 0; i< 16; i++) { sprintf(carry,"K1_CHANNEL%02d",i); retval += GetSqlCreateVar(carry, 5, "default NULL", true); } for(int32_t i = 0; i< 16; i++) { sprintf(carry,"K2_CHANNEL%02d",i); retval += GetSqlCreateVar(carry, 5, "default NULL", true); } for(int32_t i = 0; i< 16; i++) { sprintf(carry,"K3_CHANNEL%02d",i); retval += GetSqlCreateVar(carry, 5, "default NULL", true); } for(int32_t i = 0; i< 16; i++) { sprintf(carry,"L1_CHANNEL%02d",i); retval += GetSqlCreateVar(carry, 5, "default NULL", true); } for(int32_t i = 0; i< 16; i++) { sprintf(carry,"L2_CHANNEL%02d",i); retval += GetSqlCreateVar(carry, 5, "default NULL", true); } for(int32_t i = 0; i< 16; i++) { sprintf(carry,"L3_CHANNEL%02d",i); retval += GetSqlCreateVar(carry, 5, "default NULL", true); } for(int32_t i = 0; i< 16; i++) { sprintf(carry,"VFPED_CHANNEL%02d",i); retval += GetSqlCreateVar(carry, 5, "default NULL", true); } retval += GetSqlCreateVar("ZSTHR_OFFSET", 4, "default NULL", true); retval += GetSqlCreateVar("ZSTHR_ZS_THR", 4, "default NULL", true); retval += GetSqlCreateVar("BCTHR_THR_HI", 4, "default NULL", true); retval += GetSqlCreateVar("BCTHR_THR_LOW", 4, "default NULL", true); retval += GetSqlCreateVar("TRCFG_ACQ_START", 4, "default NULL", true); retval += GetSqlCreateVar("TRCFG_ACQ_END", 4, "default NULL", true); retval += GetSqlCreateVar("DPCFG_BC1_MODE", 2, "default NULL", true); retval += GetSqlCreateVar("DPCFG_BC1_POL", 1, "default NULL", true); retval += GetSqlCreateVar("DPCFG_BC2_PRE", 1, "default NULL", true); retval += GetSqlCreateVar("DPCFG_BC2_POST", 2, "default NULL", true); retval += GetSqlCreateVar("DPCFG_BC2_EN", 1, "default NULL", true); retval += GetSqlCreateVar("DPCFG_ZS_GF", 1, "default NULL", true); retval += GetSqlCreateVar("DPCFG_ZS_POST", 1, "default NULL", true); retval += GetSqlCreateVar("DPCFG_ZS_PRE", 1, "default NULL", true); retval += GetSqlCreateVar("DPCFG_ZS_EN", 1, "default NULL", true); retval += GetSqlCreateVar("DPCF2_PTRG", 5, "default NULL", true); retval += GetSqlCreateVar("DPCF2_BUF", 1, "default NULL", true); retval += GetSqlCreateVar("DPCF2_FLT_EN", 1, "default NULL", true); retval += GetSqlCreateVar("DPCF2_PWSV", 1, "default NULL",false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableALTRO_FEC() { // // Creates an sql statement which creates ALTRO_FEC table // This tables consist of the relation between the tables holding the data // ALTRO_id=unique id of the configuration table // FEC_id=unique id of the configuration table // string retval; retval = GetSqlCreateTable("ALTRO_FEC"); retval += GetSqlCreateVar("ALTRO_ID", 11, "default NULL", true); retval += GetSqlCreateVar("FEC_ID", 11, "default NULL", true); retval += GetSqlCreateConstraint("afid", "ALTRO_ID", "ALTRO", "id", true); retval += GetSqlCreateConstraint("faid", "FEC_ID", "FEC", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableFEC() { // // Creates an sql statement which creates FEC table // The table consists of 15 columns. // There are 18 or 20 or 25 // (depending on the Position of the // RCU in the Sector) FECs per RCU // id=unique id of one FEC configuration // BranchPosition= Branch-Position of the FEC // Position= Position of the ALTRO on the FEC (in readout order) // ON FEC= Switch to define the state of the card // BC_ T_ TH/... /CSR3= Configuration parameters // string retval; retval = GetSqlCreateTable("FEC"); // FEC Id retval += GetSqlCreateDefineKey("id", true); // FEC Position in Branch, Branch retval += GetSqlCreateVar("BranchPosition",1 , "default NULL", true); retval += GetSqlCreateVar("Position",2 , "default NULL", true); // FEC Configuration Registers retval += GetSqlCreateVar("ON_FEC", 1, "default NULL", true); retval += GetSqlCreateVar("BC_T_TH", 5, "default NULL", true); retval += GetSqlCreateVar("BC_AV_TH", 5, "default NULL", true); retval += GetSqlCreateVar("BC_AC_TH", 5, "default NULL", true); retval += GetSqlCreateVar("BC_DV_TH", 5, "default NULL", true); retval += GetSqlCreateVar("BC_DC_TH", 5, "default NULL", true); retval += GetSqlCreateVar("TSMWORD", 3, "default NULL", true); retval += GetSqlCreateVar("USRATIO", 5, "default NULL", true); retval += GetSqlCreateVar("CSR0", 4, "default NULL", true); retval += GetSqlCreateVar("CSR1", 4, "default NULL", true); retval += GetSqlCreateVar("CSR2", 5, "default NULL", true); retval += GetSqlCreateVar("CSR3", 5, "default NULL",false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableFEC_RCU() { // // Creates an sql statement which creates FEC_RCU table // This tables consist of the relation between the tables holding data // FEE_id=unique id of the configuration table // RCU_id=unique id of the configuration table // string retval; retval = GetSqlCreateTable("FEC_RCU"); retval += GetSqlCreateVar("FEC_ID", 11, "default NULL", true); retval += GetSqlCreateVar("RCU_ID", 11, "default NULL", true); retval += GetSqlCreateConstraint("frid", "FEC_ID", "FEC", "id", true); retval += GetSqlCreateConstraint("rfid", "RCU_ID", "RCU", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableRCU() { // // Creates an sql statement which creates the RCU table // The table consists of 24 columns. // id = unique id of one RCU configuration // Equipmentid = Equipment Id of the RCU // Position = position of the RCU in the SECTOR // ON_RCU = switch to define if Rcu should be configured // string retval = GetSqlCreateTable("RCU"); // RCU Id retval += GetSqlCreateDefineKey("id", true); retval += GetSqlCreateVar("Equipmentid", 11, "NOT NULL", true); // RCU Position retval += GetSqlCreateVar("Position", 2, "default NULL", true); // ... retval += GetSqlCreateVar("ON_RCU", 1, "default NULL", true); retval += GetSqlCreateVar("ALTROIF_NSAM_EV", 10, "default NULL", true); retval += GetSqlCreateVar("ALTROIF_CLK_RATIO", 4, "default NULL", true); retval += GetSqlCreateVar("ALTROIF_CSTB_DELAY", 2, "default NULL", true); retval += GetSqlCreateVar("RDOMOD_SPARSE_RDO", 1, "default NULL", true); retval += GetSqlCreateVar("RDOMOD_MEB_MODE", 1, "default NULL", true); retval += GetSqlCreateVar("RDOMOD_DISABLE_RDYRX", 1, "default NULL", true); retval += GetSqlCreateVar("TTC_CONTROL_CDH_VERSION", 4, "default NULL", true); retval += GetSqlCreateVar("TTC_L1_LATENCY", 12, "default NULL", true); retval += GetSqlCreateVar("TTC_L1_LATENCY_WINDOW", 4, "default NULL", true); retval += GetSqlCreateVar("TTC_L1_MSG_LATENCY_MIN", 12, "default NULL", true); retval += GetSqlCreateVar("TTC_L1_MSG_LATENCY_MAX", 12, "default NULL", true); retval += GetSqlCreateVar("TTC_L2_LATENCY_MIN", 12, "default NULL", true); retval += GetSqlCreateVar("TTC_L2_LATENCY_MAX", 12, "default NULL", true); retval += GetSqlCreateVar("TTC_ROI_CONFIG1", 18, "default NULL", true); retval += GetSqlCreateVar("TTC_ROI_CONFIG2", 18, "default NULL", true); retval += GetSqlCreateVar("TTC_ROI_LATENCY_MIN", 12, "default NULL", true); retval += GetSqlCreateVar("TTC_ROI_LATENCY_MAX", 12, "default NULL", true); retval += GetSqlCreateVar("RDOMOD_SKIP_EMPTY", 5, "default NULL", true); retval += GetSqlCreateVar("EN_INT_BA", 5, "default NULL", true); retval += GetSqlCreateVar("PLACEHOLDER", 5, "default NULL", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableRCU_SECTOR() { // // Creates an sql statement which creates RCU_SECTOR // This tables consist of the relation between the tables holding the data // RCU_id=unique id of the configuration table // SECTOR_id=unique id of the configuration table // string retval; retval = GetSqlCreateTable("RCU_SECTOR"); retval += GetSqlCreateVar("RCU_ID", 11, "default NULL", true); retval += GetSqlCreateVar("SECTOR_ID", 11, "default NULL", true); retval += GetSqlCreateConstraint("rsid", "RCU_ID", "RCU", "id", true); retval += GetSqlCreateConstraint("srid", "SECTOR_ID", "SECTOR", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableSECTOR() { // // Creates an sql statement which creates SECTOR table. The sector has no configuration. // It is only needed for the position determination. It consists of 3 colums: // id=unique id of the sector // Position=position of the SECTOR on the TPC // SidePosition= Side of TPC // string retval; retval = GetSqlCreateTable("SECTOR"); // SECTOR Id retval += GetSqlCreateDefineKey("id", true); // SECTOR Position retval += GetSqlCreateVar("Position",2 , "default NULL", true); retval += GetSqlCreateVar("SidePosition",1 , "default NULL",false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableSECTOR_TPC() { // // Creates an sql statement which creates SECTOR_TPC table. // This tables consist of the relation between the tables holding the data. // SECTOR_id=unique id of the configuration table // TPC_id= unique id of the configuration table // string retval; retval = GetSqlCreateTable("SECTOR_TPC"); retval += GetSqlCreateVar("SECTOR_ID", 11, "default NULL", true); retval += GetSqlCreateVar("TPC_ID", 11, "default NULL", true); retval += GetSqlCreateConstraint("stid", "SECTOR_ID", "SECTOR", "id", true); retval += GetSqlCreateConstraint("tsid", "TPC_ID", "TPC", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableTPC() { // // Create sql statement which creates TPC table // The table consists (curently) of 6 columns. The TPC has no configuration. // This table holds the // Meta information in the configuration. // Later some additions will be implemented here, as global // Firmwares of the FPGAs or the detector and the readout list. // string retval; retval = GetSqlCreateTable("TPC"); // TPC Id retval += GetSqlCreateDefineKey("id", true); retval += GetSqlCreateDateTime("Created", "to_timestamp('0001-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS')", true); //Oracle cant use year 0 but -4137 ??????!!!! retval += GetSqlCreateDateTime("Used", "to_timestamp('0001-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS')", true); retval += GetSqlCreateDateTime("Updated", "to_timestamp('9999-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS')", true); retval += GetSqlCreateVar("Revision", 7, "default NULL", true); retval += GetSqlCreateText("Comment", false); //1(3) firmwares for rcu (Xilinks for sure, can be configured via dcs ) //readout list retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableFEE( string side ) { // // Creates an sql statement which creates FEE_A or FEE_C table (used by InterComLayer). // string retval; string tablename = "FEE_"+side; retval = GetSqlCreateTable(tablename); // retval += GetSqlCreateDefineKey("id", true); // retval += GetSqlCreateVar("TPC_ID", 11, "default NULL", true); retval += GetSqlCreateText("Servername", true); retval += GetSqlCreateVar("X", 4, "default NULL", true); retval += GetSqlCreateVar("Y", 4, "default NULL", true); retval += GetSqlCreateVar("Z", 4, "default NULL", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableFEESERVICES(string side) { // // Creates and sql statement which creates the FEESERVICES_A/C table (used by InterComLayer). // The 3rd column marks the priority of the channel. Priority channels marked with a '1' // in the column will be faster transmitted by the ICL. // string retval; string tablename = "FEESERVICES_"+side; retval = GetSqlCreateTable(tablename); //retval += GetSqlCreateDefineKey("id", true); //retval += GetSqlCreateVar("TPC_ID", 11, "default NULL", true); /* // without priority column retval += GetSqlCreateText("Servicename", true); retval += GetSqlCreateText("Datatype", false); */ // with priority column retval += GetSqlCreateText("Servicename", true); retval += GetSqlCreateText("Datatype", false); //retval += GetSqlCreateVar("Priority", 1, "default NULL", false); retval += GetSqlCreateTableEnd(); return retval; } //---- TPC Drop Table Querys -------------------------------------------------------------------- string DBQueryCreator::getSqlDropTable(string tableName) { // // Creates an sql statement which drops a certain table // including all of its rows // string retval; retval = "DROP TABLE \""; retval += tableName; retval += "\""; return retval; } string DBQueryCreator::getSqlDropView(string tableName) { // // Creates an sql statement which drops a certain view // string retval; retval = "DROP VIEW \""; retval += tableName; retval += "\""; return retval; } //---- TPC Insert into Table Querys -------------------------------------------------------------------- string DBQueryCreator::getSqlInsertALTRO(int32_t index, int32_t sidePosition, int32_t sectorPosition, int32_t rcuPosition, int32_t branchPosition, int32_t fecPosition, int32_t position, int32_t configType) { // // Creates an sql statement which inserts values into the ALTRO table. This function expects // the coordinates in the hardware numbering (branch and FEC number). // We use a configuration given by the class AltroConfig, according to the variable configType. // AltroConfig *altroConf = new AltroConfig(configType, 0); string retval; retval = "INSERT INTO ALTRO VALUES ("; retval += numtostr(index); retval += ", "; retval += numtostr(position); retval += ", "; retval += numtostr(altroConf->getState(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; for(int32_t i = 0; i< 16; i++) { retval += numtostr(altroConf->getState(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position, i)); retval += ", "; } for(int32_t i = 0; i< 16; i++) { retval += numtostr(altroConf->getK1(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position, i)); retval += ", "; } for(int32_t i = 0; i< 16; i++) { retval += numtostr(altroConf->getK2(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position, i)); retval += ", "; } for(int32_t i = 0; i< 16; i++) { retval += numtostr(altroConf->getK3(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position, i)); retval += ", "; } for(int32_t i = 0; i< 16; i++) { retval += numtostr(altroConf->getL1(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position, i)); retval += ", "; } for(int32_t i = 0; i< 16; i++) { retval += numtostr(altroConf->getL2(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position, i)); retval += ", "; } for(int32_t i = 0; i< 16; i++) { retval += numtostr(altroConf->getL3(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position, i)); retval += ", "; } for(int32_t i = 0; i< 16; i++) { retval += numtostr(altroConf->getFPED(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position, i)); retval += ", "; } retval += numtostr(altroConf->getZSTHR_OFFSET(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getZSTHR_ZS_THR(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getBCTHR_THR_HI(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getBCTHR_THR_LOW(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getTRCFG_ACQ_START(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getTRCFG_ACQ_END(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCFG_BC1_MODE(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCFG_BC1_POL(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCFG_BC2_PRE(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCFG_BC2_POST(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCFG_BC2_EN(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCFG_ZS_GF(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCFG_ZS_POST(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCFG_ZS_PRE(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCFG_ZS_EN(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCF2_PTRG(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCF2_BUF(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCF2_FLT_EN(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ", "; retval += numtostr(altroConf->getDPCF2_PWSV(sidePosition, sectorPosition, rcuPosition, branchPosition, fecPosition, position)); retval += ")"; delete altroConf; return retval; } string DBQueryCreator::getSqlInsertALTRO_FEC(int32_t altroIndex, int32_t fecIndex) { // //TODO: check if multi insert is possible for oracle on sql statement level //Creates an sql statement which inserts values into the ALTRO_FEC table // string retval; char carry[40]; retval = "INSERT INTO ALTRO_FEC VALUES ("; sprintf(carry,"%d",altroIndex); retval += carry; retval += ", "; sprintf(carry,"%d",fecIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertFEC(int32_t index, int32_t sidePosition, int32_t sectorPosition, int32_t rcuPosition, int32_t branchPosition, int32_t position, int32_t configType) { // // Creates an sql statement which inserts values into the FEC table. Parameters are given in // the hardware numbering the Rcu expects. // FecConfig *fecConf = new FecConfig(configType, 0); string retval; retval = "INSERT INTO FEC VALUES ("; retval += numtostr(index); retval += ", "; retval += numtostr(branchPosition); retval += ", "; retval += numtostr(position); retval += ", "; retval += numtostr(fecConf->getState(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getBC_T_TH(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getBC_AV_TH(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getBC_AC_TH(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getBC_DV_TH(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getBC_DC_TH(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getTSMWORD(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getUSRATIO(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getCSR0(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getCSR1(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getCSR2(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getCSR3(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ", "; retval += numtostr(fecConf->getRDO_FEC(sidePosition, sectorPosition, rcuPosition, branchPosition, position)); retval += ")"; delete fecConf; return retval; } string DBQueryCreator::getSqlInsertFEC_RCU(int32_t fecIndex, int32_t rcuIndex) { // // Creates an sql statement which inserts values into the FEC_RCU table // TODO: check if multi insert is possible for oracle on sql statement level // string retval; char carry[40]; retval = "INSERT INTO FEC_RCU VALUES ("; sprintf(carry,"%d",fecIndex); retval += carry; retval += ", "; sprintf(carry,"%d",rcuIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertRCU(int32_t index, int32_t eqId, int32_t sidePosition, int32_t sectorPosition, int32_t position, int32_t configType) { // // Creates an sql statement which inserts values into the RCU table. // RcuConfig *rcuConf = new RcuConfig(configType, 0); string retval; retval = "INSERT INTO RCU VALUES ("; retval += numtostr(index); // rcu id retval += ", "; retval += numtostr(eqId); // equipment id id retval += ", "; retval += numtostr(position); // 0...5 retval += ", "; retval += numtostr(rcuConf->getState(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getALTROIF_NSAM_EV(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getALTROIF_CLK_RATIO(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getALTROIF_CSTB_DELAY(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getRDOMOD_SPARSE_RDO(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getRDOMOD_MEB_MODE(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getRDOMOD_DISABLE_RDYRX(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getTTC_CONTROL_CDH_VERSION(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getTTC_L1_LATENCY(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getTTC_L1_LATENCY_WINDOW(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getTTC_L1_MSG_LATENCY_MIN(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getTTC_L1_MSG_LATENCY_MAX(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getTTC_L2_LATENCY_MIN(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getTTC_L2_LATENCY_MAX(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getTTC_ROI_CONFIG1(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getTTC_ROI_CONFIG2(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getTTC_ROI_LATENCY_MIN(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getTTC_ROI_LATENCY_MAX(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getRDOMOD_SKIP_EMPTY(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getEN_INT_BA(sidePosition, sectorPosition, position)); retval += ", "; retval += numtostr(rcuConf->getPLACEHOLDER(sidePosition, sectorPosition, position)); retval += ")"; delete rcuConf; return retval; } string DBQueryCreator::getSqlInsertRCU_SECTOR(int32_t rcuIndex, int32_t sectorIndex) { // // Creates an sql statement which inserts values into the RCU_SECTOR // TODO: check if multi insert is possible for oracle on sql statement level // string retval; char carry[40]; retval = "INSERT INTO RCU_SECTOR VALUES ("; sprintf(carry,"%d",rcuIndex); retval += carry; retval += ", "; sprintf(carry,"%d",sectorIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertSECTOR(int32_t index, int32_t position, int32_t sidePosition) { // // Creates an sql statement which inserts values into the SECTOR table. // string retval; char carry[40]; retval = "INSERT INTO SECTOR VALUES ("; sprintf(carry,"%d",index); retval += carry; retval += ", "; sprintf(carry,"%d",position); retval += carry; retval += ", "; sprintf(carry,"%d",sidePosition); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertSECTOR_TPC(int32_t sectorIndex, int32_t tpcIndex) { // // Creates an sql statement which inserts values into the SECTOR_TPC table. // TODO: check if multi insert is possible for oracle on sql statement level // string retval; char carry[40]; retval = "INSERT INTO SECTOR_TPC VALUES ("; sprintf(carry,"%d",sectorIndex); retval += carry; retval += ", "; sprintf(carry,"%d",tpcIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertTPC(int32_t index, string comment) { // //Creates an sql statement which inserts values into the TPC table. // string retval; retval = "INSERT INTO TPC VALUES ("; retval += numtostr(index); // This is the tag (ConfigID). It can be 1, 2, ... . retval += ", "; retval += "SYSTIMESTAMP, to_timestamp('0001-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS'), SYSTIMESTAMP,'"; retval += numtostr(fRevision); retval += "', '"; retval += comment; retval += "'"; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertTPC(int32_t index) { // //Creates an sql statement which inserts a value into the TPC table. // return getSqlInsertTPC(index, "No Comment"); } string DBQueryCreator::getSqlInsertFEE(int32_t sidePosition, int32_t sectorPosition, int32_t rcuPosition) { // // Creates an sql statement which inserts values into the FEE table. // string retval; char carry[80]; retval = "INSERT INTO FEE"; if ( sidePosition == 0 ) retval += "_A VALUES ("; else if ( sidePosition == 1 ) retval += "_C VALUES ("; else return ""; sprintf(carry,"'TPC-FEE_%d_%02d_%d'", sidePosition, sectorPosition, rcuPosition); retval += carry; retval += ", "; retval += numtostr(sidePosition); retval += ", "; retval += numtostr(sectorPosition); retval += ", "; retval += numtostr(rcuPosition); retval += ")"; return retval; } string DBQueryCreator::getSqlInsertFEESERVICES(int32_t sidePosition, int32_t sectorPosition, int32_t rcuPosition, int32_t aliceFecPosition, string service, string datatype) { // // Creates an sql statement which inserts values into the FEESERVICES table. // Insert FeeService on Fec Level (like TEMP of Fec). // This function uses the Offline coordinates: side, sector, rcu, fec. // Note that for TPC fec = 0...18 for rcu 0, 2 // 0...20 for rcu 1 // and 0...25 for rcu 3, 4, 5. // string retval; char carry[80]; retval = "INSERT INTO FEESERVICES"; if ( sidePosition == 0 ) retval += "_A VALUES ("; else if ( sidePosition == 1 ) retval += "_C VALUES ("; else return ""; sprintf(carry,"'TPC-FEE_%d_%02d_%d_%02d_%s'", sidePosition, sectorPosition, rcuPosition, aliceFecPosition, service.c_str()); retval += carry; retval += ", '"; retval += datatype; //retval += "', "; //retval += numtostr(0); // No priority retval += "')"; return retval; } string DBQueryCreator::getSqlInsertFEESERVICES(int32_t sidePosition, int32_t sectorPosition, int32_t rcuPosition, string state, string datatype) { // // Creates an sql statement which inserts values into the FEESERVICES table. // Insert FeeService on Rcu Level (like MAIN_STATE of Rcu). // string retval; char carry[80]; retval = "INSERT INTO FEESERVICES"; if ( sidePosition == 0 ) retval += "_A VALUES ("; else if ( sidePosition == 1 ) retval += "_C VALUES ("; else return ""; sprintf(carry,"'TPC-FEE_%d_%02d_%d_%s'", sidePosition, sectorPosition, rcuPosition, state.c_str()); retval += carry; retval += ", '"; retval += datatype; //retval += "', "; //if ( state.compare("MAIN_STATE") == 0 ) retval += numtostr(1); // Priority //else retval += numtostr(0); // retval += "')"; return retval; } // Insert statements using bind variables (better for many consecutive transactions) string DBQueryCreator::getSqlBindInsertALTRO_FEC() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the ALTRO_FEC table (Oracle only) // string retval; // bind variables: // 1) altroIndex // 2) fecIndex retval = "INSERT INTO ALTRO_FEC VALUES (:1, :2)"; return retval; } string DBQueryCreator::getSqlBindInsertFEC_RCU() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the FEC_RCU table (Oracle only) // string retval; // bind variables: // 1) fecIndex // 2) rcuIndex retval = "INSERT INTO FEC_RCU VALUES (:1, :2)"; return retval; } string DBQueryCreator::getSqlBindInsertRCU_SECTOR() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the RCU_SECTOR table (Oracle only) // string retval; // bind variables: // 1) rcuIndex // 2) sectorIndex retval = "INSERT INTO RCU_SECTOR VALUES (:1, :2)"; return retval; } string DBQueryCreator::getSqlBindInsertRCU() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the RCU table (Oracle only) // string retval; // bind variables: // 1) rcu id // 2) equipment id // 3) rcu position (0...5) // 4) ON_RCU // 5-24) ... RcuFieldPositions RFP; retval = "INSERT INTO RCU VALUES ("; for(int32_t i = 1; i <= RFP.getNcols(); i++) { retval += ":"; retval += numtostr(i); if ( i != RFP.getNcols() ) retval += ", "; } retval += ")"; return retval; } string DBQueryCreator::getSqlBindInsertFEC() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the FEC table (Oracle only) // string retval; // bind variables: // 1) fec id // 2) branch position // 3) position // 4) ON_FEC // 5) BC_T_TH // ... FecFieldPositions FFP; retval = "INSERT INTO FEC VALUES ("; for(int32_t i = 1; i <= FFP.getNcols(); i++) { retval += ":"; retval += numtostr(i); if ( i != FFP.getNcols() ) retval += ", "; } retval += ")"; return retval; } string DBQueryCreator::getSqlBindInsertALTRO() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the ALTRO table (Oracle only) // string retval; // bind variables: // 1) altro id // 2) position // 3) ON_ALTRO // 4-18) ON_CHANNELxx // ... AltroFieldPositions AFP; retval = "INSERT INTO ALTRO VALUES ("; for(int32_t i = 1; i <= AFP.getNcols(); i++) { retval += ":"; retval += numtostr(i); if ( i != AFP.getNcols() ) retval += ", "; } retval += ")"; return retval; } //---- TPC Select Table Querys -------------------------------------------------------------------- string DBQueryCreator::getSqlSelectPartitionData(int32_t configID, int32_t side, int32_t sector, int32_t rcu) { // //Creates an sql statement which selects the specified partition data type. // string retval; retval = "SELECT * FROM tpc, sector_tpc, sector, rcu_sector, rcu WHERE rcu.\"id\"=rcu_sector.\"RCU_ID\" "; retval += "AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" "; retval += "AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND sector.\"SidePosition\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND rcu.\"Position\"="; retval += numtostr(rcu); return retval; } string DBQueryCreator::getSqlSelectAllPartitionConfigData(int32_t configID) { // // Creates an sql statement which selects the partition config data for all RCUs for the selected tag. // string retval; retval = "SELECT * FROM sector, rcu, fec, altro, tpc, sector_tpc, rcu_sector, fec_rcu, altro_fec "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" AND "; retval += "rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\"="; retval += numtostr(configID); retval += " ORDER BY sector.\"SidePosition\", sector.\"Position\", rcu.\"Position\", "; retval += "fec.\"BranchPosition\", fec.\"Position\", altro.\"Position\""; return retval; } string DBQueryCreator::getSqlSelectSidePartitionConfigData(int32_t configID, int32_t side) { // // Creates an sql statement which selects the partition config data for all RCUs for the selected tag. // string retval; retval = "SELECT * FROM sector, rcu, fec, altro, tpc, sector_tpc, rcu_sector, fec_rcu, altro_fec "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" AND "; retval += "rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND sector.\"SidePosition\"="; retval += numtostr(side); retval += " ORDER BY sector.\"Position\", rcu.\"Position\", fec.\"BranchPosition\", fec.\"Position\","; retval += "altro.\"Position\""; return retval; } string DBQueryCreator::getSqlSelectPartitionConfigData(int32_t rcuID) { // //Creates an sql statement which selects the partition config data for the selected RCU. // string retval; retval = "SELECT * FROM fec, fec_rcu, altro, altro_fec, rcu WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" "; retval += "AND fec.\"id\"=altro_fec.\"FEC_ID\" AND fec.\"id\"=fec_rcu.\"FEC_ID\" "; retval += "AND rcu.\"id\"=fec_rcu.\"RCU_ID\" AND rcu.\"id\" ="; retval += numtostr(rcuID); retval +=" ORDER BY fec.\"BranchPosition\", fec.\"Position\", altro.\"Position\""; return retval; } // Select statements using bind variables string DBQueryCreator::getSqlBindSelectPartitionData( ) { // // Create the sql statement to be held in the cache and ready to select the specified partition // data type (Oracle only). // string retval; // bind variables: // 1: config ID (tag) // 2: side // 3: sector // 4: rcu retval = "SELECT * FROM tpc, sector_tpc, sector, rcu_sector, rcu WHERE rcu.\"id\"=rcu_sector.\"RCU_ID\" "; retval += "AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" "; retval += "AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"=:1 AND sector.\"SidePosition\"=:2 "; retval += "AND sector.\"Position\"=:3 AND rcu.\"Position\"=:4"; return retval; } string DBQueryCreator::getSqlBindSelectAllPartitionConfigData() { // // Creates an sql statement which selects the partition config data for all RCUs for the selected tag. // string retval; // bind variables: // 1: config ID (tag) retval = "SELECT * FROM sector, rcu, fec, altro, tpc, sector_tpc, rcu_sector, fec_rcu, altro_fec "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" AND "; retval += "rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\"=:1 ORDER BY sector.\"SidePosition\", sector.\"Position\", rcu.\"Position\", "; retval += "fec.\"BranchPosition\", fec.\"Position\", altro.\"Position\""; return retval; } string DBQueryCreator::getSqlBindSelectSidePartitionConfigData() { // // Creates an sql statement which selects the partition config data for all RCUs for the selected tag. // string retval; // bind variables: // 1: config ID (tag) // 1: side retval = "SELECT * FROM sector, rcu, fec, altro, tpc, sector_tpc, rcu_sector, fec_rcu, altro_fec "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" AND "; retval += "rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\"=:1 AND sector.\"SidePosition\"=:2 ORDER BY sector.\"SidePosition\", "; retval += "sector.\"Position\", rcu.\"Position\", fec.\"BranchPosition\", fec.\"Position\", "; retval += "altro.\"Position\""; return retval; } string DBQueryCreator::getSqlBindSelectPartitionConfigData( ) { // // Create the sql statement to be held in the cache and ready to select the partition // config data of the given partition (Oracle only). // string retval; // bind variables: // 1: rcuID retval = "SELECT * FROM fec, fec_rcu, altro, altro_fec, rcu WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\""; retval += " AND fec.\"id\"=altro_fec.\"FEC_ID\" AND fec.\"id\"=fec_rcu.\"FEC_ID\""; retval += " AND rcu.\"id\"=fec_rcu.\"RCU_ID\" AND rcu.\"id\"=:1 ORDER BY fec.\"BranchPosition\","; retval += " fec.\"Position\", altro.\"Position\""; return retval; } // Select one row from table string DBQueryCreator::getSqlSelectRcuRow(int32_t configID, int32_t side, int32_t sector, int32_t rcu) { // // Create a query which selects a whole row from the RCU table for a given tag, side, // sector and partition // string retval; retval = "SELECT rcu.\"id\", rcu.\"Equipmentid\", rcu.\"Position\", rcu.\"ON_RCU\", "; retval += "rcu.\"ALTROIF_NSAM_EV\", rcu.\"ALTROIF_CLK_RATIO\", rcu.\"ALTROIF_CSTB_DELAY\", "; retval += "rcu.\"RDOMOD_SPARSE_RDO\", rcu.\"RDOMOD_MEB_MODE\", rcu.\"RDOMOD_DISABLE_RDYRX\", "; retval += "rcu.\"TTC_CONTROL_CDH_VERSION\", rcu.\"TTC_L1_LATENCY\", rcu.\"TTC_L1_LATENCY_WINDOW\", "; retval += "rcu.\"TTC_L1_MSG_LATENCY_MIN\", rcu.\"TTC_L1_MSG_LATENCY_MAX\", rcu.\"TTC_L2_LATENCY_MIN\", "; retval += "rcu.\"TTC_L2_LATENCY_MAX\", rcu.\"TTC_ROI_CONFIG1\", rcu.\"TTC_ROI_CONFIG2\", "; retval += "rcu.\"TTC_ROI_LATENCY_MIN\", rcu.\"TTC_ROI_LATENCY_MAX\", rcu.\"RDOMOD_SKIP_EMPTY\", "; retval += "rcu.\"EN_INT_BA\", rcu.\"PLACEHOLDER\" "; retval += "FROM tpc, sector_tpc, sector, rcu_sector, rcu WHERE rcu.\"id\"=rcu_sector.\"RCU_ID\" "; retval += "AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" "; retval += "AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND sector.\"SidePosition\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND rcu.\"Position\"="; retval += numtostr(rcu); return retval; } string DBQueryCreator::getSqlSelectRcuRow(int32_t rcuID) { // // Create a query which selects a whole row from the RCU table for a given tag, side, // sector and partition // string retval; retval = "SELECT * FROM rcu WHERE rcu.\"id\"="; retval += numtostr(rcuID); return retval; } string DBQueryCreator::getSqlSelectFecRow(int32_t configID, int32_t side, int32_t sector, int32_t rcu, int32_t branch, int32_t fec) { // // Create a query which selects a whole row from the FEC table for a given tag, side, // sector, partition, branch and fec number // string retval; retval = "SELECT fec.\"id\", fec.\"BranchPosition\", fec.\"Position\", fec.\"ON_FEC\", "; retval += "fec.\"BC_T_TH\", fec.\"BC_AV_TH\", fec.\"BC_AC_TH\", fec.\"BC_DV_TH\", fec.\"BC_DC_TH\", "; retval += "fec.\"TSMWORD\", fec.\"USRATIO\", fec.\"CSR0\", fec.\"CSR1\", fec.\"CSR2\", fec.\"CSR3\", "; retval += "fec.\"RDO_FEC\" FROM tpc, sector_tpc, sector, rcu_sector, rcu, fec_rcu, fec "; retval += "WHERE fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND sector.\"SidePosition\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND rcu.\"Position\"="; retval += numtostr(rcu); retval += " AND fec.\"BranchPosition\"="; retval += numtostr(branch); retval += " AND fec.\"Position\"="; retval += numtostr(fec); return retval; } string DBQueryCreator::getSqlSelectFecRow(int32_t fecID) { // // Create a query which selects a whole row from the FEC table for a given tag, side, // sector, partition, branch and fec number // string retval; retval = "SELECT * FROM fec WHERE fec.\"id\"="; retval += numtostr(fecID); return retval; } string DBQueryCreator::getSqlSelectAltroRow(int32_t configID, int32_t side, int32_t sector, int32_t rcu, int32_t branch, int32_t fec, int32_t altro) { // // Create a query which selects a whole row from the ALTRO table for a given tag, side, // sector, partition, branch and fec number // string retval; char carry[40]; retval = "SELECT altro.\"id\", altro.\"Position\", altro.\"ON_ALTRO\", "; for(int32_t i = 0; i< 16; i++ ) { sprintf(carry, "altro.\"ON_CHANNEL%02d\"", i); retval += carry; retval += ", "; } for(int32_t i = 0; i< 16; i++ ) { sprintf(carry, "altro.\"K1_CHANNEL%02d\"", i); retval += carry; retval += ", "; } for(int32_t i = 0; i< 16; i++ ) { sprintf(carry, "altro.\"K2_CHANNEL%02d\"", i); retval += carry; retval += ", "; } for(int32_t i = 0; i< 16; i++ ) { sprintf(carry, "altro.\"K3_CHANNEL%02d\"", i); retval += carry; retval += ", "; } for(int32_t i = 0; i< 16; i++ ) { sprintf(carry, "altro.\"L1_CHANNEL%02d\"", i); retval += carry; retval += ", "; } for(int32_t i = 0; i< 16; i++ ) { sprintf(carry, "altro.\"L2_CHANNEL%02d\"", i); retval += carry; retval += ", "; } for(int32_t i = 0; i< 16; i++ ) { sprintf(carry, "altro.\"L3_CHANNEL%02d\"", i); retval += carry; retval += ", "; } for(int32_t i = 0; i< 16; i++ ) { sprintf(carry, "altro.\"VFPED_CHANNEL%02d\"", i); retval += carry; retval += ", "; } retval += "altro.\"ZSTHR_OFFSET\", altro.\"ZSTHR_ZS_THR\", altro.\"BCTHR_THR_HI\", "; retval += "altro.\"BCTHR_THR_LOW\", altro.\"TRCFG_ACQ_START\", altro.\"TRCFG_ACQ_END\", "; retval += "altro.\"DPCFG_BC1_MODE\", altro.\"DPCFG_BC1_POL\", altro.\"DPCFG_BC2_PRE\", "; retval += "altro.\"DPCFG_BC2_POST\", altro.\"DPCFG_BC2_EN\", altro.\"DPCFG_ZS_GF\", "; retval += "altro.\"DPCFG_ZS_POST\", altro.\"DPCFG_ZS_PRE\", altro.\"DPCFG_ZS_EN\", "; retval += "altro.\"DPCF2_PTRG\", altro.\"DPCF2_BUF\", altro.\"DPCF2_FLT_EN\", "; retval += "altro.\"DPCF2_PWSV\" "; retval += "FROM tpc, sector_tpc, sector, rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND sector.\"SidePosition\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND rcu.\"Position\"="; retval += numtostr(rcu); retval += " AND fec.\"BranchPosition\"="; retval += numtostr(branch); retval += " AND fec.\"Position\"="; retval += numtostr(fec); retval += " AND altro.\"Position\"="; retval += numtostr(altro); return retval; } string DBQueryCreator::getSqlSelectAltroRow(int32_t altroID) { // // Create a query which selects a whole row from the ALTRO table for a given tag, side, // sector, partition, branch and fec number // string retval; retval = "SELECT * FROM altro WHERE altro.\"id\"="; retval += numtostr(altroID); return retval; } // Select one field from table string DBQueryCreator::getSqlSelectRcuField(int32_t configID, int32_t side, int32_t sector, int32_t rcu, string col) { // // Create a query which selects a single value from one row from the RCU table (for a given // tag, side, sector and partition). // string retval; retval = "SELECT rcu.\""; retval += col; retval += "\" FROM tpc, sector_tpc, sector, rcu_sector, rcu WHERE rcu.\"id\"=rcu_sector.\"RCU_ID\" "; retval += "AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" "; retval += "AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND sector.\"SidePosition\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND rcu.\"Position\"="; retval += numtostr(rcu); return retval; } string DBQueryCreator::getSqlSelectRcuField(int32_t rcuID, string col) { // // Create a query which selects a single value from one row from the RCU table (for a given // tag, side, sector and partition). // string retval; retval = "SELECT rcu.\""; retval += col; retval += "\" FROM rcu WHERE rcu.\"id\"="; retval += numtostr(rcuID); return retval; } string DBQueryCreator::getSqlSelectFecField(int32_t configID, int32_t side, int32_t sector, int32_t rcu, int32_t branch, int32_t fec, string col) { // Create a query which selects a single field from a row from the FEC table (for a given tag, side, // sector, partition, branch and fec number). // string retval; retval = "SELECT fec.\""; retval += col; retval += "\" FROM tpc, sector_tpc, sector, rcu_sector, rcu, fec_rcu, fec "; retval += "WHERE fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND sector.\"SidePosition\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND rcu.\"Position\"="; retval += numtostr(rcu); retval += " AND fec.\"BranchPosition\"="; retval += numtostr(branch); retval += " AND fec.\"Position\"="; retval += numtostr(fec); return retval; } string DBQueryCreator::getSqlSelectFecField(int32_t fecID, string col) { // // Create a query which selects a single field from a row from the FEC table (for a given tag, side, // sector, partition, branch and fec number). // string retval; retval = "SELECT fec.\""; retval += col; retval += "\" FROM fec WHERE fec.\"id\"="; retval += numtostr(fecID); return retval; } string DBQueryCreator::getSqlSelectAltroField(int32_t configID, int32_t side, int32_t sector, int32_t rcu, int32_t branch, int32_t fec, int32_t altro, string col) { // // Create a query which selects a single value from a row from the ALTRO table (for a given tag, side, // sector, partition, branch and fec number). // string retval; retval = "SELECT altro.\""; retval += col; retval += "\" FROM tpc, sector_tpc, sector, rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND sector.\"SidePosition\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND rcu.\"Position\"="; retval += numtostr(rcu); retval += " AND fec.\"BranchPosition\"="; retval += numtostr(branch); retval += " AND fec.\"Position\"="; retval += numtostr(fec); retval += " AND altro.\"Position\"="; retval += numtostr(altro); return retval; } string DBQueryCreator::getSqlSelectAltroField(int32_t altroID, string col) { // // Create a query which selects a single value from a row from the ALTRO table (for a given tag, side, // sector, partition, branch and fec number). // string retval; retval = "SELECT altro.\""; retval += col; retval += "\" FROM altro WHERE altro.\"id\"="; retval += numtostr(altroID); return retval; } string DBQueryCreator::getSqlSelectTpcRow(int32_t configID ) { // //Creates an sql statement which selects the specified data type from the TPC table. // string retval; char carry[20]; sprintf(carry,"%d",configID); retval = "SELECT * FROM TPC WHERE \"id\"="; retval += carry; return retval; } string DBQueryCreator::getSqlSelectTpcData( ) { // //Creates an sql statement which selects the specified data from the TPC table. // string retval; retval = "SELECT * FROM TPC"; return retval; } string DBQueryCreator::getSqlSelectTpcField(int32_t configID, string colName) { // // Creates an sql statement which selects the specified data type from the TPC table. string retval; char carry[20]; sprintf(carry,"%d",configID); retval = "SELECT \""; retval += colName; retval += "\" FROM TPC WHERE \"id\"="; retval += carry; return retval; } string DBQueryCreator::getSqlSelectInArray(int32_t *array, int32_t length ) { // // Converts array of integers into string holding those numbers separated by commas. // Only values > 0 are used. Why? // string retval; char carry[20]; int32_t setlength = 0; for(int32_t i = 0; i < length; i++ ) { if (array[i] > 0 ) { setlength++; } } for(int32_t i = 0; i < setlength; i++ ) { sprintf(carry,"%d",array[i]); retval += carry; if (i < (setlength-1) ) retval += ", "; } return retval; } string DBQueryCreator::getSqlMaxIdFEE( string side ) { // // Creates an sql statement which selects the maximum id from the FEE table. // string tablename = "FEE_"+side; return getSqlMaxId(tablename); } string DBQueryCreator::getSqlMaxIdFEESERVICES( string side ) { // // Creates an sql statement which selects the maximum id from the FEESERVICES table. // string tablename = "FEESERVICES_"+side; return getSqlMaxId(tablename); } string DBQueryCreator::getSqlMaxId(string table ) { // // Returns the maximum id from the table. // string retval; retval = "SELECT max(\"id\") FROM "; retval += table; return retval; } string DBQueryCreator::getSqlFindDisabledRCUs(int32_t configID) { // // Creates an sql statement which finds all RCUs that are disabled // string retval; retval = "SELECT sector.\"SidePosition\", sector.\"Position\", rcu.\"Position\" "; retval += " FROM sector, rcu, tpc, sector_tpc, rcu_sector WHERE rcu.\"id\"=rcu_sector.\"RCU_ID\""; retval += " AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" AND sector.\"id\"=sector_tpc.\"SECTOR_ID\""; retval += " AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND rcu.\"ON_RCU\"=0 ORDER BY sector.\"SidePosition\", sector.\"Position\","; retval += "rcu.\"Position\""; return retval; } string DBQueryCreator::getSqlFindDisabledFECs(int32_t configID) { // // Creates an sql statement which finds all FECs that are disabled // string retval; retval = "SELECT sector.\"SidePosition\", sector.\"Position\", rcu.\"Position\","; retval += " fec.\"BranchPosition\", fec.\"Position\" FROM sector, rcu, fec, tpc,"; retval += " sector_tpc, rcu_sector, fec_rcu WHERE (fec.\"ON_FEC\"=0 OR fec.\"RDO_FEC\"=0)"; retval += " AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" AND"; retval += " rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\""; retval += " AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\""; retval += " AND tpc.\"id\"="; retval += numtostr(configID); retval += " ORDER BY sector.\"SidePosition\", sector.\"Position\", rcu.\"Position\","; retval += " fec.\"BranchPosition\", fec.\"Position\""; return retval; } string DBQueryCreator::getSqlFindDisabledALTROs(int32_t configID) { // // Creates an sql statement which finds all ALTROs that are disabled // string retval; retval = "SELECT sector.\"SidePosition\", sector.\"Position\", rcu.\"Position\","; retval += " fec.\"BranchPosition\", fec.\"Position\", altro.\"Position\" FROM sector,"; retval += " rcu, fec, altro, tpc, sector_tpc, rcu_sector, fec_rcu, altro_fec WHERE"; retval += " altro.\"ON_ALTRO\"=0 AND altro.\"id\"=altro_fec.\"ALTRO_ID\" AND"; retval += " fec.\"id\"=altro_fec.\"FEC_ID\" AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND"; retval += " rcu.\"id\"=fec_rcu.\"RCU_ID\" AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND"; retval += " sector.\"id\"=rcu_sector.\"SECTOR_ID\" AND sector.\"id\"=sector_tpc.\"SECTOR_ID\""; retval += " AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " ORDER BY sector.\"SidePosition\", sector.\"Position\", rcu.\"Position\","; retval += " fec.\"BranchPosition\", fec.\"Position\", altro.\"Position\""; return retval; } string DBQueryCreator::getSqlFindDisabledCHANNELs(int32_t configID) { // // Creates an sql statement which finds all CHANNELs that are disabled // string retval; retval = "SELECT altro.\"ON_CHANNEL00\", altro.\"ON_CHANNEL01\", altro.\"ON_CHANNEL02\","; retval += " altro.\"ON_CHANNEL03\", altro.\"ON_CHANNEL04\", altro.\"ON_CHANNEL05\","; retval += " altro.\"ON_CHANNEL06\", altro.\"ON_CHANNEL07\", altro.\"ON_CHANNEL08\","; retval += " altro.\"ON_CHANNEL09\", altro.\"ON_CHANNEL10\", altro.\"ON_CHANNEL11\","; retval += " altro.\"ON_CHANNEL12\", altro.\"ON_CHANNEL13\", altro.\"ON_CHANNEL14\", "; retval += " altro.\"ON_CHANNEL15\", sector.\"SidePosition\", sector.\"Position\","; retval += " rcu.\"Position\", fec.\"BranchPosition\", fec.\"Position\", altro.\"Position\""; retval += " FROM sector, rcu, fec, altro, tpc, sector_tpc, rcu_sector, fec_rcu,"; retval += " altro_fec WHERE (altro.\"ON_CHANNEL00\"=0 OR altro.\"ON_CHANNEL01\"=0 OR"; retval += " altro.\"ON_CHANNEL02\"=0 OR altro.\"ON_CHANNEL03\"=0 OR altro.\"ON_CHANNEL04\"=0"; retval += " OR altro.\"ON_CHANNEL05\"=0 OR altro.\"ON_CHANNEL06\"=0 OR altro.\"ON_CHANNEL07\"=0"; retval += " OR altro.\"ON_CHANNEL08\"=0 OR altro.\"ON_CHANNEL09\"=0 OR altro.\"ON_CHANNEL10\"=0"; retval += " OR altro.\"ON_CHANNEL11\"=0 OR altro.\"ON_CHANNEL12\"=0 OR altro.\"ON_CHANNEL13\"=0"; retval += " OR altro.\"ON_CHANNEL14\"=0 OR altro.\"ON_CHANNEL15\"=0) AND"; retval += " altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" AND"; retval += " fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" AND"; retval += " rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" AND"; retval += " sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND"; retval += " tpc.\"id\"="; retval += numtostr(configID); retval += " ORDER BY sector.\"SidePosition\", sector.\"Position\", rcu.\"Position\","; retval += " fec.\"BranchPosition\", fec.\"Position\", altro.\"Position\""; return retval; } //delete configs string DBQueryCreator::getSqlDeleteTPC(int32_t tpcID ) { // // Creates an sql statement which deletes the records or rows from the TPC table // string retval; char carry[20]; retval = "Delete FROM TPC WHERE \"id\" in ("; sprintf(carry,"%d",tpcID); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlDeleteTPCID(int32_t tpcID ) { // // Creates an sql statement which deletes the id from the TPC table // string retval; char carry[20]; retval = "Delete FROM SECTOR_TPC WHERE \"TPC_ID\" in ("; sprintf(carry,"%d",tpcID); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlDeleteSECTOR(int32_t *sectorIDs ) { // // Creates an sql statement which deletes the records or rows from the SECTOR table // return getSqlDelete("SECTOR", sectorIDs, 36); } string DBQueryCreator::getSqlDeleteSECTORID(int32_t *sectorIDs ) { // // Creates an sql statement which deletes the id from the SECTOR table // return getSqlDelete("RCU_SECTOR", "SECTOR_ID", sectorIDs, 36); } string DBQueryCreator::getSqlDeleteRCU(int32_t *rcuIDs ) { // // Creates an sql statement which deletes the records // or rows from the RCU table // return getSqlDelete("RCU", rcuIDs, 6); } string DBQueryCreator::getSqlDeleteRCUID(int32_t *rcuIDs ) { // // Creates an sql statement which deletes the id from the RCU table // return getSqlDelete("FEC_RCU", "RCU_ID", rcuIDs, 6); } string DBQueryCreator::getSqlDeleteFEC(int32_t *fecIDs ) { // // Creates an sql statement which deletes records // or rows from the FEC table // return getSqlDelete("FEC", fecIDs, 32); } string DBQueryCreator::getSqlDeleteFECID(int32_t *fecIDs ) { // // Creates an sql statement which deletes the id from the FEC table // return getSqlDelete("ALTRO_FEC", "FEC_ID", fecIDs, 32); } string DBQueryCreator::getSqlDeleteALTRO(int32_t *altroIDs ) { // // Creates an sql statement which deletes the records // or rows from the ALTRO table // return getSqlDelete("ALTRO", altroIDs, 8); } string DBQueryCreator::getSqlDelete(string table, int32_t *IDs, int32_t length ) { // // Creates an sql statement which deletes the specified data type. // string retval; retval = "Delete FROM "; retval += table; retval += " WHERE \"id\" in ("; retval += getSqlDeleteInArray(IDs, length); retval += ")"; return retval; } string DBQueryCreator::getSqlDelete(string table, string name, int32_t *IDs, int32_t length ) { // // Creates an sql statement which deletes the specified data type from the tables. // string retval; retval = "Delete FROM "; retval += table; retval += " WHERE \""; retval += name; retval += " \" in ("; retval += getSqlDeleteInArray(IDs, length); retval += ")"; return retval; } string DBQueryCreator::getSqlDeleteInArray(int32_t *array, int32_t length ) { // // ?? // return getSqlSelectInArray(array, length); } //---- TPC Delete Table Query ------------------------------------------------------------------ string DBQueryCreator::getSqlDeleteTable(string tableName ) { // // Delete all entries in table // string retval; retval = "DELETE FROM "; retval += tableName; return retval; } //---- TPC Update Table Querys -------------------------------------------------------------------- string DBQueryCreator::getSqlUpdateUpdated(int32_t configID) { // // Update the "Updated" field in the TPC table to the current time // string retval; retval = "UPDATE TPC SET TPC.\"Updated\"=SYSTIMESTAMP WHERE tpc.\"id\"="; retval += numtostr(configID); return retval; } string DBQueryCreator::getSqlUpdateUpdated(vector configIDs) { // // Update the "Updated" fields in the TPC table to the current time // string retval; retval = "UPDATE TPC SET TPC.\"Updated\"=SYSTIMESTAMP WHERE tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ")"; } return retval; } string DBQueryCreator::getSqlUpdateTpcField(int32_t configID, string col, int32_t newValue) { // // Update one field in the TPC table. The field is specified by the config ID // string retval; retval = "UPDATE TPC SET TPC.\""; retval += col; retval += "\"="; retval += numtostr(newValue); retval += " WHERE tpc.\"id\"="; retval += numtostr(configID); return retval; } string DBQueryCreator::getSqlUpdateTpcField(vector configIDs, string col, int32_t newValue) { // // Update one field in the TPC table for a list of config tags. // string retval; retval = "UPDATE TPC SET TPC.\""; retval += col; retval += "\"="; retval += numtostr(newValue); retval += " WHERE tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ")"; } return retval; } string DBQueryCreator::getSqlUpdateTpcField(int32_t configID, string col, string newString) { // // Update one field (char/string) in the TPC table. The field is specified by the // config ID and the column name. // string retval; retval = "UPDATE TPC SET TPC.\""; retval += col; retval += "\"='"; retval += newString; retval += "' WHERE tpc.\"id\"="; retval += numtostr(configID); return retval; } string DBQueryCreator::getSqlUpdateTpcField(vector configIDs, string col, string newString) { // // Update one field (char/string) in the TPC table for many configs. // string retval; retval = "UPDATE TPC SET TPC.\""; retval += col; retval += "\"='"; retval += newString; retval += "' WHERE tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ")"; } return retval; } string DBQueryCreator::getSqlUpdateRcuField(int32_t configID, int32_t side, int32_t sector, int32_t rcu, string col, int32_t newValue) { // // Update one field in the RCU table. The field is specified by the rcu ID and the column name. // string retval; retval = "UPDATE RCU SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE rcu.\"id\"=(SELECT rcu.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu "; retval += "WHERE rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND sector.\"SidePosition\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND rcu.\"Position\"="; retval += numtostr(rcu); retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateRcuField(int32_t rcuID, string col, int32_t newValue) { // // Update one field in the RCU table. The field is specified by the config ID, rcu position and // the column name in the RCU table. // string retval; retval = "UPDATE RCU SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE rcu.\"id\"="; retval += numtostr(rcuID); return retval; } string DBQueryCreator::getSqlUpdateFecField(int32_t configID, int32_t side, int32_t sector, int32_t rcu, int32_t branch, int32_t fec, string col, int32_t newValue) { // // Update one field in the FEC table. The field is specified by the config ID, Fec position and // the column name. // string retval; retval = "UPDATE FEC SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE fec.\"id\"=(SELECT fec.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu, fec_rcu, fec "; retval += "WHERE fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND sector.\"SidePosition\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND rcu.\"Position\"="; retval += numtostr(rcu); retval += " AND fec.\"BranchPosition\"="; retval += numtostr(branch); retval += " AND fec.\"Position\"="; retval += numtostr(fec); retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateFecField(int32_t fecID, string col, int32_t newValue) { // // Update one field in the FEC table. The field is specified by the Fec ID and // the column name. // string retval; retval = "UPDATE FEC SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE fec.\"id\"="; retval += numtostr(fecID); return retval; } string DBQueryCreator::getSqlUpdateAltroField(int32_t configID, int32_t side, int32_t sector, int32_t rcu, int32_t branch, int32_t fec, int32_t altro, string col, int32_t newValue) { // // Update one field in the ALTRO table. The field is specified by the Config ID, the altro position // and by the column name. // string retval; retval = "UPDATE ALTRO SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE altro.\"id\"=(SELECT altro.\"id\" FROM tpc, sector_tpc, sector, "; retval += "rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND sector.\"SidePosition\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND rcu.\"Position\"="; retval += numtostr(rcu); retval += " AND fec.\"BranchPosition\"="; retval += numtostr(branch); retval += " AND fec.\"Position\"="; retval += numtostr(fec); retval += " AND altro.\"Position\"="; retval += numtostr(altro); retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateAltroField(int32_t altroID, string col, int32_t newValue) { // // Update one field in the ALTRO table. The field is specified by the Altro ID // and by the column name. // string retval; retval = "UPDATE ALTRO SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE altro.\"id\"="; retval += numtostr(altroID); return retval; } string DBQueryCreator::getSqlUpdateFieldAllAltro(int32_t configID, string col, int32_t newValue) { // // return statement which updates all values in column in the Altro table for a given configID (tag) // string retval = ""; retval = "UPDATE ALTRO SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE altro.\"id\" IN (SELECT altro.\"id\" FROM tpc, sector_tpc, sector, "; retval += "rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateFieldAllAltro(vector configIDs, string col, int32_t newValue) { // // return statement which updates all values in column in the Altro table for a list of given // configIDs (tags) // string retval = ""; retval = "UPDATE ALTRO SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE altro.\"id\" IN (SELECT altro.\"id\" FROM tpc, sector_tpc, sector, "; retval += "rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ")"; } retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateFieldAllFec(int32_t configID, string col, int32_t newValue) { // // return statement which updates all values in column in the Fec table for a given configID (tag) // string retval = ""; retval = "UPDATE FEC SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE fec.\"id\" IN (SELECT fec.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu, fec_rcu, fec "; retval += "WHERE fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateFieldAllFec(vector configIDs, string col, int32_t newValue) { // // return statement which updates all values in column in the Fec table for a list // of given configIDs (tags) // string retval = ""; retval = "UPDATE FEC SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE fec.\"id\" IN (SELECT fec.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu, "; retval += "fec_rcu, fec WHERE fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" AND "; retval += "sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ")"; } retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateFieldAllRcu(int32_t configID, string col, int32_t newValue) { // // return statement which updates all values in column in the Rcu table for a given configID (tag) // string retval = ""; retval = "UPDATE RCU SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE rcu.\"id\" IN (SELECT rcu.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu "; retval += "WHERE rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateFieldAllRcu(vector configIDs, string col, int32_t newValue) { // // return statement which updates all values in column in the Rcu table for a list // of given configIDs (tags) // string retval = ""; retval = "UPDATE RCU SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE rcu.\"id\" IN (SELECT rcu.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu "; retval += "WHERE rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" AND "; retval += "sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ")"; } retval += ")"; return retval; } // One update query instead of many consecutive transactions string DBQueryCreator::getSqlUpdateRcuFields(vector configIDs, vector sides, vector sectors, vector rcus, string col, int32_t newValue) { // // Update fields in the RCU table for the list of positions. // string retval; retval = "UPDATE RCU SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE rcu.\"id\" IN (SELECT rcu.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu "; retval += "WHERE rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"SidePosition\" IN ("; for(uint32_t i = 0; i < sides.size(); i++ ) { retval += numtostr(sides[i]); if ( i < sides.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"Position\" IN ("; for(uint32_t i = 0; i < sectors.size(); i++ ) { retval += numtostr(sectors[i]); if ( i < sectors.size()-1 ) retval += ","; else retval += ") "; } retval += "AND rcu.\"Position\" IN ("; for(uint32_t i = 0; i < rcus.size(); i++ ) { retval += numtostr(rcus[i]); if ( i < rcus.size()-1 ) retval += ","; else retval += ")"; } retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateRcuFields(vector rcuIDs, string col, int32_t newValue) { // // Update one field in the RCU table for many rcu IDs. // string retval; retval = "UPDATE RCU SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE rcu.\"id\" IN ("; for(uint32_t i = 0; i < rcuIDs.size(); i++ ) { retval += numtostr(rcuIDs[i]); if ( i < rcuIDs.size()-1 ) retval += ","; else retval += ")"; } return retval; } string DBQueryCreator::getSqlUpdateFecFields(vector configIDs, vector sides, vector sectors, vector rcus, vector branches, vector fecs, string col, int32_t newValue) { // // Update one field in the FEC table for many config IDs, Fec positions. // string retval; retval = "UPDATE FEC SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE fec.\"id\" IN (SELECT fec.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu, fec_rcu, fec "; retval += "WHERE fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"SidePosition\" IN ("; for(uint32_t i = 0; i < sides.size(); i++ ) { retval += numtostr(sides[i]); if ( i < sides.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"Position\" IN ("; for(uint32_t i = 0; i < sectors.size(); i++ ) { retval += numtostr(sectors[i]); if ( i < sectors.size()-1 ) retval += ","; else retval += ") "; } retval += "AND rcu.\"Position\" IN ("; for(uint32_t i = 0; i < rcus.size(); i++ ) { retval += numtostr(rcus[i]); if ( i < rcus.size()-1 ) retval += ","; else retval += ") "; } retval += "AND fec.\"BranchPosition\" IN ("; for(uint32_t i = 0; i < branches.size(); i++ ) { retval += numtostr(branches[i]); if ( i < branches.size()-1 ) retval += ","; else retval += ") "; } retval += "AND fec.\"Position\" IN ("; for(uint32_t i = 0; i < fecs.size(); i++ ) { retval += numtostr(fecs[i]); if ( i < fecs.size()-1 ) retval += ","; else retval += ")"; } retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateFecFields(vector fecIDs, string col, int32_t newValue) { // // Update one field in the FEC table for many fec IDs. // string retval; retval = "UPDATE FEC SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE fec.\"id\" IN ("; for(uint32_t i = 0; i < fecIDs.size(); i++ ) { retval += numtostr(fecIDs[i]); if ( i < fecIDs.size()-1 ) retval += ","; else retval += ")"; } return retval; } string DBQueryCreator::getSqlUpdateAltroFields(vector configIDs, vector sides, vector sectors, vector rcus, vector branches, vector fecs, vector altros, string col, int32_t newValue) { // // Update one field in the ALTRO table for many altro positions. // string retval; retval = "UPDATE ALTRO SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE altro.\"id\" IN (SELECT altro.\"id\" FROM tpc, sector_tpc, sector, "; retval += "rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"SidePosition\" IN ("; for(uint32_t i = 0; i < sides.size(); i++ ) { retval += numtostr(sides[i]); if ( i < sides.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"Position\" IN ("; for(uint32_t i = 0; i < sectors.size(); i++ ) { retval += numtostr(sectors[i]); if ( i < sectors.size()-1 ) retval += ","; else retval += ") "; } retval += "AND rcu.\"Position\" IN ("; for(uint32_t i = 0; i < rcus.size(); i++ ) { retval += numtostr(rcus[i]); if ( i < rcus.size()-1 ) retval += ","; else retval += ") "; } retval += "AND fec.\"BranchPosition\" IN ("; for(uint32_t i = 0; i < branches.size(); i++ ) { retval += numtostr(branches[i]); if ( i < branches.size()-1 ) retval += ","; else retval += ") "; } retval += "AND fec.\"Position\" IN ("; for(uint32_t i = 0; i < fecs.size(); i++ ) { retval += numtostr(fecs[i]); if ( i < fecs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND altro.\"Position\" IN ("; for(uint32_t i = 0; i < altros.size(); i++ ) { retval += numtostr(altros[i]); if ( i < altros.size()-1 ) retval += ","; else retval += ")"; } retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateAltroFields(vector altroIDs, string col, int32_t newValue) { // // Update one field in the ALTRO table for many altro IDs. // string retval; retval = "UPDATE ALTRO SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE altro.\"id\" IN ("; for(uint32_t i = 0; i < altroIDs.size(); i++ ) { retval += numtostr(altroIDs[i]); if ( i < altroIDs.size()-1 ) retval += ","; else retval += ")"; } return retval; } string DBQueryCreator::getSqlBindUpdateAltroField(string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the ALTRO table (Oracle only) // string retval; // bind variables: // 1: new value // 2: config ID (tag) // 3: side // 4: sector // 5: rcu // 6: fec branch // 7: fec // 8: altro retval = "UPDATE ALTRO SET "; retval += col; retval += "=:1 WHERE altro.\"id\"=(SELECT altro.\"id\" FROM tpc, sector_tpc, sector, "; retval += "rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\"=:2 AND sector.\"SidePosition\"=:3 AND sector.\"Position\"=:4 "; retval += "AND rcu.\"Position\"=:5 AND fec.\"BranchPosition\"=:6 AND fec.\"Position\"=:7 "; retval += "AND altro.\"Position\"=:8)"; return retval; } string DBQueryCreator::getSqlBindUpdateAltroFieldId(string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the ALTRO table (Oracle only) // string retval; // bind variables: // 1: new value // 2: Altro Id retval = "UPDATE ALTRO SET "; retval += col; retval += "=:1 WHERE altro.\"id\"=:2"; return retval; } string DBQueryCreator::getSqlBindUpdateAltroField(vector configIDs, string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the ALTRO table (Oracle only) // string retval; // bind variables: // 1: new value // 2: side // 3: sector // 4: rcu // 5: fec branch // 6: fec // 7: altro retval = "UPDATE ALTRO SET "; retval += col; retval += "=:1 WHERE altro.\"id\" IN (SELECT altro.\"id\" FROM tpc, sector_tpc, sector, "; retval += "rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"SidePosition\"=:2 AND sector.\"Position\"=:3 "; retval += "AND rcu.\"Position\"=:4 AND fec.\"BranchPosition\"=:5 AND fec.\"Position\"=:6 "; retval += "AND altro.\"Position\"=:7)"; return retval; } string DBQueryCreator::getSqlBindUpdateAltro2Fields(vector configIDs, string col0, string col1) { // // Create the sql statement to be held in the cache and ready to update many times the fields in // 2 columns in the ALTRO table (Oracle only) // string retval; // bind variables: // 1: new value col0 // 2: new value col1 // 3: side // 4: sector // 5: rcu // 6: fec branch // 7: fec // 8: altro retval = "UPDATE ALTRO SET "; retval += col0; retval += "=:1, "; retval += col1; retval += "=:2 "; retval += "WHERE altro.\"id\" IN (SELECT altro.\"id\" FROM tpc, sector_tpc, sector, "; retval += "rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"SidePosition\"=:3 AND sector.\"Position\"=:4 "; retval += "AND rcu.\"Position\"=:5 AND fec.\"BranchPosition\"=:6 AND fec.\"Position\"=:7 "; retval += "AND altro.\"Position\"=:8)"; return retval; } string DBQueryCreator::getSqlBindUpdateAltro3Fields(vector configIDs, string col0, string col1, string col2) { // // Create the sql statement to be held in the cache and ready to update many times the fields in // 3 columns in the ALTRO table (Oracle only) // string retval; // bind variables: // 1: new value col0 // 2: new value col1 // 3: new value col2 // 4: side // 5: sector // 6: rcu // 7: fec branch // 8: fec // 9: altro retval = "UPDATE ALTRO SET "; retval += col0; retval += "=:1, "; retval += col1; retval += "=:2, "; retval += col2; retval += "=:3 "; retval += "WHERE altro.\"id\" IN (SELECT altro.\"id\" FROM tpc, sector_tpc, sector, "; retval += "rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"SidePosition\"=:4 AND sector.\"Position\"=:5 "; retval += "AND rcu.\"Position\"=:6 AND fec.\"BranchPosition\"=:7 AND fec.\"Position\"=:8 "; retval += "AND altro.\"Position\"=:9)"; return retval; } string DBQueryCreator::getSqlBindUpdateAltroFieldAllSectors(vector configIDs, string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the ALTRO table (Oracle only) // string retval; // bind variables: // 1: new value // 2: rcu // 3: fec branch // 4: fec // 5: altro retval = "UPDATE ALTRO SET "; retval += col; retval += "=:1 WHERE altro.\"id\" IN (SELECT altro.\"id\" FROM tpc, sector_tpc, sector, "; retval += "rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND rcu.\"Position\"=:2 AND fec.\"BranchPosition\"=:3 AND fec.\"Position\"=:4 "; retval += "AND altro.\"Position\"=:5)"; return retval; } string DBQueryCreator::getSqlBindUpdateFecField(string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the FEC table (Oracle only) // string retval = ""; // bind variables: // 1: new value // 2: config ID (tag) // 3: side // 4: sector // 5: rcu // 6: fec branch // 7: fec retval = "UPDATE FEC SET "; retval += col; retval += "=:1 WHERE fec.\"id\"="; retval += "(SELECT fec.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu, fec_rcu, fec "; retval += "WHERE fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND "; retval += "tpc.\"id\"=:2 AND sector.\"SidePosition\"=:3 AND sector.\"Position\"=:4 AND rcu.\"Position\"=:5"; retval += " AND fec.\"BranchPosition\"=:6 AND fec.\"Position\"=:7)"; return retval; } string DBQueryCreator::getSqlBindUpdateFecFieldId(string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the FEC table (Oracle only) // string retval = ""; // bind variables: // 1: new value // 2: FEC id retval = "UPDATE FEC SET "; retval += col; retval += "=:1 WHERE fec.id=:2"; return retval; } string DBQueryCreator::getSqlBindUpdateFecField(vector configIDs, string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the FEC table (Oracle only) // string retval = ""; // bind variables: // 1: new value // 2: side // 3: sector // 4: rcu // 5: fec branch // 6: fec retval = "UPDATE FEC SET "; retval += col; retval += "=:1 WHERE fec.\"id\" IN "; retval += "(SELECT fec.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu, fec_rcu, fec "; retval += "WHERE fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND "; retval += "tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"SidePosition\"=:2 AND sector.\"Position\"=:3 AND rcu.\"Position\"=:4"; retval += " AND fec.\"BranchPosition\"=:5 AND fec.\"Position\"=:6)"; return retval; } string DBQueryCreator::getSqlBindUpdateRcuField(string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the RCU table (Oracle only) // string retval = ""; // bind variables: // 1: new value // 2: config ID (tag) // 3: side // 4: sector // 5: rcu retval = "UPDATE RCU SET "; retval += col; retval += "=:1 WHERE rcu.\"id\"=(SELECT rcu.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu "; retval += "WHERE rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\"=:2 AND sector.\"SidePosition\"=:3 AND sector.\"Position\"=:4"; retval += " AND rcu.\"Position\"=:5)"; return retval; } string DBQueryCreator::getSqlBindUpdateRcuFieldId(string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the RCU table (Oracle only) // string retval = ""; // bind variables: // 1: new value // 2: RcuId retval = "UPDATE RCU SET "; retval += col; retval += "=:1 WHERE rcu.\"id\"=:2"; return retval; } string DBQueryCreator::getSqlBindUpdateRcuField(vector configIDs, string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the RCU table (Oracle only) // string retval = ""; // bind variables: // 1: new value // 2: side // 3: sector // 4: rcu retval = "UPDATE RCU SET "; retval += col; retval += "=:1 WHERE rcu.\"id\" IN (SELECT rcu.\"id\" FROM tpc, sector_tpc, sector, rcu_sector, rcu "; retval += "WHERE rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"SidePosition\"=:2 AND sector.\"Position\"=:3"; retval += " AND rcu.\"Position\"=:4)"; return retval; } string DBQueryCreator::getSqlBindUpdateChannelField(vector configIDs, string col, int32_t newValue) { // // return statement which updates all values in column in the Altro table for a given rcu // and a given configID (tag) // string retval = ""; // bind variables: // 1: side // 2: sector // 3: rcu // 4: branch // 5: fec // 6: altro retval = "UPDATE ALTRO SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE altro.\"id\" IN (SELECT altro.\"id\" FROM tpc, sector_tpc, sector, "; retval += "rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"SidePosition\"=:1 AND sector.\"Position\"=:2 AND rcu.\"Position\"=:3 "; retval += "AND fec.\"BranchPosition\"=:4 AND fec.\"Position\"=:5 AND altro.\"Position\"=:6)"; return retval; } string DBQueryCreator::getSqlBindUpdateChannelFieldAllOnRcu(vector configIDs, string col, int32_t newValue) { // // return statement which updates all values in column in the Altro table for a list of given // configIDs (tags) // char carry[40]; string retval = ""; // bind variables: // 1: side // 2: sector // 3: rcu retval = "UPDATE ALTRO SET "; for(uint32_t channel = 0; channel < 16; channel++ ) { retval += col; sprintf(carry, "_CHANNEL%02d", channel); retval += carry; retval += "="; retval += numtostr(newValue); if ( channel < 15 ) retval += ", "; } retval += " WHERE altro.\"id\" IN (SELECT altro.\"id\" FROM tpc, sector_tpc, sector, "; retval += "rcu_sector, rcu, fec_rcu, fec, altro_fec, altro "; retval += "WHERE altro.\"id\"=altro_fec.\"ALTRO_ID\" AND fec.\"id\"=altro_fec.\"FEC_ID\" "; retval += "AND fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" "; retval += "AND tpc.\"id\" IN ("; for(uint32_t i = 0; i < configIDs.size(); i++ ) { retval += numtostr(configIDs[i]); if ( i < configIDs.size()-1 ) retval += ","; else retval += ") "; } retval += "AND sector.\"SidePosition\"=:1 AND sector.\"Position\"=:2 AND rcu.\"Position\"=:3)"; return retval; } // More =========================================================================== string DBQueryCreator::getSqlQueryTableExists(string tableName) { // // Return statement that checks if a table exists // string retval; retval = "SELECT COUNT(*) FROM TAB WHERE TNAME='"; retval += tableName; retval += "'"; return retval; } string DBQueryCreator::getSqlQueryTableEmpty(string tableName) { // // Return statement that checks if a table exists string retval; retval = "SELECT COUNT(*) FROM "; retval += tableName; return retval; } string DBQueryCreator::getSqlQueryInfoDisabledFECs(int32_t configID) { // // Create query that asks for disabled FECs // string retval; retval = "SELECT sector.\"SidePosition\", sector.\"Position\", rcu.\"Position\", "; retval += "fec.\"BranchPosition\", fec.\"Position\" FROM tpc, sector_tpc, sector, rcu_sector, "; retval += "rcu, fec_rcu, fec WHERE fec.\"id\"=fec_rcu.\"FEC_ID\" AND rcu.\"id\"=fec_rcu.\"RCU_ID\" "; retval += "AND rcu.\"id\"=rcu_sector.\"RCU_ID\" AND sector.\"id\"=rcu_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND tpc.\"id\"="; retval += numtostr(configID); retval += " AND fec.\"ON_FEC\"=0"; return retval; } string DBQueryCreator::numtostr(uint32_t number) { // // Convert an integer to a string // ostringstream oss; oss << number; return oss.str(); }