emcDB Class Reference
[Databases]

#include <emcDB.h>

List of all members.


Detailed Description

Helper tool to access EMCAL Databases.

It can in particular be used to see the validity ranges for some specific calibrations, dump the raw content of the calibration banks, and upload things from ASCII files to the Pg databases.

This page will teach you how to use the emcDB program to write calibration data ASCII files into the PHENIX EMCAL Postgres databases, and to browse EMCAL databases content.

Disclaimer: the emcDB program is only a convenient tool to update/dump the EMCAL databases. It is not a bullet-proof program ! It can for sure be improved.

Getting help on the emcDB program

You can get the syntax by doing:
emcDB --help

Browsing what is in a given flavour database

Use the following syntax :

emcDB --dump calib.emc.[flavourName]
where flavourName is one of those defined in General description. Note that flavours are case-sensitive.

The above command is an interactive one, i.e. for each bank header, you'll be asked if you want to dump also the content of this bank (type 0 to continue, -1 to abort program, or any number n in between to see n channels). This can be quite painful for databases with a lot of banks. To overcome this difficulty, you can either use the --batch option to not be prompted for any answer, and/or restrict the set of bank you'd like to inspect, using the --(inserted|start|end)(After|Before) and/or --bankID options, e.g.

emcDB --dump calib.emc.Gains --bankID 108 --insertedAfter "2001,12,20,12,36,45"
which will show you only Gains banks for FEM 108, inserted into database after 2001, December, the 20th, at 12 h 36 m 45 s.

Putting calibration ASCII files into the Postgres database(s)

The general syntax is :
emcDB --update directory
where directory is the path to the calibration data files. Please note that official ASCII calibration files are usually to be found somewhere under /afs/rhic/phenix/phnxemc.

The above command will read all calibration files to be found under directory and will put them into the relevant database. Special note on pedestals : depending on the number of pedestal-calibration files for one FEM (3 or 5), a different database will be filled (calib.emc.Pedestals or calib.emc.Pedestals5). It should be automatic.

31-Aug-2001 Due to a possible problem in PHTimeStamp::operator >> , please always use the --forceDate option (see below), as the timestamp specified in the ASCII files themselves is currently not properly read out.

22-Jan-2002 The above bug should be fixed. But still you might want to use the --forceDate option to bypass the date which is in the files (e.g. to insure that a set of banks has the same start-of-validity period).

Attention:
The --update option will write things into the official PHENIX Postgres database, so please mind your steps!

Special note on ToF-related calibrations

The ToF directory usually contains 3 calibration flavours : the walk corrections, least-count, and t0-drift ones. If you'd like to update only one of them, here's the procedure to follow :

Make a fresh somewhere/ToF directory Copy the relevant flavour you'd like to put in the DB, e.g. :

cp /yourplace/ToF/*WALK* somewhere/ToF
Then use emcDB as usual :
emcDB --forceDate "year,month,day,hour,minute,second" --update somewhere/ToF

Specifying the date : the --forceDate option

Usually, start-of-validity dates for the calibration data are fetch from the ASCII files themselves. If you want to override those, use the --forceDate option of the emcDB program. It takes a date string, in a format which is the one of the PHTimeStamp constructor :

emcDB --forceDate "2001,08,01,12,45,00" --update /afs/rhic/phenix/phnxemc/EMC/m_080701

Special note on PbGl gains for Run II

This is a little bit special case.

Many Gains files are split over many directories in e.g. /phenix/data24/vikonnik/Gains/RunXXXX, each of those directories being a normal top directory for calibration flavours, i.e. :

  /phenix/data24/vikonnik/Gains/Run31250/Gains
  /Run31250/QA
  /Run33350/Gains
  /Run33350/QA
  ...

The idea is to use each RunXXXX directory as a calibration set. For this, we need both start and end of validity period for each set (start=time stamp of first run of the set, end=time stamp of first run of the next set to avoid time-gaps).

So the first step is to get those time stamps. We do have a PHENIX Run Database, so we will use it for that purpose. We could have make it transparent, but a) some run used by PbGl are not in this database and hence the relationship runnumber<->time stamp can not be found using the Run DB and b) when we did use Objy as our database managment system (prior to Postgres), for testing purpose we'd like to be able to read PHENIX Run DB while writing Gains into a private Federation (and currently Objy is not able to open 2 Federations in one single process...). So we used an interim file, and this has not changed. This file is produced using the command :

  cd some_dir
  emcDB --runtimes 90000

This will select Postgre (Pg) as the DataBase Management System from which to fetch runtimes, for runnumber greater or equal to 90000, and will produce a emc_runtimes_initfromfile.tmp.txt file, like :

36503,Sun Dec 16 15:10:53 2001,Sun Dec 16 15:11:22 2001
36504,Sun Dec 16 15:11:43 2001,Sun Dec 16 15:12:13 2001
36505,Sun Dec 16 15:12:34 2001,Sun Dec 16 15:13:02 2001
36506,Sun Dec 16 15:13:25 2001,Sun Dec 16 15:13:52 2001
36507,Sun Dec 16 15:14:14 2001,Sun Dec 16 15:14:42 2001
36508,Sun Dec 16 15:15:03 2001,Sun Dec 16 15:15:32 2001
36509,Sun Dec 16 15:15:59 2001,Sun Dec 16 15:16:26 2001

Then, using information contained in Viktor's files for the run missing in PHENIX Run DB, we completed this file to obtain a new one (emc_runtimes_initfromfile.tmp.txt), covering all the runs we need.

We then use the --updatePbGlGains option to actually read the Gains files and put them into the Gains database

cd some_dir (same as before !)
emcDB --updatePbGlGains /phenix/data24/vikonnik/Gains

And that's it ! Please note that it might be a little long...

Comparing database content and ASCII files

If you'd like to know from where a given database bank is coming from (and assuming you still have the directory that was used when using --update), you may do :

emcDB --dump calib.emc.Gains --bankID 0 --insertedAfter "2002,1,1,0,0,0" 
      --compare /afs/rhic/phenix/phnxemc/EMC/m_091001
--------------------------------------------------------------------------------
emcDB 2.0 (10 June 2004)
--------------------------------------------------------------------------------
Dumping calib.emc.Gains calibration database 
--------------------------------------------------------------------------------
BankID = 0
Insert   : Mon Jan 14 13:05:22 2002
StartVal : Mon Sep 10 10:30:26 2001
EndVal   : Mon Jan 18 22:14:07 2038
Calibration Description : 
  User Name = Unknown
  [# of channels] Show channels [n] Next bank  [q] Quit, [c] Compare to file(s) 
  Please enter command > 
If you then hit the C key, you'll see something like :

  MATCHES the one in /afs/rhic/phenix/phnxemc/EMC/m_091001

Please note that you can use several --compare options to compare the current database bank against several directories.

Please note also that for pedestals, you need to use the --config gdb.dat option (which is used to find the FEM absolutePosition to PinNumber relationship). The gdb.dat file you can probably get from CVS online_configuration directory.

Definition at line 225 of file emcDB.h.

Public Member Functions

 emcDB (const char *dbms="Pg", const char *dbname="calibrations", bool interactive=false, PHTimeStamp *ts=0, PHTimeStamp *tsend=0)
 default ctor.
 ~emcDB ()
 dtor.
void Debug (bool value=true)
 Set debug to yes or no.
bool Dump (const std::string fulldbname)
 Dump a given database, e.g. calib.emc.Gains.
bool Dump (const char *fulldbname)
 same as above.
int Compare (PdbCalBank &bank, const std::string &directory, const std::string &flavour)
 Compare a bank from Objy with the same object fetch from file.
void MakeRunTimes (int minrunnumber)
 Generate a temporary file with runnumber->timestamps relationship.
void SetBankID (int bankid)
 Set the bankID to be used for next searches.
void SetConfigurationFile (const std::string &filename)
 Set configuration filename (only needed for pedestals).
void SetConfigurationFile (const char *filename)
 Same as above.
void SetDirectories (std::vector< std::string > &directories)
 Set the directories to look for comparisons.
void SetEndInterval (const PHTimeStamp &endAfter, const PHTimeStamp &endBefore)
 Set the end-of-validity interval for next searches.
void SetInsertInterval (const PHTimeStamp &insertAfter, const PHTimeStamp &insertBefore)
 Set the insert date interval for next searches.
void SetStartInterval (const PHTimeStamp &startAfter, const PHTimeStamp &startBefore)
 Set the start-of-validity interval for next searches.
bool Update (const std::string directory)
 Read a directory with calibration files and write them into DB.
bool UpdatePbGlGains (const std::string top_directory)
 Special case of update for PbGl Gains.
bool UpdateInitialCalibration (const std::string top_directory)
 Another special case for Initial Calibrations.
bool UpdateRejectList (const std::string top_directory)
 Yet Another Special case for Reject List.
bool UpdateTofSectorOffset (const std::string dir, int runnumber)
 Yet Another Special case for TofSectorOffset.

Static Public Member Functions

static std::string Version (void)
 Get the version of this class.

Private Member Functions

int AbsolutePosition (const std::string &femName)
void Abort (const std::string &method, const std::string &message)
PdbBankManager * BankManager ()
emcManageable::EStorage destination () const
void DumpContent (PdbCalBank &, int nchannels)
void CompareToDirectories (PdbCalBank &, const std::string &)
PHTimeStamp EndOfValidity (void) const
bool Error (const std::string method, const std::string message)
int GetPinNumber (int absPosition)
void initDBMS (const char *dbms)
void ParseFileName (const std::string filename, size_t &ifem, size_t &pin)
int PedestalVersion (const std::string cdir)
bool Quit (void)
bool ReadConfiguration (bool debug)
void Split (const std::string &str, std::vector< std::string > &split)
void UpdateXValue (emcTracedFEM &fem, int value)

Private Attributes

std::string fDBMS
std::string fDbname
bool fInteractive
PHTimeStamp * fForceDate
PHTimeStamp * fForceEndDate
int fBankID
bool fDebug
PHTimeStamp fInsertAfter
PHTimeStamp fInsertBefore
PHTimeStamp fStartAfter
PHTimeStamp fStartBefore
PHTimeStamp fEndAfter
PHTimeStamp fEndBefore
bool fStartIntervalGiven
bool fEndIntervalGiven
bool fInsertIntervalGiven
std::vector< std::string > fDirectories
std::string fConfigurationFile
std::vector< int > fPinNumbers


Constructor & Destructor Documentation

emcDB::emcDB const char *  dbms = "Pg",
const char *  dbname = "calibrations",
bool  interactive = false,
PHTimeStamp *  ts = 0,
PHTimeStamp *  tsend = 0
 

default ctor.

Definition at line 152 of file emcDB.C.

References fDBMS, fDbname, fDebug, fEndAfter, fEndBefore, fEndIntervalGiven, fForceDate, fForceEndDate, fInsertAfter, fInsertBefore, fInsertIntervalGiven, fInteractive, fStartAfter, fStartBefore, fStartIntervalGiven, and initDBMS().

emcDB::~emcDB  ) 
 

dtor.

Definition at line 175 of file emcDB.C.


Member Function Documentation

void emcDB::Abort const std::string &  method,
const std::string &  message
[private]
 

int emcDB::AbsolutePosition const std::string &  femName  )  [private]
 

Referenced by ReadConfiguration().

PdbBankManager * emcDB::BankManager  )  [private]
 

Definition at line 214 of file emcDB.C.

References fDBMS.

Referenced by Quit().

int emcDB::Compare PdbCalBank &  bank,
const std::string &  directory,
const std::string &  flavour
 

Compare a bank from Objy with the same object fetch from file.

void emcDB::CompareToDirectories PdbCalBank &  ,
const std::string & 
[private]
 

void emcDB::Debug bool  value = true  )  [inline]
 

Set debug to yes or no.

Definition at line 238 of file emcDB.h.

References fDebug.

emcManageable::EStorage emcDB::destination  )  const [private]
 

Definition at line 379 of file emcDB.C.

References fDBMS, emcManageable::kDB_Objy, emcManageable::kDB_Pg, and emcManageable::kFile_ASCII.

bool emcDB::Dump const char *  fulldbname  )  [inline]
 

same as above.

Definition at line 243 of file emcDB.h.

References Dump().

bool emcDB::Dump const std::string  fulldbname  ) 
 

Dump a given database, e.g. calib.emc.Gains.

Referenced by Dump().

void emcDB::DumpContent PdbCalBank &  ,
int  nchannels
[private]
 

Definition at line 525 of file emcDB.C.

PHTimeStamp emcDB::EndOfValidity void   )  const [private]
 

Definition at line 540 of file emcDB.C.

References fForceEndDate.

bool emcDB::Error const std::string  method,
const std::string  message
[private]
 

int emcDB::GetPinNumber int  absPosition  )  [private]
 

Definition at line 564 of file emcDB.C.

References EMC_ERROR_MSG, fPinNumbers, EmcIndexer::MaxNumberOfFEMs(), and ReadConfiguration().

void emcDB::initDBMS const char *  dbms  )  [private]
 

Definition at line 584 of file emcDB.C.

Referenced by emcDB(), and MakeRunTimes().

void emcDB::MakeRunTimes int  minrunnumber  ) 
 

Generate a temporary file with runnumber->timestamps relationship.

Definition at line 1508 of file emcDB.C.

References fDBMS, initDBMS(), RunTimes::MinRunNumber(), and RunTimes::Output().

void emcDB::ParseFileName const std::string  filename,
size_t &  ifem,
size_t &  pin
[private]
 

int emcDB::PedestalVersion const std::string  cdir  )  [private]
 

bool emcDB::Quit void   )  [private]
 

Definition at line 723 of file emcDB.C.

References BankManager().

bool emcDB::ReadConfiguration bool  debug  )  [private]
 

Definition at line 1529 of file emcDB.C.

References AbsolutePosition(), fConfigurationFile, fPinNumbers, EmcIndexer::MaxNumberOfFEMs(), Split(), and split().

Referenced by GetPinNumber().

void emcDB::SetBankID int  bankid  )  [inline]
 

Set the bankID to be used for next searches.

Definition at line 255 of file emcDB.h.

References fBankID.

void emcDB::SetConfigurationFile const char *  filename  )  [inline]
 

Same as above.

Definition at line 262 of file emcDB.h.

References SetConfigurationFile().

void emcDB::SetConfigurationFile const std::string &  filename  )  [inline]
 

Set configuration filename (only needed for pedestals).

Definition at line 258 of file emcDB.h.

References fConfigurationFile.

Referenced by SetConfigurationFile().

void emcDB::SetDirectories std::vector< std::string > &  directories  )  [inline]
 

Set the directories to look for comparisons.

Definition at line 267 of file emcDB.h.

References fDirectories.

void emcDB::SetEndInterval const PHTimeStamp &  endAfter,
const PHTimeStamp &  endBefore
 

Set the end-of-validity interval for next searches.

Definition at line 731 of file emcDB.C.

References fEndAfter, fEndBefore, and fEndIntervalGiven.

void emcDB::SetInsertInterval const PHTimeStamp &  insertAfter,
const PHTimeStamp &  insertBefore
 

Set the insert date interval for next searches.

Definition at line 741 of file emcDB.C.

References fInsertAfter, fInsertBefore, and fInsertIntervalGiven.

void emcDB::SetStartInterval const PHTimeStamp &  startAfter,
const PHTimeStamp &  startBefore
 

Set the start-of-validity interval for next searches.

Definition at line 751 of file emcDB.C.

References fStartAfter, fStartBefore, and fStartIntervalGiven.

void emcDB::Split const std::string &  str,
std::vector< std::string > &  split
[private]
 

Referenced by ReadConfiguration().

bool emcDB::Update const std::string  directory  ) 
 

Read a directory with calibration files and write them into DB.

bool emcDB::UpdateInitialCalibration const std::string  top_directory  ) 
 

Another special case for Initial Calibrations.

bool emcDB::UpdatePbGlGains const std::string  top_directory  ) 
 

Special case of update for PbGl Gains.

where directory structure is slightly more complicated.

bool emcDB::UpdateRejectList const std::string  top_directory  ) 
 

Yet Another Special case for Reject List.

bool emcDB::UpdateTofSectorOffset const std::string  dir,
int  runnumber
 

Yet Another Special case for TofSectorOffset.

Definition at line 1183 of file emcDB.C.

void emcDB::UpdateXValue emcTracedFEM fem,
int  value
[private]
 

Definition at line 1052 of file emcDB.C.

References emcTracedFEM::FirstItem(), emcTracedValue::GetConstant(), emcTracedFEM::GetNumberOfChannels(), emcTracedValue::GetSlope(), emcTracedFEM::NextItem(), and emcTracedValue::Set().

string emcDB::Version void   )  [static]
 

Get the version of this class.

Definition at line 1649 of file emcDB.C.


Member Data Documentation

int emcDB::fBankID [private]
 

Definition at line 335 of file emcDB.h.

Referenced by SetBankID().

std::string emcDB::fConfigurationFile [private]
 

Definition at line 347 of file emcDB.h.

Referenced by ReadConfiguration(), and SetConfigurationFile().

std::string emcDB::fDBMS [private]
 

Definition at line 330 of file emcDB.h.

Referenced by BankManager(), destination(), emcDB(), and MakeRunTimes().

std::string emcDB::fDbname [private]
 

Definition at line 331 of file emcDB.h.

Referenced by emcDB().

bool emcDB::fDebug [private]
 

Definition at line 336 of file emcDB.h.

Referenced by Debug(), and emcDB().

std::vector<std::string> emcDB::fDirectories [private]
 

Definition at line 346 of file emcDB.h.

Referenced by SetDirectories().

PHTimeStamp emcDB::fEndAfter [private]
 

Definition at line 341 of file emcDB.h.

Referenced by emcDB(), and SetEndInterval().

PHTimeStamp emcDB::fEndBefore [private]
 

Definition at line 342 of file emcDB.h.

Referenced by emcDB(), and SetEndInterval().

bool emcDB::fEndIntervalGiven [private]
 

Definition at line 344 of file emcDB.h.

Referenced by emcDB(), and SetEndInterval().

PHTimeStamp* emcDB::fForceDate [private]
 

Definition at line 333 of file emcDB.h.

Referenced by emcDB().

PHTimeStamp* emcDB::fForceEndDate [private]
 

Definition at line 334 of file emcDB.h.

Referenced by emcDB(), and EndOfValidity().

PHTimeStamp emcDB::fInsertAfter [private]
 

Definition at line 337 of file emcDB.h.

Referenced by emcDB(), and SetInsertInterval().

PHTimeStamp emcDB::fInsertBefore [private]
 

Definition at line 338 of file emcDB.h.

Referenced by emcDB(), and SetInsertInterval().

bool emcDB::fInsertIntervalGiven [private]
 

Definition at line 345 of file emcDB.h.

Referenced by emcDB(), and SetInsertInterval().

bool emcDB::fInteractive [private]
 

Definition at line 332 of file emcDB.h.

Referenced by emcDB().

std::vector<int> emcDB::fPinNumbers [private]
 

Definition at line 348 of file emcDB.h.

Referenced by GetPinNumber(), and ReadConfiguration().

PHTimeStamp emcDB::fStartAfter [private]
 

Definition at line 339 of file emcDB.h.

Referenced by emcDB(), and SetStartInterval().

PHTimeStamp emcDB::fStartBefore [private]
 

Definition at line 340 of file emcDB.h.

Referenced by emcDB(), and SetStartInterval().

bool emcDB::fStartIntervalGiven [private]
 

Definition at line 343 of file emcDB.h.

Referenced by emcDB(), and SetStartInterval().


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