| 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 | TString loc_fname,
|
|---|
| 11 | int verbosityLevel
|
|---|
| 12 | )
|
|---|
| 13 | {
|
|---|
| 14 | TFile output_rootfile(loc_fname,"UPDATE");
|
|---|
| 15 |
|
|---|
| 16 | if (output_rootfile.IsZombie())
|
|---|
| 17 | {
|
|---|
| 18 | cout << "Error opening file" << endl;
|
|---|
| 19 | exit(-1);
|
|---|
| 20 | }
|
|---|
| 21 | else {
|
|---|
| 22 | if (verbosityLevel > 1) cout << "creating root-file...successfull" << endl;
|
|---|
| 23 | output_rootfile.pwd();
|
|---|
| 24 | output_rootfile.Close();
|
|---|
| 25 | }
|
|---|
| 26 | }
|
|---|
| 27 | //end of CreateRootFile
|
|---|
| 28 | //----------------------------------------------------------------------------
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | TFile*
|
|---|
| 32 | OpenRootFile(
|
|---|
| 33 | TString loc_fname,
|
|---|
| 34 | int verbosityLevel
|
|---|
| 35 | )
|
|---|
| 36 | {
|
|---|
| 37 | TFile* output_rootfile = new TFile(loc_fname,"UPDATE");
|
|---|
| 38 | if (output_rootfile->IsZombie())
|
|---|
| 39 | {
|
|---|
| 40 | cout << "Error opening file" << endl;
|
|---|
| 41 | exit(-1);
|
|---|
| 42 | }
|
|---|
| 43 | else
|
|---|
| 44 | {
|
|---|
| 45 | if (verbosityLevel > 1)
|
|---|
| 46 | {
|
|---|
| 47 | cout << "...opening root-file:"
|
|---|
| 48 | << loc_fname
|
|---|
| 49 | << " successfull" << endl;
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 | return output_rootfile;
|
|---|
| 53 | }
|
|---|
| 54 | //end of OpenRootFile
|
|---|
| 55 | //----------------------------------------------------------------------------
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 | void
|
|---|
| 59 | CloseRootFile(
|
|---|
| 60 | TFile* output_rootfile
|
|---|
| 61 | )
|
|---|
| 62 | {
|
|---|
| 63 | if (output_rootfile->IsZombie())
|
|---|
| 64 | {
|
|---|
| 65 | cout << "Error closing file" << endl;
|
|---|
| 66 | exit(-1);
|
|---|
| 67 | } else {
|
|---|
| 68 | output_rootfile->Close();
|
|---|
| 69 | }
|
|---|
| 70 | delete output_rootfile;
|
|---|
| 71 | }
|
|---|
| 72 | //end of CloseRootFile
|
|---|
| 73 | //----------------------------------------------------------------------------
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | void
|
|---|
| 77 | SaveHistograms(
|
|---|
| 78 | TString loc_fname,
|
|---|
| 79 | TString subdirectory,
|
|---|
| 80 | TObjArray* histList,
|
|---|
| 81 | bool saveResults,
|
|---|
| 82 | int verbosityLevel
|
|---|
| 83 | )
|
|---|
| 84 | {
|
|---|
| 85 | if (!saveResults) return;
|
|---|
| 86 | if (verbosityLevel > 2) cout << endl
|
|---|
| 87 | << "...saving pixel histograms to subdirectory: "
|
|---|
| 88 | << subdirectory << endl ;
|
|---|
| 89 |
|
|---|
| 90 | TFile* output_rootfile = NULL;
|
|---|
| 91 | output_rootfile = OpenRootFile( loc_fname, verbosityLevel);
|
|---|
| 92 |
|
|---|
| 93 | if (verbosityLevel > 2) cout << endl
|
|---|
| 94 | << "...writing histogram list to root file "
|
|---|
| 95 | << endl ;
|
|---|
| 96 | gFile->WriteTObject(histList, subdirectory); // write the histograms into one Key in the top level directory
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 | if (verbosityLevel > 3) output_rootfile->ls();
|
|---|
| 100 | CloseRootFile( output_rootfile ); // close the file
|
|---|
| 101 | if (verbosityLevel > 2) cout << "...done" << endl;
|
|---|
| 102 | }
|
|---|
| 103 | // end of SaveHistograms
|
|---|
| 104 | //----------------------------------------------------------------------------
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 | TString
|
|---|
| 108 | CreateSubDirName(
|
|---|
| 109 | int pixel
|
|---|
| 110 | )
|
|---|
| 111 | {
|
|---|
| 112 | TString path = "Pixel_";
|
|---|
| 113 | path += pixel;
|
|---|
| 114 | // cout << "path " << path << endl ;
|
|---|
| 115 | return path;
|
|---|
| 116 | }
|
|---|
| 117 | // end of CreateSubDirName
|
|---|
| 118 | //----------------------------------------------------------------------------
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 | TString
|
|---|
| 122 | CreateSubDirName(
|
|---|
| 123 | TString title
|
|---|
| 124 | )
|
|---|
| 125 | {
|
|---|
| 126 | title += "_Pixel";
|
|---|
| 127 | // cout << "path " << path << endl ;
|
|---|
| 128 | return title;
|
|---|
| 129 | }
|
|---|
| 130 | // end of CreateSubDirName
|
|---|
| 131 | //----------------------------------------------------------------------------
|
|---|
| 132 |
|
|---|