// // // // 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 extern "C" { #include "ccdb_inc.h" } using namespace std; using namespace ccdb; extern int Thresholds[20][72]; extern int DAC_Values[20][72]; string create_connection_string() { /* creates example connection string to ccdb demo sqlite database*/ string ccdb_home(getenv("CCDB_CONNECTION")); return ccdb_home; } void init_arrays(){ for (int k=0;k<20;k++){ for (int j=0;j<72;j++){ Thresholds[k][j] = 100; DAC_Values[k][j] = 0x8000; } } } int GetDACfromdatabase(int ROC, char *detector){ int NADCS = 0 ; char DET[128]; if (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!"< > 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 determination 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]; // get data for DAC values vector < vector > data; sprintf(table, "/%s/dac_values",DET); calib->GetCalib(data, table); if (data.size()<1){ init_arrays(); } for(int row = 0; row < data.size(); row++) { int R = (int) data[row][0]; if (R==ROC) { int slot = (int)data[row][1]; int ch = (int)data[row][2] - 1; if (slot>10){ slot -= 5; } else { slot -= 3; } int DACValue = (int) data[row][4]; if ((DACValue<0) || (DACValue>0x8000)){ DACValue = 0x8000; } DAC_Values[slot][ch] = DACValue; double sig = data[row][6]; Thresholds[slot][ch] = (int)(sparsificationfactor*sig +0.5); if (Thresholds[slot][ch]<60){ Thresholds[slot][ch] = 60; } } } return NADCS; }