CMS 3D CMS Logo

List of all members | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes
AlignmentIORootBase Class Referenceabstract

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

#include <AlignmentIORootBase.h>

Inheritance diagram for AlignmentIORootBase:
AlignableDataIORoot AlignmentCorrelationsIORoot AlignmentParametersIORoot HIPUserVariablesIORoot MillePedeVariablesIORoot

Protected Member Functions

 AlignmentIORootBase ()
 constructor More...
 
int closeRoot (void)
 close IO More...
 
virtual void createBranches (void)=0
 create root branches More...
 
int openRoot (const char *filename, int iteration, bool writemode)
 open IO More...
 
virtual void setBranchAddresses (void)=0
 set root branches More...
 
int testFile (const char *filename, const TString &tname)
 test if file is existing and if so, what the highest iteration is More...
 
TString treeName (int iter, const TString &tname)
 compose tree name More...
 
virtual ~AlignmentIORootBase ()
 destructor More...
 

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
 

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 ( )
inlineprotected
AlignmentIORootBase::~AlignmentIORootBase ( )
protectedvirtual

destructor

Definition at line 9 of file AlignmentIORootBase.cc.

References myFile.

Referenced by AlignmentIORootBase().

10 {
11  delete myFile; // tree is deleted automatically with file
12 }

Member Function Documentation

int AlignmentIORootBase::closeRoot ( void  )
protected

close IO

Definition at line 99 of file AlignmentIORootBase.cc.

References bWrite, and myFile.

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

100 {
101  if (bWrite) { //writing
102  tree->Write();
103  }
104 
105  delete myFile;
106  myFile = 0;
107  tree = 0; // deleted with file
108 
109  return 0;
110 }
Definition: tree.py:1
virtual void AlignmentIORootBase::createBranches ( void  )
protectedpure virtual
int AlignmentIORootBase::openRoot ( const char *  filename,
int  iteration,
bool  writemode 
)
protected

open IO

Definition at line 17 of file AlignmentIORootBase.cc.

References bWrite, createBranches(), corrVsCorr::filename, align_cfg::iteration, myFile, NULL, setBranchAddresses(), testFile(), treeName(), treename, treetxt, and TriggerAnalyzer::write().

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

18 {
19  bWrite=write;
20  int iter;
21 
22  edm::LogInfo("AlignmentIORootBase") << "File: " << filename ;
23 
24  if (bWrite) { // writing
25 
26  int iterfile = testFile(filename,treename);
27  if (iterfile == -1) {
28  iter=iteration;
29  edm::LogInfo("AlignmentIORootBase") << "Write to new file; first iteration: " << iter ;
30  myFile = TFile::Open(filename,"recreate");
31  } else {
32  if (iteration == -1) {
33  iter=iterfile+1;
34  edm::LogInfo("AlignmentIORootBase")
35  << "Write to existing file; highest iteration: " << iter;
36  } else {
37  if (iteration<=iterfile) {
38  edm::LogError("AlignmentIORootBase")
39  << "Iteration " << iteration
40  <<" invalid or already exists for tree " << treename;
41  return -1;
42  }
43  iter = iteration;
44  edm::LogInfo("AlignmentIORootBase") << "Write to new iteration: " << iter;
45  }
46  myFile = TFile::Open(filename,"update");
47 
48  }
49 
50  // create tree
51  myFile->cd();
52  edm::LogInfo("AlignmentIORootBase") << "Tree: " << treeName(iter,treename);
53  tree = new TTree(treeName(iter,treename),treetxt);
55 
56  } else { // reading
57 
58  int iterfile = testFile(filename,treename);
59  if ( iterfile == -1 ) {
60  edm::LogError("AlignmentIORootBase") << "File does not exist!";
61  return -1;
62  } else if ( iterfile == -2 ) {
63  edm::LogError("AlignmentIORootBase") << "Tree " << treename
64  << " does not exist in file " << filename;
65  return -1;
66  } else {
67  if (iteration == -1) {
68  iter=iterfile;
69  edm::LogInfo("AlignmentIORootBase") << "Read from highest iteration: " << iter;
70  } else {
71  if (iteration>iterfile) {
72  edm::LogError("AlignmentIORootBase")
73  << "Iteration " << iteration << " does not exist for tree " << treename;
74  return -1;
75  }
76  iter = iteration;
77  edm::LogInfo("AlignmentIORootBase") << "Read from specified iteration: " << iter;
78  }
79  myFile = TFile::Open(filename, "read");
80  }
81 
82  myFile->cd();
83  // set trees
84  edm::LogInfo("AlignmentIORootBase") <<" Tree: " <<treeName(iter,treename);
85  tree = (TTree*)myFile->Get(treeName(iter,treename));
86  if (tree==NULL) {
87  edm::LogError("AlignmentIORootBase") <<"Tree does not exist in file!";
88  return -1;
89  }
91  }
92 
93  return 0;
94 }
TString treeName(int iter, const TString &tname)
compose tree name
int testFile(const char *filename, const TString &tname)
test if file is existing and if so, what the highest iteration is
#define NULL
Definition: scimark2.h:8
virtual void setBranchAddresses(void)=0
set root branches
virtual void createBranches(void)=0
create root branches
Definition: tree.py:1
def write(self, setup)
virtual void AlignmentIORootBase::setBranchAddresses ( void  )
protectedpure virtual
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 AlignmentIORootBase(), openRoot(), and edmIntegrityCheck.IntegrityCheck::testFileTimeOut().

117 {
118  FILE* testFILE;
119  testFILE = fopen(filename,"r");
120  if (testFILE == NULL) {
121  return -1;
122  } else {
123  fclose(testFILE);
124  int ihighest=-2;
125  TFile *aFile = TFile::Open(filename,"read");
126  for (int iter=0; iter<itermax; iter++) {
127  if ((0 != (TTree*)aFile->Get(treeName(iter,tname)))
128  && (iter>ihighest)) ihighest=iter;
129  }
130  delete aFile;
131  return ihighest;
132  }
133 }
TString treeName(int iter, const TString &tname)
compose tree name
static char const * tname
Definition: GTSchema.h:13
#define NULL
Definition: scimark2.h:8
static const int itermax
TString AlignmentIORootBase::treeName ( int  iter,
const TString &  tname 
)
protected

compose tree name

Definition at line 138 of file AlignmentIORootBase.cc.

Referenced by AlignmentIORootBase(), openRoot(), and testFile().

139 {
140  return TString(tname + Form("_%i",iter));
141 }
static char const * tname
Definition: GTSchema.h:13

Member Data Documentation

bool AlignmentIORootBase::bWrite
protected

Definition at line 43 of file AlignmentIORootBase.h.

Referenced by AlignmentParametersIORoot::close(), closeRoot(), and openRoot().

const int AlignmentIORootBase::itermax = 1000
staticprotected

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
staticprotected

Definition at line 45 of file AlignmentIORootBase.h.

Referenced by AlignmentCorrelationsIORoot::read().

TTree* AlignmentIORootBase::tree
protected
TString AlignmentIORootBase::treename
protected
TString AlignmentIORootBase::treetxt
protected