#include "DBQueryCreator.h" DBQueryCreator::DBQueryCreator() { // // Default Constructor // fRevision = 0; // table revision } DBQueryCreator::~DBQueryCreator() { // // Destructor // } string DBQueryCreator::GetSqlDBNumberString(int32_t length, int32_t scale) { // // Return integer or float data type. The data type specifies what type of data the column can hold. // If scale == 0 then an integer data type with precision specified by variable "length" is created. // If scale > 0 then a float data type with precision specified by variable "length" is created. The // number of digits to the right of the decimal point is specified by "scale" // char carry[40]; string retval = "Number"; if (length < 0) { // best precision retval += " "; } else { retval += "("; sprintf(carry,"%d", length); retval += carry; if (scale != 0) { retval += ","; sprintf(carry,"%d",scale); retval += carry; } retval += ") "; } return retval; } string DBQueryCreator::GetSqlCreateVar(string ColumnName, int32_t length, int32_t scale, string parameters, bool separator) { // // Return column name and data type (int or float) plus parameters and separator (,) if wished // string retval = " \""; retval += ColumnName; retval += "\" "; retval += GetSqlDBNumberString(length, scale); retval += parameters; if ( separator == true ) retval += ", "; return retval; } string DBQueryCreator::GetSqlCreateDateTime(string Name, string defaultVal, bool separator) { // //Return column name and date/time data type (plus separator (,) if wished) // string retval = " \""; retval += Name; retval += "\" timestamp default "; retval += defaultVal; if ( separator == true ) retval += " ,"; return retval; } string DBQueryCreator::GetSqlCreateText(string Name, bool separator) { // // Return column name and character data type (plus separator (,) if wished) // string retval = " \""; retval += Name; retval += "\" VARCHAR2(2000 CHAR)"; if ( separator == true ) retval += " ,"; return retval; } string DBQueryCreator::GetSqlCreateBlob(string ColumnName, string parameters, bool separator) { // // Return column name and integer data type (plus parameters and separator (,) if wished) // string retval = " \""; retval += ColumnName; retval += "\" BLOB"; retval += parameters; if ( separator == true ) retval += ","; return retval; } string DBQueryCreator::GetSqlCreateConstraint(string KeyName, string LinkName, string LinkTableName, string LinkTableID, bool separator) { // // 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 = "CONSTRAINT \""; retval += KeyName; retval += "\" FOREIGN KEY (\""; retval += LinkName; retval += "\") REFERENCES \""; retval += LinkTableName; retval += "\" (\""; retval += LinkTableID; retval += "\")"; if ( separator == true ) retval += " ,"; return retval; } string DBQueryCreator::GetSqlCreateDefineKey(string Name, bool separator) { // // 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, 0, "Primary Key", separator); return retval; } string DBQueryCreator::GetSqlCreateTableStart(string Name) { // // Creates the following sql statement: CREATE TABLE "tablename" ( // string 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::getSqlCreateTable(string Name) { // // // string retval = ""; if ( !Name.compare("ITCORR1") ) retval = getSqlCreateTableITCORR1(); else if ( !Name.compare("ITCORR2") ) retval = getSqlCreateTableITCORR2(); else if ( !Name.compare("CMCORR") ) retval = getSqlCreateTableCMCORR(); else if ( !Name.compare("ONCHANNEL") ) retval = getSqlCreateTableONCHANNEL(); else if ( !Name.compare("ZSTHR") ) retval = getSqlCreateTableZSTHR(); else if ( !Name.compare("PEDESTAL") ) retval = getSqlCreateTablePEDESTAL(); else if ( !Name.compare("CRU") ) retval = getSqlCreateTableCRU(); else if ( !Name.compare("FEC") ) retval = getSqlCreateTableFEC(); else if ( !Name.compare("GBTX1") ) retval = getSqlCreateTableGBTX1(); else if ( !Name.compare("PARTITION") ) retval = getSqlCreateTablePARTITION(); else if ( !Name.compare("SECTOR") ) retval = getSqlCreateTableSECTOR(); else if ( !Name.compare("TPC") ) retval = getSqlCreateTableTPC(); else if ( !Name.compare("ITCORR1_CRU") ) retval = getSqlCreateTableITCORR1_CRU(); else if ( !Name.compare("ITCORR2_CRU") ) retval = getSqlCreateTableITCORR2_CRU(); else if ( !Name.compare("CMCORR_CRU") ) retval = getSqlCreateTableCMCORR_CRU(); else if ( !Name.compare("ONCHANNEL_CRU") ) retval = getSqlCreateTableONCHANNEL_CRU(); else if ( !Name.compare("ZSTHR_CRU") ) retval = getSqlCreateTableZSTHR_CRU(); else if ( !Name.compare("PEDESTAL_CRU") ) retval = getSqlCreateTablePEDESTAL_CRU(); else if ( !Name.compare("CRU_PARTITION") ) retval = getSqlCreateTableCRU_PARTITION(); else if ( !Name.compare("FEC_PARTITION") ) retval = getSqlCreateTableFEC_PARTITION(); else if ( !Name.compare("PARTITION_SECTOR") ) retval = getSqlCreateTablePARTITION_SECTOR(); else if ( !Name.compare("SECTOR_TPC") ) retval = getSqlCreateTableSECTOR_TPC(); return retval; } string DBQueryCreator::getSqlCreateTableGBTX1() { // // Creates an sql statement which creates the GBTX1 table // The table consist of 367 columns // id = unique id of the GBTX1 configuration // REG000 ... REG365 = Default configuration for FEC GBTx1. 366 values per chip // char carry[40]; string retval = GetSqlCreateTableStart("GBTX1"); retval += GetSqlCreateDefineKey("id", true); // Unique Id for (int ii = 0; ii<366; ii++) { sprintf(carry, "REG%03d", ii); if ( ii < 365) retval += GetSqlCreateVar(carry, 5, 0, "default NULL", true); // GBTX0 config else retval += GetSqlCreateVar(carry, 5, 0, "default NULL", false); // } retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableCMCORR() { // // Creates an sql statement which creates CMCORR table // The table consists of 83 columns. // id = unique id of the link parameter (CMCORR) configuration // BranchPosition = Branch-Position of the FEC = End Point of the CRU (0,1) // Position = Position of the FEC/link in the branch / End Point // VAL00/…/VAL79 = Common correction values for the 80 channels for this link (FLOAT) // char carry[40]; string retval = GetSqlCreateTableStart("CMCORR"); retval += GetSqlCreateDefineKey("id", true); // Unique Id retval += GetSqlCreateVar("BranchPosition", 1, 0, "default NULL", true); // Branch / End Point retval += GetSqlCreateVar("Position", 2, 0, "default NULL", true); // FEC / link number for (int ich = 0; ich<80; ich++) { sprintf(carry, "VAL%02d", ich); if (ich < 79) retval += GetSqlCreateVar(carry, -1, 0, "default NULL", true); else retval += GetSqlCreateVar(carry, -1, 0, "default NULL", false); } retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableCMCORR_CRU() { // // Creates an sql statement which creates CMCORR_CRU table // This tables consist of the relation between the tables holding data // CMCORR_id = unique id of the configuration table // CRU_id = unique id of the configuration table // string retval = GetSqlCreateTableStart("CMCORR_CRU"); retval += GetSqlCreateVar("CMCORR_ID", 11, 0, "default NULL", true); retval += GetSqlCreateVar("CRU_ID", 11, 0, "default NULL", true); retval += GetSqlCreateConstraint("cm1cid", "CMCORR_ID", "CMCORR", "id", true); retval += " "; retval += GetSqlCreateConstraint("ccm1id", "CRU_ID", "CRU", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableITCORR1() { // // Creates an sql statement which creates ITCORR1 table // The table consists of 83 columns. // id = unique id of the link parameter (ITCORR1) configuration // BranchPosition = Branch-Position of the FEC = End Point of the CRU (0,1) // Position = Position of the FEC/link in the branch / End Point // VAL00/…/VAL79 = Ion tail correction values for the 80 channels for this link (FLOAT) // char carry[40]; string retval = GetSqlCreateTableStart("ITCORR1"); retval += GetSqlCreateDefineKey("id", true); // Unique Id retval += GetSqlCreateVar("BranchPosition", 1, 0, "default NULL", true); // Branch / End Point retval += GetSqlCreateVar("Position", 2, 0, "default NULL", true); // FEC / link number for (int ich = 0; ich<80; ich++) { sprintf(carry, "VAL%02d", ich); if (ich < 79) retval += GetSqlCreateVar(carry, -1, 0, "default NULL", true); else retval += GetSqlCreateVar(carry, -1, 0, "default NULL", false); } retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableITCORR1_CRU() { // // Creates an sql statement which creates ITCORR1_CRU table // This tables consist of the relation between the tables holding data // ITCORR1_id = unique id of the configuration table // CRU_id = unique id of the configuration table // string retval = GetSqlCreateTableStart("ITCORR1_CRU"); retval += GetSqlCreateVar("ITCORR1_ID", 11, 0, "default NULL", true); retval += GetSqlCreateVar("CRU_ID", 11, 0, "default NULL", true); retval += GetSqlCreateConstraint("it1cid", "ITCORR1_ID", "ITCORR1", "id", true); retval += " "; retval += GetSqlCreateConstraint("cit1id", "CRU_ID", "CRU", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableITCORR2() { // // Creates an sql statement which creates ITCORR2 table // The table consists of 83 columns. // id = unique id of the link parameter (ITCORR2) configuration // BranchPosition = Branch-Position of the FEC = End Point of the CRU (0,1) // Position = Position of the FEC/link in the branch / End Point // VAL00/…/VAL79 = Ion tail correction values for the 80 channels for this link (FLOAT) // char carry[40]; string retval = GetSqlCreateTableStart("ITCORR2"); retval += GetSqlCreateDefineKey("id", true); // Unique Id retval += GetSqlCreateVar("BranchPosition", 1, 0, "default NULL", true); // Branch / End Point retval += GetSqlCreateVar("Position", 2, 0, "default NULL", true); // FEC / link number for (int ich = 0; ich<80; ich++) { sprintf(carry, "VAL%02d", ich); if (ich < 79) retval += GetSqlCreateVar(carry, -1, 0, "default NULL", true); else retval += GetSqlCreateVar(carry, -1, 0, "default NULL", false); } retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableITCORR2_CRU() { // // Creates an sql statement which creates ITCORR2_CRU table // This tables consist of the relation between the tables holding data // ITCORR2_id = unique id of the configuration table // CRU_id = unique id of the configuration table // string retval = GetSqlCreateTableStart("ITCORR2_CRU"); retval += GetSqlCreateVar("ITCORR2_ID", 11, 0, "default NULL", true); retval += GetSqlCreateVar("CRU_ID", 11, 0, "default NULL", true); retval += GetSqlCreateConstraint("it2cid", "ITCORR2_ID", "ITCORR2", "id", true); retval += " "; retval += GetSqlCreateConstraint("cit2id", "CRU_ID", "CRU", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableONCHANNEL() { // // Creates an sql statement which creates ON_CHANNEL table // The table consists of 83 columns. // id = unique id of the link parameter (ON_CHANNEL) configuration // BranchPosition = Branch-Position of the FEC = End Point of the CRU (0,1) // Position = Position of the FEC/link in the branch / End Point // VAL00/…/VAL79 = Bits indicating if the 80 channels for this link are active or not // char carry[40]; string retval = GetSqlCreateTableStart("ON_CHANNEL"); retval += GetSqlCreateDefineKey("id", true); // Unique Id retval += GetSqlCreateVar("BranchPosition", 1, 0, "default NULL", true); // Branch / End Point retval += GetSqlCreateVar("Position", 2, 0, "default NULL", true); // FEC / link number for (int ich = 0; ich<80; ich++) { sprintf(carry, "VAL%02d", ich); if (ich < 79) retval += GetSqlCreateVar(carry, 1, 0, "default NULL", true); else retval += GetSqlCreateVar(carry, 1, 0, "default NULL", false); } retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableONCHANNEL_CRU() { // // Creates an sql statement which creates ONCHANNEL_CRU table // This tables consist of the relation between the tables holding data // ONCHANNEL_id = unique id of the configuration table // CRU_id = unique id of the configuration table // string retval = GetSqlCreateTableStart("ONCHANNEL_CRU"); retval += GetSqlCreateVar("ONCHANNEL_ID", 11, 0, "default NULL", true); retval += GetSqlCreateVar("CRU_ID", 11, 0, "default NULL", true); retval += GetSqlCreateConstraint("ocid", "ONCHANNEL_ID", "ON_CHANNEL", "id", true); retval += " "; retval += GetSqlCreateConstraint("coid", "CRU_ID", "CRU", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableZSTHR() { // // Creates an sql statement which creates ZSTHR table // The table consists of 83 columns. // id = unique id of the link parameter (Zero Suppression Threshold) configuration // BranchPosition = Branch-Position of the FEC = End Point of the CRU (0,1) // Position = Position of the FEC/link in the branch / End Point // VAL00/…/VAL79 = Threshold values for the 80 channels for this link (INT) // char carry[40]; string retval = GetSqlCreateTableStart("ZSTHR"); retval += GetSqlCreateDefineKey("id", true); // Unique Id retval += GetSqlCreateVar("BranchPosition", 1, 0, "default NULL", true); // Branch / End Point retval += GetSqlCreateVar("Position", 2, 0, "default NULL", true); // FEC / link number for (int ich = 0; ich<80; ich++) { sprintf(carry, "VAL%02d", ich); if (ich < 79) retval += GetSqlCreateVar(carry, 4, 0, "default NULL", true); else retval += GetSqlCreateVar(carry, 4, 0, "default NULL", false); } retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableZSTHR_CRU() { // // Creates an sql statement which creates ZSTHR_CRU table // This tables consist of the relation between the tables holding data // ZSTHR_id = unique id of the configuration table // CRU_id = unique id of the configuration table // string retval = GetSqlCreateTableStart("ZSTHR_CRU"); retval += GetSqlCreateVar("ZSTHR_ID", 11, 0, "default NULL", true); retval += GetSqlCreateVar("CRU_ID", 11, 0, "default NULL", true); retval += GetSqlCreateConstraint("zcid", "ZSTHR_ID", "ZSTHR", "id", true); retval += " "; retval += GetSqlCreateConstraint("czid", "CRU_ID", "CRU", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTablePEDESTAL() { // // Creates an sql statement which creates PEDESTAL table // The table consists of 83 columns. // id = unique id of the link parameter (Pedestal) configuration // BranchPosition = Branch-Position of the FEC = End Point of the CRU (0,1) // Position = Position of the FEC/link in the branch / End Point // VAL00/…/VAL79 = 80 Pedestal values for the 80 channels for this link (INT) // char carry[40]; string retval = GetSqlCreateTableStart("PEDESTAL"); retval += GetSqlCreateDefineKey("id", true); // Unique Id retval += GetSqlCreateVar("BranchPosition", 1, 0, "default NULL", true); // Branch / End Point retval += GetSqlCreateVar("Position", 2, 0, "default NULL", true); // FEC / link number for (int ich = 0; ich<80; ich++) { sprintf(carry, "VAL%02d", ich); if (ich < 79) retval += GetSqlCreateVar(carry, 4, 0, "default NULL", true); else retval += GetSqlCreateVar(carry, 4, 0, "default NULL", false); } retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTablePEDESTAL_CRU() { // // Creates an sql statement which creates PEDESTAL_CRU table // This tables consist of the relation between the tables holding data // PEDESTAL_id = unique id of the configuration table // CRU_id = unique id of the configuration table // string retval = GetSqlCreateTableStart("PEDESTAL_CRU"); retval += GetSqlCreateVar("PEDESTAL_ID", 11, 0, "default NULL", true); retval += GetSqlCreateVar("CRU_ID", 11, 0, "default NULL", true); retval += GetSqlCreateConstraint("pecid", "PEDESTAL_ID", "PEDESTAL", "id", true); retval += " "; retval += GetSqlCreateConstraint("cpeid", "CRU_ID", "CRU", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableCRU() { // // Creates an sql statement which creates CRU table // The table consists of ???? columns. // id = unique id of the CRU configuration // Position = position of this CRU (0/1). 0 = master CRU. 1 = slave CRU // ON_CRU = switch to define if this CRU should be configured // GFG_LINK_ACTIVE = Active link mask (before link selector, 24 bit) // GFD_STRICT_SYNC = Enables strict SYNC checking // GFD_ENABLE_MASK = Select on which trigger to enable // GFD_STREAM_MASK_00 .. GFD_STREAM_MASK_23 = Mask for active SAMPA streams (24 modules per CRU) // ON_LINK = Link mask (after link selector, 20 bit) // LINK_SELECTOR_A = Link selector configuration for branch A // LINK_SELECTOR_B = Link selector configuration for branch B // ZS_EN = enable zero suppression // TRG_WINDOW_SIZE = trigger window size (for triggered mode only) in TPC time-bins // MAX_PAYLOAD_SIZE = maximum payload size per packet (508 max) // SUPPRESS_HBR = suppresses HBr packages // USE_LINK_ID_15 = Use link id 15 for all UL packages // ITCORR0 = Global scaling factor for ion tail correction (FLOAT) // ITF_EN = enable ion tail filter // CMC_EN = enable common mode correction (20 bits, one for each link) // OFFSET = Offset to be added to all ADC values // RESYNC_EN = enable automatic resync of optical links // BC_EN = enable baseline correctionb (pedestal subtraction) // CMC_THRESH1 = set THRESH_1 in CMC module // CMC_MIN_MATCHES = set MIN_MATCHES in CMC module // CMC_MATCH_DISTANCE = set MATCH_DISTANCE in CMC module // CMC_WRITEOUT_EN = set writeout of CM value (not to be used in PHYSICS!) // char carry[40]; string retval = GetSqlCreateTableStart("CRU"); retval += GetSqlCreateDefineKey("id", true); // CRU Id retval += GetSqlCreateVar("Position", 1, 0, "default NULL", true); // Position. Master=0, Slave=1 retval += GetSqlCreateVar("ON_CRU", 1, 0, "default NULL", true); // ON_CRU retval += GetSqlCreateVar("GFD_LINK_ACTIVE", 24, 0, "default NULL", true); // Active link mask (before link selector, 24 bit) retval += GetSqlCreateVar("GFD_STRICT_SYNC", 1, 0, "default NULL", true); // Enables strict SYNC checking retval += GetSqlCreateVar("GFD_ENABLE_MASK", 4, 0, "default NULL", true); // Select on which trigger to enable for (int ii = 0; ii<24; ii++) { sprintf(carry, "GFD_STREAM_MASK_%02d", ii); retval += GetSqlCreateVar(carry, 5, 0, "default NULL", true); // GFD_STREAM_MASK_00 .. GFD_SAMPA_MASK_23 } retval += GetSqlCreateVar("ON_LINK", 20, 0, "default NULL", true); // Active link mask retval += GetSqlCreateVar("LINK_SELECTOR_A", 20, 0, "default NULL", true); // Link selector configuration for branch A retval += GetSqlCreateVar("LINK_SELECTOR_B", 20, 0, "default NULL", true); // Link selector configuration for branch B retval += GetSqlCreateVar("ZS_EN", 1, 0, "default NULL", true); // Enable ZS (enable encoder, packetizer and assembler retval += GetSqlCreateVar("TRG_WINDOW_SIZE", 10, 0, "default NULL", true); // Trigger window size (for triggered mode only) in TPC time-bins retval += GetSqlCreateVar("MAX_PAYLOAD_SIZE", 9, 0, "default NULL", true); // Maximum payload size per packet (508 max) retval += GetSqlCreateVar("SUPPRESS_HBR", 1, 0, "default NULL", true); // Suppress HBr packages retval += GetSqlCreateVar("USE_LINK_ID_15", 1, 0, "default NULL", true); // Use link id 15 for all UL packages retval += GetSqlCreateVar("ITCORR0", -1, 0, "default NULL", true); // Ion tail scaling parameter (FLOAT) retval += GetSqlCreateVar("ITF_EN", 1, 0, "default NULL", true); // Enable ion tail filter retval += GetSqlCreateVar("CMC_EN", 20, 0, "default NULL", true); // Enable common mode correction (1 bit per link) retval += GetSqlCreateVar("OFFSET", 4, 0, "default NULL", true); // Offset to be added to all ADC values retval += GetSqlCreateVar("RESYNC_EN", 1, 0, "default NULL", true); // Enable automatic resync of optical links retval += GetSqlCreateVar("BC_EN", 1, 0, "default NULL", true); // Enable baseline correctionb (pedestal subtraction) retval += GetSqlCreateVar("CMC_THRESH1", 20, 0, "default NULL", true); // Set THRESH_1 in CMC module retval += GetSqlCreateVar("CMC_MIN_MATCHES", 4, 0, "default NULL", true); // Set MIN_MATCHES in CMC module retval += GetSqlCreateVar("CMC_MATCH_DISTANCE", 11, 0, "default NULL", true); // Set MATCH_DISTANCE in CMC module retval += GetSqlCreateVar("CMC_WRITEOUT_EN", 1, 0, "default NULL", false); // Enable writeout of CM value (not to be used in PHYSICS!) retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableCRU_PARTITION() { // // Creates an sql statement which creates CRU_PARTITION table // This tables consist of the relation between the tables holding data // CRU_id=unique id of the configuration table // PARTITION_id=unique id of the configuration table // string retval = GetSqlCreateTableStart("CRU_PARTITION"); retval += GetSqlCreateVar("CRU_ID", 11, 0, "default NULL", true); retval += GetSqlCreateVar("PARTITION_ID", 11, 0, "default NULL", true); retval += GetSqlCreateConstraint("cpid", "CRU_ID", "CRU", "id", true); retval += " "; retval += GetSqlCreateConstraint("pcid", "PARTITION_ID", "PARTITION", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableFEC() { // // Creates an sql statement which creates FEC table // The table consists of 34 columns. // id = unique id of the FEC configuration // BranchPosition = Branch-Position of the FEC (A,B / 0,1) // Position = Position of the FEC in the branch // ON_FEC = Switch to define the state of the FEC (0,1) // SAMPA_MASK = SAMPA mask, defines powering state (5 bit) // SAMPA_ANA_CFG = SAMPA analog configuration pins (4 bit: CG0, CG1, CTS, POL) // SAMPA_CLK_CFG = SAMPA clock configuration pins (7 bit) // GBTX0_SAMPLINGPHASE_G0_CH0 = GBTx0 sampling phase for SAMPA 0 Low, Stream 0, IN-00. GBTx Regs 69, 73 and 77 // GBTX0_SAMPLINGPHASE_G0_CH2 = GBTx0 sampling phase for SAMPA 0 Low, Stream 0, IN-02. GBTx Regs 68, 72 and 76 // GBTX0_SAMPLINGPHASE_G0_CH4 = GBTx0 sampling phase for SAMPA 0 Low, Stream 0, IN-04. GBTx Regs 67, 71 and 75 // GBTX0_SAMPLINGPHASE_G0_CH6 = GBTx0 sampling phase for SAMPA 0 Low, Stream 0, IN-06. GBTx Regs 66, 70 and 74 // GBTX0_SAMPLINGPHASE_G1_CH0 = GBTx0 sampling phase for SAMPA 0 Low, Stream 0, IN-08. GBTx Regs 93, 97 and 101 // GBTX0_SAMPLINGPHASE_G1_CH2 = GBTx0 sampling phase for SAMPA 0 High, Stream 1, IN-10. GBTx Regs 92, 96 and 100 // GBTX0_SAMPLINGPHASE_G1_CH4 = GBTx0 sampling phase for SAMPA 0 High, Stream 1, IN-12. GBTx Regs 91, 94 and 99 // GBTX0_SAMPLINGPHASE_G1_CH6 = GBTx0 sampling phase for SAMPA 0 High, Stream 1, IN-14. GBTx Regs 90, 93 and 98 // GBTX0_SAMPLINGPHASE_G2_CH0 = GBTx0 sampling phase for SAMPA 0 High, Stream 1, IN-16. GBTx Regs 117, 121 and 125 // GBTX0_SAMPLINGPHASE_G2_CH2 = GBTx0 sampling phase for SAMPA 0 High, Stream 1, IN-18. GBTx Regs 116, 120 and 124 // GBTX0_SAMPLINGPHASE_G2_CH4 = GBTx0 sampling phase for SAMPA 0 ADC clock, IN-20. GBTx Regs 115, 119 and 123 // GBTX0_SAMPLINGPHASE_G2_CH6 = GBTx0 sampling phase for SAMPA 1 Low, Stream 2, IN-22. GBTx Regs 114, 118 and 122 // GBTX0_SAMPLINGPHASE_G3_CH0 = GBTx0 sampling phase for SAMPA 1 Low, Stream 2, IN-24. GBTx Regs 141, 145 and 149 // GBTX0_SAMPLINGPHASE_G3_CH2 = GBTx0 sampling phase for SAMPA 1 Low, Stream 2, IN-26. GBTx Regs 140, 144 and 148 // GBTX0_SAMPLINGPHASE_G3_CH4 = GBTx0 sampling phase for SAMPA 1 Low, Stream 2, IN-28. GBTx Regs 139, 143 and 147 // GBTX0_SAMPLINGPHASE_G3_CH6 = GBTx0 sampling phase for SAMPA 1 Low, Stream 2, IN-30. GBTx Regs 138, 142 and 146 // GBTX0_SAMPLINGPHASE_G4_CH0 = GBTx0 sampling phase for SAMPA 1 High, Stream 3, IN-32. GBTx Regs 165, 169 and 173 // GBTX0_SAMPLINGPHASE_G4_CH2 = GBTx0 sampling phase for SAMPA 1 High, Stream 3, IN-34. GBTx Regs 164, 168 and 172 // GBTX0_SAMPLINGPHASE_G4_CH4 = GBTx0 sampling phase for SAMPA 1 High, Stream 3, IN-36. GBTx Regs 163, 167 and 171 // GBTX0_SAMPLINGPHASE_G4_CH6 = GBTx0 sampling phase for SAMPA 1 High, Stream 3, IN-38. GBTx Regs 162, 166 and 170 // GBTX0_SAMPLINGPHASE_G5_CH1 = GBTx0 sampling phase for SAMPA 1 High, Stream 3, IN-01. GBTx Regs 189, 193 and 197 // GBTX0_SAMPLINGPHASE_G5_CH3 = GBTx0 sampling phase for SAMPA 1 ADC clock, IN-03. GBTx Regs 188, 192 and 196 // GBTX0_SAMPLINGPHASE_G5_CH5 = GBTx0 sampling phase for SAMPA 2 Low, Stream 4, IN-05. GBTx Regs 187, 191 and 195 // GBTX0_SAMPLINGPHASE_G5_CH7 = GBTx0 sampling phase for SAMPA 2 Low, Stream 4, IN-07. GBTx Regs 186, 190 and 194 // GBTX0_SAMPLINGPHASE_G6_CH1 = GBTx0 sampling phase for SAMPA 2 Low, Stream 4, IN-09. GBTx Regs 213, 217 and 221 // GBTX0_SAMPLINGPHASE_G6_CH3 = GBTx0 sampling phase for SAMPA 2 Low, Stream 4, IN-11. GBTx Regs 212, 216 and 220 // GBTX0_SAMPLINGPHASE_G6_CH5 = GBTx0 sampling phase for SAMPA 2 Low, Stream 4, IN-13. GBTx Regs 211, 215 and 219 // GBTX0_SAMPLINGPHASE_G6_CH7 = GBTx0 sampling phase for SAMPA 2 ADC clock, IN-15. GBTx Regs 210, 214 and 218 // // (Note: G5 & G6 use uneven channels (1,3,5,7) but are controlled via the even channels (0,2,4,6) for GBTx in WB mode) // char carry[40]; string retval = GetSqlCreateTableStart("FEC"); retval += GetSqlCreateDefineKey("id", true); // FEC Id retval += GetSqlCreateVar("BranchPosition", 1, 0, "default NULL", true); // Branch (A/B) retval += GetSqlCreateVar("Position", 2, 0, "default NULL", true); //FEC Position in Branch retval += GetSqlCreateVar("ON_FEC", 1, 0, "default NULL", true); // ON_FEC retval += GetSqlCreateVar("SAMPA_MASK", 2, 0, "default NULL", true); // ON_FEC retval += GetSqlCreateVar("SAMPA_ANA_CFG", 2, 0, "default NULL", true); // SAMPA analog config (4 bit: CG0, CG1, CTS, POL) retval += GetSqlCreateVar("SAMPA_CLK_CFG", 3, 0, "default NULL", true); // SAMPA clock configuration pins (7 bit) for (int ig = 0; ig<7; ig++) { for (int ich = 0; ich<7; ich+=2) { if ( ig < 5 ) sprintf(carry, "GBTX0_SAMPLINGPHASE_G%d_CH%d", ig, ich); else sprintf(carry, "GBTX0_SAMPLINGPHASE_G%d_CH%d", ig, ich+1); if ( (ig == 6) && (ich == 6) ) retval += GetSqlCreateVar(carry, 2, 0, "default NULL", false); // GBTX0 phase tuning else retval += GetSqlCreateVar(carry, 2, 0, "default NULL", true); // GBTX0 phase tuning } } retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTableFEC_PARTITION() { // // Creates an sql statement which creates FEC_PARTITION table // This tables consist of the relation between the tables holding data // FEE_id=unique id of the configuration table // PARTITION_id=unique id of the configuration table // string retval = GetSqlCreateTableStart("FEC_PARTITION"); retval += GetSqlCreateVar("FEC_ID", 11, 0, "default NULL", true); retval += GetSqlCreateVar("PARTITION_ID", 11, 0, "default NULL", true); retval += GetSqlCreateConstraint("fpid", "FEC_ID", "FEC", "id", true); retval += " "; retval += GetSqlCreateConstraint("pfid", "PARTITION_ID", "PARTITION", "id", false); retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTablePARTITION() { // // Creates an sql statement which creates the PARTITION table // The table consists of 24 columns. // id = unique id of one PARTITION configuration // Position = position of the PARTITION in the SECTOR (0..4) // ON_PARTITION = switch to define if Partition should be configured (0/1) // string retval = GetSqlCreateTableStart("PARTITION"); retval += GetSqlCreateDefineKey("id", true); // PARTITION Id retval += GetSqlCreateVar("Position", 2, 0, "default NULL", true); // PARTITION Position (0..4) retval += GetSqlCreateVar("ON_PARTITION", 1, 0, "default NULL", false); // ON_PARTITION retval += GetSqlCreateTableEnd(); return retval; } string DBQueryCreator::getSqlCreateTablePARTITION_SECTOR() { // // Creates an sql statement which creates PARTITION_SECTOR // This tables consist of the relation between the tables holding the data // PARTITION_id = unique id of the configuration table // SECTOR_id = unique id of the configuration table // string retval = GetSqlCreateTableStart("PARTITION_SECTOR"); retval += GetSqlCreateVar("PARTITION_ID", 11, 0, "default NULL", true); retval += GetSqlCreateVar("SECTOR_ID", 11, 0, "default NULL", true); retval += GetSqlCreateConstraint("psid", "PARTITION_ID", "PARTITION", "id", true); retval += " "; retval += GetSqlCreateConstraint("spid", "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 (0/1) // string retval = GetSqlCreateTableStart("SECTOR"); retval += GetSqlCreateDefineKey("id", true); // SECTOR Id retval += GetSqlCreateVar("Position",2 , 0, "default NULL", true); // SECTOR position retval += GetSqlCreateVar("SidePosition", 1, 0, "default NULL",false); // Side position 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 = GetSqlCreateTableStart("SECTOR_TPC"); retval += GetSqlCreateVar("SECTOR_ID", 11, 0, "default NULL", true); retval += GetSqlCreateVar("TPC_ID", 11, 0, "default NULL", true); retval += GetSqlCreateConstraint("stid", "SECTOR_ID", "SECTOR", "id", true); retval += " "; 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 of 6 columns. The TPC has no configuration. // This table holds the meta information in the configuration. // string retval = GetSqlCreateTableStart("TPC"); retval += GetSqlCreateDefineKey("id", true); // TPC Id 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("Updated", "to_timestamp('9999-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS')", true); retval += GetSqlCreateVar("Revision", 5, 0, "default NULL", true); retval += GetSqlCreateText("Comment", 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 = "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::getSqlInsertGBTX1() { // // Creates an sql statement which inserts values into the GBTX1 table. // string retval; char buf[5] = {0}; int32_t ctr = 0; std::ifstream ifs; ifs.open ("config_fec-gbtx1.txt", std::ifstream::in); ifs.width(5); retval = "INSERT INTO GBTX1 VALUES ("; retval += numtostr(0); retval += ", "; if ( ifs.is_open() ) { while ( ifs >> buf ) { string stmp = buf; char *p; long regval = strtol(buf, &p, 16); if ( *p != 0 ) { cerr << "Function DBQueryCreator::getSqlInsertGBTX1(): Found bad value in file: " << buf << endl; return ""; } retval += numtostr(regval); if ( ctr < 365 ) retval += ", "; //cout << ctr << "\t" << buf << "\t" << regval << endl; ctr++; } ifs.close(); if ( ctr > 366 ) { cerr << "Function DBQueryCreator::getSqlInsertGBTX1(): Too many entries found in GBTX1 configuration file! Found" << ctr << endl; return ""; } if ( ctr < 366 ) { cerr << "Function DBQueryCreator::getSqlInsertGBTX1(): Not enough entries found in GBTX1 configuration file! Found " << ctr << endl; return ""; } } else { cerr << "Function DBQueryCreator::getSqlInsertGBTX1(): Error opening GBTX1 configuration file!" << endl; return ""; } retval += ")"; return retval; } string DBQueryCreator::getSqlInsertPEDESTAL_CRU(int32_t rowIndex, int32_t cruIndex) { // // Creates an sql statement which inserts values into the PEDESTAL_CRU table // string retval; char carry[40]; retval = "INSERT INTO PEDESTAL_CRU VALUES ("; sprintf(carry,"%d", rowIndex); retval += carry; retval += ", "; sprintf(carry,"%d", cruIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertPEDESTAL(int32_t index, int32_t branchPosition, int32_t fecPosition) { // // Creates an sql statement which inserts values into the PEDESTAL table. // string retval; retval = "INSERT INTO PEDESTAL VALUES ("; retval += numtostr(index); // id retval += ", "; retval += numtostr(branchPosition); retval += ", "; retval += numtostr(fecPosition); retval += ", "; for (int ii = 0; ii<80; ii++) { retval += numtostr(0); // Default pedestal value: 0 if ( ii < 79 ) retval += ", "; } retval += ")"; return retval; } string DBQueryCreator::getSqlInsertZSTHR_CRU(int32_t rowIndex, int32_t cruIndex) { // // Creates an sql statement which inserts values into the ZSTHR_CRU table // string retval; char carry[40]; retval = "INSERT INTO ZSTHR_CRU VALUES ("; sprintf(carry,"%d", rowIndex); retval += carry; retval += ", "; sprintf(carry,"%d", cruIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertZSTHR(int32_t index, int32_t branchPosition, int32_t fecPosition) { // // Creates an sql statement which inserts values into the ZSTHR table. // string retval; retval = "INSERT INTO ZSTHR VALUES ("; retval += numtostr(index); // id retval += ", "; retval += numtostr(branchPosition); retval += ", "; retval += numtostr(fecPosition); retval += ", "; for (int ii = 0; ii<80; ii++) { retval += numtostr(0); // Default threshold value: 0 if ( ii < 79 ) retval += ", "; } retval += ")"; return retval; } string DBQueryCreator::getSqlInsertONCHANNEL_CRU(int32_t rowIndex, int32_t cruIndex) { // // Creates an sql statement which inserts values into the ONCHANNEL_CRU table // string retval; char carry[40]; retval = "INSERT INTO ONCHANNEL_CRU VALUES ("; sprintf(carry,"%d", rowIndex); retval += carry; retval += ", "; sprintf(carry,"%d", cruIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertONCHANNEL(int32_t index, int32_t branchPosition, int32_t fecPosition) { // // Creates an sql statement which inserts values into the ON_CHANNEL table. // string retval; retval = "INSERT INTO ON_CHANNEL VALUES ("; retval += numtostr(index); // id retval += ", "; retval += numtostr(branchPosition); retval += ", "; retval += numtostr(fecPosition); retval += ", "; for (int ii = 0; ii<80; ii++) { retval += numtostr(1); // Default channel state: ON (1) if ( ii < 79 ) retval += ", "; } retval += ")"; return retval; } string DBQueryCreator::getSqlInsertCMCORR_CRU(int32_t rowIndex, int32_t cruIndex) { // // Creates an sql statement which inserts values into the CMCORR_CRU table // string retval; char carry[40]; retval = "INSERT INTO CMCORR_CRU VALUES ("; sprintf(carry,"%d", rowIndex); retval += carry; retval += ", "; sprintf(carry,"%d", cruIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertCMCORR(int32_t index, int32_t branchPosition, int32_t fecPosition) { // // Creates an sql statement which inserts values into the CMCORR table. // string retval; retval = "INSERT INTO CMCORR VALUES ("; retval += numtostr(index); // id retval += ", "; retval += numtostr(branchPosition); retval += ", "; retval += numtostr(fecPosition); retval += ", "; for (int ii = 0; ii<80; ii++) { retval += numtostr(1); // Default value: 1 if ( ii < 79 ) retval += ", "; } retval += ")"; return retval; } string DBQueryCreator::getSqlInsertITCORR1_CRU(int32_t rowIndex, int32_t cruIndex) { // // Creates an sql statement which inserts values into the ITCORR1_CRU table // string retval; char carry[40]; retval = "INSERT INTO ITCORR1_CRU VALUES ("; sprintf(carry,"%d", rowIndex); retval += carry; retval += ", "; sprintf(carry,"%d", cruIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertITCORR1(int32_t index, int32_t branchPosition, int32_t fecPosition) { // // Creates an sql statement which inserts values into the ITCORR1 table. // string retval; retval = "INSERT INTO ITCORR1 VALUES ("; retval += numtostr(index); // id retval += ", "; retval += numtostr(branchPosition); retval += ", "; retval += numtostr(fecPosition); retval += ", "; for (int ii = 0; ii<80; ii++) { retval += numtostr(1); // Default value: 1 if ( ii < 79 ) retval += ", "; } retval += ")"; return retval; } string DBQueryCreator::getSqlInsertITCORR2_CRU(int32_t rowIndex, int32_t cruIndex) { // // Creates an sql statement which inserts values into the ITCORR2_CRU table // string retval; char carry[40]; retval = "INSERT INTO ITCORR2_CRU VALUES ("; sprintf(carry,"%d", rowIndex); retval += carry; retval += ", "; sprintf(carry,"%d", cruIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertITCORR2(int32_t index, int32_t branchPosition, int32_t fecPosition) { // // Creates an sql statement which inserts values into the ITCORR2 table. // string retval; retval = "INSERT INTO ITCORR2 VALUES ("; retval += numtostr(index); // id retval += ", "; retval += numtostr(branchPosition); retval += ", "; retval += numtostr(fecPosition); retval += ", "; for (int ii = 0; ii<80; ii++) { retval += numtostr(1); // Default value: 1 if ( ii < 79 ) retval += ", "; } retval += ")"; return retval; } string DBQueryCreator::getSqlInsertCRU_PARTITION(int32_t cruIndex, int32_t partitionIndex) { // // Creates an sql statement which inserts values into the CRU_PARTITION table // string retval; char carry[40]; retval = "INSERT INTO CRU_PARTITION VALUES ("; sprintf(carry,"%d",cruIndex); retval += carry; retval += ", "; sprintf(carry,"%d",partitionIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertCRU(int32_t index, int32_t sidePosition, int32_t sectorPosition, int32_t partitionPosition, int32_t cruPosition, int32_t configType) { // // Creates an sql statement which inserts values into the CRU table. // CruConfig *cruConf = new CruConfig(configType, 0); string retval; retval = "INSERT INTO CRU VALUES ("; retval += numtostr(index); // CRU id retval += ", "; retval += numtostr(cruPosition); // CRU Position (0=Master, 1=Slave) retval += ", "; retval += numtostr(cruConf->getState(sidePosition, sectorPosition, partitionPosition, cruPosition)); // ON_CRU (on/off) retval += ", "; retval += numtostr(cruConf->getGFD_LINK_ACTIVE(sidePosition, sectorPosition, partitionPosition, cruPosition)); // Active link mask (before link selector, 24 bit) retval += ", "; retval += numtostr(cruConf->getGFD_STRICT_SYNC(sidePosition, sectorPosition, partitionPosition, cruPosition)); // Enables strict SYNC checking retval += ", "; retval += numtostr(cruConf->getGFD_ENABLE_MASK(sidePosition, sectorPosition, partitionPosition, cruPosition)); // Select on which trigger to enable retval += ", "; for (uint32_t ilink = 0; ilink<24; ilink++) { retval += numtostr(cruConf->getGFD_STREAM_MASK(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; } retval += numtostr(cruConf->getON_LINK(sidePosition, sectorPosition, partitionPosition, cruPosition)); // ON_LINK = Link mask (after link selector, 20 bit) retval += ", "; retval += numtostr(cruConf->getLINK_SELECTOR_A(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getLINK_SELECTOR_B(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getZS_EN(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getTRG_WINDOW_SIZE(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getMAX_PAYLOAD_SIZE(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getSUPPRESS_HBR(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getUSE_LINK_ID_15(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getITCORR0(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getITF_EN(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getCMC_EN(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getOFFSET(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getRESYNC_EN(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getBC_EN(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getCMC_THRESH1(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getCMC_MIN_MATCHES(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getCMC_MATCH_DISTANCE(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ", "; retval += numtostr(cruConf->getCMC_WRITEOUT_EN(sidePosition, sectorPosition, partitionPosition, cruPosition)); retval += ")"; delete cruConf; return retval; } string DBQueryCreator::getSqlInsertFEC(int32_t index, int32_t sidePosition, int32_t sectorPosition, int32_t partitionPosition, int32_t branchPosition, int32_t fecPosition, int32_t configType) { // // Creates an sql statement which inserts values into the FEC table. Coordinates and parameters // are given in the hardware numbering the Partition expects. // FecConfig *fecConf = new FecConfig(configType, 0); string retval; retval = "INSERT INTO FEC VALUES ("; retval += numtostr(index); retval += ", "; retval += numtostr(branchPosition); retval += ", "; retval += numtostr(fecPosition); retval += ", "; retval += numtostr(fecConf->getState(sidePosition, sectorPosition, partitionPosition, branchPosition, fecPosition)); retval += ", "; retval += numtostr(fecConf->getSAMPA_MASK(sidePosition, sectorPosition, partitionPosition, branchPosition, fecPosition)); retval += ", "; retval += numtostr(fecConf->getSAMPA_ANA_CFG(sidePosition, sectorPosition, partitionPosition, branchPosition, fecPosition)); retval += ", "; retval += numtostr(fecConf->getSAMPA_CLK_CFG(sidePosition, sectorPosition, partitionPosition, branchPosition, fecPosition)); retval += ", "; for ( int32_t ii = 0; ii < 28; ii++ ) { retval += numtostr(fecConf->getGBTX0_SAMPLINGPHASE(sidePosition, sectorPosition, partitionPosition, branchPosition, fecPosition, ii)); if ( ii < 27 ) retval += ", "; } retval += ")"; delete fecConf; return retval; } string DBQueryCreator::getSqlInsertFEC_PARTITION(int32_t fecIndex, int32_t partitionIndex) { // // Creates an sql statement which inserts values into the FEC_PARTITION table // TODO: check if multi insert is possible for oracle on sql statement level // string retval; char carry[40]; retval = "INSERT INTO FEC_PARTITION VALUES ("; sprintf(carry,"%d",fecIndex); retval += carry; retval += ", "; sprintf(carry,"%d",partitionIndex); retval += carry; retval += ")"; return retval; } string DBQueryCreator::getSqlInsertPARTITION(int32_t index, int32_t sidePosition, int32_t sectorPosition, int32_t partitionPosition, int32_t configType) { // // Creates an sql statement which inserts values into the PARTITION table. // string retval; retval = "INSERT INTO PARTITION VALUES ("; retval += numtostr(index); // partition id retval += ", "; retval += numtostr(partitionPosition); // 0...4 retval += ", "; retval += numtostr(1); // Read out all partitions by default retval += ")"; return retval; } string DBQueryCreator::getSqlInsertPARTITION_SECTOR(int32_t partitionIndex, int32_t sectorIndex) { // // Creates an sql statement which inserts values into the PARTITION_SECTOR table // string retval; char carry[40]; retval = "INSERT INTO PARTITION_SECTOR VALUES ("; sprintf(carry,"%d",partitionIndex); 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 configID) { // //Creates an sql statement which inserts values into the TPC table. // TpcConfig *tpcConf = new TpcConfig(); string retval; retval = "INSERT INTO TPC VALUES ("; retval += numtostr(configID); // This is the tag or configuration ID ( > 0 ) retval += ", "; retval += "SYSTIMESTAMP, SYSTIMESTAMP,'"; retval += numtostr(fRevision); retval += "', '"; retval += tpcConf->getConfigName(configID); retval += "'"; retval += ")"; delete tpcConf; return retval; } /////////////////////////////////////////////////////////////////////////////////////// // Insert statements using bind variables (better for many consecutive transactions) /////////////////////////////////////////////////////////////////////////////////////// string DBQueryCreator::getSqlBindInsert(string tablename, int32_t ncols) { // // Create the sql statement to be held in the cache and ready to insert many fields // into a table (Oracle only) // string retval; retval = "INSERT INTO "; retval += tablename; retval += " VALUES ("; for(int32_t icol = 1; icol <= ncols; icol++) { retval += ":"; retval += numtostr(icol); if ( icol != ncols ) retval += ", "; } retval += ")"; return retval; } string DBQueryCreator::getSqlBindInsertPEDESTAL_CRU() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the PEDESTAL_CRU table (Oracle only) // // bind variables: // 1) pedestalIndex // 2) cruIndex return getSqlBindInsert("PEDESTAL_CRU", 2); } string DBQueryCreator::getSqlBindInsertZSTHR_CRU() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the ZSTHR_CRU table (Oracle only) // // bind variables: // 1) zsthrIndex // 2) cruIndex return getSqlBindInsert("ZSTHR_CRU", 2); } string DBQueryCreator::getSqlBindInsertONCHANNEL_CRU() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the ONCHANNEL_CRU table (Oracle only) // // bind variables: // 1) onchannelIndex // 2) cruIndex return getSqlBindInsert("ONCHANNEL_CRU", 2); } string DBQueryCreator::getSqlBindInsertCMCORR_CRU() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the CMCORR_CRU table (Oracle only) // // bind variables: // 1) cmcorrIndex // 2) cruIndex return getSqlBindInsert("CMCORR_CRU", 2); } string DBQueryCreator::getSqlBindInsertITCORR1_CRU() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the ITCORR1_CRU table (Oracle only) // // bind variables: // 1) itcorr1Index // 2) cruIndex return getSqlBindInsert("ITCORR1_CRU", 2); } string DBQueryCreator::getSqlBindInsertITCORR2_CRU() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the ITCORR2_CRU table (Oracle only) // // bind variables: // 1) itcorr2Index // 2) cruIndex return getSqlBindInsert("ITCORR2_CRU", 2); } string DBQueryCreator::getSqlBindInsertCRU_PARTITION() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the CRU_PARTITION table (Oracle only) // // bind variables: // 1) cruIndex // 2) partitionIndex return getSqlBindInsert("CRU_PARTITION", 2); } string DBQueryCreator::getSqlBindInsertFEC_PARTITION() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the FEC_PARTITION table (Oracle only) // // bind variables: // 1) fecIndex // 2) partitionIndex return getSqlBindInsert("FEC_PARTITION", 2); } string DBQueryCreator::getSqlBindInsertPARTITION_SECTOR() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the PARTITION_SECTOR table (Oracle only) // // bind variables: // 1) partitionIndex // 2) sectorIndex return getSqlBindInsert("PARTITION_SECTOR", 2); } string DBQueryCreator::getSqlBindInsertSECTOR_TPC() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the PARTITION_SECTOR table (Oracle only) // // bind variables: // 1) sectorIndex // 2) tpcIndex return getSqlBindInsert("SECTOR_TPC", 2); } string DBQueryCreator::getSqlBindInsertTPC() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the TPC table (Oracle only) // TpcFieldPositions TFP; return getSqlBindInsert("TPC", TFP.getNcols()); } string DBQueryCreator::getSqlBindInsertSECTOR() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the SECTOR table (Oracle only) // return getSqlBindInsert("SECTOR", 3); } string DBQueryCreator::getSqlBindInsertPARTITION() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the PARTITION table (Oracle only) // return getSqlBindInsert("PARTITION", 3); } 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) // FecFieldPositions FFP; return getSqlBindInsert("FEC", FFP.getNcols()); } string DBQueryCreator::getSqlBindInsertCRU() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the CRU table (Oracle only) // CruFieldPositions CFP; return getSqlBindInsert("CRU", CFP.getNcols()); } string DBQueryCreator::getSqlBindInsertPEDESTAL() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the PEDESTAL table (Oracle only) // UlFieldPositions ULFP; return getSqlBindInsert("PEDESTAL", ULFP.getNcols()); } string DBQueryCreator::getSqlBindInsertZSTHR() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the ZSTHR table (Oracle only) // UlFieldPositions ULFP; return getSqlBindInsert("ZSTHR", ULFP.getNcols()); } string DBQueryCreator::getSqlBindInsertONCHANNEL() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the ON_CHANNEL table (Oracle only) // UlFieldPositions ULFP; return getSqlBindInsert("ON_CHANNEL", ULFP.getNcols()); } string DBQueryCreator::getSqlBindInsertCMCORR() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the CMCORR table (Oracle only) // UlFieldPositions ULFP; return getSqlBindInsert("CMCORR", ULFP.getNcols()); } string DBQueryCreator::getSqlBindInsertITCORR1() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the ITCORR1 table (Oracle only) // UlFieldPositions ULFP; return getSqlBindInsert("ITCORR1", ULFP.getNcols()); } string DBQueryCreator::getSqlBindInsertITCORR2() { // // Create the sql statement to be held in the cache and ready to insert many fields // into the ITCORR2 table (Oracle only) // UlFieldPositions ULFP; return getSqlBindInsert("ITCORR2", ULFP.getNcols()); } //---- TPC Select Table Querys -------------------------------------------------------------------- string DBQueryCreator::getSqlSelectTpcData() { // //Creates an sql statement which selects the specified data from the TPC table. // string retval; retval = "SELECT * FROM TPC ORDER BY \"id\""; 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::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::getSqlSelectPartitionRow(int32_t configID, int32_t side, int32_t sector, int32_t partition) { // // Create a query which selects a whole row from the Partition table for a given tag, side, // sector and partition // string retval; retval = "SELECT partition.\"id\", partition.\"Position\", partition.\"ON_PARTITION\" "; retval += "FROM tpc, sector_tpc, sector, partition_sector, partition WHERE partition.\"id\"=partition_sector.\"PARTITION_ID\" "; retval += "AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); return retval; } string DBQueryCreator::getSqlSelectPartitionField(int32_t configID, int32_t side, int32_t sector, int32_t partition, string col) { // // Create a query which selects a single value from one row from the PARTITION table (for a given // tag, side, sector and partition). // string retval; retval = "SELECT partition.\""; retval += col; retval += "\" FROM tpc, sector_tpc, sector, partition_sector, partition WHERE partition.\"id\"=partition_sector.\"PARTITION_ID\" "; retval += "AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); return retval; } string DBQueryCreator::getSqlSelectFecRow(int32_t partitionID, int32_t branch, int32_t fec) { // // Creates an sql statement which selects the FEC config data for the selected FEC. // FecFieldPositions FFP; string retval = "SELECT "; for (uint32_t icol = 0; icol < FFP.getNcols(); icol++) { retval += "fec.\""; retval += FFP.getColName(icol); retval += "\""; if ( icol < FFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "FROM fec, fec_partition, partition WHERE fec.\"id\"=fec_partition.\"FEC_ID\" "; retval += "AND partition.\"id\"=fec_partition.\"PARTITION_ID\" AND partition.\"id\" ="; retval += numtostr(partitionID); retval +=" AND fec.\"BranchPosition\"="; retval += numtostr(branch); retval += " AND fec.\"Position\"="; retval += numtostr(fec); return retval; } string DBQueryCreator::getSqlSelectFecRow(int32_t configID, int32_t side, int32_t sector, int32_t partition, 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 // FecFieldPositions FFP; string retval = "SELECT "; for (uint32_t icol = 0; icol < FFP.getNcols(); icol++) { retval += "fec.\""; retval += FFP.getColName(icol); retval += "\""; if ( icol < FFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "FROM tpc, sector_tpc, sector, partition_sector, partition, fec_partition, fec "; retval += "WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); retval += " AND fec.\"BranchPosition\"="; retval += numtostr(branch); retval += " AND fec.\"Position\"="; retval += numtostr(fec); return retval; } string DBQueryCreator::getSqlSelectFecConfigData(int32_t configID) { // // Creates an sql statement which selects the FEC config data for all 3276 FECs for a given tag // FecFieldPositions FFP; string retval = "SELECT "; retval += "sector.\"SidePosition\", sector.\"Position\", partition.\"Position\", "; for (uint32_t icol = 1; icol < FFP.getNcols(); icol++) { // Skip "id" retval += "fec.\""; retval += FFP.getColName(icol); retval += "\""; if ( icol < FFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "FROM tpc, sector_tpc, sector, partition_sector, partition, fec_partition, fec "; retval += "WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 += " ORDER BY sector.\"SidePosition\" ASC, sector.\"Position\" ASC, partition.\"Position\" ASC, "; retval += "fec.\"BranchPosition\" ASC, fec.\"Position\" ASC"; return retval; } string DBQueryCreator::getSqlSelectFecConfigData(int32_t configID, int32_t side, int32_t sector, int32_t partition) { // // Create a query which selects all FEC configuration data (one row per FEC) for a given partition and tag // FecFieldPositions FFP; string retval = "SELECT "; for (uint32_t icol = 0; icol < FFP.getNcols(); icol++) { retval += "fec.\""; retval += FFP.getColName(icol); retval += "\""; if ( icol < FFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "FROM tpc, sector_tpc, sector, partition_sector, partition, fec_partition, fec "; retval += "WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); return retval; } string DBQueryCreator::getSqlSelectFecField(int32_t configID, int32_t side, int32_t sector, int32_t partition, 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, partition_sector, partition, fec_partition, fec "; retval += "WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); retval += " AND fec.\"BranchPosition\"="; retval += numtostr(branch); retval += " AND fec.\"Position\"="; retval += numtostr(fec); return retval; } string DBQueryCreator::getSqlSelectCruID(int32_t configID, int32_t side, int32_t sector, int32_t partition, int32_t cru) { // // Creates an sql statement which selects the ID of the CRU specified by the given coordinates // string retval; retval = "SELECT CRU_ID FROM tpc, sector_tpc, sector, partition_sector, partition, cru_partition, cru "; retval += "WHERE cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); retval += " AND cru.\"Position\"="; retval += numtostr(cru); return retval; } string DBQueryCreator::getSqlSelectPartitionID(int32_t configID, int32_t side, int32_t sector, int32_t partition) { // // Creates an sql statement which selects the ID of the partition specified by the given coordinates // string retval; retval = "SELECT PARTITION_ID FROM tpc, sector_tpc, sector, partition_sector, partition "; retval += "WHERE partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); return retval; } string DBQueryCreator::getSqlSelectGbtx1ConfigData() { // // Creates an sql statement which selects the GBTX1 config data. At this point we assume that all // FECs need the same configuration. An "id" field is foreseen in case different versions of this // configuration will be needed. Returns 1 row. // string retval; retval = "SELECT * FROM GBTX1"; return retval; } string DBQueryCreator::getSqlSelectCruConfigData(int32_t configID) { // // Creates an sql statement which selects the CRU config data for all 3276 FECs for the selected PARTITION. // CruFieldPositions CFP; string retval = "SELECT sector.\"SidePosition\", sector.\"Position\", partition.\"Position\", "; for (uint32_t icol = 1; icol < CFP.getNcols(); icol++) { // Skip "id" retval += "cru.\""; retval += CFP.getColName(icol); retval += "\""; if ( icol < CFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "FROM tpc, sector_tpc, sector, partition_sector, partition, cru_partition, cru "; retval += "WHERE cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 += " ORDER BY sector.\"SidePosition\" ASC, sector.\"Position\" ASC, partition.\"Position\" ASC, cru.\"Position\" ASC"; return retval; } string DBQueryCreator::getSqlSelectCruConfigData(int32_t configID, int32_t side, int32_t sector, int32_t partition) { // // Creates an sql statement which selects the CRU config data for the selected PARTITION. // Needed for the configuration of the CRU. Returns 2 rows: Master and slave CRU data. // CruFieldPositions CFP; string retval = "SELECT "; for (uint32_t icol = 0; icol < CFP.getNcols(); icol++) { retval += "cru.\""; retval += CFP.getColName(icol); retval += "\""; if ( icol < CFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "FROM tpc, sector_tpc, sector, partition_sector, partition, cru_partition, cru "; retval += "WHERE cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); //retval +=" ORDER BY cru.\"Position\""; return retval; } string DBQueryCreator::getSqlSelectCruRow(int32_t partitionID, int32_t cru) { // // Creates an sql statement which selects the CRU config data for the selected PARTITION. // Needed for the configuration of the CRU. Returns 1 row // CruFieldPositions CFP; string retval = "SELECT "; for (uint32_t icol = 0; icol < CFP.getNcols(); icol++) { retval += "cru.\""; retval += CFP.getColName(icol); retval += "\""; if ( icol < CFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "FROM cru, cru_partition, partition WHERE "; retval += "cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\" ="; retval += numtostr(partitionID); retval += " AND cru.\"Position\"="; retval += numtostr(cru); return retval; } string DBQueryCreator::getSqlSelectCruRow(int32_t configID, int32_t side, int32_t sector, int32_t partition, int32_t cru) { // // Creates an sql statement which selects the CRU config data for the selected PARTITION. // Needed for the configuration of the CRU. Returns 1 row // CruFieldPositions CFP; string retval = "SELECT "; for (uint32_t icol = 0; icol < CFP.getNcols(); icol++) { retval += "cru.\""; retval += CFP.getColName(icol); retval += "\""; if ( icol < CFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "FROM tpc, sector_tpc, sector, partition_sector, partition, cru_partition, cru WHERE "; retval += "cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); retval += " AND cru.\"Position\"="; retval += numtostr(cru); //retval +=" ORDER BY cru.\"Position\""; return retval; } string DBQueryCreator::getSqlSelectCruField(int32_t configID, int32_t side, int32_t sector, int32_t partition, int32_t cru, string col) { // // Creates an sql statement which selects one field from the CRU table for the selected PARTITION. // CruFieldPositions CFP; string retval = "SELECT cru.\""; retval += col; retval += "\" FROM tpc, sector_tpc, sector, partition_sector, partition, cru_partition, cru WHERE "; retval += "cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); retval += " AND cru.\"Position\"="; retval += numtostr(cru); //retval +=" ORDER BY cru.\"Position\""; return retval; } string DBQueryCreator::getSqlSelectUlConfigData(string tablename, int32_t configID) { // // Creates an sql statement which selects all rows from a given UL table for a given tag // UlFieldPositions ULFP; string retval = "SELECT sector.\"SidePosition\", sector.\"Position\", partition.\"Position\", cru.\"Position\", "; for (uint32_t icol = 1; icol < ULFP.getNcols(); icol++) { // Skip "id" retval += tablename+".\""; retval += ULFP.getColName(icol); retval += "\""; if ( icol < ULFP.getNcols()-1 ) retval += ", "; else retval += " "; } string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); retval += "FROM tpc, sector_tpc, sector, partition_sector, partition, cru_partition, cru, "+table2+"_cru, "+tablename; retval += " WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 += " ORDER BY sector.\"SidePosition\" ASC, sector.\"Position\" ASC, partition.\"Position\" ASC,"; retval += " cru.\"Position\" ASC, "+tablename+".\"BranchPosition\" ASC, "+tablename+".\"Position\" ASC"; return retval; } string DBQueryCreator::getSqlSelectUlConfigData(string tablename, int32_t configID, int32_t side, int32_t sector, int32_t partition, int32_t cru) { // // Creates an sql statement which selects all rows from the given UL table for one CRU at the given coordinates. // UlFieldPositions ULFP; string retval = "SELECT "; for (uint32_t icol = 0; icol < ULFP.getNcols(); icol++) { retval += tablename+".\""; retval += ULFP.getColName(icol); retval += "\""; if ( icol < ULFP.getNcols()-1 ) retval += ", "; else retval += " "; } string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); retval += "FROM "+tablename+", "+table2+"_cru, cru, cru_partition, partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); retval += " AND cru.\"Position\"="; retval += numtostr(cru); return retval; } string DBQueryCreator::getSqlSelectUlField(string tablename, int32_t configID, int32_t side, int32_t sector, int32_t partition, int32_t cru, int32_t branch, int32_t fec, string col) { // // Creates an sql statement which selects one row from the given UL table. // string retval; string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); retval = "SELECT "+tablename+".\""; retval += col; retval += "\" FROM "+tablename+", "+table2+"_cru, cru, cru_partition, partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); retval += " AND cru.\"Position\"="; retval += numtostr(cru); retval += " AND "+tablename+".\"BranchPosition\"="; retval += numtostr(branch); retval += " AND "+tablename+".\"Position\"="; retval += numtostr(fec); return retval; } string DBQueryCreator::getSqlSelectUlRow(string tablename, int32_t configID, int32_t side, int32_t sector, int32_t partition, int32_t cru, int32_t branch, int32_t fec) { // // Creates an sql statement which selects one row from the given UL table. // UlFieldPositions ULFP; string retval = "SELECT "; for (uint32_t icol = 0; icol < ULFP.getNcols(); icol++) { retval += tablename+".\""; retval += ULFP.getColName(icol); retval += "\""; if ( icol < ULFP.getNcols()-1 ) retval += ", "; else retval += " "; } string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); retval += "FROM "+tablename+", "+table2+"_cru, cru, cru_partition, partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); retval += " AND cru.\"Position\"="; retval += numtostr(cru); retval += " AND "+tablename+".\"BranchPosition\"="; retval += numtostr(branch); retval += " AND "+tablename+".\"Position\"="; retval += numtostr(fec); return retval; } string DBQueryCreator::getSqlSelectUlRow(string tablename, int32_t cruID, int32_t branch, int32_t fec) { // // Creates an sql statement which selects one row from the given UL table. // UlFieldPositions ULFP; string retval = "SELECT "; for (uint32_t icol = 0; icol < ULFP.getNcols(); icol++) { retval += tablename+".\""; retval += ULFP.getColName(icol); retval += "\""; if ( icol < ULFP.getNcols()-1 ) retval += ", "; else retval += " "; } string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); retval += "FROM "+tablename+", "+table2+"_cru, cru "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"="; retval += numtostr(cruID); retval += " AND "+tablename+".\"BranchPosition\"="; retval += numtostr(branch); retval += " AND "+tablename+".\"Position\"="; retval += numtostr(fec); 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: partition retval = "SELECT * FROM tpc, sector_tpc, sector, partition_sector, partition WHERE partition.\"id\"=partition_sector.\"PARTITION_ID\" "; retval += "AND sector.\"id\"=partition_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 partition.\"Position\"=:4"; return retval; } string DBQueryCreator::getSqlBindSelectAllPartitionConfigData() { // // Creates an sql statement which selects the partition config data for all PARTITIONs for the selected tag. // string retval; // bind variables: // 1: config ID (tag) retval = "SELECT * FROM sector, partition, fec, tpc, sector_tpc, partition_sector, fec_partition "; retval += "WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" AND "; retval += "partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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\", partition.\"Position\", "; retval += "fec.\"BranchPosition\", fec.\"Position\""; return retval; } string DBQueryCreator::getSqlBindSelectSidePartitionConfigData() { // // Creates an sql statement which selects the partition config data for all PARTITIONs for the selected tag. // string retval; // bind variables: // 1: config ID (tag) // 1: side retval = "SELECT * FROM sector, partition, fec, tpc, sector_tpc, partition_sector, fec_partition "; retval += "WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" AND "; retval += "partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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\", partition.\"Position\", fec.\"BranchPosition\", fec.\"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: partitionID retval = "SELECT * FROM fec, fec_partition, partition WHERE fec.\"id\"=fec_partition.\"FEC_ID\""; retval += " AND partition.\"id\"=fec_partition.\"PARTITION_ID\" AND partition.\"id\"=:1"; retval += "ORDER BY fec.\"BranchPosition\", fec.\"Position\", sampa.\"Position\""; 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::getSqlMaxId(string tablename ) { // // Returns the maximum id from the table. // string retval; retval = "SELECT max(\"id\") FROM "; retval += tablename; return retval; } string DBQueryCreator::getSqlFindDisabledPARTITIONs(int32_t configID) { // // Creates an sql statement which finds all PARTITIONs that are disabled // string retval; retval = "SELECT sector.\"SidePosition\", sector.\"Position\", partition.\"Position\" "; retval += " FROM sector, partition, tpc, sector_tpc, partition_sector WHERE partition.\"id\"=partition_sector.\"PARTITION_ID\""; retval += " AND sector.\"id\"=partition_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 partition.\"ON_PARTITION\"=0 ORDER BY sector.\"SidePosition\", sector.\"Position\","; retval += "partition.\"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\", partition.\"Position\","; retval += " fec.\"BranchPosition\", fec.\"Position\" FROM sector, partition, fec, tpc,"; retval += " sector_tpc, partition_sector, fec_partition WHERE (fec.\"ON_FEC\"=0 OR fec.\"RDO_FEC\"=0)"; retval += " AND fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" AND"; retval += " partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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\", partition.\"Position\","; retval += " fec.\"BranchPosition\", fec.\"Position\""; return retval; } string DBQueryCreator::getSqlFindDisabledCHANNELs(int32_t configID) { // // Creates an sql statement which finds all CHANNELs that are disabled // string retval; retval = "SELECT fec.\"SAMPA_MASK\", sector.\"SidePosition\", sector.\"Position\","; retval += " partition.\"Position\", fec.\"BranchPosition\", fec.\"Position\", sampa.\"Position\""; retval += " FROM sector, partition, fec, tpc, sector_tpc, partition_sector, fec_partition,"; retval += " WHERE (sampa.\"ON_CHANNEL00\"=0 OR sampa.\"ON_CHANNEL01\"=0 OR"; retval += " sampa.\"ON_CHANNEL02\"=0 OR sampa.\"ON_CHANNEL03\"=0 OR sampa.\"ON_CHANNEL04\"=0"; retval += " OR sampa.\"ON_CHANNEL05\"=0 OR sampa.\"ON_CHANNEL06\"=0 OR sampa.\"ON_CHANNEL07\"=0"; retval += " OR sampa.\"ON_CHANNEL08\"=0 OR sampa.\"ON_CHANNEL09\"=0 OR sampa.\"ON_CHANNEL10\"=0"; retval += " OR sampa.\"ON_CHANNEL11\"=0 OR sampa.\"ON_CHANNEL12\"=0 OR sampa.\"ON_CHANNEL13\"=0"; retval += " OR sampa.\"ON_CHANNEL14\"=0 OR sampa.\"ON_CHANNEL15\"=0) AND"; retval += " fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" AND"; retval += " partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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\", partition.\"Position\","; retval += " fec.\"BranchPosition\", fec.\"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("PARTITION_SECTOR", "SECTOR_ID", sectorIDs, 36); } string DBQueryCreator::getSqlDeletePARTITION(int32_t *partitionIDs ) { // // Creates an sql statement which deletes the records // or rows from the PARTITION table // return getSqlDelete("PARTITION", partitionIDs, 6); } string DBQueryCreator::getSqlDeletePARTITIONID(int32_t *partitionIDs ) { // // Creates an sql statement which deletes the id from the PARTITION table // return getSqlDelete("FEC_PARTITION", "PARTITION_ID", partitionIDs, 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("SAMPA_FEC", "FEC_ID", fecIDs, 32); } string DBQueryCreator::getSqlDelete(string tablename, int32_t *IDs, int32_t length ) { // // Creates an sql statement which deletes the specified data type. // string retval; retval = "Delete FROM "+tablename+" WHERE \"id\" in ("; retval += getSqlDeleteInArray(IDs, length); retval += ")"; return retval; } string DBQueryCreator::getSqlDelete(string tablename, 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 "+tablename+" WHERE \""+name+" \" 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::getSqlUpdatePartitionField(int32_t configID, int32_t side, int32_t sector, int32_t partition, string col, int32_t newValue) { // // Update one field in the PARTITION table. The field is specified by the partition ID and the column name. // string retval; retval = "UPDATE PARTITION SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE partition.\"id\"=(SELECT partition.\"id\" FROM tpc, sector_tpc, sector, partition_sector, partition "; retval += "WHERE partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); retval += ")"; return retval; } string DBQueryCreator::getSqlUpdatePartitionField(int32_t partitionID, string col, int32_t newValue) { // // Update one field in the PARTITION table. The field is specified by the config ID, partition position and // the column name in the PARTITION table. // string retval; retval = "UPDATE PARTITION SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE partition.\"id\"="; retval += numtostr(partitionID); return retval; } string DBQueryCreator::getSqlUpdateFecField(int32_t configID, int32_t side, int32_t sector, int32_t partition, 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, partition_sector, partition, fec_partition, fec "; retval += "WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); 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::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, partition_sector, partition, fec_partition, fec "; retval += "WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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, partition_sector, partition, "; retval += "fec_partition, fec WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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::getSqlUpdateUlField(string tablename, int32_t configID, int32_t side, int32_t sector, int32_t partition, int32_t cru, int32_t branch, int32_t fec, string col, int32_t newValueInt, float newValueFloat) { // // Update one field in the given UL table. The field is specified by the config ID, Cru position, the link position, and // the column name. // string retval; bool useFloat = false; if ( tablename.compare("ITCORR1") == 0 ) useFloat = true; if ( tablename.compare("ITCORR2") == 0 ) useFloat = true; if ( tablename.compare("CMCORR") == 0 ) useFloat = true; if ( tablename.compare("itcorr1") == 0 ) useFloat = true; if ( tablename.compare("cmcorr2") == 0 ) useFloat = true; if ( tablename.compare("cmcorr") == 0 ) useFloat = true; string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); retval = "UPDATE "+tablename+" SET "; retval += col; retval += "="; if (useFloat) retval += floattostr(newValueFloat); else retval += numtostr(newValueInt); retval += " WHERE "+tablename+".\"id\"=(SELECT "+tablename+".\"id\" FROM "+tablename+", "+table2+"_cru, cru, cru_partition, "; retval += "partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"="; retval += numtostr(partition); retval += " AND cru.\"Position\"="; retval += numtostr(cru); retval += " AND "+tablename+".\"BranchPosition\"="; retval += numtostr(branch); retval += " AND "+tablename+".\"Position\"="; retval += numtostr(fec); retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateUlField(string tablename, int32_t ulID, string col, int32_t newValueInt, float newValueFloat) { // // Update one field in the given UL table. The field is specified by the unique ID and the column name. // string retval; bool useFloat = false; if ( tablename.compare("ITCORR1") == 0 ) useFloat = true; if ( tablename.compare("ITCORR2") == 0 ) useFloat = true; if ( tablename.compare("CMCORR") == 0 ) useFloat = true; if ( tablename.compare("cmcorr") == 0 ) useFloat= true; if ( tablename.compare("itcorr1") == 0 ) useFloat= true; if ( tablename.compare("itcorr2") == 0 ) useFloat= true; retval = "UPDATE "+tablename+" SET "; retval += col; retval += "="; if (useFloat) retval += floattostr(newValueFloat); else retval += numtostr(newValueInt); retval += " WHERE "+tablename+".\"id\"="; retval += numtostr(ulID); return retval; } string DBQueryCreator::getSqlUpdateFieldAllUl(string tablename, int32_t configID, string col, int32_t newValueInt, float newValueFloat) { // // return statement which updates all values in column col in the given UL table for a given configID (tag) // string retval; string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); bool useFloat = false; if ( tablename.compare("ITCORR1") == 0 ) useFloat = true; if ( tablename.compare("ITCORR2") == 0 ) useFloat = true; if ( tablename.compare("CMCORR") == 0 ) useFloat = true; if ( tablename.compare("cmcorr") == 0 ) useFloat= true; if ( tablename.compare("itcorr1") == 0 ) useFloat= true; if ( tablename.compare("itcorr2") == 0 ) useFloat= true; retval = "UPDATE "+tablename+" SET "; retval += col; retval += "="; if (useFloat) retval += floattostr(newValueFloat); else retval += numtostr(newValueInt); retval += " WHERE "+tablename+".\"id\" IN (SELECT "+tablename+".\"id\" FROM "+tablename+", "+table2+"_cru, cru, cru_partition, "; retval += "partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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::getSqlUpdateFieldAllUl(string tablename, vector configIDs, string col, int32_t newValueInt, float newValueFloat) { // // return statement which updates all values in column in the given UL table for a list // of configIDs (tags) // string retval; string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); bool useFloat = false; if ( tablename.compare("ITCORR1") == 0 ) useFloat = true; if ( tablename.compare("ITCORR2") == 0 ) useFloat = true; if ( tablename.compare("CMCORR") == 0 ) useFloat = true; if ( tablename.compare("cmcorr") == 0 ) useFloat= true; if ( tablename.compare("itcorr1") == 0 ) useFloat= true; if ( tablename.compare("itcorr2") == 0 ) useFloat= true; retval = "UPDATE "+tablename+" SET "; retval += col; retval += "="; if (useFloat) retval += floattostr(newValueFloat); else retval += numtostr(newValueInt); retval += " WHERE "+tablename+".\"id\" IN (SELECT "+tablename+".\"id\" FROM "+tablename+", "+table2+"_cru, cru, cru_partition, "; retval += "partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 += ")"; return retval; } string DBQueryCreator::getSqlUpdateFieldAllCru(int32_t configID, string col, int newValueInt, float newValueFloat) { // // return statement which updates all values in column in the CRU table for a given configID (tag) // string retval = ""; retval = "UPDATE CRU SET "; retval += col; retval += "="; if ( col.compare("ITCORR0") == 0 ) retval += floattostr(newValueFloat); else retval += numtostr(newValueInt); retval += " WHERE cru.\"id\" IN (SELECT cru.\"id\" FROM tpc, sector_tpc, sector, partition_sector, partition, cru_partition, cru "; retval += "WHERE cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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::getSqlUpdateFieldAllCru(vector configIDs, string col, int newValueInt, float newValueFloat) { // // return statement which updates all values in column in the CRU table for a list // of given configIDs (tags) // string retval = ""; retval = "UPDATE CRU SET "; retval += col; retval += "="; if ( col.compare("ITCORR0") == 0 ) retval += floattostr(newValueFloat); else retval += numtostr(newValueInt); retval += " WHERE cru.\"id\" IN (SELECT cru.\"id\" FROM tpc, sector_tpc, sector, partition_sector, partition, "; retval += "cru_partition, cru WHERE cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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::getSqlUpdateFieldAllPartitions(int32_t configID, string col, int32_t newValue) { // // return statement which updates all values in column in the Partition table for a given configID (tag) // string retval = ""; retval = "UPDATE PARTITION SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE partition.\"id\" IN (SELECT partition.\"id\" FROM tpc, sector_tpc, sector, partition_sector, partition "; retval += "WHERE partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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::getSqlUpdateFieldAllPartitions(vector configIDs, string col, int32_t newValue) { // // return statement which updates all values in column in the Partition table for a list // of given configIDs (tags) // string retval = ""; retval = "UPDATE PARTITION SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE partition.\"id\" IN (SELECT partition.\"id\" FROM tpc, sector_tpc, sector, partition_sector, partition "; retval += "WHERE partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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::getSqlUpdatePartitionFieldVectors(vector configIDs, vector sides, vector sectors, vector partitions, string col, int32_t newValue) { // // Update fields in the PARTITION table for the list of positions. // string retval; retval = "UPDATE PARTITION SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE partition.\"id\" IN (SELECT partition.\"id\" FROM tpc, sector_tpc, sector, partition_sector, partition "; retval += "WHERE partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\" IN ("; for(uint32_t i = 0; i < partitions.size(); i++ ) { retval += numtostr(partitions[i]); if ( i < partitions.size()-1 ) retval += ","; else retval += ")"; } retval += ")"; return retval; } string DBQueryCreator::getSqlUpdatePartitionFieldVectors(vector partitionIDs, string col, int32_t newValue) { // // Update one field in the PARTITION table for many partition IDs. // string retval; retval = "UPDATE PARTITION SET "; retval += col; retval += "="; retval += numtostr(newValue); retval += " WHERE partition.\"id\" IN ("; for(uint32_t i = 0; i < partitionIDs.size(); i++ ) { retval += numtostr(partitionIDs[i]); if ( i < partitionIDs.size()-1 ) retval += ","; else retval += ")"; } return retval; } string DBQueryCreator::getSqlUpdateCruFieldVectors(vector configIDs, vector sides, vector sectors, vector partitions, vector crus, string col, int32_t newValueInt, float newValueFloat) { // // Update one field in the FEC table for many config IDs, Fec positions. // string retval; retval = "UPDATE CRU SET "; retval += col; retval += "="; if ( col.compare("ITCORR0") == 0 ) retval += floattostr(newValueFloat); else retval += numtostr(newValueInt); retval += " WHERE cru.\"id\" IN (SELECT cru.\"id\" FROM tpc, sector_tpc, sector, partition_sector, partition, cru_partition, cru "; retval += "WHERE cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\" IN ("; for(uint32_t i = 0; i < partitions.size(); i++ ) { retval += numtostr(partitions[i]); if ( i < partitions.size()-1 ) retval += ","; else retval += ") "; } retval += "AND cru.\"Position\" IN ("; for(uint32_t i = 0; i < crus.size(); i++ ) { retval += numtostr(crus[i]); if ( i < crus.size()-1 ) retval += ","; else retval += ")"; } retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateCruFieldVectors(vector cruIDs, string col, int32_t newValueInt, float newValueFloat) { // // Update one field in the CRU table for many cru IDs. // string retval; retval = "UPDATE CRU SET "; retval += col; retval += "="; if ( col.compare("ITCORR0") == 0 ) retval += floattostr(newValueFloat); else retval += numtostr(newValueInt); retval += " WHERE cru.\"id\" IN ("; for(uint32_t i = 0; i < cruIDs.size(); i++ ) { retval += numtostr(cruIDs[i]); if ( i < cruIDs.size()-1 ) retval += ","; else retval += ")"; } return retval; } string DBQueryCreator::getSqlUpdateFecFieldVectors(vector configIDs, vector sides, vector sectors, vector partitions, 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, partition_sector, partition, fec_partition, fec "; retval += "WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\" IN ("; for(uint32_t i = 0; i < partitions.size(); i++ ) { retval += numtostr(partitions[i]); if ( i < partitions.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::getSqlUpdateFecFieldVectors(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::getSqlUpdateUlFieldVectors(string tablename, vector configIDs, vector sides, vector sectors, vector partitions, vector crus, vector branches, vector fecs, string col, int32_t newValueInt, float newValueFloat) { // // Update one field in the given UL table for many config IDs, CRU positions and links. // string retval; string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); bool useFloat = false; if ( tablename.compare("ITCORR1") == 0 ) useFloat = true; if ( tablename.compare("ITCORR2") == 0 ) useFloat = true; if ( tablename.compare("CMCORR") == 0 ) useFloat = true; if ( tablename.compare("cmcorr") == 0 ) useFloat= true; if ( tablename.compare("itcorr1") == 0 ) useFloat= true; if ( tablename.compare("itcorr2") == 0 ) useFloat= true; //cout << tablename << " " << useFloat << " " << numtostr(newValueInt) << " " << floattostr(newValueFloat) << endl; retval = "UPDATE "+tablename+" SET "; retval += col; retval += "="; if (useFloat) retval += floattostr(newValueFloat); else retval += numtostr(newValueInt); retval += " WHERE "+tablename+".\"id\" IN (SELECT "+tablename+".\"id\" FROM "+tablename+", "+table2+"_cru, cru, cru_partition, "; retval += "partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\" IN ("; for(uint32_t i = 0; i < partitions.size(); i++ ) { retval += numtostr(partitions[i]); if ( i < partitions.size()-1 ) retval += ","; else retval += ") "; } retval += "AND cru.\"Position\" IN ("; for(uint32_t i = 0; i < crus.size(); i++ ) { retval += numtostr(crus[i]); if ( i < crus.size()-1 ) retval += ","; else retval += ") "; } retval += "AND "+tablename+".\"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 "+tablename+".\"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::getSqlUpdateUlFieldVectors(string tablename, vector IDs, string col, int32_t newValueInt, float newValueFloat) { // // Update one field in the FEC table for many fec IDs. // string retval; bool useFloat = false; if ( tablename.compare("ITCORR1") == 0 ) useFloat = true; if ( tablename.compare("ITCORR2") == 0 ) useFloat = true; if ( tablename.compare("CMCORR") == 0 ) useFloat = true; if ( tablename.compare("cmcorr") == 0 ) useFloat= true; if ( tablename.compare("itcorr1") == 0 ) useFloat= true; if ( tablename.compare("itcorr2") == 0 ) useFloat= true; retval = "UPDATE "+tablename+" SET "; retval += col; retval += "="; if ( useFloat ) retval += floattostr(newValueFloat); else retval += numtostr(newValueInt); retval += " WHERE "+tablename+".\"id\" IN ("; for(uint32_t i = 0; i < IDs.size(); i++ ) { retval += numtostr(IDs[i]); if ( i < IDs.size()-1 ) retval += ","; else retval += ")"; } return retval; } string DBQueryCreator::getSqlUpdateUlRowFloat(string tablename, vector configIDs, int32_t side, int32_t sector, int32_t partition, int32_t cru, int32_t branch, int32_t fec, vector newValues) { // // Update one full row in the given UL table for a given position for many config IDs // UlFieldPositions ULFP; string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); string retval = "UPDATE "+tablename+" SET "; for (uint32_t icol = 3; icol < ULFP.getNcols(); icol++) { retval += ULFP.getColName(icol)+"="; retval += floattostr(newValues[icol-3]); if ( icol < ULFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "WHERE "+tablename+".\"id\" IN (SELECT "+tablename+".\"id\" FROM "+tablename+", "+table2+"_cru, "; retval += "cru, cru_partition, partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND partition.\"Position\"="; retval += numtostr(partition); retval += " AND cru.\"Position\"="; retval += numtostr(cru); retval += " AND "+tablename+".\"BranchPosition\"="; retval += numtostr(branch); retval += " AND "+tablename+".\"Position\"="; retval += numtostr(fec); retval += ")"; return retval; } string DBQueryCreator::getSqlUpdateUlRowInt(string tablename, vector configIDs, int32_t side, int32_t sector, int32_t partition, int32_t cru, int32_t branch, int32_t fec, vector newValues) { // // Update one full row in the given UL table for a given position for many config IDs // UlFieldPositions ULFP; string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); string retval = "UPDATE "+tablename+" SET "; for (uint32_t icol = 3; icol < ULFP.getNcols(); icol++) { retval += ULFP.getColName(icol)+"="; retval += numtostr(newValues[icol-3]); if ( icol < ULFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "WHERE "+tablename+".\"id\" IN (SELECT "+tablename+".\"id\" FROM "+tablename+", "+table2+"_cru, "; retval += "cru, cru_partition, partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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\"="; retval += numtostr(side); retval += " AND sector.\"Position\"="; retval += numtostr(sector); retval += " AND partition.\"Position\"="; retval += numtostr(partition); retval += " AND cru.\"Position\"="; retval += numtostr(cru); retval += " AND "+tablename+".\"BranchPosition\"="; retval += numtostr(branch); retval += " AND "+tablename+".\"Position\"="; retval += numtostr(fec); retval += ")"; 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: partition // 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, partition_sector, partition, fec_partition, fec "; retval += "WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"=:5"; retval += " AND fec.\"BranchPosition\"=:6 AND fec.\"Position\"=:7)"; 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: partition // 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, partition_sector, partition, fec_partition, fec "; retval += "WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"=:4"; retval += " AND fec.\"BranchPosition\"=:5 AND fec.\"Position\"=:6)"; return retval; } string DBQueryCreator::getSqlBindUpdateCruField(string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the CRU table (Oracle only) // string retval = ""; // bind variables: // 1: new value // 2: config ID (tag) // 3: side // 4: sector // 5: partition // 6: cru retval = "UPDATE CRU SET "; retval += col; retval += "=:1 WHERE cru.\"id\"="; retval += "(SELECT cru.\"id\" FROM tpc, sector_tpc, sector, partition_sector, partition, cru_partition, cru "; retval += "WHERE cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"=:5"; retval += " AND cru.\"Position\"=:6)"; return retval; } string DBQueryCreator::getSqlBindUpdateCruField(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 CRU table (Oracle only) // string retval = ""; // bind variables: // 1: new value // 2: side // 3: sector // 4: partition // 5: cru retval = "UPDATE CRU SET "; retval += col; retval += "=:1 WHERE cru.\"id\" IN "; retval += "(SELECT cru.\"id\" FROM tpc, sector_tpc, sector, partition_sector, partition, cru_partition, cru "; retval += "WHERE cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"=:4 "; retval += "AND cru.\"Position\"=:5"; return retval; } string DBQueryCreator::getSqlBindUpdateUlField(string tablename, string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the given UL table (Oracle only) // // bind variables: // 1: new value // 2: config ID (tag) // 3: side // 4: sector // 5: partition // 6: cru // 7: fec branch // 8: fec // string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); string retval = "UPDATE "+tablename+" SET "; retval += col; retval += "=:1 WHERE "+tablename+".\"id\"=(SELECT "+tablename+".\"id\" FROM "+tablename+", "+table2+"_cru, "; retval += "cru, cru_partition, partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"=:5"; retval += " AND cru.\"Position\"=:6 AND "+tablename+".\"BranchPosition\"=:7 AND "+tablename+".\"Position\"=:8)"; return retval; } string DBQueryCreator::getSqlBindUpdateUlField(string tablename, 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 given UL table (Oracle only) // // bind variables: // 1: new value // 2: side // 3: sector // 4: partition // 5: cru // 6: fec branch // 7: fec // string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); string retval = "UPDATE "+tablename+" SET "; retval += col; retval += "=:1 WHERE "+tablename+".\"id\" IN (SELECT "+tablename+".\"id\" FROM "+tablename+", "+table2+"_cru, "; retval += "cru, cru_partition, partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"=:4 "; retval += "AND cru.\"Position\"=:5 AND "+tablename+".\"BranchPosition\"=:6 AND "+tablename+".\"Position\"=:7)"; return retval; } string DBQueryCreator::getSqlBindUpdatePartitionField(string col) { // // Create the sql statement to be held in the cache and ready to update many fields // in a column in the PARTITION table (Oracle only) // string retval = ""; // bind variables: // 1: new value // 2: config ID (tag) // 3: side // 4: sector // 5: partition retval = "UPDATE PARTITION SET "; retval += col; retval += "=:1 WHERE partition.\"id\"=(SELECT partition.\"id\" FROM tpc, sector_tpc, sector, partition_sector, partition "; retval += "WHERE partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"=:5)"; return retval; } string DBQueryCreator::getSqlBindUpdatePartitionField(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 PARTITION table (Oracle only) // string retval = ""; // bind variables: // 1: new value // 2: side // 3: sector // 4: partition retval = "UPDATE PARTITION SET "; retval += col; retval += "=:1 WHERE partition.\"id\" IN (SELECT partition.\"id\" FROM tpc, sector_tpc, sector, partition_sector, partition "; retval += "WHERE partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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 partition.\"Position\"=:4)"; return retval; } string DBQueryCreator::getSqlBindUpdateUlRow(string tablename) { // // Create the sql statement to be held in the cache and ready to update a full row // in the given UL table (Oracle only) // // bind variables: // 1 - 80: new values // 81: config ID (tag) // 82: side // 83: sector // 84: partition // 85: cru // 86: fec branch // 87: fec // char carry[40]; UlFieldPositions ULFP; string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); string retval = "UPDATE "+tablename+" SET "; for (uint32_t icol = 3; icol < ULFP.getNcols(); icol++) { retval += ULFP.getColName(icol)+"=:"; sprintf(carry,"%d", icol-2); retval += carry; if ( icol < ULFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "WHERE "+tablename+".\"id\"=(SELECT "+tablename+".\"id\" FROM "+tablename+", "+table2+"_cru, "; retval += "cru, cru_partition, partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_sector.\"SECTOR_ID\" "; retval += "AND sector.\"id\"=sector_tpc.\"SECTOR_ID\" AND tpc.\"id\"=sector_tpc.\"TPC_ID\" AND "; retval += "tpc.\"id\"=:81 AND sector.\"SidePosition\"=:82 AND sector.\"Position\"=:83 AND partition.\"Position\"=:84"; retval += " AND cru.\"Position\"=:85 AND "+tablename+".\"BranchPosition\"=:86 AND "+tablename+".\"Position\"=:87)"; return retval; } string DBQueryCreator::getSqlBindUpdateUlRow(string tablename, vector configIDs) { // // Create the sql statement to be held in the cache and ready to update one row // in the given UL table (Oracle only) // // bind variables: // 1-80: new values // 81: side // 82: sector // 83: partition // 84: cru // 85: fec branch // 86: fec // char carry[40]; UlFieldPositions ULFP; string table2 = tablename; table2.erase(remove(table2.begin(), table2.end(), '_'), table2.end()); string table3 = table2; std::transform(table3.begin(), table3.end(), table3.begin(), ::toupper); string retval = "UPDATE "+tablename+" SET "; for (uint32_t icol = 3; icol < ULFP.getNcols(); icol++) { retval += ULFP.getColName(icol)+"=:"; sprintf(carry,"%d", icol-2); retval += carry; if ( icol < ULFP.getNcols()-1 ) retval += ", "; else retval += " "; } retval += "WHERE "+tablename+".\"id\" IN (SELECT "+tablename+".\"id\" FROM "+tablename+", "+table2+"_cru, "; retval += "cru, cru_partition, partition, partition_sector, sector, sector_tpc, tpc "; retval += "WHERE "+tablename+".\"id\"="+table2+"_cru.\""+table3+"_ID\" AND cru.\"id\"="+table2+"_cru.\"CRU_ID\" "; retval += "AND cru.\"id\"=cru_partition.\"CRU_ID\" AND partition.\"id\"=cru_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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\"=:81 AND sector.\"Position\"=:82 AND partition.\"Position\"=:83 "; retval += "AND cru.\"Position\"=:84 AND "+tablename+".\"BranchPosition\"=:85 AND "+tablename+".\"Position\"=:86)"; 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\", partition.\"Position\", "; retval += "fec.\"BranchPosition\", fec.\"Position\" FROM tpc, sector_tpc, sector, partition_sector, "; retval += "partition, fec_partition, fec WHERE fec.\"id\"=fec_partition.\"FEC_ID\" AND partition.\"id\"=fec_partition.\"PARTITION_ID\" "; retval += "AND partition.\"id\"=partition_sector.\"PARTITION_ID\" AND sector.\"id\"=partition_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::getSqlQueryShowTables() { // // Create query that shows all user tables in the DB // string retval = "SELECT table_name FROM user_tables ORDER BY table_name"; return retval; } string DBQueryCreator::numtostr(int32_t number) { // // Convert an integer to a string // ostringstream oss; oss << number; return oss.str(); } string DBQueryCreator::floattostr(float number) { // // Convert a float to a string // ostringstream oss; oss << number; return oss.str(); }