3 /**************************************************************************
4 * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Per Thomas Hille for the ALICE *
7 * offline/HLT Project. Contributors are mentioned in the code where *
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 **************************************************************************/
19 #include "AliHLTPHOSPattern.h"
21 #include "AliHLTPHOSUtilities.h"
26 AliHLTPHOSPattern::AliHLTPHOSPattern(const int *pattern, const int length) : AliHLTPHOSBase(),
33 fUtilitiesPtr = new AliHLTPHOSUtilities();
34 SetPattern(pattern, length);
39 AliHLTPHOSPattern::~AliHLTPHOSPattern()
41 // cout << "AliHLTPHOSPattern::~AliHLTPHOSPattern()" << endl;
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)
56 AliHLTPHOSPattern::ValidatePattern(const int *readbackpattern, const int nSamples, const int nPresamples) const
60 if(CheckPatternLength(nSamples, nPresamples) == true)
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);
75 AliHLTPHOSPattern::AddPattern(const int *readbackpattern, const int nSamples, const int nPresamples)
77 int iRet = ValidatePattern(readbackpattern, nSamples, nPresamples);
86 // fPattern->ValidatePattern(readbackpattern, nSamples, nPresamples);
87 fPattern->AddPattern(readbackpattern, nSamples, nPresamples);
91 // cout << "AliHLTPHOSPattern::AddPattern, creating new pattern" << endl;
92 fPattern = new AliHLTPHOSPattern(readbackpattern, nSamples);
100 AliHLTPHOSPattern::CheckDoExistPattern(const int *readbackpattern, const int nSamples, const int nPresamples)
104 if(ValidatePattern(readbackpattern, nSamples, nPresamples) == 0)
108 else if(fPattern !=0)
110 iRet = fPattern->CheckDoExistPattern(readbackpattern, nSamples, nPresamples);
118 AliHLTPHOSPattern::DoComparePattern(const int *pattern1, const int *pattern2, const int length) const
122 for(int i=0; i< length; i++)
124 if(pattern1[i] != pattern2[i])
134 AliHLTPHOSPattern::CheckPatternLength(const int nSamples, const int nPresamples) const
138 if( nSamples > ALTROMAXSAMPLES)
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;
144 else if(nPresamples > ALTROMAXPRESAMPLES)
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;
156 AliHLTPHOSPattern::SetPattern(const int *pattern, const int length)
158 for(int i=0; i< ALTROMAXSAMPLES; i++)
163 for(int i = 0; i < length; i++)
165 fVal[i] = pattern[i];
168 if(length > ALTROMAXSAMPLES)
170 fPatternLength = ALTROMAXSAMPLES;
174 fPatternLength = length;
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
187 AliHLTPHOSPattern::GetPattern(int *pattern, const int maxlength) const
191 if(maxlength > fPatternLength )
193 tmplength = fPatternLength;
197 tmplength = maxlength;
200 for(int i=0; i < tmplength; i++)
202 pattern[i] = fVal[i];
210 AliHLTPHOSPattern::PrintPattern(const int nPerLine)
212 fUtilitiesPtr->DumpData(fVal, fPatternLength , nPerLine);
215 // void DumpData(T *array, int N, int nPerLine)