// // // // purpose: Establish connection to online_ccdb, read current values // of the DAC settings for each ADC125 channel of each FDC // Crate (identified by ROC number). It also read for each // channel the sigma of the pedestal and calculates a sparsification // factor based on the sparsification factor. // SPARSIFICATIONVALUE_i = SIGMA_i * SPARSIFICATIONFACTOR // i = ROC/SLOT/CHANNEL // // protection agains runaway DAC values is included. // // online_ccdb tables: XXX = FDC or CDC // /XXX/dac_values row for each channel // /XXX/baseline single row for all channels // // //#include //#include #include #include #include #include #include #include "ccdb_main.hxx" extern "C" { #include "ccdb_inc.h" #include } extern int Thresholds[20][72]; extern int DAC_Values[20][72]; extern int FA125ReadOutMode; extern int FA125Latency; extern int FA125WindowSize; extern int FA125NSB; extern int FA125NSA; extern int FA125NP; int DACDefault; string create_connection_string() { /* creates example connection string to ccdb demo sqlite database*/ string ccdb_home(getenv("CCDB_CONNECTION")); return ccdb_home; } void init_DACValues(int val){ for (int k=0;k<20;k++){ for (int j=0;j<72;j++){ Thresholds[k][j] = 100; DAC_Values[k][j] = val; } } } void set_DAC_Defaults(char *detector){ DACDefault = FDCDACDefault; if (toupper(detector[0]) == 'C'){ DACDefault = CDCDACDefault; } init_DACValues(DACDefault); } int GetDACfromdatabase(int ROC, char *detector){ // retrieve configuration data for this particular ROC from data base // returns number of ADCs in this crate and fills the arrays DAC_Values[slots][channels] // and Thresholds[slot][channels] int NADCS = 0 ; char DET[128]; DACDefault = FDCDACDefault; if (toupper(detector[0]) == 'C'){ sprintf(DET,"CDC"); DACDefault = CDCDACDefault; } else { sprintf(DET,"FDC"); } MySQLCalibration *calib = new MySQLCalibration(100); string connection_str = create_connection_string(); if (!connection_str.size()) { cout<<"ERROR: CCDB_CONNECTION not defined!"<Connect(connection_str); if (!result) { cout<<"ERROR: CCDB connection failed!"< > crate; char table[128]; sprintf(table, "/%s/crate_setup",DET); calib->GetCalib(crate, table); for(int row = 0; row < crate.size(); row++) { int R = (int) crate[row][0]; if (R==ROC) { NADCS = (int) crate[row][1]; } } // get data for base line // what is the target baseline and the multiplication factor for the sigma (ped width) vector < vector > bl; table[128]; sprintf(table, "/%s/baseline",DET); calib->GetCalib(bl, table); double targetbaseline = bl[0][0]; double baselinefactor = bl[0][1]; double sparsificationfactor = bl[0][2]; // needed to calculate threshold=baseline+this*ped_width // get common timing thresholds for the timing alorithm // this is required with the new firmware of the fadc125 vector < vector > thresh; table[128]; sprintf(table, "/%s/common_timing_thresholds",DET); calib->GetCalib(bl, table); int LowTimingThreshold = (int)bl[0][0]; int HighTimingThreshold = (int)bl[0][1]; // scale factors for the Integral, Amplitude and Pedestal vector < vector > scales; table[128]; sprintf(table, "/%s/scale_factors",DET); calib->GetCalib(bl, table); int IBIT = (int)bl[0][0]; int ABIT = (int)bl[0][1]; int PBIT = (int)bl[0][2]; // get data for DAC values vector < vector > data; sprintf(table, "/%s/dac_values",DET); calib->GetCalib(data, table); if (data.size()<1){ init_DACValues(DACDefault); } else { cout<<"Database table "<10){ slot -= 5; } else { slot -= 3; } int DACValue = (int) data[row][4]; if ((DACValue<1000) || (DACValue>DACDefault)){ DACValue = DACDefault; } DAC_Values[slot][ch] = DACValue; int bl = (int) data[row][5]; double sig = data[row][6]; Thresholds[slot][ch] = (int)(sparsificationfactor*sig +0.5); if (Thresholds[slot][ch]Connect(connection_str); if (!result) { cout<<"ERROR: CCDB connection failed!"< > crate; char table[128]; sprintf(table, "/%s/crate_setup",DET); calib->GetCalib(crate, table); for(int row = 0; row < crate.size(); row++) { int R = (int) crate[row][0]; if (R==ROC) { NADCS = (int) crate[row][1]; } } return NADCS; } int GetReadOutConfigfromdatabase(char *detector){ // reads the parameters of the ADC configuration for the detector // this is valid for all ROC containing ADCs of the detector // retreives readoutmode, latency, windowsize, NSB, NSA and NP // and returns readout mode int NADCS = 0 ; char DET[128]; if (toupper(detector[0]) == 'C'){ sprintf(DET,"CDC"); } else { sprintf(DET,"FDC"); } MySQLCalibration *calib = new MySQLCalibration(100); string connection_str = create_connection_string(); if (!connection_str.size()) { cout<<"ERROR: CCDB_CONNECTION not defined!"<Connect(connection_str); if (!result) { cout<<"ERROR: CCDB connection failed!"< > RO_config; char table[128]; sprintf(table, "/%s/readout_config",DET); calib->GetCalib(RO_config, table); FA125ReadOutMode = (int) RO_config[0][0]; FA125Latency = (int) RO_config[0][1]; FA125WindowSize = (int) RO_config[0][2]; FA125NSB = (int) RO_config[0][3]; FA125NSA = (int) RO_config[0][4]; FA125NP = (int) RO_config[0][5]; return FA125ReadOutMode; } // ========================================================== // ********************************************************** // // start of class DetectorReadoutConfig // Member function definitions // // ********************************************************** // ========================================================== void DetectorReadoutConfig::InitDACValues(){ for (int ROC=0;ROC<20;ROC++){ for (int slot=0;slot<20;slot++){ for (int ch=0;chConnect(connection_str); if (!result) { cout<<"ERROR: CCDB connection failed!"< > RO_config; char table[128]; sprintf(table, "/%s/readout_config%s",DetectorName,specifics); calibDB->GetCalib(RO_config, table); FA125_MODE = (int) RO_config[0][0]; FA125_W_OFFSET = (int) RO_config[0][1]; FA125_W_WIDTH = (int) RO_config[0][2]; FA125_NSB = (int) RO_config[0][3]; FA125_NSA = (int) RO_config[0][4]; FA125_NPEAK = (int) RO_config[0][5]; // get crate configuration vector < vector > crate; table[128]; sprintf(table, "/%s/crate_setup%s",DetectorName,specifics); calibDB->GetCalib(crate, table); if (DetectorIndex == 1) { NumberOfCrates = crate.size(); for(int row = 0; row < NumberOfCrates; row++) { DetectorROCNumber[row] = (int) crate[row][0]; DetectorCrateModules[row] = (int) crate[row][1]; } } else if (DetectorIndex == 2) { NumberOfCrates = crate.size() - 4; // only counting fadc crates int idx =0; for(int row = 1; row < NumberOfCrates+2; row++) { if (row!=3){ DetectorROCNumber[idx] = (int) crate[row][0]; DetectorCrateModules[idx++] = (int) crate[row][1]; } } } // get data for base line determination vector < vector > bl; table[128]; sprintf(table, "/%s/baseline%s",DetectorName,specifics); calibDB->GetCalib(bl, table); FADC125_TARGET_BASELINE = (int) bl[0][0]; FADC125_THRESHOLD_FACTOR = (float) bl[0][2]; // get common timing thresholds for the timing alorithm // this is required with the new firmware of the fadc125 vector < vector > thresh; table[128]; sprintf(table, "/%s/common_timing_thresholds%s",DetectorName,specifics); calibDB->GetCalib(bl, table); int LowTimingThreshold = (int)bl[0][0]; int HighTimingThreshold = (int)bl[0][1]; FADC125_COMMON_LTT = LowTimingThreshold; FADC125_COMMON_HTT = HighTimingThreshold; // scale factors for the Integral, Amplitude and Pedestal vector < vector > scales; table[128]; sprintf(table, "/%s/scale_factors%s",DetectorName,specifics); calibDB->GetCalib(bl, table); FADC125_IBIT = (int)bl[0][0]; FADC125_ABIT = (int)bl[0][1]; FADC125_PBIT = (int)bl[0][2]; // get DAC values and determine sparsification thresholds vector < vector > data; sprintf(table, "/%s/dac_values%s",DetectorName,specifics); //cout<<"read table "<GetCalib(data, table); if (data.size()<1){ InitDACValues(); } for(int row = 0; row < data.size(); row++) { int ROC = (int) data[row][0]; if (DetectorIndex == 2) { ROC -= 2; if (ROC>2){ ROC -= 1; } } else if (DetectorIndex == 1) { ROC -= 1; } int slot = (int)data[row][1]; int ch = (int)data[row][2]; if (slot>10){ slot -= 5; } else { slot -= 3; } int DACValue = (int) data[row][4]; if ((DACValue<1000) || (DACValue>DACDefault)){ DACValue = DACDefault; } FADC125_DAC_VALUES[ROC][slot][ch] = DACValue; float bl = (float) data[row][5]; float sig = (float) data[row][6]; FADC125_BASELINE_VALUES[ROC][slot][ch] = bl; FADC125_SIGMA_VALUES[ROC][slot][ch] = sig; int Threshold = int (FADC125_THRESHOLD_FACTOR*sig + 0.5); if (Threshold< FADC125_COMMON_HTT){ Threshold = FADC125_COMMON_HTT + 10; } FADC125_THRESHOLD_VALUES[ROC][slot][ch] = Threshold; } } void DetectorReadoutConfig::Convert2Lower(char* str){ int len = strlen(str); for (int k=0; k10){ SLOT+=2; } CreateStream[k]<