CaloCalib Class Reference

Interface to CaloCalib DB table. More...

#include <CaloCalib.h>

List of all members.

Public Member Functions

 ~CaloCalib ()
float HCalAdcCorr (int channel)
float AdcToEnergy (int detector)
bool Init (int run, int subrun=-1)
bool Set (Entry_t &e)
void SetRunRange (int minrun, int maxrun)
void WriteToXML (const char *fname)
void WriteToDB ()
void Clear ()

Static Public Member Functions

static CaloCalibInstance ()

Private Member Functions

 CaloCalib ()

Private Attributes

int fMinRun
int fMaxRun
Entry_tfEntries

Static Private Attributes

static CaloCalibfInstance = 0

Classes

struct  Entry_t


Detailed Description

Interface to CaloCalib DB table.

Definition at line 15 of file CaloCalib.h.


Constructor & Destructor Documentation

CaloCalib::~CaloCalib (  ) 

Definition at line 41 of file CaloCalib.cxx.

References Clear().

00042 {
00043   Clear();
00044 }

CaloCalib::CaloCalib (  )  [private]

Definition at line 33 of file CaloCalib.cxx.

References Clear().

00033                      :
00034   fMinRun(0), fMaxRun(0)
00035 {
00036   Clear();
00037 }


Member Function Documentation

float CaloCalib::AdcToEnergy ( int  detector  ) 

Definition at line 59 of file CaloCalib.cxx.

References CaloCalib::Entry_t::fEnergyScale, and fEntries.

Referenced by EMCalReco::NewRun().

00060 {
00061   assert (detector >= 0 && detector < 2);
00062   if (fEntries)
00063     return fEntries->fEnergyScale[detector];
00064   else
00065     return -1;
00066 }

void CaloCalib::Clear (  ) 

Definition at line 70 of file CaloCalib.cxx.

References fEntries.

Referenced by CaloCalib(), Init(), and ~CaloCalib().

00071 {
00072     memset(&fEntries,0,sizeof(fEntries));
00073 }

float CaloCalib::HCalAdcCorr ( int  channel  ) 

Definition at line 48 of file CaloCalib.cxx.

References fEntries, and CaloCalib::Entry_t::fHadcCorr.

Referenced by EMCalReco::NewRun().

00049 {
00050   assert (channel >= 0 && channel <= 7);
00051   if (fEntries)
00052     return fEntries->fHadcCorr[channel];
00053   else
00054     return -1;
00055 }

bool CaloCalib::Init ( int  run,
int  subrun = -1 
)

Definition at line 77 of file CaloCalib.cxx.

References Clear(), CaloCalib::Entry_t::fEnergyScale, fEntries, CaloCalib::Entry_t::fHadcCorr, fMaxRun, fMinRun, GET_FLOAT, GET_INT, MdbTableDict::GetTableRSR(), MdbTableDict::Instance(), MdbAbsRelDBTable::NumberOfCachedRows(), MdbTableRunSubRun::Select(), and Set().

Referenced by EMCalReco::NewRun().

00078 {
00079   if ((run >= fMinRun) && (run <= fMaxRun)) return true;
00080 
00081   Clear();
00082 
00083   MdbTableRunSubRun* table = 
00084     MdbTableDict::Instance()->GetTableRSR("CaloCalib");
00085   if (!table) return false;
00086 
00087   vector<string> cols;
00088   MdbAbsRelDBTable* query = table->Select(cols, run, 0);
00089 
00090   int nRows = query->NumberOfCachedRows();
00091   if (nRows == 0) {
00092     cout << "CaloCalib: found no rows for run " << run << ", subrun " 
00093      << subrun << endl;
00094     return false;      
00095   }
00096   
00097   vector<string> comment;
00098   
00099 #define GET_INT(name) query->getCachedTableDataPtr(string(name), row)->valInt()[0]
00100 #define GET_FLOAT(name) query->getCachedTableDataPtr(string(name), row)->valFloat()
00101   Entry_t ent;
00102   for (int row = 0; row < nRows; ++row) {
00103     for (int j=0; j<8; ++j)
00104       {
00105          ent.fHadcCorr[j]    = GET_FLOAT("HADCCorr")[j];
00106       }
00107     ent.fEnergyScale[0] = GET_FLOAT("EnergyScale")[0];
00108     ent.fEnergyScale[1] = GET_FLOAT("EnergyScale")[1];
00109 
00110     Set(ent);
00111 
00112     if (row == 0) {
00113       fMinRun = GET_INT("runNumMin");
00114       fMaxRun = GET_INT("runNumMax");
00115     }
00116   }
00117 
00118 #undef GET_INT
00119 #undef GET_FLOAT
00120 
00121   cout << "CaloCalib: got " << sizeof(fEntries) << " entries." << endl;
00122 
00123   return true;
00124 }

CaloCalib & CaloCalib::Instance (  )  [static]

Definition at line 24 of file CaloCalib.cxx.

References fInstance.

Referenced by EMCalReco::EMCalReco().

00025 {
00026   if (!fInstance) fInstance = new CaloCalib;
00027 
00028   return *fInstance;
00029 }

bool CaloCalib::Set ( Entry_t e  ) 

Definition at line 128 of file CaloCalib.cxx.

References fEntries.

Referenced by Init().

00129 {
00130 
00131   Entry_t* ent = new Entry_t;
00132   memcpy(ent, &e, sizeof(Entry_t));
00133   fEntries = ent;
00134   return true;
00135 }

void CaloCalib::SetRunRange ( int  minrun,
int  maxrun 
) [inline]

Definition at line 32 of file CaloCalib.h.

References fMaxRun, and fMinRun.

00032                                            {
00033     fMinRun = minrun; fMaxRun = maxrun; 
00034   }

void CaloCalib::WriteToDB (  ) 

Definition at line 177 of file CaloCalib.cxx.

References MdbDatabase::dbVar(), CaloCalib::Entry_t::fEnergyScale, fEntries, CaloCalib::Entry_t::fHadcCorr, fMaxRun, fMinRun, MdbTableDict::GetTableRSR(), MdbTableRunSubRun::InsertRow(), MdbDatabase::Instance(), and MdbTableDict::Instance().

00178 {
00179   if (strcmp(getenv("PGUSER"), "mippdbwrite") != 0) {
00180     cout << "CaloCalib: User " << getenv("PGUSER")
00181      << " is not allowed to write to DB"
00182      << endl;
00183   }
00184 
00185   MdbTableRunSubRun* table = 
00186     MdbTableDict::Instance()->GetTableRSR("CaloCalib");  
00187   if (!table) return;
00188   
00189   std::cout << "preparing to write..." << std::endl;
00190 
00191   MdbDatabase *dbFact=MdbDatabase::Instance();
00192 
00193   vector<MdbAbsRelDBVar*> vars;
00194 
00195   vector<float> fhv(0);
00196   vector<float> fev(0);
00197 
00198     for (int i=0; i<8; ++i)
00199       {
00200     fhv.push_back(fEntries->fHadcCorr[i]);
00201       }
00202     for (int i=0; i<2; ++i)
00203       {
00204     fev.push_back(fEntries->fEnergyScale[i]);
00205       }
00206         
00207 
00208     vars.push_back(dbFact->dbVar(fhv));
00209     vars.push_back(dbFact->dbVar(fev));
00210 
00211     std::cout << vars.size() << " " << " " << vars[0] << " " << vars[9] << std::endl;
00212 
00213     table->InsertRow( vars,        // The variables to insert
00214               fMinRun,     // runNumMin
00215               0,           // subrunnummin
00216               fMaxRun,     // runnumMax
00217               9999,        // subrunmax
00218               1);          // write data to db & to cached rows
00219     vars.clear();
00220 }

void CaloCalib::WriteToXML ( const char *  fname  ) 

Definition at line 139 of file CaloCalib.cxx.

References CaloCalib::Entry_t::fEnergyScale, fEntries, CaloCalib::Entry_t::fHadcCorr, fMaxRun, and fMinRun.

00140 {
00141   ofstream ofile(fname, ios::out);
00142   
00143   if (!ofile.is_open()) {
00144     cout << "Couldn't open " << fname << " for writing" << endl;
00145     return;
00146   }
00147   
00148   ofile << "<dbTableEntry TableName=\"CaloCalib\"\n"
00149         << "              TableType=\"RunSubRun\"\n"
00150         << "              runNumMin=\"" << fMinRun << "\"\n"
00151         << "              runNumMax=\"" << fMaxRun << "\"\n"
00152         << "              subrunMin=\"0\"\n"
00153         << "              subrunMax=\"9999\"\n"
00154         << "              creator=\"" << getenv("USER") << "\"\n\n";
00155 
00156   
00157   //Entry_t* tEntry = new Entry_t;
00158     ofile << "  <dbRow>  ";
00159     ofile << fEntries->fHadcCorr[0];
00160     ofile << ", " << fEntries->fHadcCorr[1];
00161     ofile << ", " << fEntries->fHadcCorr[2];
00162     ofile << ", " << fEntries->fHadcCorr[3];
00163     ofile << ", " << fEntries->fHadcCorr[4];
00164     ofile << ", " << fEntries->fHadcCorr[5];
00165     ofile << ", " << fEntries->fHadcCorr[6];
00166     ofile << ", " << fEntries->fHadcCorr[7];
00167     ofile << ", " << fEntries->fEnergyScale[0];
00168     ofile << ", " << fEntries->fEnergyScale[1];
00169     ofile << "  </dbRow>\n";
00170     ofile << "\n  </dbTableEntry>";
00171 
00172   ofile.close();
00173 
00174 }


Member Data Documentation

Entry_t* CaloCalib::fEntries [private]

Definition at line 50 of file CaloCalib.h.

Referenced by AdcToEnergy(), Clear(), HCalAdcCorr(), Init(), Set(), WriteToDB(), and WriteToXML().

CaloCalib * CaloCalib::fInstance = 0 [static, private]

Definition at line 45 of file CaloCalib.h.

Referenced by Instance().

int CaloCalib::fMaxRun [private]

Definition at line 48 of file CaloCalib.h.

Referenced by Init(), SetRunRange(), WriteToDB(), and WriteToXML().

int CaloCalib::fMinRun [private]

Definition at line 47 of file CaloCalib.h.

Referenced by Init(), SetRunRange(), WriteToDB(), and WriteToXML().


The documentation for this class was generated from the following files:
Generated on Mon Nov 23 08:03:59 2009 for MIPP(E907) by  doxygen 1.4.7