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

Look up absolute attenuation constants. More...

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

Classes

struct  Record
 

Public Member Functions

 AbsCache ()
 
virtual ~AbsCache ()
 
double GetPECorrToGeVScale (novadaq::cnv::DetId det, int diblock, bool isData)
 
void SetCSVSource (const std::string &src)
 
void UseCSVsFromUPS (bool use=true)
 
void SetTag (const std::string &tag)
 
void SetGainSetting (int g)
 
int GainSetting ()
 
void Reinit ()
 
void SetUseEpochs (bool b)
 
bool UseEpochs ()
 
void SetEpoch (const std::string &epoch)
 
void SetEpochTag (const std::string &tag)
 
std::string Epoch ()
 
std::string EpochTag ()
 
void GetEpochFromDB (int idet, bool isData)
 
void ReadEpochsFromCSV (bool readEpochs=true)
 
void SetRun (int run)
 
int Run ()
 

Protected Member Functions

void LoadFromVldDatabase (novadaq::cnv::DetId det, bool isData)
 

Protected Attributes

bool fUseEpochs
 
int fRun
 
std::string fCSVSource
 
bool fUseCSVsFromUPS
 
int fGainSetting
 
std::string fTag
 
std::string fEpoch
 
std::string fEpochTag
 
bool fReadEpochsFromCSV
 
bool fInitializedData
 Whether we have (attempted to) read from db or csv yet. More...
 
bool fInitializedMC
 
std::map< int, RecordfRecordsData
 Map is from diblock number. More...
 
std::map< int, RecordfRecordsMC
 Map is from diblock number. More...
 

Detailed Description

Look up absolute attenuation constants.

Definition at line 16 of file AbsCache.h.

Constructor & Destructor Documentation

calib::AbsCache::AbsCache ( )

Definition at line 22 of file AbsCache.cxx.

23  : fGainSetting(0),
24  fInitializedData(false), fInitializedMC(false)
25  {
26  }
bool fInitializedMC
Definition: AbsCache.h:84
int fGainSetting
Definition: AbsCache.h:74
bool fInitializedData
Whether we have (attempted to) read from db or csv yet.
Definition: AbsCache.h:83
calib::AbsCache::~AbsCache ( )
virtual

Definition at line 29 of file AbsCache.cxx.

30  {
31  }

Member Function Documentation

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

Definition at line 50 of file AbsCache.h.

References fEpoch.

50 {return fEpoch;}
std::string fEpoch
Definition: AbsCache.h:76
std::string calib::AbsCache::EpochTag ( )
inline

Definition at line 51 of file AbsCache.h.

References fEpochTag, and GetEpochFromDB().

51 {return fEpochTag;}
std::string fEpochTag
Definition: AbsCache.h:77
int calib::AbsCache::GainSetting ( )
inline

Definition at line 33 of file AbsCache.h.

References fGainSetting.

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

33 {return fGainSetting;}
int fGainSetting
Definition: AbsCache.h:74
void calib::AbsCache::GetEpochFromDB ( int  idet,
bool  isData 
)

Definition at line 155 of file AbsCache.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 EpochTag(), and LoadFromVldDatabase().

156  {
157  nova::dbi::Table tbl("Calibration/tables/CalibAbsEpochs.xml");
158  if (isData)
159  tbl.SetDataTypeMask(nova::dbi::kDataOnly);
160  else
161  tbl.SetDataTypeMask(nova::dbi::kMCOnly);
162  tbl.SetDetector(idet);
163  tbl.SetTag(fEpochTag);
164  tbl.SetMinTSVld(fRun);
165  tbl.SetMaxTSVld(fRun);
166  assert(tbl.Load());
167  assert(tbl.NRow() == 1);
168 
169 
170  //RJN does this table have a row for a default testbeam epoch??
171  int epochIdx = tbl.GetColIndex("epoch");
172  tbl.GetRow(0)->Col(epochIdx).Get(fEpoch);
173  }
std::string fEpoch
Definition: AbsCache.h:76
assert(nhit_max >=nhit_nbins)
std::string fEpochTag
Definition: AbsCache.h:77
double calib::AbsCache::GetPECorrToGeVScale ( novadaq::cnv::DetId  det,
int  diblock,
bool  isData 
)

Definition at line 34 of file AbsCache.cxx.

References fRecordsData, fRecordsMC, it, LoadFromVldDatabase(), calib::AbsCache::Record::meu, calib::AbsCache::Record::meuGeV, and rec.

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

37  {
38  LoadFromVldDatabase(det, isData);
39 
40  const std::map<int, Record>& recs = isData ? fRecordsData : fRecordsMC;
41 
42  auto it = recs.find(diblock);
43  if(it == recs.end()) return -1;
44  const Record& rec = it->second;
45  return rec.meuGeV / rec.meu;
46  }
diblock
print "ROW IS " print row
Definition: geo2elec.py:31
set< int >::iterator it
caf::StandardRecord * rec
Definition: tutCAFMacro.C:20
void LoadFromVldDatabase(novadaq::cnv::DetId det, bool isData)
Definition: AbsCache.cxx:49
std::map< int, Record > fRecordsData
Map is from diblock number.
Definition: AbsCache.h:86
std::map< int, Record > fRecordsMC
Map is from diblock number.
Definition: AbsCache.h:87
void calib::AbsCache::LoadFromVldDatabase ( novadaq::cnv::DetId  det,
bool  isData 
)
protected

Definition at line 49 of file AbsCache.cxx.

References ana::assert(), om::cerr, nova::dbi::Row::Channel(), nova::dbi::Row::Col(), geo2elec::diblock, allTimeWatchdog::endl, fCSVSource, fEpoch, fGainSetting, fInitializedData, fInitializedMC, genie::utils::style::Format(), fReadEpochsFromCSV, fRecordsData, fRecordsMC, 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(), calib::AbsCache::Record::meu, calib::AbsCache::Record::meuErr, calib::AbsCache::Record::meuGeV, 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(), and nova::dbi::Table::SetVerbosity().

Referenced by GetPECorrToGeVScale().

50  {
51  if(isData){
52  if(fInitializedData) return;
53  // Even if it goes wrong there's no point trying again
54  fInitializedData = true;
55  }
56  else{
57  if(fInitializedMC) return;
58  fInitializedMC = true;
59  }
60 
61 
62  mf::LogInfo("AbsCache")
63  << "Loading absolute energy constants for " << novadaq::cnv::DetInfo::GetName(det) << " from CSV... fReadEpochsFromCSV " << fReadEpochsFromCSV <<"\tisData\t" << isData << "\n" ;
64 
65  nova::dbi::Table tblConsts("Calibration/tables/CalibAbsConsts.xml");
66  tblConsts.SetDetector(det);
67  tblConsts.SetDataTypeMask(isData ? nova::dbi::kDataOnly : nova::dbi::kMCOnly);
68  if(!fTag.empty()) tblConsts.SetTag(fTag);
69  tblConsts.SetVerbosity(100);
70 
71  tblConsts.SetMinTSVld(1);
72  tblConsts.SetMaxTSVld(100);
73 
74  bool ok = true;
75 
76  if(fUseCSVsFromUPS || !fCSVSource.empty()){
77  std::string csvSource = fCSVSource;
78  if(fUseCSVsFromUPS){
79  const char* ups_path = getenv("CALIBCSVS_CSV_PATH");
80  assert(ups_path);
81  const char* detStr = getDetString(det);
82  const char* mcStr = isData ? "data" : "mc";
83 
84  if(fReadEpochsFromCSV) {
85  //Wil now attempt to read the absolute calibration filename
86  std::string prePattern=TString::Format("%s/%s/calib_abs_consts.%s.%s.%s", ups_path, fTag.c_str(),
87  detStr, mcStr, fTag.c_str()).Data();
88  std::string postPattern=TString::Format(".csv").Data();
89  csvSource=getCSVFilenameByParsingDirectory(fRun,prePattern,postPattern);
90  }
91  else if (fUseEpochs) {
92  GetEpochFromDB(det,isData);
93  assert(!fEpoch.empty());
94  csvSource = TString::Format("%s/%s/calib_abs_consts.%s.%s.%s.%s.csv",
95  ups_path, fTag.c_str(), detStr,
96  mcStr, fTag.c_str(), fEpoch.c_str()).Data();
97  }
98  else {
99  if (!fGainSetting)
100  csvSource = TString::Format("%s/%s/calib_abs_consts.%s.%s.%s.csv",
101  ups_path, fTag.c_str(),
102  detStr, mcStr, fTag.c_str()).Data();
103  else {
104  csvSource = TString::Format("%s/%s/calib_abs_consts.%s.%s.%s.g%d.csv",
105  ups_path, fTag.c_str(), detStr, mcStr,
106  fTag.c_str(), fGainSetting).Data();
107  }
108  }
109  }
110 
111  mf::LogInfo("AbsCache") << "Loading absolute cache from "
112  << csvSource << std::endl;
113  ok = ok && (tblConsts.LoadFromCSV(csvSource) > 0);
114  }
115  else{
116  ok = ok && tblConsts.Load();
117  }
118 
119  if(!ok){
120  // No safe way to handle this
121  mf::LogError("AbsCache") << "Unable to load absolute tables. Aborting"
122  << std::endl;
123  // I've definitely seen mf lose races with shutdown
124  std::cerr << "Unable to load absolute tables. Aborting"
125  << std::endl;
126  abort();
127  }
128 
129  const int meuCol = tblConsts.GetColIndex("meu");
130  const int meuErrCol = tblConsts.GetColIndex("meu_err");
131  const int meuGeVCol = tblConsts.GetColIndex("meu_gev");
132 
133  const int Nconsts = tblConsts.NRow();
134  for(int nconsts = 0; nconsts < Nconsts; ++nconsts){
135  nova::dbi::Row* row = tblConsts.GetRow(nconsts);
136 
137  const int diblock = row->Channel();
138 
139  Record rec;
140 
141  ok = ok && row->Col(meuCol).Get(rec.meu);
142  ok = ok && row->Col(meuErrCol).Get(rec.meuErr);
143  ok = ok && row->Col(meuGeVCol).Get(rec.meuGeV);
144 
145  assert(ok);
146 
147  if(isData)
149  else
151  } // end for nconsts
152  }
static std::string GetName(int id)
void GetEpochFromDB(int idet, bool isData)
Definition: AbsCache.cxx:155
diblock
print "ROW IS " print row
Definition: geo2elec.py:31
Column & Col(int i)
Find index of column with name. Suitable for passing to Col.
Definition: Row.h:63
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool fReadEpochsFromCSV
Definition: AbsCache.h:79
OStream cerr
Definition: OStream.cxx:7
caf::StandardRecord * rec
Definition: tutCAFMacro.C:20
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool Get(T &val) const
Definition: Column.h:85
std::string getCSVFilenameByParsingDirectory(int fCurrentRun, std::string prePattern, std::string postPattern)
Definition: CalibUtil.cxx:706
std::string fCSVSource
Definition: AbsCache.h:72
bool fUseEpochs
Definition: AbsCache.h:70
std::string getenv(std::string const &name)
std::string fTag
Definition: AbsCache.h:75
std::map< int, Record > fRecordsData
Map is from diblock number.
Definition: AbsCache.h:86
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::string fEpoch
Definition: AbsCache.h:76
bool fInitializedMC
Definition: AbsCache.h:84
int fGainSetting
Definition: AbsCache.h:74
const char * getDetString(novadaq::cnv::DetId det)
Utility function to get detector name as a string for file manipulations.
Definition: CalibUtil.cxx:29
unsigned long long Channel()
Definition: Row.h:68
assert(nhit_max >=nhit_nbins)
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
bool fUseCSVsFromUPS
Definition: AbsCache.h:73
std::map< int, Record > fRecordsMC
Map is from diblock number.
Definition: AbsCache.h:87
bool fInitializedData
Whether we have (attempted to) read from db or csv yet.
Definition: AbsCache.h:83
void calib::AbsCache::ReadEpochsFromCSV ( bool  readEpochs = true)
inline

Definition at line 55 of file AbsCache.h.

References fReadEpochsFromCSV.

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

55 {fReadEpochsFromCSV=readEpochs;}
bool fReadEpochsFromCSV
Definition: AbsCache.h:79
void calib::AbsCache::Reinit ( )
inline

Definition at line 35 of file AbsCache.h.

References fInitializedData, fInitializedMC, fRecordsData, and fRecordsMC.

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

36  {
37  fRecordsData.clear();
38  fInitializedData = false;
39  fRecordsMC.clear();
40  fInitializedMC = false;
41  }
std::map< int, Record > fRecordsData
Map is from diblock number.
Definition: AbsCache.h:86
bool fInitializedMC
Definition: AbsCache.h:84
std::map< int, Record > fRecordsMC
Map is from diblock number.
Definition: AbsCache.h:87
bool fInitializedData
Whether we have (attempted to) read from db or csv yet.
Definition: AbsCache.h:83
int calib::AbsCache::Run ( )
inline

Definition at line 58 of file AbsCache.h.

References fRun.

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

Definition at line 26 of file AbsCache.h.

References fCSVSource.

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

26 {fCSVSource = src;}
std::string fCSVSource
Definition: AbsCache.h:72
void calib::AbsCache::SetEpoch ( const std::string &  epoch)
inline

Definition at line 47 of file AbsCache.h.

References fEpoch.

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

47 {fEpoch = epoch;}
std::string fEpoch
Definition: AbsCache.h:76
void calib::AbsCache::SetEpochTag ( const std::string &  tag)
inline

Definition at line 48 of file AbsCache.h.

References fEpochTag, and getGoodRuns4SAM::tag.

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

48 {fEpochTag = tag;}
std::string fEpochTag
Definition: AbsCache.h:77
void calib::AbsCache::SetGainSetting ( int  g)
inline
void calib::AbsCache::SetRun ( int  run)
inline

Definition at line 57 of file AbsCache.h.

References fRun, and updateRunHistoryTables::run.

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

void calib::AbsCache::SetTag ( const std::string &  tag)
inline

Definition at line 30 of file AbsCache.h.

References fTag, and getGoodRuns4SAM::tag.

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

30 {fTag = tag;}
std::string fTag
Definition: AbsCache.h:75
void calib::AbsCache::SetUseEpochs ( bool  b)
inline

Definition at line 43 of file AbsCache.h.

References b, and fUseEpochs.

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

43 { fUseEpochs = b; }
bool fUseEpochs
Definition: AbsCache.h:70
const hit & b
Definition: hits.cxx:21
void calib::AbsCache::UseCSVsFromUPS ( bool  use = true)
inline

Definition at line 28 of file AbsCache.h.

References fUseCSVsFromUPS.

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

28 {fUseCSVsFromUPS = use;}
bool fUseCSVsFromUPS
Definition: AbsCache.h:73
bool calib::AbsCache::UseEpochs ( )
inline

Definition at line 45 of file AbsCache.h.

References fUseEpochs.

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

45 {return fUseEpochs;}
bool fUseEpochs
Definition: AbsCache.h:70

Member Data Documentation

std::string calib::AbsCache::fCSVSource
protected

Definition at line 72 of file AbsCache.h.

Referenced by LoadFromVldDatabase(), and SetCSVSource().

std::string calib::AbsCache::fEpoch
protected

Definition at line 76 of file AbsCache.h.

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

std::string calib::AbsCache::fEpochTag
protected

Definition at line 77 of file AbsCache.h.

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

int calib::AbsCache::fGainSetting
protected

Definition at line 74 of file AbsCache.h.

Referenced by GainSetting(), LoadFromVldDatabase(), and SetGainSetting().

bool calib::AbsCache::fInitializedData
protected

Whether we have (attempted to) read from db or csv yet.

Definition at line 83 of file AbsCache.h.

Referenced by LoadFromVldDatabase(), and Reinit().

bool calib::AbsCache::fInitializedMC
protected

Definition at line 84 of file AbsCache.h.

Referenced by LoadFromVldDatabase(), and Reinit().

bool calib::AbsCache::fReadEpochsFromCSV
protected

Definition at line 79 of file AbsCache.h.

Referenced by LoadFromVldDatabase(), and ReadEpochsFromCSV().

std::map<int, Record> calib::AbsCache::fRecordsData
protected

Map is from diblock number.

Definition at line 86 of file AbsCache.h.

Referenced by GetPECorrToGeVScale(), LoadFromVldDatabase(), and Reinit().

std::map<int, Record> calib::AbsCache::fRecordsMC
protected

Map is from diblock number.

Definition at line 87 of file AbsCache.h.

Referenced by GetPECorrToGeVScale(), LoadFromVldDatabase(), and Reinit().

int calib::AbsCache::fRun
protected

Definition at line 71 of file AbsCache.h.

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

std::string calib::AbsCache::fTag
protected

Definition at line 75 of file AbsCache.h.

Referenced by LoadFromVldDatabase(), and SetTag().

bool calib::AbsCache::fUseCSVsFromUPS
protected

Definition at line 73 of file AbsCache.h.

Referenced by LoadFromVldDatabase(), and UseCSVsFromUPS().

bool calib::AbsCache::fUseEpochs
protected

Definition at line 70 of file AbsCache.h.

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


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