| 1 | #include "rootfilehandler.h"
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 | void
|
|---|
| 5 | CreateRootFile(
|
|---|
| 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 |
|
|---|
| 25 | TFile*
|
|---|
| 26 | OpenRootFile(
|
|---|
| 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 |
|
|---|
| 48 | void
|
|---|
| 49 | CloseRootFile(
|
|---|
| 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 |
|
|---|
| 65 | void
|
|---|
| 66 | SaveHistograms(
|
|---|
| 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 |
|
|---|
| 97 | TString
|
|---|
| 98 | CreateSubDirName(
|
|---|
| 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 |
|
|---|
| 111 | TString
|
|---|
| 112 | CreateSubDirName(
|
|---|
| 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 |
|
|---|