]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSPattern.cxx
adding Copy and Clone methods inherited from TObject for abstract access and
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSPattern.cxx
1 // $Id$
2
3 /**************************************************************************
4  * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved.      *
5  *                                                                        *
6  * Authors: Per Thomas Hille for the ALICE                                *
7  * offline/HLT Project. Contributors are mentioned in the code where      *
8  * appropriate.                                                           *
9  *                                                                        *
10  * Permission to use, copy, modify and distribute this software and its   *
11  * documentation strictly for non-commercial purposes is hereby granted   *
12  * without fee, provided that the above copyright notice appears in all   *
13  * copies and that both the copyright notice and this permission notice   *
14  * appear in the supporting documentation. The authors make no claims     *
15  * about the suitability of this software for any purpose. It is          *
16  * provided "as is" without express or implied warranty.                  *
17  **************************************************************************/
18
19 #include "AliHLTPHOSPattern.h"
20 #include <iostream>
21 #include "AliHLTPHOSUtilities.h" 
22
23 using namespace std;
24
25
26 AliHLTPHOSPattern::AliHLTPHOSPattern(const int *pattern, const int length) : AliHLTPHOSBase(),
27                                                                              fPatternLength(0), 
28                                                                              fN(0), 
29                                                                              fCnt(0), 
30                                                                              fPattern(0),
31                                                                              fUtilitiesPtr(0)
32 {
33   fUtilitiesPtr = new  AliHLTPHOSUtilities(); 
34   SetPattern(pattern, length);
35 }
36
37
38
39 AliHLTPHOSPattern::~AliHLTPHOSPattern()
40 {
41   //  cout << "AliHLTPHOSPattern::~AliHLTPHOSPattern()"  << endl;
42   delete  fPattern;
43   fPattern = 0;
44 }
45
46
47
48 /*
49  * Checks if the input pattern is equal to fPattern
50  * @param inputPattern the pattern to be compared to @ref fPattern
51  * @param length the number of samples to compare i.e starting at zero and comparing "length samples"
52  * @retrun the number of samples that mismatch, zero fo a complete macth, or -1 if the comparison
53  * could not be done due to an incorrect input (wrong number of samples and/or presamples)
54 */
55 int 
56 AliHLTPHOSPattern::ValidatePattern(const int *readbackpattern, const int nSamples, const int nPresamples) const
57 {
58   int iRet = 0;
59
60   if(CheckPatternLength(nSamples, nPresamples) == true)
61     {
62       // The presamples must be exluded from the comparison since they are not present in the altro pattern memeory
63       iRet =  DoComparePattern(&readbackpattern[nPresamples], fVal, nSamples);
64     }
65   else
66     {
67       iRet = -1;
68     }
69   
70   return iRet;
71 }
72
73
74 int 
75 AliHLTPHOSPattern::AddPattern(const int *readbackpattern,  const int nSamples, const int nPresamples)
76 {
77   int iRet = ValidatePattern(readbackpattern, nSamples, nPresamples);
78   if(iRet == 0)
79     {
80       fN ++;
81     }
82   else if(iRet > 0)
83     {
84       if(fPattern != 0)
85         {
86           //      fPattern->ValidatePattern(readbackpattern, nSamples, nPresamples);
87           fPattern->AddPattern(readbackpattern, nSamples, nPresamples);
88         }
89       else
90         {
91           //      cout << "AliHLTPHOSPattern::AddPattern, creating new pattern"  << endl;
92           fPattern = new AliHLTPHOSPattern(readbackpattern, nSamples);
93         }
94     }
95   return iRet;
96 }
97
98
99 bool 
100 AliHLTPHOSPattern::CheckDoExistPattern(const int *readbackpattern,  const int nSamples, const int nPresamples)
101 {
102   bool iRet = false;
103   
104   if(ValidatePattern(readbackpattern, nSamples, nPresamples) == 0)
105     {
106       iRet = true;
107     }
108   else if(fPattern !=0)
109     {
110       iRet = fPattern->CheckDoExistPattern(readbackpattern, nSamples, nPresamples);
111     }
112       
113   return iRet;
114 }
115
116
117 int 
118 AliHLTPHOSPattern::DoComparePattern(const int *pattern1, const int *pattern2, const int length) const
119 {
120   int nomatch = 0;
121   
122   for(int i=0; i< length; i++)
123     {
124       if(pattern1[i] != pattern2[i])
125         {
126           nomatch ++;
127         }
128     }
129   return nomatch;
130 }
131
132
133 bool 
134 AliHLTPHOSPattern::CheckPatternLength(const int nSamples, const int nPresamples) const
135 {
136   bool iRet = true;
137
138   if( nSamples  > ALTROMAXSAMPLES)
139     {
140       cout << "Warning: attemp to set pattern array of length " << nSamples << " wich is out of range" <<endl;
141       cout <<"Max length of pattern array is " << ALTROMAXSAMPLES  <<endl;
142       iRet = false;
143     }
144   else if(nPresamples >  ALTROMAXPRESAMPLES)
145     {
146       cout << "ERROR: attemp to set teh number of  " << nPresamples << " wich is out of range" <<endl;
147       cout <<"Max length of pattern array is " << ALTROMAXPRESAMPLES  <<endl;
148       iRet = false;
149     }
150
151   return iRet;
152 }
153
154
155 void 
156 AliHLTPHOSPattern::SetPattern(const int *pattern, const int length)
157 {
158   for(int i=0; i< ALTROMAXSAMPLES; i++)
159      {
160        fVal[i] = 0;
161      }
162
163   for(int i = 0; i < length; i++)
164      {
165        fVal[i] = pattern[i];
166      }
167
168   if(length > ALTROMAXSAMPLES)
169     {
170       fPatternLength = ALTROMAXSAMPLES;
171     }
172   else
173     {
174       fPatternLength = length;
175     }
176 }
177
178
179 /*
180  * Returns the pattern integer array
181  * @param *pattern the pattern will be filleded in the array pointed to by this pointer
182  * @param maxlength the maximum number of samples to fill 
183  * @return the number of samples actually filled, retruns the smalles value of maxlength and
184  * and the length of the pattern array
185  */
186 int  
187 AliHLTPHOSPattern::GetPattern(int *pattern,  const int maxlength) const
188 {
189   int tmplength = 0;
190
191   if(maxlength > fPatternLength )
192     {
193       tmplength = fPatternLength;
194     }
195   else
196     {
197       tmplength = maxlength;
198     }
199
200   for(int i=0; i < tmplength; i++)
201     {
202       pattern[i] = fVal[i];
203     }
204   return  tmplength;
205 }
206
207
208
209 void 
210 AliHLTPHOSPattern::PrintPattern(const int nPerLine)
211 {
212   fUtilitiesPtr->DumpData(fVal, fPatternLength  , nPerLine);
213 }
214
215 // void  DumpData(T *array, int N, int nPerLine)