CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TEcnaRootFile.cc
Go to the documentation of this file.
1 //----------Author's Names: FX Gentit, B.Fabbro DSM/IRFU/SPP CEA-Saclay
2 //----------Copyright:Those valid for CEA sofware
3 //----------Modified:30/09/2011
4 
6 #include "Riostream.h"
7 
8 //--------------------------------------
9 // TEcnaRootFile.cc
10 // Class creation: 03 Dec 2002
11 // Documentation: see TEcnaRootFile.h
12 //--------------------------------------
13 
15 
16 ClassImp(TEcnaRootFile)
17 //___________________________________________________________________________
18 //
19 // Reading of the ROOT file written by TEcnaRunEB
20 //
22 //constructor without arguments
23 
24  // cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << endl;
25 
26  Init();
27 }
28 
29 TEcnaRootFile::TEcnaRootFile(TEcnaObject* pObjectManager, const Text_t *name, TString status) {
30 //constructor
31 
32  // cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << endl;
33 
34  Init();
35  Long_t i_this = (Long_t)this;
36  pObjectManager->RegisterPointer("TEcnaRootFile", i_this);
37 
40 }
41 
42 TEcnaRootFile::TEcnaRootFile(TEcnaObject* pObjectManager, const Text_t *name) {
43 //constructor
44 
45  // cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << endl;
46 
47  Init();
48  Long_t i_this = (Long_t)this;
49  pObjectManager->RegisterPointer("TEcnaRootFile", i_this);
50 
52  fRootFileStatus = "READ";
53 }
54 
55 TEcnaRootFile::TEcnaRootFile(const Text_t *name, TString status) {
56 //constructor
57 
58  // cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << endl;
59 
60  Init();
63 }
64 
66 //constructor
67 
68  // cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << endl;
69 
70  Init();
72  fRootFileStatus = "READ";
73 }
74 
76 //destructor
77 
78  //cout << "[Info Management] CLASS: TEcnaRootFile. DESTROY OBJECT: this = " << this << endl;
79 
80  if( fCnaIndivResult != 0 ){delete fCnaIndivResult;}
81 }
82 
84 {
85 //Set default values in all variables
86 
87  TString sEmpty = "";
88  fRootFileName = sEmpty.Data();
89  fRootFileStatus = sEmpty.Data();
90 
91  fRootFile = 0;
93  fNbEntries = 0;
94  fCnaResultsTree = 0;
96  fCnaIndivResult = 0;
97 }
98 
99 void TEcnaRootFile::ReStart(const Text_t *name)
100 {
101  // Set default values + fRootFileName + fRootFileStatus
102 
103  Init();
105  fRootFileStatus = "READ";
106 }
107 
108 void TEcnaRootFile::ReStart(const Text_t *name, TString status)
109 {
110  // Set default values + fRootFileName + fRootFileStatus
111 
112  Init();
115 }
116 
118 //Close the CNA root file for reading
119  if( fRootFile != 0 )
120  {
121  fRootFile->Close();
122  delete fRootFile; fRootFile = 0;
123  }
125  fCnaResultsTree = 0;
126  fCnaResultsBranch = 0;
127 }
128 
129 Bool_t TEcnaRootFile::OpenR(const Text_t *name) {
130 //Open the CNA root file for reading
131  Bool_t ok;
132  TString sEmpty = "";
133  if( name != sEmpty ){fRootFileName = name;}
134 
135  if( fRootFile == 0 ){fRootFile = new TFile(fRootFileName.Data(),"READ");}
136 
137  ok = fRootFile->IsOpen();
138  if (ok) {
139  fCnaResultsTree = (TTree *)fRootFile->Get("CNAResults");
140  if (fCnaResultsTree) {
141  if( fCnaIndivResult == 0 ){fCnaIndivResult = new TEcnaResultType();}
142  fCnaResultsBranch = fCnaResultsTree->GetBranch("Results");
143  fCnaResultsBranch->SetAddress(&fCnaIndivResult);
144  fNbEntries = (Int_t)fCnaResultsTree->GetEntries();
145  }
146  else ok = kFALSE;
147  }
148  return ok;
149 }
150 
151 Bool_t TEcnaRootFile::OpenW(const Text_t *name) {
152 //Open root file for writing
153  Bool_t ok = kTRUE;
154  TString sEmpty = "";
155  if( name != sEmpty ){fRootFileName = name;}
156 
157  if( fRootFile == 0 ){fRootFile = new TFile(fRootFileName.Data(),"RECREATE");}
158  if (fRootFile) {
159  fCnaResultsTree = new TTree("CNAResults","CNAResults");
162  Branch("Results","TEcnaResultType", &fCnaIndivResult, 64000, 0);
163  }
164  else ok = kFALSE;
165  return ok;
166 }
167 
169 //Read element i
170  Bool_t ok = kTRUE;
172  return ok;
173 }
174 
176 //Look for kth element of type typ
177  Bool_t ok = kFALSE;
178  Int_t i = 0;
179  do {
181  ok = ( ( fCnaIndivResult->fIthElement == k ) &&
182  ( fCnaIndivResult->fTypOfCnaResult == typ ));
183  i++;
184  } while ((i<fNbEntries) && (!ok));
185  return ok;
186 }
187 
189 //Look for kth element of type typ and return the next entry number
190  Bool_t ok = kFALSE;
191 
192  Int_t i = 0;
193  do {
195  ok = ( ( fCnaIndivResult->fIthElement == k ) &&
196  ( fCnaIndivResult->fTypOfCnaResult == typ ));
197  i++;
198  } while ((i<fNbEntries) && (!ok));
199 
200  if( ok == kFALSE ){i = -1;}
201  return i;
202 }
TEcnaResultType * fCnaIndivResult
Definition: TEcnaRootFile.h:45
Bool_t OpenR(const Text_t *="")
int i
Definition: DBlmapReader.cc:9
CnaResultTyp
R__EXTERN TEcnaRootFile * gCnaRootFile
Definition: TEcnaRootFile.h:68
TBranch * fCnaResultsBranch
Definition: TEcnaRootFile.h:44
CnaResultTyp fTypOfCnaResult
TString fRootFileStatus
Definition: TEcnaRootFile.h:34
Bool_t RegisterPointer(const TString, const Long_t &)
Definition: TEcnaObject.cc:102
int k[5][pyjets_maxn]
Int_t fCounterBytesCnaResults
Definition: TEcnaRootFile.h:38
Int_t ReadElementNextEntryNumber(CnaResultTyp, Int_t)
TString fRootFileName
Definition: TEcnaRootFile.h:33
void ReStart(const Text_t *)
Bool_t ReadElement(Int_t)
Bool_t OpenW(const Text_t *="")
tuple status
Definition: ntuplemaker.py:245
TTree * fCnaResultsTree
Definition: TEcnaRootFile.h:40
TFile * fRootFile
Definition: TEcnaRootFile.h:36