]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALTriggerBoard.cxx
fix coverity # 22583, 22584, 25074, 24075, possibly null geom pointer, remove, factor...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerBoard.cxx
CommitLineData
916f1e76 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
18
19EMCal trigger board super class
20run the sliding window algorithm
21Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
22*/
23
24#include "AliEMCALTriggerBoard.h"
25#include "AliEMCALTriggerPatch.h"
99c85b27 26#include "AliLog.h"
916f1e76 27
28#include <TClonesArray.h>
dc483a03 29#include <iostream>
30#include <cstdlib>
31
32using namespace std;
916f1e76 33
34ClassImp(AliEMCALTriggerBoard)
35
36//_______________
37AliEMCALTriggerBoard::AliEMCALTriggerBoard() : TObject(),
38fRegion(0x0),
39fMap(0x0),
40fRegionSize(0x0),
41fSubRegionSize(0x0),
42fPatchSize(0x0),
79b05051 43fPatches(0x0)
916f1e76 44{
45
46}
47
48//_______________
fff39dd1 49AliEMCALTriggerBoard::AliEMCALTriggerBoard(const TVector2& RS) : TObject(),
916f1e76 50fRegion(0x0),
51fMap(0x0),
52fRegionSize( new TVector2( RS ) ),
53fSubRegionSize( new TVector2() ),
54fPatchSize( new TVector2() ),
55fPatches( new TClonesArray("AliEMCALTriggerPatch",10) )
56{
79b05051 57 // Ctor
58
a51e676d 59 fRegion = (int**)malloc( (int)fRegionSize->X() * sizeof( int* ) );
60
61 if (!fRegion) printf("Error: malloc could not allocate %d bytes for fRegion\n",
62 int(fRegionSize->X() * sizeof( int* )));
63
64 fMap = (int**)malloc( (int)fRegionSize->X() * sizeof( int* ) );
65
66 if (!fMap) printf("Error: malloc could not allocate %d bytes for fMap\n",
67 int(fRegionSize->X() * sizeof( int* )));
68
69 for (Int_t i=0;i<fRegionSize->X();i++)
70 {
71 if(fRegion){
916f1e76 72 fRegion[i] = (int*)malloc( (int)fRegionSize->Y() * sizeof( int ) );
a51e676d 73
916f1e76 74 if (!fRegion[i]) printf("Error: malloc could not allocate %d bytes for fRegion[%d]\n",
a51e676d 75 i,int(fRegionSize->Y() * sizeof( int )));
76 }
77 if(fMap){
78 fMap[i] = (int*)malloc( (int)fRegionSize->Y() * sizeof( int ) );
79
80 if (!fMap[i]) printf("Error: malloc could not allocate %d bytes for fMap[%d]\n",
81 i,int(fRegionSize->Y() * sizeof( int )));
82 }
83 }
84
916f1e76 85 // Initialize region matrix
86 ZeroRegion();
a51e676d 87 if(fMap){
916f1e76 88 for (int i=0; i<fRegionSize->X(); ++i)
89 for (int j=0; j<fRegionSize->Y(); ++j) fMap[i][j] = 0;
a51e676d 90 }
916f1e76 91}
92
93//_______________
94AliEMCALTriggerBoard::~AliEMCALTriggerBoard()
95{
79b05051 96 // Dtor
97
916f1e76 98 for (Int_t i=0;i<fRegionSize->X();i++)
99 {
de39a0ff 100 if (fRegion[i]) {free(fRegion[i]); fRegion[i] = 0;}
101 if ( fMap[i]) {free(fMap[i]); fMap[i] = 0;}
916f1e76 102 }
103
de39a0ff 104 free(fRegion); fRegion = 0x0;
105 free(fMap); fMap = 0x0;
916f1e76 106
0341167b 107 if(fPatches)fPatches->Delete();
de39a0ff 108
0341167b 109 delete fPatches;
916f1e76 110}
111
112//_______________
113void AliEMCALTriggerBoard::ZeroRegion()
114{
99c85b27 115 // Initilize fRegion
116
117 if(fRegion){
118 for (Int_t i=0;i<int(fRegionSize->X());i++) for (Int_t j=0;j<int(fRegionSize->Y());j++) fRegion[i][j] = 0;
119 }
120 else {
121 AliFatal("fRegion was not previously initialized");
122 }
123
916f1e76 124}
125
126//_______________
63c22917 127void AliEMCALTriggerBoard::SlidingWindow(Int_t thres)
916f1e76 128{
63c22917 129 // Sliding window
130 for (int i = 0; i <= int(fRegionSize->X() - fPatchSize->X() * fSubRegionSize->X()); i += int(fSubRegionSize->X())) {
131 for (int j = 0; j <= int(fRegionSize->Y() - fPatchSize->Y() * fSubRegionSize->Y()); j += int(fSubRegionSize->Y())) {
132 //
28bcaaaa 133 AliDebug(999, Form("--- Current window at (%2d,%2d) ---",i,j));
63c22917 134 int sum = 0;
916f1e76 135
63c22917 136 for (int k = 0; k < int(fPatchSize->X() * fSubRegionSize->X()); k++) {
137 for (int l = 0; l < int(fPatchSize->Y() * fSubRegionSize->Y()); l++) {
138 //
28bcaaaa 139 sum += fRegion[i + k][j + l];
140 AliDebug(999, Form("Adding fRegion[%2d + %2d][%2d + %2d]: %d and sum is %d",i,k,j,l,fRegion[i + k][j + l],sum));
916f1e76 141 }
142 }
63c22917 143
144 if (sum > thres) {
28bcaaaa 145 AliDebug(999, Form("Adding new patch at (%2d,%2d) w/ amplitude %d", i, j, sum));
63c22917 146 new((*fPatches)[fPatches->GetEntriesFast()]) AliEMCALTriggerPatch(i, j, sum);
916f1e76 147 }
148 }
149 }
150}
151
152//__________
153void AliEMCALTriggerBoard::Scan()
154{
79b05051 155 // Dump
156
916f1e76 157 cout << " ";
158 for (Int_t i=0; i<int(fRegionSize->X()); i++) printf("%8d ",i);
159 cout << "\n";
160 for (Int_t i=0; i<int(fRegionSize->X())-5; i++) printf("-------");
161 cout << "\n";
162
163 for (Int_t i=0; i<int(fRegionSize->Y()); i++)
164 {
165 if (i && !(i%12))
166 {
167 for (Int_t j=0; j<int(fRegionSize->X())-5; j++) printf("-------");
168 cout << endl;
169 }
170
171 printf("%3d |",i);
172 for (Int_t j=0; j<int(fRegionSize->X()); j++)
173 {
174 printf("%2d/%5d ", fMap[j][i], fRegion[j][i]);
175 }
176 cout << endl;
177 }
178}
179
180//__________
181void AliEMCALTriggerBoard::Reset()
182{
183 //
184 fPatches->Delete();
185 ZeroRegion();
186}
187