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 using namespace std;
8 
9 //--------------------------------------
10 // TEcnaRootFile.cc
11 // Class creation: 03 Dec 2002
12 // Documentation: see TEcnaRootFile.h
13 //--------------------------------------
14 
16 
17 ClassImp(TEcnaRootFile)
18 //___________________________________________________________________________
19 //
20 // Reading of the ROOT file written by TEcnaRunEB
21 //
23 //constructor without arguments
24 
25  // cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << endl;
26 
27  Init();
28 }
29 
30 TEcnaRootFile::TEcnaRootFile(TEcnaObject* pObjectManager, const Text_t *name, const TString& status) {
31 //constructor
32 
33  // cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << endl;
34 
35  Init();
36  Long_t i_this = (Long_t)this;
37  pObjectManager->RegisterPointer("TEcnaRootFile", i_this);
38 
39  fRootFileName = name;
40  fRootFileStatus = status;
41 }
42 
43 TEcnaRootFile::TEcnaRootFile(TEcnaObject* pObjectManager, const Text_t *name) {
44 //constructor
45 
46  // cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << endl;
47 
48  Init();
49  Long_t i_this = (Long_t)this;
50  pObjectManager->RegisterPointer("TEcnaRootFile", i_this);
51 
52  fRootFileName = name;
53  fRootFileStatus = "READ";
54 }
55 
56 TEcnaRootFile::TEcnaRootFile(const Text_t *name, const TString& status) {
57 //constructor
58 
59  // cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << endl;
60 
61  Init();
62  fRootFileName = name;
63  fRootFileStatus = status;
64 }
65 
67 //constructor
68 
69  // cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << endl;
70 
71  Init();
72  fRootFileName = name;
73  fRootFileStatus = "READ";
74 }
75 
77 //destructor
78 
79  //cout << "[Info Management] CLASS: TEcnaRootFile. DESTROY OBJECT: this = " << this << endl;
80 
81  if( fCnaIndivResult != 0 ){delete fCnaIndivResult;}
82 }
83 
85 {
86 //Set default values in all variables
87 
88  TString sEmpty = "";
89  fRootFileName = sEmpty.Data();
90  fRootFileStatus = sEmpty.Data();
91 
92  fRootFile = 0;
93  fCounterBytesCnaResults = 0;
94  fNbEntries = 0;
95  fCnaResultsTree = 0;
96  fCnaResultsBranch = 0;
97  fCnaIndivResult = 0;
98 }
99 
100 void TEcnaRootFile::ReStart(const Text_t *name)
101 {
102  // Set default values + fRootFileName + fRootFileStatus
103 
104  Init();
105  fRootFileName = name;
106  fRootFileStatus = "READ";
107 }
108 
109 void TEcnaRootFile::ReStart(const Text_t *name, const TString& status)
110 {
111  // Set default values + fRootFileName + fRootFileStatus
112 
113  Init();
114  fRootFileName = name;
115  fRootFileStatus = status;
116 }
117 
119 //Close the CNA root file for reading
120  if( fRootFile != 0 )
121  {
122  fRootFile->Close();
123  delete fRootFile; fRootFile = 0;
124  }
125  fCounterBytesCnaResults = 0;
126  fCnaResultsTree = 0;
127  fCnaResultsBranch = 0;
128 }
129 
130 Bool_t TEcnaRootFile::OpenR(const Text_t *name) {
131 //Open the CNA root file for reading
132  Bool_t ok;
133  TString sEmpty = "";
134  if( name != sEmpty ){fRootFileName = name;}
135 
136  if( fRootFile == 0 ){fRootFile = new TFile(fRootFileName.Data(),"READ");}
137 
138  ok = fRootFile->IsOpen();
139  if (ok) {
140  fCnaResultsTree = (TTree *)fRootFile->Get("CNAResults");
141  if (fCnaResultsTree) {
142  if( fCnaIndivResult == 0 ){fCnaIndivResult = new TEcnaResultType();}
143  fCnaResultsBranch = fCnaResultsTree->GetBranch("Results");
144  fCnaResultsBranch->SetAddress(&fCnaIndivResult);
145  fNbEntries = (Int_t)fCnaResultsTree->GetEntries();
146  }
147  else ok = kFALSE;
148  }
149  return ok;
150 }
151 
152 Bool_t TEcnaRootFile::OpenW(const Text_t *name) {
153 //Open root file for writing
154  Bool_t ok = kTRUE;
155  TString sEmpty = "";
156  if( name != sEmpty ){fRootFileName = name;}
157 
158  if( fRootFile == 0 ){fRootFile = new TFile(fRootFileName.Data(),"RECREATE");}
159  if (fRootFile) {
160  fCnaResultsTree = new TTree("CNAResults","CNAResults");
161  fCnaIndivResult = new TEcnaResultType();
162  fCnaResultsBranch = fCnaResultsTree->
163  Branch("Results","TEcnaResultType", &fCnaIndivResult, 64000, 0);
164  }
165  else ok = kFALSE;
166  return ok;
167 }
168 
170 //Read element i
171  Bool_t ok = kTRUE;
172  fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
173  return ok;
174 }
175 
177 //Look for kth element of type typ
178  Bool_t ok = kFALSE;
179  Int_t i = 0;
180  do {
181  fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
182  ok = ( ( fCnaIndivResult->fIthElement == k ) &&
183  ( fCnaIndivResult->fTypOfCnaResult == typ ));
184  i++;
185  } while ((i<fNbEntries) && (!ok));
186  return ok;
187 }
188 
190 //Look for kth element of type typ and return the next entry number
191  Bool_t ok = kFALSE;
192 
193  Int_t i = 0;
194  do {
195  fCounterBytesCnaResults += fCnaResultsTree->GetEntry(i);
196  ok = ( ( fCnaIndivResult->fIthElement == k ) &&
197  ( fCnaIndivResult->fTypOfCnaResult == typ ));
198  i++;
199  } while ((i<fNbEntries) && (!ok));
200 
201  if( ok == kFALSE ){i = -1;}
202  return i;
203 }
Bool_t OpenR(const Text_t *="")
int i
Definition: DBlmapReader.cc:9
CnaResultTyp
R__EXTERN TEcnaRootFile * gCnaRootFile
Definition: TEcnaRootFile.h:68
Bool_t RegisterPointer(const TString &, const Long_t &)
Definition: TEcnaObject.cc:103
int k[5][pyjets_maxn]
Int_t ReadElementNextEntryNumber(CnaResultTyp, Int_t)
void ReStart(const Text_t *)
Bool_t ReadElement(Int_t)
Bool_t OpenW(const Text_t *="")
tuple status
Definition: ntuplemaker.py:245