CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
17 //___________________________________________________________________________
18 //
19 // Reading of the ROOT file written by TEcnaRunEB
20 //
22  //constructor without arguments
23 
24  // std::cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << std::endl;
25 
26  Init();
27 }
28 
29 TEcnaRootFile::TEcnaRootFile(TEcnaObject *pObjectManager, const Text_t *name, const TString &status) {
30  //constructor
31 
32  // std::cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << std::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  // std::cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << std::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, const TString &status) {
56  //constructor
57 
58  // std::cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << std::endl;
59 
60  Init();
63 }
64 
66  //constructor
67 
68  // std::cout << "[Info Management] CLASS: TEcnaRootFile. CREATE OBJECT: this = " << this << std::endl;
69 
70  Init();
72  fRootFileStatus = "READ";
73 }
74 
76  //destructor
77 
78  //std::cout << "[Info Management] CLASS: TEcnaRootFile. DESTROY OBJECT: this = " << this << std::endl;
79 
80  if (fCnaIndivResult != nullptr) {
81  delete fCnaIndivResult;
82  }
83 }
84 
86  //Set default values in all variables
87 
88  TString sEmpty = "";
89  fRootFileName = sEmpty.Data();
90  fRootFileStatus = sEmpty.Data();
91 
92  fRootFile = nullptr;
94  fNbEntries = 0;
95  fCnaResultsTree = nullptr;
96  fCnaResultsBranch = nullptr;
97  fCnaIndivResult = nullptr;
98 }
99 
100 void TEcnaRootFile::ReStart(const Text_t *name) {
101  // Set default values + fRootFileName + fRootFileStatus
102 
103  Init();
105  fRootFileStatus = "READ";
106 }
107 
108 void TEcnaRootFile::ReStart(const Text_t *name, const TString &status) {
109  // Set default values + fRootFileName + fRootFileStatus
110 
111  Init();
114 }
115 
117  //Close the CNA root file for reading
118  if (fRootFile != nullptr) {
119  fRootFile->Close();
120  delete fRootFile;
121  fRootFile = nullptr;
122  }
124  fCnaResultsTree = nullptr;
125  fCnaResultsBranch = nullptr;
126 }
127 
128 Bool_t TEcnaRootFile::OpenR(const Text_t *name) {
129  //Open the CNA root file for reading
130  Bool_t ok;
131  TString sEmpty = "";
132  if (name != sEmpty) {
134  }
135 
136  if (fRootFile == nullptr) {
137  fRootFile = new TFile(fRootFileName.Data(), "READ");
138  }
139 
140  ok = fRootFile->IsOpen();
141  if (ok) {
142  fCnaResultsTree = (TTree *)fRootFile->Get("CNAResults");
143  if (fCnaResultsTree) {
144  if (fCnaIndivResult == nullptr) {
146  }
147  fCnaResultsBranch = fCnaResultsTree->GetBranch("Results");
148  fCnaResultsBranch->SetAddress(&fCnaIndivResult);
149  fNbEntries = (Int_t)fCnaResultsTree->GetEntries();
150  } else
151  ok = kFALSE;
152  }
153  return ok;
154 }
155 
156 Bool_t TEcnaRootFile::OpenW(const Text_t *name) {
157  //Open root file for writing
158  Bool_t ok = kTRUE;
159  TString sEmpty = "";
160  if (name != sEmpty) {
162  }
163 
164  if (fRootFile == nullptr) {
165  fRootFile = new TFile(fRootFileName.Data(), "RECREATE");
166  }
167  if (fRootFile) {
168  fCnaResultsTree = new TTree("CNAResults", "CNAResults");
170  fCnaResultsBranch = fCnaResultsTree->Branch("Results", "TEcnaResultType", &fCnaIndivResult, 64000, 0);
171  } else
172  ok = kFALSE;
173  return ok;
174 }
175 
177  //Read element i
178  Bool_t ok = kTRUE;
180  return ok;
181 }
182 
184  //Look for kth element of type typ
185  Bool_t ok = kFALSE;
186  Int_t i = 0;
187  do {
189  ok = ((fCnaIndivResult->fIthElement == k) && (fCnaIndivResult->fTypOfCnaResult == typ));
190  i++;
191  } while ((i < fNbEntries) && (!ok));
192  return ok;
193 }
194 
196  //Look for kth element of type typ and return the next entry number
197  Bool_t ok = kFALSE;
198 
199  Int_t i = 0;
200  do {
202  ok = ((fCnaIndivResult->fIthElement == k) && (fCnaIndivResult->fTypOfCnaResult == typ));
203  i++;
204  } while ((i < fNbEntries) && (!ok));
205 
206  if (ok == kFALSE) {
207  i = -1;
208  }
209  return i;
210 }
TEcnaResultType * fCnaIndivResult
Definition: TEcnaRootFile.h:42
Bool_t OpenR(const Text_t *="")
CnaResultTyp
list status
Definition: mps_update.py:107
R__EXTERN TEcnaRootFile * gCnaRootFile
Definition: TEcnaRootFile.h:65
Bool_t RegisterPointer(const TString &, const Long_t &)
Definition: TEcnaObject.cc:100
TBranch * fCnaResultsBranch
Definition: TEcnaRootFile.h:41
CnaResultTyp fTypOfCnaResult
ClassImp(AliDaqEventHeader)
TString fRootFileStatus
Definition: TEcnaRootFile.h:31
~TEcnaRootFile() override
Int_t fCounterBytesCnaResults
Definition: TEcnaRootFile.h:35
Int_t ReadElementNextEntryNumber(CnaResultTyp, Int_t)
TString fRootFileName
Definition: TEcnaRootFile.h:30
void ReStart(const Text_t *)
Bool_t ReadElement(Int_t)
Bool_t OpenW(const Text_t *="")
TTree * fCnaResultsTree
Definition: TEcnaRootFile.h:37
TFile * fRootFile
Definition: TEcnaRootFile.h:33