]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODCaloCells.cxx
Fixed Mem leaks occuring with Analysis Manager and coding violations
[u/mrichter/AliRoot.git] / STEER / AliAODCaloCells.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, 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 /* $Id$ */
17
18 //-------------------------------------------------------------------------
19 //     AOD class to store calorimeter cell data
20 //     Author: Markus Oldenburg, CERN
21 //-------------------------------------------------------------------------
22
23 #include "AliAODCaloCells.h"
24
25 ClassImp(AliAODCaloCells)
26
27 AliAODCaloCells::AliAODCaloCells() : TNamed(), fNCells(0), fCellNumber(0), fAmplitude(0), fIsSorted(kTRUE), fType(kUndef)
28 {
29   // default constructor
30 }
31
32 AliAODCaloCells::AliAODCaloCells(const char* name, const char* title, AODTwrs_t ttype) : TNamed(name, title), fNCells(0), fCellNumber(0), fAmplitude(0), fIsSorted(kTRUE), fType(ttype)
33 {
34   // TNamed constructor
35 }
36
37 AliAODCaloCells::~AliAODCaloCells()
38 {
39   // destructor
40
41   DeleteContainer();
42 }
43
44 void AliAODCaloCells::CreateContainer(Short_t nCells)
45 {
46   // function that creates container to store calorimeter cell data
47
48   DeleteContainer();
49   
50   if (nCells <= 0) {
51     fNCells = 0;
52     return;
53   }
54
55   fNCells = nCells;
56
57   fCellNumber = new Short_t[fNCells];
58   fAmplitude = new Double32_t[fNCells];
59 }
60
61 void AliAODCaloCells::DeleteContainer()
62 {
63   // deletes allocated memory
64
65   if (fCellNumber)
66   {
67     delete[] fCellNumber;
68     fCellNumber = 0;
69   }
70
71   if (fAmplitude)
72   {
73     delete[] fAmplitude;
74     fAmplitude = 0;
75   }
76
77   fNCells = 0;
78   fIsSorted = kFALSE;
79 }
80
81 void AliAODCaloCells::Sort() 
82 {
83   // sort the cell array by cell number
84   
85   Int_t *idxArray = new Int_t[fNCells];
86   TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
87   
88   Short_t *newIndex = new Short_t[fNCells];
89   Double32_t *newAmplitude = new Double32_t[fNCells];
90   for (Int_t i=0; i < fNCells; i++) {
91     newIndex[i] = fCellNumber[idxArray[i]];
92     newAmplitude[i] = fAmplitude[idxArray[i]];
93   }
94   delete [] fCellNumber;
95   delete [] fAmplitude;
96   fCellNumber = newIndex;
97   fAmplitude = newAmplitude;
98   
99   delete [] idxArray;
100   
101   fIsSorted = kTRUE;
102
103
104 Bool_t AliAODCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude)
105 {
106   // Sets a cell at the given position
107
108   if (pos>=0 && pos < fNCells) {
109     fCellNumber[pos] = cellNumber;
110     fAmplitude[pos] = amplitude;
111     fIsSorted = kFALSE;
112     return kTRUE;
113   } else {
114     return kFALSE;
115   }
116 }