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

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