BeamMomTable Class Reference

Interface to BeamMomTable database table. More...

#include <BeamMomTable.h>

List of all members.

Public Member Functions

 ~BeamMomTable ()
bool Init (int run)
float Momentum () const
float Width () const
void Set (float mom, float width)
void SetRunRange (int minrun, int maxrun)
void WriteToDB ()

Static Public Member Functions

static BeamMomTableInstance ()

Private Member Functions

 BeamMomTable ()

Private Attributes

int fMinRun
int fMaxRun
float fMomentum
 Momentum * Q (GeV/c).
float fWidth
 Width of momentum distribution (GeV/c).

Static Private Attributes

static BeamMomTablefsInstance = 0


Detailed Description

Interface to BeamMomTable database table.

Definition at line 16 of file BeamMomTable.h.


Constructor & Destructor Documentation

BeamMomTable::~BeamMomTable (  )  [inline]

Definition at line 19 of file BeamMomTable.h.

00019 {;}

BeamMomTable::BeamMomTable (  )  [private]

Definition at line 27 of file BeamMomTable.cxx.

00027                            :
00028   fMinRun(0),
00029   fMaxRun(0),
00030   fMomentum(0),
00031   fWidth(0)
00032 {
00033 }


Member Function Documentation

bool BeamMomTable::Init ( int  run  ) 

Definition at line 45 of file BeamMomTable.cxx.

References fMaxRun, fMinRun, fMomentum, fWidth, GET_FLOAT, GET_INT, MdbTableDict::GetTableRSR(), MdbTableDict::Instance(), MdbAbsRelDBTable::NumberOfCachedRows(), MXML::ReadFile(), and MdbTableRunSubRun::Select().

00046 {
00047   if (fMinRun <= run && fMaxRun >= run) return true;
00048   
00049   MXML::ReadFile("BeamMomTable.xml");
00050   MdbTableRunSubRun* table =
00051     MdbTableDict::Instance()->GetTableRSR("BeamMom");
00052   if(!table) {
00053     cout << "Couldn't find BeamMom table!" << endl;
00054     return false;
00055   }
00056 
00057   fMinRun = run;
00058   fMaxRun = run;
00059   fMomentum = 0;
00060   fWidth = 0;
00061 
00062   vector<string> cols;
00063   MdbAbsRelDBTable* query = table->Select(cols, run);
00064   int nRows = query->NumberOfCachedRows();
00065   if (nRows == 0) {
00066     cout << "BeamMomTable: found no rows for run " << run
00067               << endl;
00068     return false;
00069   }
00070 
00071   if (nRows != 1) {
00072     cout << "BeamMomTable: found " << nRows << " rows for run " << run
00073      << "; only the first row will be used" << endl;
00074   }
00075 #define GET_INT(name) query->getCachedTableDataPtr(string(name), 0)->valInt()[0]
00076 #define GET_FLOAT(name) query->getCachedTableDataPtr(string(name), 0)->valFloat()[0]
00077   
00078   fMinRun = GET_INT("runNumMin");
00079   fMaxRun = GET_INT("runNumMax");
00080   fMomentum = GET_FLOAT("momentum");
00081   fWidth    = GET_FLOAT("width");
00082 
00083 #undef GET_VEC  
00084   return true;
00085 } 

BeamMomTable & BeamMomTable::Instance (  )  [static]

Definition at line 37 of file BeamMomTable.cxx.

References fsInstance.

Referenced by BeamMomCalc::EndRun().

00038 {
00039   if (!fsInstance) fsInstance = new BeamMomTable;
00040   return *fsInstance;
00041 }

float BeamMomTable::Momentum (  )  const [inline]

Definition at line 23 of file BeamMomTable.h.

References fMomentum.

00023 {return fMomentum;}

void BeamMomTable::Set ( float  mom,
float  width 
) [inline]

Definition at line 26 of file BeamMomTable.h.

References fMomentum, and fWidth.

Referenced by BeamMomCalc::EndRun().

00026 { fMomentum = mom; fWidth = width; }

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

Definition at line 27 of file BeamMomTable.h.

References fMaxRun, and fMinRun.

Referenced by BeamMomCalc::EndRun().

00027                                            {
00028     fMinRun = minrun; fMaxRun = maxrun;
00029   }

float BeamMomTable::Width (  )  const [inline]

Definition at line 24 of file BeamMomTable.h.

References fWidth.

00024 {return fWidth;}

void BeamMomTable::WriteToDB (  ) 

Definition at line 89 of file BeamMomTable.cxx.

References MdbDatabase::dbVar(), fMaxRun, fMinRun, fMomentum, fWidth, MdbTableDict::GetTableRSR(), MdbTableRunSubRun::InsertRow(), MdbDatabase::Instance(), MdbTableDict::Instance(), and MXML::ReadFile().

Referenced by BeamMomCalc::EndRun().

00090 {
00091   if (strcmp(getenv("PGUSER"), "mippdbwrite") != 0) {
00092     cout << "BeamMomTable: asked to write to DB, but PGUSER="
00093      << getenv("PGUSER") << ". Cannot perform task."
00094      << endl;
00095     return;
00096   }
00097 
00098   MXML::ReadFile("BeamMomTable.xml");
00099   MdbTableRunSubRun* table =
00100     MdbTableDict::Instance()->GetTableRSR("BeamMom");
00101   if (!table) return;
00102 
00103   MdbDatabase* dbFact = MdbDatabase::Instance();
00104   std::vector<MdbAbsRelDBVar*> vars(0);
00105 
00106   vars.push_back(dbFact->dbVar(fMomentum));
00107   vars.push_back(dbFact->dbVar(fWidth));
00108 
00109   table->InsertRow(vars, fMinRun, 0, fMaxRun, 9999, 1);
00110 }


Member Data Documentation

int BeamMomTable::fMaxRun [private]

Definition at line 40 of file BeamMomTable.h.

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

int BeamMomTable::fMinRun [private]

Definition at line 39 of file BeamMomTable.h.

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

float BeamMomTable::fMomentum [private]

Momentum * Q (GeV/c).

Definition at line 42 of file BeamMomTable.h.

Referenced by Init(), Momentum(), Set(), and WriteToDB().

BeamMomTable * BeamMomTable::fsInstance = 0 [static, private]

Definition at line 37 of file BeamMomTable.h.

Referenced by Instance().

float BeamMomTable::fWidth [private]

Width of momentum distribution (GeV/c).

Definition at line 43 of file BeamMomTable.h.

Referenced by Init(), Set(), Width(), and WriteToDB().


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