| 1 | #include <iostream> | 
|---|
| 2 | #include "TObjArray.h" | 
|---|
| 3 |  | 
|---|
| 4 | #include "rootfilehandler.h" | 
|---|
| 5 | #include <stdlib.h> | 
|---|
| 6 | using namespace std; | 
|---|
| 7 |  | 
|---|
| 8 | void | 
|---|
| 9 | CreateRootFile( | 
|---|
| 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 |  | 
|---|
| 29 | TFile* | 
|---|
| 30 | OpenRootFile( | 
|---|
| 31 | const char * loc_fname, | 
|---|
| 32 | int verbosityLevel | 
|---|
| 33 | ) | 
|---|
| 34 | { | 
|---|
| 35 | TFile* tf = new TFile(loc_fname,"UPDATE"); | 
|---|
| 36 | if (tf->IsZombie()) | 
|---|
| 37 | { | 
|---|
| 38 | cout << "Error opening file" << endl; | 
|---|
| 39 | exit(-1); | 
|---|
| 40 | } | 
|---|
| 41 | else { | 
|---|
| 42 | if (verbosityLevel > 1) cout << "...opening root-file:" | 
|---|
| 43 | << loc_fname | 
|---|
| 44 | << " successfull" << endl; | 
|---|
| 45 | } | 
|---|
| 46 | return tf; | 
|---|
| 47 | } | 
|---|
| 48 | //end of OpenRootFile | 
|---|
| 49 | //---------------------------------------------------------------------------- | 
|---|
| 50 |  | 
|---|
| 51 |  | 
|---|
| 52 | void | 
|---|
| 53 | CloseRootFile( | 
|---|
| 54 | TFile* tf | 
|---|
| 55 | ) | 
|---|
| 56 | { | 
|---|
| 57 | if (tf->IsZombie()) | 
|---|
| 58 | { | 
|---|
| 59 | cout << "Error closing file" << endl; | 
|---|
| 60 | exit(-1); | 
|---|
| 61 | } else { | 
|---|
| 62 | tf->Close(); | 
|---|
| 63 | } | 
|---|
| 64 | } | 
|---|
| 65 | //end of CloseRootFile | 
|---|
| 66 | //---------------------------------------------------------------------------- | 
|---|
| 67 |  | 
|---|
| 68 |  | 
|---|
| 69 | void | 
|---|
| 70 | SaveHistograms( | 
|---|
| 71 | const char*     loc_fname, | 
|---|
| 72 | TString         subdirectory, | 
|---|
| 73 | TObjArray*      histList, | 
|---|
| 74 | bool            saveResults, | 
|---|
| 75 | int             verbosityLevel | 
|---|
| 76 | ) | 
|---|
| 77 | { | 
|---|
| 78 | if (!saveResults) return; | 
|---|
| 79 | if (verbosityLevel > 2) cout << endl | 
|---|
| 80 | << "...saving pixel histograms to subdirectory: " | 
|---|
| 81 | << subdirectory << endl ; | 
|---|
| 82 |  | 
|---|
| 83 | TFile* tf = OpenRootFile(loc_fname, verbosityLevel); | 
|---|
| 84 | if ( !( subdirectory.CompareTo("root") ) ) //if subdirectory = root | 
|---|
| 85 | { | 
|---|
| 86 | tf->cd(); | 
|---|
| 87 | tf->mkdir(subdirectory,subdirectory); | 
|---|
| 88 | tf->cd(subdirectory); | 
|---|
| 89 | } | 
|---|
| 90 | else | 
|---|
| 91 | { | 
|---|
| 92 | tf->cd(); | 
|---|
| 93 | } | 
|---|
| 94 | histList->Write(); // write the major histograms into the top level directory | 
|---|
| 95 | if (verbosityLevel > 3) tf->ls(); | 
|---|
| 96 | CloseRootFile( tf ); // close the file | 
|---|
| 97 | if (verbosityLevel > 2) cout << "...done" << endl; | 
|---|
| 98 | } | 
|---|
| 99 | // end of SaveHistograms | 
|---|
| 100 | //---------------------------------------------------------------------------- | 
|---|
| 101 |  | 
|---|
| 102 |  | 
|---|
| 103 | TString | 
|---|
| 104 | CreateSubDirName( | 
|---|
| 105 | int pixel | 
|---|
| 106 | ) | 
|---|
| 107 | { | 
|---|
| 108 | TString path = "Pixel_"; | 
|---|
| 109 | path += pixel; | 
|---|
| 110 | //    cout << "path " << path << endl ; | 
|---|
| 111 | return path; | 
|---|
| 112 | } | 
|---|
| 113 | // end of CreateSubDirName | 
|---|
| 114 | //---------------------------------------------------------------------------- | 
|---|
| 115 |  | 
|---|
| 116 |  | 
|---|
| 117 | TString | 
|---|
| 118 | CreateSubDirName( | 
|---|
| 119 | const char* title | 
|---|
| 120 | ) | 
|---|
| 121 | { | 
|---|
| 122 | TString path = title; | 
|---|
| 123 | path += "_Pixel"; | 
|---|
| 124 | //    cout << "path " << path << endl ; | 
|---|
| 125 | return path; | 
|---|
| 126 | } | 
|---|
| 127 | // end of CreateSubDirName | 
|---|
| 128 | //---------------------------------------------------------------------------- | 
|---|
| 129 |  | 
|---|