Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:45

0001 //----------Author's Names: FX Gentit, B.Fabbro  DSM/IRFU/SPP CEA-Saclay

0002 //----------Copyright:Those valid for CEA sofware

0003 //----------Modified:30/09/2011

0004 
0005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEcnaRootFile.h"
0006 #include "Riostream.h"
0007 
0008 //--------------------------------------

0009 //  TEcnaRootFile.cc

0010 //  Class creation: 03 Dec 2002

0011 //  Documentation: see TEcnaRootFile.h

0012 //--------------------------------------

0013 
0014 TEcnaRootFile *gCnaRootFile = nullptr;
0015 
0016 ClassImp(TEcnaRootFile);
0017 //___________________________________________________________________________

0018 //

0019 //  Reading of the ROOT file written by TEcnaRunEB

0020 //

0021 TEcnaRootFile::TEcnaRootFile() {
0022   //constructor without arguments

0023 
0024   // std::cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << std::endl;

0025 
0026   Init();
0027 }
0028 
0029 TEcnaRootFile::TEcnaRootFile(TEcnaObject *pObjectManager, const Text_t *name, const TString &status) {
0030   //constructor

0031 
0032   // std::cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << std::endl;

0033 
0034   Init();
0035   Long_t i_this = (Long_t)this;
0036   pObjectManager->RegisterPointer("TEcnaRootFile", i_this);
0037 
0038   fRootFileName = name;
0039   fRootFileStatus = status;
0040 }
0041 
0042 TEcnaRootFile::TEcnaRootFile(TEcnaObject *pObjectManager, const Text_t *name) {
0043   //constructor

0044 
0045   // std::cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << std::endl;

0046 
0047   Init();
0048   Long_t i_this = (Long_t)this;
0049   pObjectManager->RegisterPointer("TEcnaRootFile", i_this);
0050 
0051   fRootFileName = name;
0052   fRootFileStatus = "READ";
0053 }
0054 
0055 TEcnaRootFile::TEcnaRootFile(const Text_t *name, const TString &status) {
0056   //constructor

0057 
0058   // std::cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << std::endl;

0059 
0060   Init();
0061   fRootFileName = name;
0062   fRootFileStatus = status;
0063 }
0064 
0065 TEcnaRootFile::TEcnaRootFile(const Text_t *name) {
0066   //constructor

0067 
0068   // std::cout << "[Info Management] CLASS: TEcnaRootFile.      CREATE OBJECT: this = " << this << std::endl;

0069 
0070   Init();
0071   fRootFileName = name;
0072   fRootFileStatus = "READ";
0073 }
0074 
0075 TEcnaRootFile::~TEcnaRootFile() {
0076   //destructor

0077 
0078   //std::cout << "[Info Management] CLASS: TEcnaRootFile.      DESTROY OBJECT: this = " << this << std::endl;

0079 
0080   if (fCnaIndivResult != nullptr) {
0081     delete fCnaIndivResult;
0082   }
0083 }
0084 
0085 void TEcnaRootFile::Init() {
0086   //Set default values in all variables

0087 
0088   TString sEmpty = "";
0089   fRootFileName = sEmpty.Data();
0090   fRootFileStatus = sEmpty.Data();
0091 
0092   fRootFile = nullptr;
0093   fCounterBytesCnaResults = 0;
0094   fNbEntries = 0;
0095   fCnaResultsTree = nullptr;
0096   fCnaResultsBranch = nullptr;
0097   fCnaIndivResult = nullptr;
0098 }
0099 
0100 void TEcnaRootFile::ReStart(const Text_t *name) {
0101   // Set default values + fRootFileName + fRootFileStatus

0102 
0103   Init();
0104   fRootFileName = name;
0105   fRootFileStatus = "READ";
0106 }
0107 
0108 void TEcnaRootFile::ReStart(const Text_t *name, const TString &status) {
0109   // Set default values + fRootFileName + fRootFileStatus

0110 
0111   Init();
0112   fRootFileName = name;
0113   fRootFileStatus = status;
0114 }
0115 
0116 void TEcnaRootFile::CloseFile() {
0117   //Close the CNA root file for reading

0118   if (fRootFile != nullptr) {
0119     fRootFile->Close();
0120     delete fRootFile;
0121     fRootFile = nullptr;
0122   }
0123   fCounterBytesCnaResults = 0;
0124   fCnaResultsTree = nullptr;
0125   fCnaResultsBranch = nullptr;
0126 }
0127 
0128 Bool_t TEcnaRootFile::OpenR(const Text_t *name) {
0129   //Open the CNA root file for reading

0130   Bool_t ok;
0131   TString sEmpty = "";
0132   if (name != sEmpty) {
0133     fRootFileName = name;
0134   }
0135 
0136   if (fRootFile == nullptr) {
0137     fRootFile = new TFile(fRootFileName.Data(), "READ");
0138   }
0139 
0140   ok = fRootFile->IsOpen();
0141   if (ok) {
0142     fCnaResultsTree = (TTree *)fRootFile->Get("CNAResults");
0143     if (fCnaResultsTree) {
0144       if (fCnaIndivResult == nullptr) {
0145         fCnaIndivResult = new TEcnaResultType();
0146       }
0147       fCnaResultsBranch = fCnaResultsTree->GetBranch("Results");
0148       fCnaResultsBranch->SetAddress(&fCnaIndivResult);
0149       fNbEntries = (Int_t)fCnaResultsTree->GetEntries();
0150     } else
0151       ok = kFALSE;
0152   }
0153   return ok;
0154 }
0155 
0156 Bool_t TEcnaRootFile::OpenW(const Text_t *name) {
0157   //Open root file for writing

0158   Bool_t ok = kTRUE;
0159   TString sEmpty = "";
0160   if (name != sEmpty) {
0161     fRootFileName = name;
0162   }
0163 
0164   if (fRootFile == nullptr) {
0165     fRootFile = new TFile(fRootFileName.Data(), "RECREATE");
0166   }
0167   if (fRootFile) {
0168     fCnaResultsTree = new TTree("CNAResults", "CNAResults");
0169     fCnaIndivResult = new TEcnaResultType();
0170     fCnaResultsBranch = fCnaResultsTree->Branch("Results", "TEcnaResultType", &fCnaIndivResult, 64000, 0);
0171   } else
0172     ok = kFALSE;
0173   return ok;
0174 }
0175 
0176 Bool_t TEcnaRootFile::ReadElement(Int_t i) {
0177   //Read element i

0178   Bool_t ok = kTRUE;
0179   fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
0180   return ok;
0181 }
0182 
0183 Bool_t TEcnaRootFile::ReadElement(CnaResultTyp typ, Int_t k) {
0184   //Look for kth element of type typ

0185   Bool_t ok = kFALSE;
0186   Int_t i = 0;
0187   do {
0188     fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
0189     ok = ((fCnaIndivResult->fIthElement == k) && (fCnaIndivResult->fTypOfCnaResult == typ));
0190     i++;
0191   } while ((i < fNbEntries) && (!ok));
0192   return ok;
0193 }
0194 
0195 Int_t TEcnaRootFile::ReadElementNextEntryNumber(CnaResultTyp typ, Int_t k) {
0196   //Look for kth element of type typ and return the next entry number

0197   Bool_t ok = kFALSE;
0198 
0199   Int_t i = 0;
0200   do {
0201     fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
0202     ok = ((fCnaIndivResult->fIthElement == k) && (fCnaIndivResult->fTypOfCnaResult == typ));
0203     i++;
0204   } while ((i < fNbEntries) && (!ok));
0205 
0206   if (ok == kFALSE) {
0207     i = -1;
0208   }
0209   return i;
0210 }