LinCalibProtoDUNE.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file LinCalibProtoDUNE.cxx
3 //
4 // \brief implementation of class for accessing linearity calibration
5 // constants for ProtoDUNE
6 //
7 // \author jpaley@fnal.gov
8 //
9 ////////////////////////////////////////////////////////////////////////
10 
11 // C++ language includes
12 #include <iostream>
13 #include <fstream>
14 #include <string>
15 #include <vector>
16 #include "math.h"
17 #include "stdio.h"
18 
19 // LArSoft includes
21 
22 // nutools includes
23 #include "nuevdb/IFDatabase/Table.h"
24 
25 // Framework includes
26 #include "cetlib_except/exception.h"
28 
29 //-----------------------------------------------
31 {
32  fIsMC = true;
33  fConstsLoaded = false;
34  fCurrentTS = 0;
35  fCSVFileName="";
36  fDBTag="";
37 }
38 
39 
40 //-----------------------------------------------
42  fhicl::ParameterSet const& pset
43 )
44 {
45  fIsMC = true;
46  fConstsLoaded = false;
47  fCurrentTS = 0;
48  fCSVFileName="";
49  fDBTag="";
50 }
51 
52 //------------------------------------------------
54 {
55  fUseCondb = pset.get<bool>("UseCondb");
56  fCSVFileName = pset.get<std::string>("CSVFileName");
57  fDBTag = pset.get<std::string>("DBTag");
58 
59  return true;
60 }
61 
62 //------------------------------------------------
64 {
65 
66  if (fConstsLoaded && ts != fCurrentTS) {
67  fLinConsts.clear();
68  fConstsLoaded = false;
69  }
70 
71  fCurrentTS = ts;
72  // all done!
73 
74  return true;
75 }
76 
77 //------------------------------------------------
79 {
80  if (!fConstsLoaded) this->LoadConsts();
81 
82  if (fLinConsts.find(chanId) == fLinConsts.end()) {
83  mf::LogError("LinCalibProtoDUNE") << "Channel " << chanId
84  << "not found!";
85  std::abort();
86  }
87 
88  return fLinConsts[chanId];
89 }
90 
91 //------------------------------------------------
93 {
94  if (!fUseCondb) return true;
95 
96  if (fConstsLoaded) return true;
97 
98  nutools::dbi::Table t;
99 
100  t.SetDetector("pdunesp");
101  t.SetTableName("linconsts");
102  t.SetTableType(nutools::dbi::kConditionsTable);
103  t.SetDataTypeMask(nutools::dbi::kDataOnly);
104  if (fIsMC)
105  t.SetDataTypeMask(nutools::dbi::kMCOnly);
106 
107  int statusIdx = t.AddCol("status","int");
108  int gainIdx = t.AddCol("gain","float");
109  int offsetIdx = t.AddCol("offset","float");
110  int shapeIdx = t.AddCol("shape","float");
111  int chi2Idx = t.AddCol("chi2","float");
112  int adcLowIdx = t.AddCol("adc_low","int");
113  int adcHiIdx = t.AddCol("adc_high","int");
114  int nlIdx[20];
115  char buff[64];
116  for (int i=0; i<20; ++i) {
117  sprintf(buff,"nl%d",i);
118  nlIdx[i] = t.AddCol(buff,"float");
119  }
120 
121  t.SetMinTSVld(fCurrentTS);
122  t.SetMaxTSVld(fCurrentTS);
123  t.SetTag(fDBTag);
124 
125  t.SetVerbosity(100);
126 
127  bool readOk = false;
128  if (!fCSVFileName.empty())
129  readOk = t.LoadFromCSV(fCSVFileName);
130  else
131  readOk = t.Load();
132 
133  if (! readOk) {
134  mf::LogError("LinCalibProtoDUNE") << "Load from norm linconsts database table failed.";
135 
136  return false; //std::abort();
137 
138  }
139 
140  if (t.NRow() == 0) {
141  mf::LogError("LinCalibProtoDUNE") << "Number of rows in linconsts calib table is 0. This should never be the case!";
142  return false;
143  }
144 
145  nutools::dbi::Row* row;
146  uint64_t chan;
147  for (int i=0; i<t.NRow(); ++i) {
148  LinConsts_t c;
149  row = t.GetRow(i);
150  chan = row->Channel();
151  row->Col(statusIdx).Get(c.status);
152  row->Col(gainIdx).Get(c.gain);
153  row->Col(offsetIdx).Get(c.offset);
154  row->Col(shapeIdx).Get(c.shape);
155  row->Col(chi2Idx).Get(c.chi2);
156  row->Col(adcLowIdx).Get(c.adc_low);
157  row->Col(adcHiIdx).Get(c.adc_high);
158  for (int j=0; j<20; ++j) {
159  row->Col(nlIdx[j]).Get(c.nl[j]);
160  }
161 
162  fLinConsts[chan] = c;
163  }
164 
165  fConstsLoaded = true;
166  return true;
167 }
168 
169 
bool Configure(fhicl::ParameterSet const &pset)
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool Update(uint64_t ts=0)
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::map< int, LinConsts_t > fLinConsts
LinConsts_t GetLinConsts(int chanId)