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

Last change on this file since 13480 was 13476, checked in by Jens Buss, 13 years ago
bugfixes after first compilation
File size: 2.8 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 int verbosityLevel
71 )
72{
73 if (verbosityLevel > 2) cout << endl
74 << "...saving pixel histograms to subdirectory: "
75 << subdirectory << endl ;
76
77 TFile* tf = OpenRootFile(loc_fname, verbosityLevel);
78 if ( !( subdirectory.CompareTo("root") ) ) //if subdirectory = root
79 {
80 tf->cd();
81 tf->mkdir(subdirectory,subdirectory);
82 tf->cd(subdirectory);
83 }
84 else
85 {
86 tf->cd();
87 }
88 histList->Write(); // write the major histograms into the top level directory
89 if (verbosityLevel > 3) tf->ls();
90 CloseRootFile( tf ); // close the file
91 if (verbosityLevel > 2) cout << "...done" << endl;
92}
93// end of SaveHistograms
94//----------------------------------------------------------------------------
95
96
97TString
98CreateSubDirName(
99 int pixel
100 )
101{
102 TString path = "Pixel_";
103 path += pixel;
104// cout << "path " << path << endl ;
105 return path;
106}
107// end of CreateSubDirName
108//----------------------------------------------------------------------------
109
110
111TString
112CreateSubDirName(
113 const char* title
114 )
115{
116 TString path = title;
117 path += "_Pixel";
118// cout << "path " << path << endl ;
119 return path;
120}
121// end of CreateSubDirName
122//----------------------------------------------------------------------------
123
Note: See TracBrowser for help on using the repository browser.