Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
calib::TimingCache Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-10-28/Calibrator/func/TimingCache.h"

Classes

struct  DelayRec
 

Public Member Functions

 TimingCache ()
 
virtual ~TimingCache ()
 
void SetCSVSource (const std::string &src)
 
void UseCSVsFromUPS (bool use=true)
 
void SetTag (const std::string &tag)
 
void SetUseEpochs (bool use=true)
 
bool UseEpochs ()
 
void SetEpoch (const std::string &epoch)
 
void SetEpochTag (const std::string &tag)
 
std::string Epoch ()
 
std::string EpochTag ()
 
void SetRun (int run)
 
int Run ()
 
void GetEpochFromDB (int idet, bool isData)
 
void ReadEpochsFromCSV (bool readEpochs=true)
 
double GetOffset (int dcm, int diblock, std::uint32_t time, bool isData)
 
double GetSigma (int dcm, int diblock, std::uint32_t time, bool isData)
 
void SetVldTime (novadaq::cnv::DetId det, std::uint32_t minTime, std::uint32_t maxTime)
 

Protected Member Functions

void LoadFromDatabase (bool isData)
 

Protected Attributes

bool fInitializedMC
 
bool fInitializedData
 
std::string fCSVSource
 
bool fUseCSVsFromUPS
 
std::string fTag
 
bool fUseEpochs
 
std::string fEpoch
 
std::string fEpochTag
 
int fRun
 
bool fReadEpochsFromCSV
 
novadaq::cnv::DetId fCurDet
 
std::uint32_t fMinTime
 
std::uint32_t fMaxTime
 
std::map< int, DelayRecfMapData
 
std::map< int, DelayRecfMapMC
 

Detailed Description

Definition at line 15 of file TimingCache.h.

Constructor & Destructor Documentation

calib::TimingCache::TimingCache ( )

Definition at line 24 of file TimingCache.cxx.

25  : fInitializedMC(false), fInitializedData(false),
26  fUseEpochs(false),
27  fRun(0),
31  {
32  }
novadaq::cnv::DetId fCurDet
Definition: TimingCache.h:67
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
std::uint32_t fMinTime
Definition: TimingCache.h:68
std::uint32_t fMaxTime
Definition: TimingCache.h:68
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
calib::TimingCache::~TimingCache ( )
virtual

Definition at line 35 of file TimingCache.cxx.

36  {
37  }

Member Function Documentation

std::string calib::TimingCache::Epoch ( )
inline

Definition at line 30 of file TimingCache.h.

References fEpoch.

30 {return fEpoch;}
std::string fEpoch
Definition: TimingCache.h:61
std::string calib::TimingCache::EpochTag ( )
inline

Definition at line 31 of file TimingCache.h.

References fEpochTag.

31 {return fEpochTag;}
std::string fEpochTag
Definition: TimingCache.h:62
void calib::TimingCache::GetEpochFromDB ( int  idet,
bool  isData 
)

Definition at line 123 of file TimingCache.cxx.

References ana::assert(), nova::dbi::Row::Col(), fEpoch, fEpochTag, fRun, nova::dbi::Column::Get(), nova::dbi::Table::GetColIndex(), nova::dbi::Table::GetRow(), nova::dbi::kDataOnly, nova::dbi::kMCOnly, nova::dbi::Table::Load(), nova::dbi::Table::NRow(), nova::dbi::Table::SetDataTypeMask(), nova::dbi::Table::SetDetector(), nova::dbi::Table::SetMaxTSVld(), nova::dbi::Table::SetMinTSVld(), and nova::dbi::Table::SetTag().

Referenced by LoadFromDatabase(), and Run().

124  {
125  nova::dbi::Table tbl("Calibration/tables/TimingEpochs.xml");
126  if (isData)
127  tbl.SetDataTypeMask(nova::dbi::kDataOnly);
128  else
129  tbl.SetDataTypeMask(nova::dbi::kMCOnly);
130  tbl.SetTag(fEpochTag);
131  tbl.SetDetector(idet);
132  tbl.SetMinTSVld(fRun);
133  tbl.SetMaxTSVld(fRun);
134  assert(tbl.Load());
135  assert(tbl.NRow() == 1);
136 
137  int epochIdx = tbl.GetColIndex("epoch");
138  tbl.GetRow(0)->Col(epochIdx).Get(fEpoch);
139 
140  }
std::string fEpochTag
Definition: TimingCache.h:62
std::string fEpoch
Definition: TimingCache.h:61
assert(nhit_max >=nhit_nbins)
double calib::TimingCache::GetOffset ( int  dcm,
int  diblock,
std::uint32_t  time,
bool  isData 
)

Definition at line 40 of file TimingCache.cxx.

References febshutoff_auto::dcm, calib::TimingCache::DelayRec::dcmoffset, fInitializedData, fInitializedMC, fMapData, fMapMC, it, findDuplicateFiles::key, LoadFromDatabase(), and rec.

Referenced by calib::Calibrator::GetTimingOffset(), calib::Calibrator::MakeCellHit(), and ReadEpochsFromCSV().

41  {
42 
43  if(!fInitializedData&&isData){
44  LoadFromDatabase(isData);
45  }
46  if(!fInitializedMC&&!isData){
47  LoadFromDatabase(isData);
48  }
49 
50  int key = (diblock*1000)+dcm;
51 
52  std::map<int, DelayRec>::iterator it;
53 
54  if(isData){
55  it = fMapData.find(key);
56  if(it == fMapData.end()){
57  mf::LogDebug("TimingCache") << "No timing offset for dcm "<<dcm;
58  std::abort();
59  }
60  }
61  else{
62  it = fMapMC.find(key);
63  if(it == fMapMC.end()){
64  mf::LogDebug("TimingCache") << "No timing offset for dcm "<<dcm;
65  std::abort();
66  }
67  }
68 
69  const DelayRec& rec = it->second;
70  return rec.dcmoffset;
71  }
void LoadFromDatabase(bool isData)
diblock
print "ROW IS " print row
Definition: geo2elec.py:31
set< int >::iterator it
std::map< int, DelayRec > fMapData
Definition: TimingCache.h:70
caf::StandardRecord * rec
Definition: tutCAFMacro.C:20
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
std::map< int, DelayRec > fMapMC
Definition: TimingCache.h:71
double calib::TimingCache::GetSigma ( int  dcm,
int  diblock,
std::uint32_t  time,
bool  isData 
)

Definition at line 74 of file TimingCache.cxx.

References febshutoff_auto::dcm, fInitializedData, fInitializedMC, fMapData, fMapMC, it, findDuplicateFiles::key, LoadFromDatabase(), rec, and calib::TimingCache::DelayRec::sigma.

Referenced by ReadEpochsFromCSV().

75  {
76 
77  if(!fInitializedData&&isData){
78  LoadFromDatabase(isData);
79  }
80 
81  if(!fInitializedMC&&!isData){
82  LoadFromDatabase(isData);
83  }
84 
85  std::map<int, DelayRec>::iterator it;
86  int key = (diblock*1000)+dcm;
87 
88  if(isData){
89  it = fMapData.find(key);
90  if(it == fMapData.end()){
91  mf::LogDebug("TimingCache") << "No timing offset sigma for dcm "<<dcm;
92  std::abort();
93  }
94  }
95  else{
96  it = fMapMC.find(key);
97  if(it == fMapMC.end()){
98  mf::LogDebug("TimingCache") << "No timing offset sigma for dcm "<<dcm;
99  std::abort();
100  }
101  }
102 
103  const DelayRec& rec = it->second;
104  return rec.sigma;
105  }
void LoadFromDatabase(bool isData)
diblock
print "ROW IS " print row
Definition: geo2elec.py:31
set< int >::iterator it
std::map< int, DelayRec > fMapData
Definition: TimingCache.h:70
caf::StandardRecord * rec
Definition: tutCAFMacro.C:20
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
std::map< int, DelayRec > fMapMC
Definition: TimingCache.h:71
void calib::TimingCache::LoadFromDatabase ( bool  isData)
protected

Definition at line 143 of file TimingCache.cxx.

References ana::assert(), nova::dbi::Row::Channel(), nova::dbi::Row::Col(), calib::TimingCache::DelayRec::dcmoffset, allTimeWatchdog::endl, fCSVSource, fCurDet, fEpoch, fInitializedData, fInitializedMC, fMapData, fMapMC, fMaxTime, fMinTime, genie::utils::style::Format(), fReadEpochsFromCSV, fRun, fTag, fUseCSVsFromUPS, fUseEpochs, nova::dbi::Column::Get(), nova::dbi::Table::GetColIndex(), calib::getCSVFilenameByParsingDirectory(), calib::getDetString(), cet::getenv(), GetEpochFromDB(), novadaq::cnv::DetInfo::GetName(), nova::dbi::Table::GetRow(), nova::dbi::kDataOnly, nova::dbi::kMCOnly, nova::dbi::Table::Load(), nova::dbi::Table::LoadFromCSV(), nova::dbi::Table::NRow(), rec, check_grl::row, nova::dbi::Table::SetDataTypeMask(), nova::dbi::Table::SetDetector(), nova::dbi::Table::SetMaxTSVld(), nova::dbi::Table::SetMinTSVld(), nova::dbi::Table::SetTag(), nova::dbi::Table::SetVerbosity(), calib::TimingCache::DelayRec::sigma, and calib::TimingCache::DelayRec::stats.

Referenced by GetOffset(), and GetSigma().

144  {
145  // Even if it goes wrong there's no point trying again
146  if(isData){
147  fInitializedData = true;
148  }
149  else{
150  fInitializedMC = true;
151  }
152 
153  //if this is MC, move the mintime away from 0
154  if (!isData && fMinTime == 0){
155  fMinTime = 1;
156  fMaxTime = 2;
157  }
158  mf::LogInfo("TimingCache")
159  << "Initializing timing delay cache for "
160  << novadaq::cnv::DetInfo::GetName(fCurDet) << " from database...\n";
161 
162 
163  nova::dbi::Table tblConsts("Calibration/tables/CalibTimingConsts.xml");
164  tblConsts.SetDetector(fCurDet);
165  tblConsts.SetDataTypeMask(isData ? nova::dbi::kDataOnly : nova::dbi::kMCOnly);
166  if(!fTag.empty()) tblConsts.SetTag(fTag);
167  tblConsts.SetVerbosity(100);
168 
169  tblConsts.SetMinTSVld(fMinTime);
170  tblConsts.SetMaxTSVld(fMaxTime);
171 
172  bool ok = true;
173 
174  if(fUseCSVsFromUPS || !fCSVSource.empty()){
175  std::string csvSource = fCSVSource;
176  if(fUseCSVsFromUPS){
177  const char* ups_path = getenv("CALIBCSVS_CSV_PATH");
178  assert(ups_path);
179  //RJN fix dteStr
180  const char* detStr = getDetString(fCurDet);
181  const char* mcStr = isData ? "data" : "mc";
182 
183 
184  if (fReadEpochsFromCSV){
185  //Wil now attempt to read the dcm_offsets filename
186  std::string prePattern=TString::Format("%s/%s/calib_dcm_delay_consts.%s.%s.%s", ups_path, fTag.c_str(),
187  detStr, mcStr, fTag.c_str()).Data();
188  std::string postPattern=TString::Format(".csv").Data();
189  csvSource=getCSVFilenameByParsingDirectory(fRun,prePattern,postPattern);
190  }
191  else if (fUseEpochs) {
192  GetEpochFromDB(fCurDet,isData);
193  assert(!fEpoch.empty());
194  csvSource = TString::Format("%s/%s/calib_dcm_delay_consts.%s.%s.%s.%s.csv",
195  ups_path, fTag.c_str(),
196  detStr, mcStr, fTag.c_str(),
197  fEpoch.c_str()).Data();
198  }
199  else {
200  csvSource = TString::Format("%s/%s/calib_dcm_delay_consts.%s.%s.%s.csv",
201  ups_path, fTag.c_str(),
202  detStr, mcStr, fTag.c_str()).Data();
203  }
204  }
205 
206  mf::LogInfo("TimingCache") << "Loading timing cache from "
207  << csvSource << std::endl;
208  ok = ok && (tblConsts.LoadFromCSV(csvSource) > 0);
209  }
210  else{
211  ok = ok && tblConsts.Load();
212  }
213 
214 
215  if(!ok){
216  // No safe way to handle this
217  mf::LogError("TimingCache") << "Unable to load timing delay tables. No timing delays will be set."
218  << std::endl;
219  std::abort();
220  }
221  else{
222  const int dcmoffsetCol = tblConsts.GetColIndex("dcmoffset");
223  const int sigmaCol = tblConsts.GetColIndex("sigma");
224  const int statsCol = tblConsts.GetColIndex("stats");
225 
226  const int Nconsts = tblConsts.NRow();
227  for(int nconsts = 0; nconsts < Nconsts; ++nconsts){
228  nova::dbi::Row* row = tblConsts.GetRow(nconsts);
229 
230  const int dcmkey = row->Channel();
231 
232  DelayRec rec;
233 
234  ok = ok && row->Col(dcmoffsetCol).Get(rec.dcmoffset);
235  ok = ok && row->Col(sigmaCol).Get(rec.sigma);
236  ok = ok && row->Col(statsCol).Get(rec.stats);
237 
238  //For data, abort if the value is bad,
239  if(isData && !ok) std::abort();
240 
241  if (ok&&isData) fMapData[dcmkey] = rec;
242  if (ok&&!isData) fMapMC[dcmkey] = rec;
243  } // end for nconsts
244  }
245 
246  }
void GetEpochFromDB(int idet, bool isData)
static std::string GetName(int id)
Column & Col(int i)
Find index of column with name. Suitable for passing to Col.
Definition: Row.h:63
novadaq::cnv::DetId fCurDet
Definition: TimingCache.h:67
std::map< int, DelayRec > fMapData
Definition: TimingCache.h:70
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
caf::StandardRecord * rec
Definition: tutCAFMacro.C:20
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool Get(T &val) const
Definition: Column.h:85
std::string fCSVSource
Definition: TimingCache.h:57
std::string getCSVFilenameByParsingDirectory(int fCurrentRun, std::string prePattern, std::string postPattern)
Definition: CalibUtil.cxx:706
std::string getenv(std::string const &name)
std::string fTag
Definition: TimingCache.h:59
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const char * getDetString(novadaq::cnv::DetId det)
Utility function to get detector name as a string for file manipulations.
Definition: CalibUtil.cxx:29
std::uint32_t fMinTime
Definition: TimingCache.h:68
unsigned long long Channel()
Definition: Row.h:68
std::string fEpoch
Definition: TimingCache.h:61
assert(nhit_max >=nhit_nbins)
std::map< int, DelayRec > fMapMC
Definition: TimingCache.h:71
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
std::uint32_t fMaxTime
Definition: TimingCache.h:68
void calib::TimingCache::ReadEpochsFromCSV ( bool  readEpochs = true)
inline
int calib::TimingCache::Run ( )
inline

Definition at line 33 of file TimingCache.h.

References fRun, and GetEpochFromDB().

33 { return fRun; }
void calib::TimingCache::SetCSVSource ( const std::string &  src)
inline

Definition at line 22 of file TimingCache.h.

References fCSVSource.

Referenced by calib::Calibrator::Calibrator().

22 {fCSVSource = src;}
std::string fCSVSource
Definition: TimingCache.h:57
void calib::TimingCache::SetEpoch ( const std::string &  epoch)
inline

Definition at line 28 of file TimingCache.h.

References fEpoch.

Referenced by calib::Calibrator::postBeginRun().

28 {fEpoch = epoch; }
std::string fEpoch
Definition: TimingCache.h:61
void calib::TimingCache::SetEpochTag ( const std::string &  tag)
inline

Definition at line 29 of file TimingCache.h.

References fEpochTag, and getGoodRuns4SAM::tag.

Referenced by calib::Calibrator::Calibrator().

void calib::TimingCache::SetRun ( int  run)
inline
void calib::TimingCache::SetTag ( const std::string &  tag)
inline

Definition at line 24 of file TimingCache.h.

References fTag, and getGoodRuns4SAM::tag.

Referenced by calib::Calibrator::Calibrator().

void calib::TimingCache::SetUseEpochs ( bool  use = true)
inline

Definition at line 26 of file TimingCache.h.

References fUseEpochs.

Referenced by calib::Calibrator::Calibrator().

26 {fUseEpochs = use;}
void calib::TimingCache::SetVldTime ( novadaq::cnv::DetId  det,
std::uint32_t  minTime,
std::uint32_t  maxTime 
)

Definition at line 108 of file TimingCache.cxx.

References fillBadChanDBTables::det, fCurDet, fInitializedData, fInitializedMC, fMapData, fMapMC, fMaxTime, and fMinTime.

Referenced by calib::Calibrator::EnsureTimingCacheVldTime(), and ReadEpochsFromCSV().

109  {
110  if(det != fCurDet || minTime != fMinTime || maxTime != fMaxTime){
111  fInitializedData = false;
112  fInitializedMC = false;
113  fMapMC.clear();
114  fMapData.clear();
115 
116  fCurDet = det;
117  fMinTime= minTime;
118  fMaxTime = maxTime;
119  }
120  }
novadaq::cnv::DetId fCurDet
Definition: TimingCache.h:67
std::map< int, DelayRec > fMapData
Definition: TimingCache.h:70
std::uint32_t fMinTime
Definition: TimingCache.h:68
std::map< int, DelayRec > fMapMC
Definition: TimingCache.h:71
std::uint32_t fMaxTime
Definition: TimingCache.h:68
void calib::TimingCache::UseCSVsFromUPS ( bool  use = true)
inline

Definition at line 23 of file TimingCache.h.

References fUseCSVsFromUPS.

Referenced by calib::Calibrator::Calibrator().

23 {fUseCSVsFromUPS = use;}
bool calib::TimingCache::UseEpochs ( )
inline

Definition at line 27 of file TimingCache.h.

References fUseEpochs.

Referenced by calib::Calibrator::postBeginRun().

27 {return fUseEpochs; }

Member Data Documentation

std::string calib::TimingCache::fCSVSource
protected

Definition at line 57 of file TimingCache.h.

Referenced by LoadFromDatabase(), and SetCSVSource().

novadaq::cnv::DetId calib::TimingCache::fCurDet
protected

Definition at line 67 of file TimingCache.h.

Referenced by LoadFromDatabase(), and SetVldTime().

std::string calib::TimingCache::fEpoch
protected

Definition at line 61 of file TimingCache.h.

Referenced by Epoch(), GetEpochFromDB(), LoadFromDatabase(), and SetEpoch().

std::string calib::TimingCache::fEpochTag
protected

Definition at line 62 of file TimingCache.h.

Referenced by EpochTag(), GetEpochFromDB(), and SetEpochTag().

bool calib::TimingCache::fInitializedData
protected

Definition at line 55 of file TimingCache.h.

Referenced by GetOffset(), GetSigma(), LoadFromDatabase(), and SetVldTime().

bool calib::TimingCache::fInitializedMC
protected

Definition at line 54 of file TimingCache.h.

Referenced by GetOffset(), GetSigma(), LoadFromDatabase(), and SetVldTime().

std::map<int, DelayRec> calib::TimingCache::fMapData
protected

Definition at line 70 of file TimingCache.h.

Referenced by GetOffset(), GetSigma(), LoadFromDatabase(), and SetVldTime().

std::map<int, DelayRec> calib::TimingCache::fMapMC
protected

Definition at line 71 of file TimingCache.h.

Referenced by GetOffset(), GetSigma(), LoadFromDatabase(), and SetVldTime().

std::uint32_t calib::TimingCache::fMaxTime
protected

Definition at line 68 of file TimingCache.h.

Referenced by LoadFromDatabase(), and SetVldTime().

std::uint32_t calib::TimingCache::fMinTime
protected

Definition at line 68 of file TimingCache.h.

Referenced by LoadFromDatabase(), and SetVldTime().

bool calib::TimingCache::fReadEpochsFromCSV
protected

Definition at line 65 of file TimingCache.h.

Referenced by LoadFromDatabase(), and ReadEpochsFromCSV().

int calib::TimingCache::fRun
protected

Definition at line 63 of file TimingCache.h.

Referenced by GetEpochFromDB(), LoadFromDatabase(), Run(), and SetRun().

std::string calib::TimingCache::fTag
protected

Definition at line 59 of file TimingCache.h.

Referenced by LoadFromDatabase(), and SetTag().

bool calib::TimingCache::fUseCSVsFromUPS
protected

Definition at line 58 of file TimingCache.h.

Referenced by LoadFromDatabase(), and UseCSVsFromUPS().

bool calib::TimingCache::fUseEpochs
protected

Definition at line 60 of file TimingCache.h.

Referenced by LoadFromDatabase(), SetUseEpochs(), and UseEpochs().


The documentation for this class was generated from the following files: