00001 //----------Author's Names: FX Gentit, B.Fabbro DAPNIA/SPP CEN Saclay 00002 //----------Copyright:Those valid for CEA sofware 00003 //----------Modified:07/06/2007 00004 00005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TCnaRootFile.h" 00006 00007 //#include "Riostream.h" 00008 00009 TCnaRootFile *gCnaRootFile = 0; 00010 00011 ClassImp(TCnaRootFile) 00012 //___________________________________________________________________________ 00013 // 00014 // Reading of the ROOT file written by TCnaRunEB 00015 // 00016 TCnaRootFile::TCnaRootFile(const Text_t *name) { 00017 //constructor 00018 Init(); 00019 fRootFileName = name; 00020 } 00021 00022 TCnaRootFile::TCnaRootFile(const Text_t *name, TString status) { 00023 //constructor 00024 Init(); 00025 fRootFileName = name; 00026 fRootFileStatus = status; 00027 } 00028 00029 TCnaRootFile::~TCnaRootFile() { 00030 //destructor 00031 } 00032 00033 void TCnaRootFile::Init() { 00034 //Set default values in all variables 00035 fRootFileName = ""; 00036 fRootFileStatus = ""; 00037 fRootFile = 0; 00038 fCounterBytesCnaResults = 0; 00039 fNbEntries = 0; 00040 fCnaResultsTree = 0; 00041 fCnaResultsBranch = 0; 00042 fCnaIndivResult = 0; 00043 } 00044 00045 void TCnaRootFile::CloseFile() { 00046 //Close the CNA root file for reading 00047 fRootFile->Close(); 00048 delete fRootFile; 00049 fRootFile = 0; 00050 fCounterBytesCnaResults = 0; 00051 fCnaResultsTree = 0; 00052 fCnaResultsBranch = 0; 00053 } 00054 00055 Bool_t TCnaRootFile::OpenR(Text_t *name) { 00056 //Open the CNA root file for reading 00057 Bool_t ok; 00058 if (name != "") fRootFileName = name; 00059 fRootFile = new TFile(fRootFileName.Data(),"READ"); 00060 ok = fRootFile->IsOpen(); 00061 if (ok) { 00062 fCnaResultsTree = (TTree *)fRootFile->Get("CNAResults"); 00063 //cout << "*TCnaRootFile::OpenR(..)> fCnaResultsTree : " << fCnaResultsTree << endl; 00064 if (fCnaResultsTree) { 00065 fCnaIndivResult = new TCnaResultType(); 00066 //cout << "*TCnaRootFile::OpenR(..)> fCnaIndivResult : " << fCnaIndivResult << endl; 00067 fCnaResultsBranch = fCnaResultsTree->GetBranch("Results"); 00068 fCnaResultsBranch->SetAddress(&fCnaIndivResult); 00069 fNbEntries = (Int_t) fCnaResultsTree->GetEntries(); 00070 //cout << "*TCnaRootFile::OpenR(..)> fNbEntries : " << fNbEntries << endl; 00071 } 00072 else ok = kFALSE; 00073 } 00074 return ok; 00075 } 00076 00077 Bool_t TCnaRootFile::OpenW(Text_t *name) { 00078 //Open root file for writing 00079 Bool_t ok = kTRUE; 00080 if (name != "") fRootFileName = name; 00081 00082 //cout << "*TCnaRootFile::OpenW(...)> fRootFileName.Data() = " 00083 // << fRootFileName.Data() << endl; 00084 00085 fRootFile = new TFile(fRootFileName.Data(),"RECREATE"); 00086 if (fRootFile) { 00087 fCnaResultsTree = new TTree("CNAResults","CNAResults"); 00088 fCnaIndivResult = new TCnaResultType(); 00089 fCnaResultsBranch = fCnaResultsTree-> 00090 Branch("Results","TCnaResultType", &fCnaIndivResult, 64000, 0); 00091 } 00092 else ok = kFALSE; 00093 return ok; 00094 } 00095 00096 Bool_t TCnaRootFile::ReadElement(Int_t i) { 00097 //Read element i 00098 Bool_t ok = kTRUE; 00099 fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i); 00100 return ok; 00101 } 00102 00103 Bool_t TCnaRootFile::ReadElement(CnaResultTyp typ, Int_t k) { 00104 //Look for kth element of type typ 00105 Bool_t ok = kFALSE; 00106 Int_t i = 0; 00107 do { 00108 // cout << "*TCnaRootFile::ReadElement(typ,k)> fIthElement = " 00109 // << fCnaIndivResult->fIthElement << endl; 00110 // cout << "*TCnaRootFile::ReadElement(typ,k)> fTypOfCnaResult = " 00111 // << fCnaIndivResult->fTypOfCnaResult << endl; 00112 00113 fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i); 00114 ok = ( ( fCnaIndivResult->fIthElement == k ) && 00115 ( fCnaIndivResult->fTypOfCnaResult == typ )); 00116 i++; 00117 } while ((i<fNbEntries) && (!ok)); 00118 return ok; 00119 }