CMS 3D CMS Logo

CMSSW_4_4_3_patch1/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:24/03/2011
00004 
00005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEcnaRootFile.h"
00006 #include "Riostream.h"
00007 
00008 //--------------------------------------
00009 //  TEcnaRootFile.cc
00010 //  Class creation: 03 Dec 2002
00011 //  Documentation: see TEcnaRootFile.h
00012 //--------------------------------------
00013 
00014 TEcnaRootFile *gCnaRootFile = 0;
00015 
00016 ClassImp(TEcnaRootFile)
00017 //___________________________________________________________________________
00018 //
00019 //  Reading of the ROOT file written by TEcnaRunEB
00020 //
00021 TEcnaRootFile::TEcnaRootFile() {
00022 //constructor without arguments
00023 
00024   // cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << endl;
00025 
00026   Init();
00027 }
00028 
00029 TEcnaRootFile::TEcnaRootFile(TEcnaObject* pObjectManager, const Text_t *name, TString status) {
00030 //constructor
00031 
00032  // cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << endl;
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 //constructor
00044 
00045  // cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << endl;
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 //constructor
00057 
00058  // cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << endl;
00059 
00060   Init();
00061   fRootFileName   = name;
00062   fRootFileStatus = status;
00063 }
00064 
00065 TEcnaRootFile::TEcnaRootFile(const Text_t *name) {
00066 //constructor
00067 
00068  // cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << endl;
00069 
00070   Init();
00071   fRootFileName = name;
00072   fRootFileStatus = "READ";
00073 }
00074 
00075 TEcnaRootFile::~TEcnaRootFile() {
00076 //destructor
00077 
00078   //cout << "[Info Management] CLASS: TEcnaRootFile.      DESTROY OBJECT: this = " << this << endl;
00079 
00080   if( fCnaIndivResult != 0 ){delete fCnaIndivResult;}
00081 }
00082 
00083 void TEcnaRootFile::Init()
00084 {
00085 //Set default values in all variables
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   // Set default values + fRootFileName + fRootFileStatus
00099 
00100   Init();
00101   fRootFileName   = name;
00102   fRootFileStatus = "READ";
00103 }
00104 
00105 void TEcnaRootFile::ReStart(const Text_t *name, TString status)
00106 {
00107   // Set default values + fRootFileName + fRootFileStatus
00108 
00109   Init();
00110   fRootFileName   = name;
00111   fRootFileStatus = status;
00112 }
00113 
00114 void TEcnaRootFile::CloseFile() {
00115 //Close the CNA root file for reading
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 //Open the CNA root file for reading
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 //Open root file for writing
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 //Read element i
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 //Look for kth element of type typ
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 //Look for kth element of type typ and return the next entry number
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 }