Base class for ROOT-based I/O of Alignment parameters etc. More...
#include <AlignmentIORootBase.h>
Protected Member Functions | |
AlignmentIORootBase () | |
constructor | |
int | closeRoot (void) |
close IO | |
virtual void | createBranches (void)=0 |
create root branches | |
int | openRoot (const char *filename, int iteration, bool writemode) |
open IO | |
virtual void | setBranchAddresses (void)=0 |
set root branches | |
int | testFile (const char *filename, const TString &tname) |
test if file is existing and if so, what the highest iteration is | |
TString | treeName (int iter, const TString &tname) |
compose tree name | |
virtual | ~AlignmentIORootBase () |
destructor | |
Protected Attributes | |
bool | bWrite |
TTree * | tree |
TString | treename |
TString | treetxt |
Static Protected Attributes | |
static const int | itermax = 1000 |
static const int | nParMax = 20 |
Private Attributes | |
TFile * | myFile |
Base class for ROOT-based I/O of Alignment parameters etc.
Definition at line 11 of file AlignmentIORootBase.h.
AlignmentIORootBase::AlignmentIORootBase | ( | ) | [inline, protected] |
AlignmentIORootBase::~AlignmentIORootBase | ( | ) | [protected, virtual] |
destructor
Definition at line 9 of file AlignmentIORootBase.cc.
References myFile.
{ delete myFile; // tree is deleted automatically with file }
int AlignmentIORootBase::closeRoot | ( | void | ) | [protected] |
close IO
Definition at line 99 of file AlignmentIORootBase.cc.
References bWrite, myFile, and tree.
Referenced by AlignmentCorrelationsIORoot::close(), MillePedeVariablesIORoot::close(), AlignmentParametersIORoot::close(), AlignableDataIORoot::close(), and HIPUserVariablesIORoot::close().
virtual void AlignmentIORootBase::createBranches | ( | void | ) | [protected, pure virtual] |
create root branches
Implemented in AlignableDataIORoot, AlignmentCorrelationsIORoot, AlignmentParametersIORoot, HIPUserVariablesIORoot, and MillePedeVariablesIORoot.
Referenced by openRoot().
int AlignmentIORootBase::openRoot | ( | const char * | filename, |
int | iteration, | ||
bool | writemode | ||
) | [protected] |
open IO
Definition at line 17 of file AlignmentIORootBase.cc.
References bWrite, createBranches(), lut2db_cfg::filename, align_cfg::iteration, myFile, NULL, setBranchAddresses(), testFile(), tree, treeName(), treename, treetxt, and TablePrint::write.
Referenced by AlignableDataIORoot::open(), MillePedeVariablesIORoot::open(), HIPUserVariablesIORoot::open(), AlignmentParametersIORoot::open(), and AlignmentCorrelationsIORoot::open().
{ bWrite=write; int iter; edm::LogInfo("AlignmentIORootBase") << "File: " << filename ; if (bWrite) { // writing int iterfile = testFile(filename,treename); if (iterfile == -1) { iter=iteration; edm::LogInfo("AlignmentIORootBase") << "Write to new file; first iteration: " << iter ; myFile = TFile::Open(filename,"recreate"); } else { if (iteration == -1) { iter=iterfile+1; edm::LogInfo("AlignmentIORootBase") << "Write to existing file; highest iteration: " << iter; } else { if (iteration<=iterfile) { edm::LogError("AlignmentIORootBase") << "Iteration " << iteration <<" invalid or already exists for tree " << treename; return -1; } iter = iteration; edm::LogInfo("AlignmentIORootBase") << "Write to new iteration: " << iter; } myFile = TFile::Open(filename,"update"); } // create tree myFile->cd(); edm::LogInfo("AlignmentIORootBase") << "Tree: " << treeName(iter,treename); tree = new TTree(treeName(iter,treename),treetxt); createBranches(); } else { // reading int iterfile = testFile(filename,treename); if ( iterfile == -1 ) { edm::LogError("AlignmentIORootBase") << "File does not exist!"; return -1; } else if ( iterfile == -2 ) { edm::LogError("AlignmentIORootBase") << "Tree " << treename << " does not exist in file " << filename; return -1; } else { if (iteration == -1) { iter=iterfile; edm::LogInfo("AlignmentIORootBase") << "Read from highest iteration: " << iter; } else { if (iteration>iterfile) { edm::LogError("AlignmentIORootBase") << "Iteration " << iteration << " does not exist for tree " << treename; return -1; } iter = iteration; edm::LogInfo("AlignmentIORootBase") << "Read from specified iteration: " << iter; } myFile = TFile::Open(filename, "read"); } myFile->cd(); // set trees edm::LogInfo("AlignmentIORootBase") <<" Tree: " <<treeName(iter,treename); tree = (TTree*)myFile->Get(treeName(iter,treename)); if (tree==NULL) { edm::LogError("AlignmentIORootBase") <<"Tree does not exist in file!"; return -1; } setBranchAddresses(); } return 0; }
virtual void AlignmentIORootBase::setBranchAddresses | ( | void | ) | [protected, pure virtual] |
set root branches
Implemented in AlignableDataIORoot, AlignmentCorrelationsIORoot, AlignmentParametersIORoot, HIPUserVariablesIORoot, and MillePedeVariablesIORoot.
Referenced by openRoot().
int AlignmentIORootBase::testFile | ( | const char * | filename, |
const TString & | tname | ||
) | [protected] |
test if file is existing and if so, what the highest iteration is
Definition at line 116 of file AlignmentIORootBase.cc.
References itermax, NULL, and treeName().
Referenced by openRoot().
{ FILE* testFILE; testFILE = fopen(filename,"r"); if (testFILE == NULL) { return -1; } else { fclose(testFILE); int ihighest=-2; TFile *aFile = TFile::Open(filename,"read"); for (int iter=0; iter<itermax; iter++) { if ((0 != (TTree*)aFile->Get(treeName(iter,tname))) && (iter>ihighest)) ihighest=iter; } delete aFile; return ihighest; } }
TString AlignmentIORootBase::treeName | ( | int | iter, |
const TString & | tname | ||
) | [protected] |
compose tree name
Definition at line 138 of file AlignmentIORootBase.cc.
Referenced by openRoot(), and testFile().
{ return TString(tname + Form("_%i",iter)); }
bool AlignmentIORootBase::bWrite [protected] |
Definition at line 43 of file AlignmentIORootBase.h.
Referenced by AlignmentParametersIORoot::close(), closeRoot(), and openRoot().
const int AlignmentIORootBase::itermax = 1000 [static, protected] |
Definition at line 46 of file AlignmentIORootBase.h.
Referenced by testFile().
TFile* AlignmentIORootBase::myFile [private] |
Definition at line 49 of file AlignmentIORootBase.h.
Referenced by closeRoot(), openRoot(), and ~AlignmentIORootBase().
const int AlignmentIORootBase::nParMax = 20 [static, protected] |
Definition at line 45 of file AlignmentIORootBase.h.
Referenced by AlignmentCorrelationsIORoot::read().
TTree* AlignmentIORootBase::tree [protected] |
Definition at line 40 of file AlignmentIORootBase.h.
Referenced by AlignmentParametersIORoot::close(), closeRoot(), AlignmentParametersIORoot::createBranches(), HIPUserVariablesIORoot::createBranches(), AlignmentCorrelationsIORoot::createBranches(), AlignableDataIORoot::createBranches(), MillePedeVariablesIORoot::createBranches(), AlignableDataIORoot::findEntry(), HIPUserVariablesIORoot::findEntry(), openRoot(), AlignmentCorrelationsIORoot::read(), AlignableDataIORoot::readAbsRaw(), HIPUserVariablesIORoot::readOne(), AlignmentParametersIORoot::readOne(), MillePedeVariablesIORoot::readOne(), AlignableDataIORoot::readRelRaw(), MillePedeVariablesIORoot::setBranchAddresses(), HIPUserVariablesIORoot::setBranchAddresses(), AlignableDataIORoot::setBranchAddresses(), AlignmentParametersIORoot::setBranchAddresses(), AlignmentCorrelationsIORoot::setBranchAddresses(), AlignmentCorrelationsIORoot::write(), AlignableDataIORoot::writeAbsRaw(), AlignmentParametersIORoot::writeOne(), HIPUserVariablesIORoot::writeOne(), MillePedeVariablesIORoot::writeOne(), and AlignableDataIORoot::writeRelRaw().
TString AlignmentIORootBase::treename [protected] |
Definition at line 41 of file AlignmentIORootBase.h.
Referenced by AlignableDataIORoot::AlignableDataIORoot(), AlignmentCorrelationsIORoot::AlignmentCorrelationsIORoot(), AlignmentParametersIORoot::AlignmentParametersIORoot(), HIPUserVariablesIORoot::HIPUserVariablesIORoot(), MillePedeVariablesIORoot::MillePedeVariablesIORoot(), and openRoot().
TString AlignmentIORootBase::treetxt [protected] |
Definition at line 42 of file AlignmentIORootBase.h.
Referenced by AlignableDataIORoot::AlignableDataIORoot(), AlignmentCorrelationsIORoot::AlignmentCorrelationsIORoot(), AlignmentParametersIORoot::AlignmentParametersIORoot(), HIPUserVariablesIORoot::HIPUserVariablesIORoot(), MillePedeVariablesIORoot::MillePedeVariablesIORoot(), and openRoot().