]>
Commit | Line | Data |
---|---|---|
b85c748e | 1 | /************************************************************************** |
2 | * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Authors: Per Thomas Hille for the ALICE * | |
5 | * offline/HLT Project. Contributors are mentioned in the code where * | |
6 | * appropriate. * | |
7 | * * | |
8 | * Permission to use, copy, modify and distribute this software and its * | |
9 | * documentation strictly for non-commercial purposes is hereby granted * | |
10 | * without fee, provided that the above copyright notice appears in all * | |
11 | * copies and that both the copyright notice and this permission notice * | |
12 | * appear in the supporting documentation. The authors make no claims * | |
13 | * about the suitability of this software for any purpose. It is * | |
14 | * provided "as is" without express or implied warranty. * | |
15 | **************************************************************************/ | |
16 | ||
17 | ||
18 | ||
19 | #include "AliHLTPHOSRcuAltroPatternTestComponent.h" | |
20 | #include "AliHLTPHOSSharedMemoryInterface.h" | |
21 | #include "AliHLTPHOSValidCellDataStruct.h" | |
22 | #include "AliHLTPHOSRcuAltroPatternTest.h" | |
23 | ||
24 | AliHLTPHOSRcuAltroPatternTestComponent gAliHLTPHOSRcuAltroPatternTestComponent; | |
25 | ||
26 | AliHLTPHOSRcuAltroPatternTestComponent:: AliHLTPHOSRcuAltroPatternTestComponent() : AliHLTPHOSRcuProcessor(), | |
27 | fPatternTestPtr(0), | |
28 | fShmPtr(0), | |
29 | fNTotalPatterns(0), | |
30 | fNWrongPatterns(0), | |
31 | fNTotalSamples(0), | |
32 | fNWrongSamples(0) | |
33 | { | |
34 | fShmPtr = new AliHLTPHOSSharedMemoryInterface(); | |
35 | } | |
36 | ||
37 | ||
38 | AliHLTPHOSRcuAltroPatternTestComponent::~ AliHLTPHOSRcuAltroPatternTestComponent() | |
39 | { | |
40 | //Destructor | |
41 | } | |
42 | ||
43 | ||
44 | int | |
45 | AliHLTPHOSRcuAltroPatternTestComponent::Deinit() | |
46 | { | |
47 | //See html documentation of base class | |
48 | return 0; | |
49 | } | |
50 | ||
51 | ||
52 | const char* | |
53 | AliHLTPHOSRcuAltroPatternTestComponent::GetComponentID() | |
54 | { | |
55 | //See html documentation of base class | |
56 | return "AltroPatternTester"; | |
57 | } | |
58 | ||
59 | ||
60 | void | |
61 | AliHLTPHOSRcuAltroPatternTestComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) | |
62 | { | |
63 | //See html documentation of base class | |
64 | const AliHLTComponentDataType* pType=fgkInputDataTypes; | |
65 | while (pType->fID!=0) | |
66 | { | |
67 | list.push_back(*pType); | |
68 | pType++; | |
69 | } | |
70 | } | |
71 | ||
72 | ||
73 | AliHLTComponentDataType | |
74 | AliHLTPHOSRcuAltroPatternTestComponent::GetOutputDataType() | |
75 | { | |
76 | //See html documentation of base class | |
77 | return AliHLTPHOSDefinitions::fgkCellEnergyDataType; | |
78 | } | |
79 | ||
80 | ||
81 | void | |
82 | AliHLTPHOSRcuAltroPatternTestComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier ) | |
83 | { | |
84 | //See html documentation of base class | |
85 | constBase = 30; | |
86 | inputMultiplier = 1; | |
87 | } | |
88 | ||
89 | ||
90 | ||
91 | int AliHLTPHOSRcuAltroPatternTestComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, | |
92 | AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, | |
93 | AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& /*outputBlocks */) | |
94 | { | |
95 | //See html documentation of base class | |
96 | //cout << "AliHLTPHOSRcuAltroPatternTestComponent::DoEvent, processing event "<< fPhosEventCount << endl; | |
97 | ||
98 | AliHLTPHOSValidCellDataStruct *currentChannel =0; | |
99 | unsigned long ndx = 0; | |
100 | // UInt_t offset = 0; | |
101 | // UInt_t mysize = 0; | |
102 | UInt_t tSize = 0; | |
103 | const AliHLTComponentBlockData* iter = NULL; | |
104 | AliHLTPHOSRcuCellEnergyDataStruct *cellDataPtr; | |
105 | AliHLTUInt8_t* outBPtr; | |
106 | ||
107 | ||
108 | ||
109 | for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) | |
110 | { | |
111 | iter = blocks+ndx; | |
112 | if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType) | |
113 | { | |
114 | continue; | |
115 | } | |
116 | ||
117 | cellDataPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)( iter->fPtr); | |
118 | fShmPtr->SetMemory(cellDataPtr); | |
119 | currentChannel = fShmPtr->NextChannel(); | |
120 | ||
121 | int tmp =0; | |
122 | while(currentChannel != 0) | |
123 | { | |
124 | ||
125 | int tmpZ = currentChannel->fZ; | |
126 | int tmpX = currentChannel->fX; | |
127 | int tmpGain = currentChannel->fGain; | |
128 | int tmpSamples = currentChannel->fNSamples; | |
129 | ||
130 | ||
131 | if( (tmpZ > N_ZROWS_RCU) || (tmpX > N_XCOLUMNS_RCU) || (tmpGain > N_GAINS)) | |
132 | { | |
133 | cout <<" ERROR parameters out of range z = "<< tmpZ <<" x = "<< tmpX<< " gain = " << tmpGain<<" nSamples = " << tmpSamples <<endl; | |
134 | } | |
135 | else | |
136 | { | |
137 | // cout <<" all parameters in range" << endl; | |
138 | } | |
139 | ||
140 | // cout << "analyzing channelnr " << tmp <<" of event " << fPhosEventCount << endl; | |
141 | // cout << " z = " << currentChannel->fZ << " x = " << currentChannel->fX << " gain = " << currentChannel->fGain << " samples =" << currentChannel->fNSamples <<endl; | |
142 | tmp ++; | |
143 | ||
144 | fPatternTestPtr->AddPattern(currentChannel->fData, currentChannel->fZ, currentChannel->fX, currentChannel->fGain, currentChannel->fNSamples, fNPresamples); | |
145 | int ret = fPatternTestPtr->ValidateAltroPattern(currentChannel->fData, currentChannel->fNSamples); | |
146 | ||
147 | if(ret >= 0) | |
148 | { | |
149 | ||
150 | fNTotalSamples += currentChannel->fNSamples; | |
151 | fNTotalPatterns ++; | |
152 | ||
153 | if(ret > 0) | |
154 | { | |
155 | fNWrongSamples += ret; | |
156 | fNWrongPatterns ++; | |
157 | ||
158 | if(fPhosEventCount%100 == 0) | |
159 | { | |
160 | /* | |
161 | cout << "warning: incorrect pattern found for event " << fPhosEventCount <<" X = " << currentChannel->fX <<" Z = " << currentChannel->fZ ; | |
162 | cout << "number of correct aptterns is " << fNTotalPatterns << "number of wrong patterns is " << fNWrongPatterns<<endl; | |
163 | float percent = 100*((float)fNWrongPatterns)/( float(fNTotalPatterns)); | |
164 | cout <<"The corrpution rate is " << percent << " percent " <<endl; | |
165 | cout <<" ERROR: incorrect parameters" << endl; | |
166 | */ | |
167 | } | |
168 | ||
169 | ||
170 | if(fPhosEventCount%100 == 0 && fPhosEventCount !=0) | |
171 | { | |
172 | fPatternTestPtr->countAllPatterns(fNSamples); | |
173 | fPatternTestPtr->PrintStatistics(); | |
174 | ||
175 | } | |
176 | } | |
177 | } | |
178 | else | |
179 | { | |
180 | cout <<" ERROR: incorrect parameters" << endl; | |
181 | } | |
182 | currentChannel = fShmPtr->NextChannel(); | |
183 | ||
184 | } | |
185 | } | |
186 | ||
187 | ||
188 | outBPtr = outputPtr; | |
189 | ||
190 | // mysize += sizeof(AliHLTPHOSRcuCellAccumulatedEnergyDataStruct); | |
191 | ||
192 | /* | |
193 | AliHLTComponentBlockData bd; | |
194 | FillBlockData( bd ); | |
195 | bd.fOffset = offset; | |
196 | bd.fSize = mysize; | |
197 | bd.fDataType = AliHLTPHOSDefinitions::fgkCellAccumulatedEnergyDataType; | |
198 | bd.fSpecification = 0xFFFFFFFF; | |
199 | outputBlocks.push_back( bd ); | |
200 | tSize += mysize; | |
201 | outBPtr += mysize; | |
202 | */ | |
203 | ||
204 | if( tSize > size ) | |
205 | { | |
206 | Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoEvent", "Too much data", | |
207 | "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu." | |
208 | , tSize, size ); | |
209 | return EMSGSIZE; | |
210 | } | |
211 | ||
212 | fPhosEventCount++; | |
213 | ||
214 | ||
215 | return 0; | |
216 | }//end DoEvent | |
217 | ||
218 | ||
219 | ||
220 | ||
221 | ||
222 | int | |
223 | AliHLTPHOSRcuAltroPatternTestComponent::DoInit(int argc, const char** argv ) | |
224 | { | |
225 | //See html documentation of base class | |
226 | cout << "AliHLTPHOSRcuAltroPatternTestComponent::DoInit, argc =" << argc << endl; | |
227 | char patternFilename[2000]; | |
228 | bool isSetPartternArg = false; | |
229 | fPrintInfo = kFALSE; | |
230 | int iResult=0; | |
231 | TString argument=""; | |
232 | iResult = ScanArguments(argc, argv); | |
233 | // fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ); | |
234 | ||
235 | if(iResult < 0) | |
236 | { | |
237 | return iResult; | |
238 | } | |
239 | ||
240 | if(fIsSetEquippmentID == kFALSE) | |
241 | { | |
242 | Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "Missing argument", | |
243 | "The argument equippmentID is not set: set it with a component argumet like this: -equippmentID <number>"); | |
244 | // iResult = -2; | |
245 | return -5; | |
246 | } | |
247 | ||
248 | for(int i = 0; i < argc; i++) | |
249 | { | |
250 | if(!strcmp("-patternfile", argv[i])) | |
251 | { | |
252 | if(argc < (i+1)) | |
253 | { | |
254 | Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "Missing argument", | |
255 | "The argument -patternfile requires that a filename follows: set it with a component argumet like this: -patternfile <filename>"); | |
256 | return -6; | |
257 | } | |
258 | else | |
259 | { | |
260 | sprintf(patternFilename, argv[i+1]); | |
261 | isSetPartternArg = true; | |
262 | } | |
263 | } | |
264 | } | |
265 | ||
266 | if(isSetPartternArg == false) | |
267 | { | |
268 | Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "Missing argument", | |
269 | "The argument patternfile is not set: set it with a component argumet like this: -patternfile <filename>"); | |
270 | return -7; | |
271 | ||
272 | } | |
273 | else if(CheckFile(patternFilename, "r") == false) | |
274 | { | |
275 | char tmpMessage[1024]; | |
276 | sprintf(tmpMessage, "the file %s could not be found, please check that file exist and that you have read access to it", patternFilename); | |
277 | Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "File not found",tmpMessage); | |
278 | ||
279 | return -8; | |
280 | ||
281 | } | |
282 | else | |
283 | { | |
284 | int tmpPattern[ALTRO_MAX_SAMPLES]; | |
285 | ScanPatternFromFile(patternFilename, tmpPattern, ALTRO_MAX_SAMPLES) ; | |
286 | fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ, tmpPattern, ALTRO_MAX_SAMPLES); | |
287 | } | |
288 | ||
289 | // return iResult; | |
290 | return 0; | |
291 | } | |
292 | ||
293 | ||
294 | AliHLTComponent* | |
295 | AliHLTPHOSRcuAltroPatternTestComponent::Spawn() | |
296 | { | |
297 | //See html documentation of base class | |
298 | return new AliHLTPHOSRcuAltroPatternTestComponent; | |
299 | } | |
300 | ||
301 | ||
302 | void | |
303 | AliHLTPHOSRcuAltroPatternTestComponent::ScanPatternFromFile(const char *filename, int *pattern, const int length) const | |
304 | { | |
305 | FILE *fp = fopen(filename, "r"); | |
306 | ||
307 | // int tmpPattern[ALTRO_MAX_SAMPLES]; | |
308 | int dummy = 0; | |
309 | ||
310 | for(int i=0; i<ALTRO_MAX_SAMPLES; i++) | |
311 | { | |
312 | fscanf(fp,"w 0x%X 0x%X\n", &dummy, &pattern[i]); | |
313 | // cout << tmpPattern[i] << endl; | |
314 | } | |
315 | ||
316 | // fPatternTestPtr->SetAltroPattern(tmpPattern); | |
317 | } | |
318 | ||
319 | //w 0x6801 0x1 |