Diana Software
QChannelRunDataHandle.cc
Go to the documentation of this file.
2 #include "QDianaDb.hh"
3 #include "QStringHandler.hh"
4 #include <cmath>
5 
6 using namespace Diana;
7 
8 QChannelRunDataHandle::QChannelRunDataHandle(const int run, const int channel, const std::string& name) : GlobalHandle<QChannelRunData>(name,"DAQ")
9 {
11  SetRun(run);
12 }
13 
15 {
17  QChannelRunData chanData;
18  chanData.Clear();
19 
20  std::string sbSubQuery = "(SELECT settings_basket_id FROM runs"
21  " WHERE run_number = " + QStringHandler::IntToString(GetRun()) + ")";
22  std::string profileIdSubQuery = "(SELECT profile_id FROM settings_basket"
23  " WHERE settings_basket_id = " + sbSubQuery + ")";
24 
25  std::string query = "SELECT"
26  " daq_nbits, sampling_frequency, v_adc_limit_min, v_adc_limit_max, window_length_ms"
27  " FROM digitizers, daqsettings, buildersettings"
28  " WHERE"
29  " channel = " + QStringHandler::IntToString(GetChannel())
30  + " AND daq_set = (SELECT daq_set from settings_basket WHERE settings_basket_id = " + sbSubQuery + ")"
31  " AND bld_set = (SELECT bld_set from settings_basket WHERE settings_basket_id = " + sbSubQuery + ")"
32  " AND digitizers.daq_id = (SELECT daq_id FROM maps WHERE channel = " + QStringHandler::IntToString(GetChannel())
33  + " AND profile_id = " + profileIdSubQuery + ")"
34  " AND digitizers.daq_id = daqsettings.daq_id;";
35 
36  // std::cout << " = = = = = = = = = = = = = = "
37  // << std::endl << query << std::endl
38  // << " = = = = = = = = = = = = = = " << std::endl;
39 
40  QDb::QDbTable chanDataInfo;
41  err = QDianaDb::Get()->DoQuery(query, chanDataInfo);
42  if(err != QERR_SUCCESS)
43  return err;
44 
45 
46  chanData.fSamplingFrequency = chanDataInfo["sampling_frequency"].begin()->GetInt();
47  int ADCRange = (1<<(chanDataInfo["daq_nbits"].begin()->GetInt()));
48  double adcMaxV = chanDataInfo["v_adc_limit_max"].begin()->GetDouble();
49  double adcMinV = chanDataInfo["v_adc_limit_min"].begin()->GetDouble();
50  chanData.fADC2mV = (adcMaxV - adcMinV) / ADCRange;
51  chanData.fADCMax = (int) (adcMaxV / chanData.fADC2mV)-1;
52  chanData.fADCMin = (int) (adcMinV / chanData.fADC2mV);
53  chanData.fADC2mV*=1000;
54  chanData.fNumberOfSamples
55  = (chanDataInfo["window_length_ms"].begin()->GetInt()*chanData.fSamplingFrequency)/1000; //
56 
57 
58  query = "SELECT td_kind FROM thermaldetectors WHERE td_id ="
59  " (SELECT td_id FROM maps WHERE channel = " + QStringHandler::IntToString(GetChannel())
60  + " AND profile_id = " + profileIdSubQuery + ")"
61  " UNION SELECT NULL;";
62 
63  // std::cout << " =+=+=+=+=+=+=+=+=+=+=+=+=+= "
64  // << std::endl << query << std::endl
65  // << " =+=+=+=+=+=+=+=+=+=+=+=+=+= " << std::endl;
66 
67  QDb::QDbTable tdInfo;
68  err = QDianaDb::Get()->DoQuery(query, chanDataInfo);
69  if(err != QERR_SUCCESS)
70  return err;
71 
72  chanData.fIsBolometer = false;
73  chanData.fIsThermometer = false;
74  std::string tdKind = chanDataInfo["td_kind"].begin()->GetString();
75  if(!tdKind.empty())
76  {
77  if("bolometer" == tdKind)
78  chanData.fIsBolometer= true;
79  else if("thermometer" == tdKind)
80  chanData.fIsThermometer = true;
81  } // else it is another DAQ channel used in specific cases like pulser channel or bias channel
82 
83  Set(chanData);
84  return QERR_SUCCESS;
85 }
err
Definition: CheckOF.C:114
hvec2 SetRun(753)
const int channel
hvec SetChannel(3)
hvec Set(vec)
@ QERR_SUCCESS
Definition: QError.hh:27
QChannelRunDataHandle(const int run, const int channel, const std::string &name="ChannelRunData")
basic channel and run based info. Used in the QRunData object.
double fSamplingFrequency
sampling frequency in Hz
int fADCMin
ADC minimum in ADC units.
bool fIsThermometer
is thermometer
int fNumberOfSamples
number of samples in ADC window
int fADCMax
ADC maximum in ADC units.
double fADC2mV
conversion: mV = ADC * fADC2mV
bool fIsBolometer
is bolometer
void Clear()
clear members
QError DoQuery(const std::string &query, QDbTable &table)
Definition: QDb.cc:409
std::map< std::string, column > QDbTable
Definition: QDb.hh:34
static QDianaDb * Get()
Definition: QDianaDb.cc:21
error class with error type and description
Definition: QError.hh:115
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...
std::string IntToString(int val, int width=0, char pad='0')
convert int value to string