Public Member Functions | Private Attributes | List of all members
calib::CDPStorage Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-08-04/Calibration/CDPStorage.h"

Public Member Functions

 CDPStorage (fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
 
 ~CDPStorage ()
 
void reconfigure (const fhicl::ParameterSet &pset)
 
void postCloseOutputFile (art::OutputFileInfo const &ofi)
 
void postOpenFile (std::string const &fn)
 
void DriftResponseToStore (std::vector< caldp::DriftResponse > &drvec)
 
void WriteDriftResponse (art::SQLite3Wrapper &sql3w)
 
void RetrieveDriftCalFromFile (art::SQLite3Wrapper &sql3w)
 
std::vector< caldp::DriftResponse > const & DriftRepsonses () const
 

Private Attributes

std::vector< caldp::DriftResponsefDriftResponseVec
 vector of DriftResponse objects to store More...
 
bool fRetrieveDriftCalFromFile
 

Detailed Description

Definition at line 26 of file CDPStorage.h.

Constructor & Destructor Documentation

calib::CDPStorage::CDPStorage ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry reg 
)

Definition at line 18 of file CDPStorage_service.cc.

References postCloseOutputFile(), postOpenFile(), reconfigure(), art::ActivityRegistry::sPostCloseOutputFile, and art::ActivityRegistry::sPostOpenFile.

20  {
21  this->reconfigure(pset);
23  reg.sPostOpenFile.watch(this, &CDPStorage::postOpenFile);
24  }
void reconfigure(const fhicl::ParameterSet &pset)
void postOpenFile(std::string const &fn)
void postCloseOutputFile(art::OutputFileInfo const &ofi)
GlobalSignal< detail::SignalResponseType::LIFO, void(std::string const &)> sPostOpenFile
GlobalSignal< detail::SignalResponseType::LIFO, void(OutputFileInfo const &)> sPostCloseOutputFile
calib::CDPStorage::~CDPStorage ( )

Definition at line 27 of file CDPStorage_service.cc.

28  {
29  }

Member Function Documentation

std::vector<caldp::DriftResponse> const& calib::CDPStorage::DriftRepsonses ( ) const
inline

Definition at line 41 of file CDPStorage.h.

41 { return fDriftResponseVec; }
std::vector< caldp::DriftResponse > fDriftResponseVec
vector of DriftResponse objects to store
Definition: CDPStorage.h:45
void calib::CDPStorage::DriftResponseToStore ( std::vector< caldp::DriftResponse > &  drvec)

Definition at line 167 of file CDPStorage_service.cc.

References fDriftResponseVec.

Referenced by calib::DriftCorrection::respondToCloseOutputFiles().

168  {
169  fDriftResponseVec.swap(drvec);
170 
171  return;
172  }
std::vector< caldp::DriftResponse > fDriftResponseVec
vector of DriftResponse objects to store
Definition: CDPStorage.h:45
void calib::CDPStorage::postCloseOutputFile ( art::OutputFileInfo const &  ofi)

Definition at line 63 of file CDPStorage_service.cc.

References file, art::OutputFileInfo::fileName(), and WriteDriftResponse().

Referenced by CDPStorage().

64  {
65  std::shared_ptr<TFile> file(TFile::Open(ofi.fileName().c_str(), "UPDATE"));
66 
67  // get the wrapper to the SQLite3 DB
68  art::SQLite3Wrapper sql3w(file.get(),
69  "NOvACalibrations",
70  SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE);
71 
72  this->WriteDriftResponse(sql3w);
73 
74  // write the DB
75  sql3w.reset();
76 
77  // close the ROOT file
78  file->Close();
79 
80  return;
81  }
void WriteDriftResponse(art::SQLite3Wrapper &sql3w)
TFile * file
Definition: cellShifts.C:17
void calib::CDPStorage::postOpenFile ( std::string const &  fn)

Definition at line 40 of file CDPStorage_service.cc.

References file, fRetrieveDriftCalFromFile, and RetrieveDriftCalFromFile().

Referenced by CDPStorage().

41  {
42  // test the input flags to see if we are to get the
43  // stored calibrations from the file - currently only
44  // using this functionality for the drift calibration, but
45  // could use it for others in the future by including ||
46  // with each flag in the following line
48 
49  std::shared_ptr<TFile> file(TFile::Open(fn.c_str(), "READ"));
50 
51  // get the wrapper to the SQLite3 DB
52  art::SQLite3Wrapper sql3w(file.get(),
53  "NOvACalibrations",
54  SQLITE_OPEN_READONLY);
55 
57  }
58 
59  return;
60  }
void RetrieveDriftCalFromFile(art::SQLite3Wrapper &sql3w)
TFile * file
Definition: cellShifts.C:17
bool fRetrieveDriftCalFromFile
Definition: CDPStorage.h:46
void calib::CDPStorage::reconfigure ( const fhicl::ParameterSet pset)

Definition at line 32 of file CDPStorage_service.cc.

References fRetrieveDriftCalFromFile, and fhicl::ParameterSet::get().

Referenced by CDPStorage().

33  {
34  fRetrieveDriftCalFromFile = pset.get<bool>("RetrieveDriftCalFromFile");
35 
36  return;
37  }
T get(std::string const &key) const
Definition: ParameterSet.h:231
bool fRetrieveDriftCalFromFile
Definition: CDPStorage.h:46
void calib::CDPStorage::RetrieveDriftCalFromFile ( art::SQLite3Wrapper sql3w)

Definition at line 175 of file CDPStorage_service.cc.

References make_syst_table_plots::c, DEFINE_ART_SERVICE, LOG_DEBUG, febshutoff_auto::query, and febshutoff_auto::stmt.

Referenced by postOpenFile().

176  {
177 
178  // Read the ParameterSets into memory.
179  sqlite3_stmt *stmt = 0;
180 
181  std::string query("SELECT ID, Channel, Mean, MeanErr, RMS, NHits, StartTime, EndTime from DriftResponse;");
182 
183  LOG_DEBUG("CDPStorage") << query;
184 
185  sqlite3_prepare_v2(sql3w,
186  query.c_str(),
187  -1,
188  &stmt,
189  NULL);
190 
191 
192  while(sqlite3_step(stmt) == SQLITE_ROW){
193  LOG_DEBUG("CDPStorage") << "row returned with " << sqlite3_column_count(stmt) << " columns";
194  for(int c = 0; c < sqlite3_column_count(stmt); ++c)
195  LOG_DEBUG("CDPStorage") << c << " " << sqlite3_column_text(stmt, c);
196  }
197 
198  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void calib::CDPStorage::WriteDriftResponse ( art::SQLite3Wrapper sql3w)

Definition at line 84 of file CDPStorage_service.cc.

References novadaq::messages::error::rc::errMsg, fDriftResponseVec, LOG_DEBUG, caldp::MeanStruct::Mean(), extractScale::mean, caldp::MeanStruct::MeanErr(), caldp::MeanStruct::NHits(), caldp::MeanStruct::RMS(), febshutoff_auto::stmt, and art::SQLErrMsg::throwIfError().

Referenced by postCloseOutputFile().

85  {
87 
88  // make the table for the drift response, one column for each of the important
89  // quantities
90  sqlite3_exec(sql3w,
91  "BEGIN TRANSACTION; " // +
92  "DROP TABLE IF EXISTS DriftResponse; " // +
93  "CREATE TABLE DriftResponse(ID PRIMARY KEY, " // +
94  " Channel INT, " // +
95  " Mean REAL, " // +
96  " MeanErr REAL, " // +
97  " RMS REAL, " // +
98  " NHits INT, " // +
99  " StartTime INT, " // +
100  " EndTime INT );" // +
101  "COMMIT;",
102  0,
103  0,
104  errMsg);
105 
106  // make sure there were no problems
107  errMsg.throwIfError();
108 
109  sqlite3_exec(sql3w, "BEGIN TRANSACTION;", 0, 0, errMsg);
110  sqlite3_stmt *stmt = 0;
111  sqlite3_prepare_v2(sql3w,
112  "INSERT INTO DriftResponse(Channel, Mean, "
113  "MeanErr, RMS, NHits, StartTime, "
114  "EndTime) "
115  "VALUES(?, ?, ?, ?, ?, ?, ?);",
116  -1,
117  &stmt,
118  NULL);
119 
120  LOG_DEBUG("CDPStorage") << " vector size: " << fDriftResponseVec.size();
121 
122 
123  for( auto const& dr : fDriftResponseVec){
124 
125  LOG_DEBUG("CDPStorage") << dr;
126 
127  // get the map of means for each channel number for each
128  // dr
129  auto const& meanMap = dr.ReturnMap();
130 
131  LOG_DEBUG("CDPStorage") << "map size: " << meanMap.size()
132  << " ReturnMap size: " << dr.ReturnMap().size();
133 
134  for(auto const& mitr : meanMap){
135 
136  int channel = mitr.first;
137  caldp::MeanStruct mean = mitr.second;
138 
139  sqlite3_bind_int (stmt, 1, channel );
140  sqlite3_bind_double(stmt, 2, mean.Mean() );
141  sqlite3_bind_double(stmt, 3, mean.MeanErr() );
142  sqlite3_bind_double(stmt, 4, mean.RMS() );
143  sqlite3_bind_int (stmt, 5, mean.NHits() );
144  sqlite3_bind_int (stmt, 6, dr.StartTime() );
145  sqlite3_bind_int (stmt, 7, dr.EndTime() );
146  if( sqlite3_step(stmt) != SQLITE_DONE)
147  throw cet::exception("CDPStorage") << "problem writing to SQLite3 DB";
148  sqlite3_reset(stmt);
149  sqlite3_clear_bindings(stmt);
150 
151  } // end loop over channel to MeanStruct map
152 
153  } // end loop over DriftResponse data products
154 
155  sqlite3_finalize(stmt);
156 
157  sqlite3_exec(sql3w,
158  "END TRANSACTION;",
159  0,
160  0,
161  art::SQLErrMsg());
162 
163  return;
164  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
int NHits() const
Return rms of distribution.
Definition: DriftResponse.h:29
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
static const char *const errMsg[]
Definition: Error.h:69
double RMS() const
Return error on mean.
Definition: DriftResponse.h:28
double Mean() const
Number of hits in mean calculation.
Definition: DriftResponse.h:26
std::vector< caldp::DriftResponse > fDriftResponseVec
vector of DriftResponse objects to store
Definition: CDPStorage.h:45
double MeanErr() const
Return mean.
Definition: DriftResponse.h:27
void throwIfError()

Member Data Documentation

std::vector<caldp::DriftResponse> calib::CDPStorage::fDriftResponseVec
private

vector of DriftResponse objects to store

Definition at line 45 of file CDPStorage.h.

Referenced by DriftResponseToStore(), and WriteDriftResponse().

bool calib::CDPStorage::fRetrieveDriftCalFromFile
private

get the response from the SQLite database after opening the file

Definition at line 46 of file CDPStorage.h.

Referenced by postOpenFile(), and reconfigure().


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