Delete only existent objects.
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitsManager.cxx
CommitLineData
6f1e466d 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17$Log$
18Revision 1.1.2.1 2000/05/08 14:44:01 cblume
19Add new class AliTRDdigitsManager
20
21*/
22
23///////////////////////////////////////////////////////////////////////////////
24// //
25// Manages the digits and the track dictionary in the form of //
26// AliTRDdataArray objects. //
27// //
28///////////////////////////////////////////////////////////////////////////////
29
30#include "AliRun.h"
31
32#include "AliTRDdigitsManager.h"
33#include "AliTRDconst.h"
34
35ClassImp(AliTRDdigitsManager)
36
37//_____________________________________________________________________________
38AliTRDdigitsManager::AliTRDdigitsManager():TObject()
39{
40 //
41 // Default constructor
42 //
43
44 fIsRaw = kFALSE;
45
46 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",kNdet);
47
48 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
49 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI",kNdet);
50 }
51
52}
53
54//_____________________________________________________________________________
55AliTRDdigitsManager::~AliTRDdigitsManager()
56{
57
58 if (fDigits) {
59 fDigits->Delete();
60 delete fDigits;
61 }
62
63 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
64 fDictionary[iDict]->Delete();
65 delete fDictionary[iDict];
66 }
67
68}
69
70//_____________________________________________________________________________
71void AliTRDdigitsManager::SetRaw()
72{
73
74 fIsRaw = kTRUE;
75
76 fDigits->SetBit(kRawDigit);
77
78}
79
80//_____________________________________________________________________________
81Bool_t AliTRDdigitsManager::MakeBranch()
82{
83 //
84 // Creates the branches for the digits and the dictionary in the digits tree
85 //
86
87 Int_t buffersize = 64000;
88
89 Bool_t status = kTRUE;
90
91 if (gAlice->TreeD()) {
92
93 // Make the branch for the digits
94 if (fDigits) {
95 const AliTRDdataArrayI *Digits =
96 (AliTRDdataArrayI *) fDigits->At(0);
97 if (Digits) {
98 gAlice->TreeD()->Branch("TRDdigits",Digits->IsA()->GetName()
99 ,&Digits,buffersize,1);
100 printf("AliTRDdigitsManager::MakeBranch -- ");
101 printf("Making branch TRDdigits\n");
102 }
103 else {
104 status = kFALSE;
105 }
106 }
107 else {
108 status = kFALSE;
109 }
110
111 // Make the branches for the dictionaries
112 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
113
114 Char_t branchname[15];
115 sprintf(branchname,"TRDdictionary%d",iDict);
116 if (fDictionary[iDict]) {
117 const AliTRDdataArrayI *Dictionary =
118 (AliTRDdataArrayI *) fDictionary[iDict]->At(0);
119 if (Dictionary) {
120 gAlice->TreeD()->Branch(branchname,Dictionary->IsA()->GetName()
121 ,&Dictionary,buffersize,1);
122 printf("AliTRDdigitsManager::MakeBranch -- ");
123 printf("Making branch %s\n",branchname);
124 }
125 else {
126 status = kFALSE;
127 }
128 }
129 else {
130 status = kFALSE;
131 }
132 }
133
134 }
135 else {
136 status = kFALSE;
137 }
138
139 return status;
140
141}
142
143//_____________________________________________________________________________
144Bool_t AliTRDdigitsManager::ReadDigits()
145{
146
147 Bool_t status = kTRUE;
148
149 status = fDigits->LoadArray("TRDdigits");
150
151 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
152 Char_t branchname[15];
153 sprintf(branchname,"TRDdictionary%d",iDict);
154 status = fDictionary[iDict]->LoadArray(branchname);
155 }
156
157 if (fDigits->TestBit(kRawDigit)) {
158 fIsRaw = kTRUE;
159 }
160 else {
161 fIsRaw = kFALSE;
162 }
163
164 return kTRUE;
165
166}
167
168//_____________________________________________________________________________
169Bool_t AliTRDdigitsManager::WriteDigits()
170{
171 //
172 // Writes out the TRD-digits and the dictionaries
173 //
174
175 // Create the branches
176 if (!(gAlice->TreeD()->GetBranch("TRDdigits"))) {
177 if (!MakeBranch()) return kFALSE;
178 }
179
180 // Store the contents of the segment array in the tree
181 if (!fDigits->StoreArray("TRDdigits")) {
182 printf("AliTRDdigitsManager::WriteDigits -- ");
183 printf("Error while storing digits in branch TRDdigits\n");
184 return kFALSE;
185 }
186 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
187 Char_t branchname[15];
188 sprintf(branchname,"TRDdictionary%d",iDict);
189 if (!fDictionary[iDict]->StoreArray(branchname)) {
190 printf("AliTRDdigitsManager::WriteDigits -- ");
191 printf("Error while storing dictionary in branch %s\n",branchname);
192 return kFALSE;
193 }
194 }
195
196 return kTRUE;
197
198}