Go to the documentation of this file.00001
00002
00003
00004
00005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEcnaRootFile.h"
00006 #include "Riostream.h"
00007
00008
00009
00010
00011
00012
00013
00014 TEcnaRootFile *gCnaRootFile = 0;
00015
00016 ClassImp(TEcnaRootFile)
00017
00018
00019
00020
00021 TEcnaRootFile::TEcnaRootFile() {
00022
00023
00024
00025
00026 Init();
00027 }
00028
00029 TEcnaRootFile::TEcnaRootFile(TEcnaObject* pObjectManager, const Text_t *name, TString status) {
00030
00031
00032
00033
00034 Init();
00035 Long_t i_this = (Long_t)this;
00036 pObjectManager->RegisterPointer("TEcnaRootFile", i_this);
00037
00038 fRootFileName = name;
00039 fRootFileStatus = status;
00040 }
00041
00042 TEcnaRootFile::TEcnaRootFile(TEcnaObject* pObjectManager, const Text_t *name) {
00043
00044
00045
00046
00047 Init();
00048 Long_t i_this = (Long_t)this;
00049 pObjectManager->RegisterPointer("TEcnaRootFile", i_this);
00050
00051 fRootFileName = name;
00052 fRootFileStatus = "READ";
00053 }
00054
00055 TEcnaRootFile::TEcnaRootFile(const Text_t *name, TString status) {
00056
00057
00058
00059
00060 Init();
00061 fRootFileName = name;
00062 fRootFileStatus = status;
00063 }
00064
00065 TEcnaRootFile::TEcnaRootFile(const Text_t *name) {
00066
00067
00068
00069
00070 Init();
00071 fRootFileName = name;
00072 fRootFileStatus = "READ";
00073 }
00074
00075 TEcnaRootFile::~TEcnaRootFile() {
00076
00077
00078
00079
00080 if( fCnaIndivResult != 0 ){delete fCnaIndivResult;}
00081 }
00082
00083 void TEcnaRootFile::Init()
00084 {
00085
00086 fRootFileName = "";
00087 fRootFileStatus = "";
00088 fRootFile = 0;
00089 fCounterBytesCnaResults = 0;
00090 fNbEntries = 0;
00091 fCnaResultsTree = 0;
00092 fCnaResultsBranch = 0;
00093 fCnaIndivResult = 0;
00094 }
00095
00096 void TEcnaRootFile::ReStart(const Text_t *name)
00097 {
00098
00099
00100 Init();
00101 fRootFileName = name;
00102 fRootFileStatus = "READ";
00103 }
00104
00105 void TEcnaRootFile::ReStart(const Text_t *name, TString status)
00106 {
00107
00108
00109 Init();
00110 fRootFileName = name;
00111 fRootFileStatus = status;
00112 }
00113
00114 void TEcnaRootFile::CloseFile() {
00115
00116 if( fRootFile != 0 )
00117 {
00118 fRootFile->Close();
00119 delete fRootFile; fRootFile = 0;
00120 }
00121 fCounterBytesCnaResults = 0;
00122 fCnaResultsTree = 0;
00123 fCnaResultsBranch = 0;
00124 }
00125
00126 Bool_t TEcnaRootFile::OpenR(const Text_t *name) {
00127
00128 Bool_t ok;
00129 TString sEmpty = "";
00130 if( name != sEmpty ){fRootFileName = name;}
00131
00132 if( fRootFile == 0 ){fRootFile = new TFile(fRootFileName.Data(),"READ");}
00133
00134 ok = fRootFile->IsOpen();
00135 if (ok) {
00136 fCnaResultsTree = (TTree *)fRootFile->Get("CNAResults");
00137 if (fCnaResultsTree) {
00138 if( fCnaIndivResult == 0 ){fCnaIndivResult = new TEcnaResultType();}
00139 fCnaResultsBranch = fCnaResultsTree->GetBranch("Results");
00140 fCnaResultsBranch->SetAddress(&fCnaIndivResult);
00141 fNbEntries = (Int_t)fCnaResultsTree->GetEntries();
00142 }
00143 else ok = kFALSE;
00144 }
00145 return ok;
00146 }
00147
00148 Bool_t TEcnaRootFile::OpenW(const Text_t *name) {
00149
00150 Bool_t ok = kTRUE;
00151 TString sEmpty = "";
00152 if( name != sEmpty ){fRootFileName = name;}
00153
00154 if( fRootFile == 0 ){fRootFile = new TFile(fRootFileName.Data(),"RECREATE");}
00155 if (fRootFile) {
00156 fCnaResultsTree = new TTree("CNAResults","CNAResults");
00157 fCnaIndivResult = new TEcnaResultType();
00158 fCnaResultsBranch = fCnaResultsTree->
00159 Branch("Results","TEcnaResultType", &fCnaIndivResult, 64000, 0);
00160 }
00161 else ok = kFALSE;
00162 return ok;
00163 }
00164
00165 Bool_t TEcnaRootFile::ReadElement(Int_t i) {
00166
00167 Bool_t ok = kTRUE;
00168 fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
00169 return ok;
00170 }
00171
00172 Bool_t TEcnaRootFile::ReadElement(CnaResultTyp typ, Int_t k) {
00173
00174 Bool_t ok = kFALSE;
00175 Int_t i = 0;
00176 do {
00177 fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
00178 ok = ( ( fCnaIndivResult->fIthElement == k ) &&
00179 ( fCnaIndivResult->fTypOfCnaResult == typ ));
00180 i++;
00181 } while ((i<fNbEntries) && (!ok));
00182 return ok;
00183 }
00184
00185 Int_t TEcnaRootFile::ReadElementNextEntryNumber(CnaResultTyp typ, Int_t k) {
00186
00187 Bool_t ok = kFALSE;
00188
00189 Int_t i = 0;
00190 do {
00191 fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
00192 ok = ( ( fCnaIndivResult->fIthElement == k ) &&
00193 ( fCnaIndivResult->fTypOfCnaResult == typ ));
00194 i++;
00195 } while ((i<fNbEntries) && (!ok));
00196
00197 if( ok == kFALSE ){i = -1;}
00198 return i;
00199 }