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