CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/src/TEcnaRootFile.cc

Go to the documentation of this file.
00001 //----------Author's Names: FX Gentit, B.Fabbro  DSM/IRFU/SPP CEA-Saclay
00002 //----------Copyright:Those valid for CEA sofware
00003 //----------Modified:22/03/2010
00004 
00005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEcnaRootFile.h"
00006 #include "Riostream.h"
00007 
00008 TEcnaRootFile *gCnaRootFile = 0;
00009 
00010 ClassImp(TEcnaRootFile)
00011 //___________________________________________________________________________
00012 //
00013 //  Reading of the ROOT file written by TEcnaRunEB
00014 //
00015 TEcnaRootFile::TEcnaRootFile() {
00016 //constructor without arguments
00017 
00018   // cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << endl;
00019 
00020   Init();
00021 }
00022 
00023 TEcnaRootFile::TEcnaRootFile(const Text_t *name) {
00024 //constructor
00025 
00026  // cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << endl;
00027 
00028   Init();
00029   fRootFileName = name;
00030 }
00031 
00032 TEcnaRootFile::TEcnaRootFile(const Text_t *name, TString status) {
00033 //constructor
00034 
00035  // cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << endl;
00036 
00037   Init();
00038   fRootFileName   = name;
00039   fRootFileStatus = status;
00040 }
00041 
00042 TEcnaRootFile::~TEcnaRootFile() {
00043 //destructor
00044 
00045   //cout << "[Info Management] CLASS: TEcnaRootFile.      DESTROY OBJECT: this = " << this << endl;
00046 
00047   if( fCnaIndivResult != 0 ){delete fCnaIndivResult;}
00048 }
00049 
00050 void TEcnaRootFile::Init()
00051 {
00052 //Set default values in all variables
00053   fRootFileName           = "";
00054   fRootFileStatus         = "";
00055   fRootFile               = 0;
00056   fCounterBytesCnaResults = 0;
00057   fNbEntries              = 0;
00058   fCnaResultsTree         = 0;
00059   fCnaResultsBranch       = 0;
00060   fCnaIndivResult         = 0;
00061 }
00062 
00063 void TEcnaRootFile::CloseFile() {
00064 //Close the CNA root file for reading
00065   fRootFile->Close();
00066   delete fRootFile; fRootFile = 0;
00067   fCounterBytesCnaResults = 0;
00068   fCnaResultsTree         = 0;
00069   fCnaResultsBranch       = 0;
00070 }
00071 
00072 Bool_t TEcnaRootFile::OpenR(const Text_t *name) {
00073 //Open the CNA root file for reading
00074   Bool_t ok;
00075   TString sEmpty = "";
00076   if( name != sEmpty ){fRootFileName = name;}
00077 
00078   if( fRootFile == 0 ){fRootFile = new TFile(fRootFileName.Data(),"READ");}
00079 
00080   ok = fRootFile->IsOpen();
00081   if (ok) {
00082     fCnaResultsTree = (TTree *)fRootFile->Get("CNAResults");
00083     if (fCnaResultsTree) {
00084       if( fCnaIndivResult == 0 ){fCnaIndivResult = new TEcnaResultType();}
00085       fCnaResultsBranch = fCnaResultsTree->GetBranch("Results");
00086       fCnaResultsBranch->SetAddress(&fCnaIndivResult);
00087       fNbEntries = (Int_t) fCnaResultsTree->GetEntries();
00088     }
00089     else ok = kFALSE;
00090   }
00091   return ok;
00092 }
00093 
00094 Bool_t TEcnaRootFile::OpenW(const Text_t *name) {
00095 //Open root file for writing
00096   Bool_t ok = kTRUE;
00097   TString sEmpty = "";
00098   if( name != sEmpty ){fRootFileName = name;}
00099 
00100   if( fRootFile == 0 ){fRootFile = new TFile(fRootFileName.Data(),"RECREATE");}
00101   if (fRootFile) {
00102     fCnaResultsTree = new TTree("CNAResults","CNAResults");
00103     fCnaIndivResult = new TEcnaResultType();
00104     fCnaResultsBranch = fCnaResultsTree->
00105       Branch("Results","TEcnaResultType", &fCnaIndivResult, 64000, 0);
00106   }
00107   else ok = kFALSE;
00108   return ok;
00109 }
00110 
00111 Bool_t TEcnaRootFile::ReadElement(Int_t i) {
00112 //Read element i
00113   Bool_t ok = kTRUE;
00114   fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
00115   return ok;
00116 }
00117 
00118 Bool_t TEcnaRootFile::ReadElement(CnaResultTyp typ, Int_t k) {
00119 //Look for kth element of type typ
00120   Bool_t ok = kFALSE;
00121   Int_t i = 0;
00122   do {
00123     fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
00124     ok = ( ( fCnaIndivResult->fIthElement == k ) &&
00125            ( fCnaIndivResult->fTypOfCnaResult == typ ));
00126     i++;
00127   } while ((i<fNbEntries) && (!ok));
00128   return ok;
00129 }
00130 
00131 Int_t TEcnaRootFile::ReadElementNextEntryNumber(CnaResultTyp typ, Int_t k) {
00132 //Look for kth element of type typ and return the next entry number
00133   Bool_t ok = kFALSE;
00134 
00135   Int_t i = 0;
00136   do {
00137     fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
00138     ok = ( ( fCnaIndivResult->fIthElement == k ) &&
00139            ( fCnaIndivResult->fTypOfCnaResult == typ ));
00140     i++;
00141   } while ((i<fNbEntries) && (!ok));
00142 
00143   if( ok == kFALSE ){i = -1;}
00144   return i;
00145 }