CMS 3D CMS Logo

AlignmentIORootBase Class Reference

Base class for ROOT-based I/O of Alignment parameters etc. More...

#include <Alignment/CommonAlignmentAlgorithm/interface/AlignmentIORootBase.h>

Inheritance diagram for AlignmentIORootBase:

AlignableDataIORoot AlignmentCorrelationsIORoot AlignmentParametersIORoot HIPUserVariablesIORoot MillePedeVariablesIORoot

List of all members.

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 = 6

Private Attributes

TFile * myFile


Detailed Description

Base class for ROOT-based I/O of Alignment parameters etc.

Definition at line 11 of file AlignmentIORootBase.h.


Constructor & Destructor Documentation

AlignmentIORootBase::AlignmentIORootBase (  )  [inline, protected]

constructor

Definition at line 16 of file AlignmentIORootBase.h.

00016 : tree(0), myFile(0) {}

AlignmentIORootBase::~AlignmentIORootBase (  )  [protected, virtual]

destructor

Definition at line 9 of file AlignmentIORootBase.cc.

References myFile.

00010 {
00011   delete myFile; // tree is deleted automatically with file
00012 }


Member Function Documentation

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().

00100 {
00101   if (bWrite) { //writing
00102     tree->Write();
00103   }
00104 
00105   delete myFile;
00106   myFile = 0;
00107   tree = 0; // deleted with file
00108 
00109   return 0;
00110 }

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(), iter, myFile, NULL, setBranchAddresses(), testFile(), tree, treeName(), treename, and treetxt.

Referenced by AlignableDataIORoot::open(), MillePedeVariablesIORoot::open(), HIPUserVariablesIORoot::open(), AlignmentParametersIORoot::open(), and AlignmentCorrelationsIORoot::open().

00018 {
00019   bWrite=write;
00020   int iter;
00021 
00022   edm::LogInfo("AlignmentIORootBase") << "File: " << filename ;
00023 
00024   if (bWrite) { // writing
00025 
00026     int iterfile = testFile(filename,treename);
00027     if (iterfile == -1) {
00028       iter=iteration;
00029           edm::LogInfo("AlignmentIORootBase") << "Write to new file; first iteration: " << iter ;
00030           myFile = TFile::Open(filename,"recreate");
00031     } else {
00032       if (iteration == -1) {
00033         iter=iterfile+1;
00034                 edm::LogInfo("AlignmentIORootBase") 
00035                   << "Write to existing file; highest iteration: " << iter;
00036       } else {
00037         if (iteration<=iterfile) {
00038           edm::LogError("AlignmentIORootBase") 
00039             << "Iteration " << iteration 
00040             <<" invalid or already exists for tree " << treename;
00041                   return -1;
00042         }
00043         iter = iteration;
00044         edm::LogInfo("AlignmentIORootBase")  << "Write to new iteration: " << iter;
00045       }
00046       myFile = TFile::Open(filename,"update");
00047           
00048     }
00049 
00050     // create tree
00051     myFile->cd();
00052     edm::LogInfo("AlignmentIORootBase") << "Tree: " << treeName(iter,treename);
00053     tree = new TTree(treeName(iter,treename),treetxt);
00054     createBranches();
00055 
00056   } else { // reading
00057 
00058     int iterfile = testFile(filename,treename);
00059     if ( iterfile == -1 ) {
00060       edm::LogError("AlignmentIORootBase") << "File does not exist!";
00061       return -1;
00062     } else if ( iterfile == -2 ) {
00063       edm::LogError("AlignmentIORootBase") << "Tree " << treename 
00064                                            << " does not exist in file " << filename;
00065       return -1;
00066     } else {
00067       if (iteration == -1) {
00068         iter=iterfile;
00069         edm::LogInfo("AlignmentIORootBase") << "Read from highest iteration: " << iter;
00070       } else {
00071         if (iteration>iterfile) {
00072         edm::LogError("AlignmentIORootBase")
00073           << "Iteration " << iteration << " does not exist for tree " << treename;
00074         return -1;
00075         }
00076         iter = iteration;
00077         edm::LogInfo("AlignmentIORootBase")  << "Read from specified iteration: " << iter;
00078       }
00079       myFile = TFile::Open(filename, "read");
00080     }
00081 
00082     myFile->cd();
00083     // set trees
00084     edm::LogInfo("AlignmentIORootBase") <<" Tree: " <<treeName(iter,treename);
00085     tree = (TTree*)myFile->Get(treeName(iter,treename));
00086     if (tree==NULL) {
00087       edm::LogError("AlignmentIORootBase") <<"Tree does not exist in file!";
00088       return -1;
00089     }
00090     setBranchAddresses();
00091   }
00092 
00093   return 0;
00094 }

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 iter, itermax, NULL, and treeName().

Referenced by openRoot().

00117 {
00118   FILE* testFILE;
00119   testFILE = fopen(filename,"r");
00120   if (testFILE == NULL) {
00121     return -1;
00122   } else {
00123     fclose(testFILE);
00124     int ihighest=-2;
00125     TFile *aFile = TFile::Open(filename,"read");
00126     for (int iter=0; iter<itermax; iter++) {
00127       if ((0 != (TTree*)aFile->Get(treeName(iter,tname))) 
00128           && (iter>ihighest)) ihighest=iter; 
00129     }
00130     delete aFile;
00131     return ihighest;
00132   }
00133 }

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().

00139 {
00140   return TString(tname + Form("_%i",iter));
00141 }


Member Data Documentation

bool AlignmentIORootBase::bWrite [protected]

Definition at line 43 of file AlignmentIORootBase.h.

Referenced by 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 = 6 [static, protected]

Definition at line 45 of file AlignmentIORootBase.h.

Referenced by AlignmentCorrelationsIORoot::read(), and AlignmentParametersIORoot::readOne().

TTree* AlignmentIORootBase::tree [protected]

Definition at line 40 of file AlignmentIORootBase.h.

Referenced by closeRoot(), AlignmentParametersIORoot::createBranches(), HIPUserVariablesIORoot::createBranches(), AlignmentCorrelationsIORoot::createBranches(), AlignableDataIORoot::createBranches(), MillePedeVariablesIORoot::createBranches(), AlignableDataIORoot::findEntry(), AlignmentParametersIORoot::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(), MillePedeVariablesIORoot::writeMillePedeVariables(), 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().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:14:28 2009 for CMSSW by  doxygen 1.5.4