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

constructor

Definition at line 14 of file AlignmentIORootBase.h.

14 : tree(nullptr), myFile(nullptr) {}

◆ ~AlignmentIORootBase()

AlignmentIORootBase::~AlignmentIORootBase ( )
protectedvirtual

destructor

Definition at line 9 of file AlignmentIORootBase.cc.

References myFile.

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

Member Function Documentation

◆ closeRoot()

int AlignmentIORootBase::closeRoot ( void  )
protected

close IO

Definition at line 92 of file AlignmentIORootBase.cc.

References bWrite, and myFile.

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

92  {
93  if (bWrite) { //writing
94  tree->Write();
95  }
96 
97  delete myFile;
98  myFile = nullptr;
99  tree = nullptr; // deleted with file
100 
101  return 0;
102 }
Definition: tree.py:1

◆ createBranches()

virtual void AlignmentIORootBase::createBranches ( void  )
protectedpure virtual

◆ openRoot()

int AlignmentIORootBase::openRoot ( const char *  filename,
int  iteration,
bool  writemode 
)
protected

open IO

Definition at line 16 of file AlignmentIORootBase.cc.

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

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

16  {
17  bWrite = write;
18  int iter;
19 
20  edm::LogInfo("AlignmentIORootBase") << "File: " << filename;
21 
22  if (bWrite) { // writing
23 
24  int iterfile = testFile(filename, treename);
25  if (iterfile == -1) {
26  iter = iteration;
27  edm::LogInfo("AlignmentIORootBase") << "Write to new file; first iteration: " << iter;
28  myFile = TFile::Open(filename, "recreate");
29  } else {
30  if (iteration == -1) {
31  iter = iterfile + 1;
32  edm::LogInfo("AlignmentIORootBase") << "Write to existing file; highest iteration: " << iter;
33  } else {
34  if (iteration <= iterfile) {
35  edm::LogError("AlignmentIORootBase")
36  << "Iteration " << iteration << " invalid or already exists for tree " << treename;
37  return -1;
38  }
39  iter = iteration;
40  edm::LogInfo("AlignmentIORootBase") << "Write to new iteration: " << iter;
41  }
42  myFile = TFile::Open(filename, "update");
43  }
44 
45  // create tree
46  myFile->cd();
47  edm::LogInfo("AlignmentIORootBase") << "Tree: " << treeName(iter, treename);
48  tree = new TTree(treeName(iter, treename), treetxt);
50 
51  } else { // reading
52 
53  int iterfile = testFile(filename, treename);
54  if (iterfile == -1) {
55  edm::LogError("AlignmentIORootBase") << "File does not exist!";
56  return -1;
57  } else if (iterfile == -2) {
58  edm::LogError("AlignmentIORootBase") << "Tree " << treename << " does not exist in file " << filename;
59  return -1;
60  } else {
61  if (iteration == -1) {
62  iter = iterfile;
63  edm::LogInfo("AlignmentIORootBase") << "Read from highest iteration: " << iter;
64  } else {
65  if (iteration > iterfile) {
66  edm::LogError("AlignmentIORootBase") << "Iteration " << iteration << " does not exist for tree " << treename;
67  return -1;
68  }
69  iter = iteration;
70  edm::LogInfo("AlignmentIORootBase") << "Read from specified iteration: " << iter;
71  }
72  myFile = TFile::Open(filename, "read");
73  }
74 
75  myFile->cd();
76  // set trees
77  edm::LogInfo("AlignmentIORootBase") << " Tree: " << treeName(iter, treename);
78  tree = (TTree*)myFile->Get(treeName(iter, treename));
79  if (tree == nullptr) {
80  edm::LogError("AlignmentIORootBase") << "Tree does not exist in file!";
81  return -1;
82  }
84  }
85 
86  return 0;
87 }
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
Log< level::Error, false > LogError
virtual void setBranchAddresses(void)=0
set root branches
Log< level::Info, false > LogInfo
virtual void createBranches(void)=0
create root branches
Definition: tree.py:1

◆ setBranchAddresses()

virtual void AlignmentIORootBase::setBranchAddresses ( void  )
protectedpure virtual

◆ testFile()

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 108 of file AlignmentIORootBase.cc.

References corrVsCorr::filename, itermax, tname(), and treeName().

Referenced by openRoot(), and edmIntegrityCheck.IntegrityCheck::testFileTimeOut().

108  {
109  FILE* testFILE;
110  testFILE = fopen(filename, "r");
111  if (testFILE == nullptr) {
112  return -1;
113  } else {
114  fclose(testFILE);
115  int ihighest = -2;
116  TFile* aFile = TFile::Open(filename, "read");
117  for (int iter = 0; iter < itermax; iter++) {
118  if ((nullptr != (TTree*)aFile->Get(treeName(iter, tname))) && (iter > ihighest))
119  ihighest = iter;
120  }
121  delete aFile;
122  return ihighest;
123  }
124 }
TString treeName(int iter, const TString &tname)
compose tree name
static const int itermax
std::string tname(const std::string &tableName, const std::string &schemaVersion)

◆ treeName()

TString AlignmentIORootBase::treeName ( int  iter,
const TString &  tname 
)
protected

compose tree name

Definition at line 129 of file AlignmentIORootBase.cc.

References tname().

Referenced by openRoot(), and testFile().

129 { return TString(tname + Form("_%i", iter)); }
std::string tname(const std::string &tableName, const std::string &schemaVersion)

Member Data Documentation

◆ bWrite

bool AlignmentIORootBase::bWrite
protected

Definition at line 41 of file AlignmentIORootBase.h.

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

◆ itermax

const int AlignmentIORootBase::itermax = 1000
staticprotected

Definition at line 44 of file AlignmentIORootBase.h.

Referenced by testFile().

◆ myFile

TFile* AlignmentIORootBase::myFile
private

Definition at line 47 of file AlignmentIORootBase.h.

Referenced by closeRoot(), openRoot(), and ~AlignmentIORootBase().

◆ nParMax

const int AlignmentIORootBase::nParMax = 20
staticprotected

Definition at line 43 of file AlignmentIORootBase.h.

Referenced by AlignmentCorrelationsIORoot::read().

◆ tree

TTree* AlignmentIORootBase::tree
protected

◆ treename

TString AlignmentIORootBase::treename
protected

◆ treetxt

TString AlignmentIORootBase::treetxt
protected