| 1 | #include "rootfilehandler.h"
|
|---|
| 2 | #include <TROOT.h>
|
|---|
| 3 | #include <TFile.h>
|
|---|
| 4 |
|
|---|
| 5 | void
|
|---|
| 6 | CreateRootFile(
|
|---|
| 7 | const char * loc_fname,
|
|---|
| 8 | int verbosityLevel
|
|---|
| 9 | )
|
|---|
| 10 | {
|
|---|
| 11 | TFile* tf = new TFile(loc_fname,"UPDATE");
|
|---|
| 12 | if (tf->IsZombie())
|
|---|
| 13 | {
|
|---|
| 14 | cout << "Error opening file" << endl;
|
|---|
| 15 | exit(-1);
|
|---|
| 16 | }
|
|---|
| 17 | else {
|
|---|
| 18 | if (verbosityLevel > 1) cout << "creating root-file successfull" << endl;
|
|---|
| 19 | tf->Close();
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 | //end of CreateRootFile
|
|---|
| 23 | //----------------------------------------------------------------------------
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | TFile*
|
|---|
| 27 | OpenRootFile(
|
|---|
| 28 | const char * loc_fname,
|
|---|
| 29 | int verbosityLevel
|
|---|
| 30 | )
|
|---|
| 31 | {
|
|---|
| 32 | TFile* tf = new TFile(loc_fname,"UPDATE");
|
|---|
| 33 | if (tf->IsZombie())
|
|---|
| 34 | {
|
|---|
| 35 | cout << "Error opening file" << endl;
|
|---|
| 36 | exit(-1);
|
|---|
| 37 | }
|
|---|
| 38 | else {
|
|---|
| 39 | if (verbosityLevel > 1) cout << "...opening root-file:"
|
|---|
| 40 | << loc_fname
|
|---|
| 41 | << " successfull" << endl;
|
|---|
| 42 | }
|
|---|
| 43 | return tf;
|
|---|
| 44 | }
|
|---|
| 45 | //end of OpenRootFile
|
|---|
| 46 | //----------------------------------------------------------------------------
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | void
|
|---|
| 50 | CloseRootFile(
|
|---|
| 51 | TFile* tf
|
|---|
| 52 | )
|
|---|
| 53 | {
|
|---|
| 54 | if (tf->IsZombie())
|
|---|
| 55 | {
|
|---|
| 56 | cout << "Error closing file" << endl;
|
|---|
| 57 | exit(-1);
|
|---|
| 58 | } else {
|
|---|
| 59 | tf->Close();
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|
| 62 | //end of CloseRootFile
|
|---|
| 63 | //----------------------------------------------------------------------------
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 | void
|
|---|
| 67 | SaveHistograms(
|
|---|
| 68 | const char* loc_fname,
|
|---|
| 69 | const char* subdirectory,
|
|---|
| 70 | TObjArray* histList,
|
|---|
| 71 | int verbosityLevel
|
|---|
| 72 | )
|
|---|
| 73 | {
|
|---|
| 74 | if (verbosityLevel > 2) cout << endl
|
|---|
| 75 | << "...saving pixel histograms to subdirectory: "
|
|---|
| 76 | << subdirectory << endl ;
|
|---|
| 77 |
|
|---|
| 78 | TFile* tf = OpenRootFile(loc_fname, verbosityLevel);
|
|---|
| 79 | if ( subdirectory != "root")
|
|---|
| 80 | {
|
|---|
| 81 | tf->cd();
|
|---|
| 82 | tf->mkdir(subdirectory,subdirectory);
|
|---|
| 83 | tf->cd(subdirectory);
|
|---|
| 84 | }
|
|---|
| 85 | else
|
|---|
| 86 | {
|
|---|
| 87 | tf->cd();
|
|---|
| 88 | }
|
|---|
| 89 | histList->Write(); // write the major histograms into the top level directory
|
|---|
| 90 | if (verbosityLevel > 3) tf->ls();
|
|---|
| 91 | CloseRootFile( tf ); // close the file
|
|---|
| 92 | if (verbosityLevel > 2) cout << "...done" << endl;
|
|---|
| 93 | }
|
|---|
| 94 | // end of SaveHistograms
|
|---|
| 95 | //----------------------------------------------------------------------------
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 | TString
|
|---|
| 99 | CreateSubDirName(
|
|---|
| 100 | int pixel
|
|---|
| 101 | )
|
|---|
| 102 | {
|
|---|
| 103 | TString path = "Pixel_";
|
|---|
| 104 | path += pixel;
|
|---|
| 105 | // cout << "path " << path << endl ;
|
|---|
| 106 | return path;
|
|---|
| 107 | }
|
|---|
| 108 | // end of CreateSubDirName
|
|---|
| 109 | //----------------------------------------------------------------------------
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | TString
|
|---|
| 113 | CreateSubDirName(
|
|---|
| 114 | const char* title
|
|---|
| 115 | )
|
|---|
| 116 | {
|
|---|
| 117 | TString path = title;
|
|---|
| 118 | path += "_Pixel";
|
|---|
| 119 | // cout << "path " << path << endl ;
|
|---|
| 120 | return path;
|
|---|
| 121 | }
|
|---|
| 122 | // end of CreateSubDirName
|
|---|
| 123 | //----------------------------------------------------------------------------
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | int
|
|---|
| 127 | CalculateHistogramId(
|
|---|
| 128 | int pixelID,
|
|---|
| 129 | int pulseOrder,
|
|---|
| 130 | int maxPulseOrder
|
|---|
| 131 | )
|
|---|
| 132 | {
|
|---|
| 133 | return (pixelID*maxPulseOrder + pulseOrder);
|
|---|
| 134 | }
|
|---|
| 135 | // end of CalculateHistogramId
|
|---|
| 136 | //----------------------------------------------------------------------------
|
|---|
| 137 |
|
|---|
| 138 | int
|
|---|
| 139 | CalculatePixelId(
|
|---|
| 140 | int mHistogramId,
|
|---|
| 141 | int pulseOrder,
|
|---|
| 142 | int maxPulseOrder
|
|---|
| 143 | )
|
|---|
| 144 | {
|
|---|
| 145 | return (mHistogramId - pulseOrder)/(maxPulseOrder - 1);
|
|---|
| 146 | }
|
|---|
| 147 | // end of CalculatePixelIdFromHistogramId
|
|---|
| 148 | //----------------------------------------------------------------------------
|
|---|
| 149 |
|
|---|
| 150 | CalculatePulseOrder(
|
|---|
| 151 | int mHistogramId,
|
|---|
| 152 | int maxPulseOrder
|
|---|
| 153 | )
|
|---|
| 154 | {
|
|---|
| 155 | if (mHistogramId < maxPulseOrder)
|
|---|
| 156 | {
|
|---|
| 157 | return mHistogramId;
|
|---|
| 158 | }
|
|---|
| 159 | else
|
|---|
| 160 | {
|
|---|
| 161 | return mHistogramId % (maxPulseOrder - 1);
|
|---|
| 162 | }
|
|---|
| 163 | }
|
|---|
| 164 | // end of CalculatePulseOrderFromHistogramId
|
|---|
| 165 | //----------------------------------------------------------------------------
|
|---|