source: fact/tools/rootmacros/PulseTemplates/rootfilehandler.C@ 13521

Last change on this file since 13521 was 13490, checked in by Jens Buss, 13 years ago
added bool for saving histograms or not
File size: 2.9 KB
Line 
1#include "rootfilehandler.h"
2
3
4void
5CreateRootFile(
6 const char* loc_fname,
7 int verbosityLevel
8 )
9{
10 TFile* tf = new TFile(loc_fname,"UPDATE");
11 if (tf->IsZombie())
12 {
13 cout << "Error opening file" << endl;
14 exit(-1);
15 }
16 else {
17 if (verbosityLevel > 1) cout << "creating root-file successfull" << endl;
18 tf->Close();
19 }
20}
21//end of CreateRootFile
22//----------------------------------------------------------------------------
23
24
25TFile*
26OpenRootFile(
27 const char * loc_fname,
28 int verbosityLevel
29 )
30{
31 TFile* tf = new TFile(loc_fname,"UPDATE");
32 if (tf->IsZombie())
33 {
34 cout << "Error opening file" << endl;
35 exit(-1);
36 }
37 else {
38 if (verbosityLevel > 1) cout << "...opening root-file:"
39 << loc_fname
40 << " successfull" << endl;
41 }
42 return tf;
43}
44//end of OpenRootFile
45//----------------------------------------------------------------------------
46
47
48void
49CloseRootFile(
50 TFile* tf
51 )
52{
53 if (tf->IsZombie())
54 {
55 cout << "Error closing file" << endl;
56 exit(-1);
57 } else {
58 tf->Close();
59 }
60}
61//end of CloseRootFile
62//----------------------------------------------------------------------------
63
64
65void
66SaveHistograms(
67 const char* loc_fname,
68 TString subdirectory,
69 TObjArray* histList,
70 bool saveResults,
71 int verbosityLevel
72 )
73{
74 if (!saveResults) return;
75 if (verbosityLevel > 2) cout << endl
76 << "...saving pixel histograms to subdirectory: "
77 << subdirectory << endl ;
78
79 TFile* tf = OpenRootFile(loc_fname, verbosityLevel);
80 if ( !( subdirectory.CompareTo("root") ) ) //if subdirectory = root
81 {
82 tf->cd();
83 tf->mkdir(subdirectory,subdirectory);
84 tf->cd(subdirectory);
85 }
86 else
87 {
88 tf->cd();
89 }
90 histList->Write(); // write the major histograms into the top level directory
91 if (verbosityLevel > 3) tf->ls();
92 CloseRootFile( tf ); // close the file
93 if (verbosityLevel > 2) cout << "...done" << endl;
94}
95// end of SaveHistograms
96//----------------------------------------------------------------------------
97
98
99TString
100CreateSubDirName(
101 int pixel
102 )
103{
104 TString path = "Pixel_";
105 path += pixel;
106// cout << "path " << path << endl ;
107 return path;
108}
109// end of CreateSubDirName
110//----------------------------------------------------------------------------
111
112
113TString
114CreateSubDirName(
115 const char* title
116 )
117{
118 TString path = title;
119 path += "_Pixel";
120// cout << "path " << path << endl ;
121 return path;
122}
123// end of CreateSubDirName
124//----------------------------------------------------------------------------
125
Note: See TracBrowser for help on using the repository browser.