CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/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:30/09/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 
00087   TString sEmpty = "";
00088   fRootFileName   = sEmpty.Data();
00089   fRootFileStatus = sEmpty.Data();
00090 
00091   fRootFile               = 0;
00092   fCounterBytesCnaResults = 0;
00093   fNbEntries              = 0;
00094   fCnaResultsTree         = 0;
00095   fCnaResultsBranch       = 0;
00096   fCnaIndivResult         = 0;
00097 }
00098 
00099 void TEcnaRootFile::ReStart(const Text_t *name)
00100 {
00101   // Set default values + fRootFileName + fRootFileStatus
00102 
00103   Init();
00104   fRootFileName   = name;
00105   fRootFileStatus = "READ";
00106 }
00107 
00108 void TEcnaRootFile::ReStart(const Text_t *name, TString status)
00109 {
00110   // Set default values + fRootFileName + fRootFileStatus
00111 
00112   Init();
00113   fRootFileName   = name;
00114   fRootFileStatus = status;
00115 }
00116 
00117 void TEcnaRootFile::CloseFile() {
00118 //Close the CNA root file for reading
00119   if( fRootFile != 0 )
00120     {
00121       fRootFile->Close();
00122       delete fRootFile; fRootFile = 0;
00123     }
00124   fCounterBytesCnaResults = 0;
00125   fCnaResultsTree         = 0;
00126   fCnaResultsBranch       = 0;
00127 }
00128 
00129 Bool_t TEcnaRootFile::OpenR(const Text_t *name) {
00130 //Open the CNA root file for reading
00131   Bool_t ok;
00132   TString sEmpty = "";
00133   if( name != sEmpty ){fRootFileName = name;}
00134 
00135   if( fRootFile == 0 ){fRootFile = new TFile(fRootFileName.Data(),"READ");}
00136 
00137   ok = fRootFile->IsOpen();
00138   if (ok) {
00139     fCnaResultsTree = (TTree *)fRootFile->Get("CNAResults");
00140     if (fCnaResultsTree) {
00141       if( fCnaIndivResult == 0 ){fCnaIndivResult = new TEcnaResultType();}
00142       fCnaResultsBranch = fCnaResultsTree->GetBranch("Results");
00143       fCnaResultsBranch->SetAddress(&fCnaIndivResult);
00144       fNbEntries = (Int_t)fCnaResultsTree->GetEntries();
00145     }
00146     else ok = kFALSE;
00147   }
00148   return ok;
00149 }
00150 
00151 Bool_t TEcnaRootFile::OpenW(const Text_t *name) {
00152 //Open root file for writing
00153   Bool_t ok = kTRUE;
00154   TString sEmpty = "";
00155   if( name != sEmpty ){fRootFileName = name;}
00156 
00157   if( fRootFile == 0 ){fRootFile = new TFile(fRootFileName.Data(),"RECREATE");}
00158   if (fRootFile) {
00159     fCnaResultsTree = new TTree("CNAResults","CNAResults");
00160     fCnaIndivResult = new TEcnaResultType();
00161     fCnaResultsBranch = fCnaResultsTree->
00162       Branch("Results","TEcnaResultType", &fCnaIndivResult, 64000, 0);
00163   }
00164   else ok = kFALSE;
00165   return ok;
00166 }
00167 
00168 Bool_t TEcnaRootFile::ReadElement(Int_t i) {
00169 //Read element i
00170   Bool_t ok = kTRUE;
00171   fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
00172   return ok;
00173 }
00174 
00175 Bool_t TEcnaRootFile::ReadElement(CnaResultTyp typ, Int_t k) {
00176 //Look for kth element of type typ
00177   Bool_t ok = kFALSE;
00178   Int_t i = 0;
00179   do {
00180     fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
00181     ok = ( ( fCnaIndivResult->fIthElement == k ) &&
00182            ( fCnaIndivResult->fTypOfCnaResult == typ ));
00183     i++;
00184   } while ((i<fNbEntries) && (!ok));
00185   return ok;
00186 }
00187 
00188 Int_t TEcnaRootFile::ReadElementNextEntryNumber(CnaResultTyp typ, Int_t k) {
00189 //Look for kth element of type typ and return the next entry number
00190   Bool_t ok = kFALSE;
00191 
00192   Int_t i = 0;
00193   do {
00194     fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
00195     ok = ( ( fCnaIndivResult->fIthElement == k ) &&
00196            ( fCnaIndivResult->fTypOfCnaResult == typ ));
00197     i++;
00198   } while ((i<fNbEntries) && (!ok));
00199 
00200   if( ok == kFALSE ){i = -1;}
00201   return i;
00202 }