]>
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 | ||
b85c748e | 108 | for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) |
109 | { | |
110 | iter = blocks+ndx; | |
111 | if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType) | |
112 | { | |
113 | continue; | |
114 | } | |
115 | ||
116 | cellDataPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)( iter->fPtr); | |
117 | fShmPtr->SetMemory(cellDataPtr); | |
118 | currentChannel = fShmPtr->NextChannel(); | |
119 | ||
7ce40e5c | 120 | Int_t* tmpRawPtr = 0; |
121 | ||
b85c748e | 122 | int tmp =0; |
123 | while(currentChannel != 0) | |
124 | { | |
125 | ||
126 | int tmpZ = currentChannel->fZ; | |
127 | int tmpX = currentChannel->fX; | |
128 | int tmpGain = currentChannel->fGain; | |
7ce40e5c | 129 | int tmpSamples = 0; |
130 | tmpRawPtr = fShmPtr->GetRawData(tmpSamples); | |
b85c748e | 131 | |
132 | ||
133 | if( (tmpZ > N_ZROWS_RCU) || (tmpX > N_XCOLUMNS_RCU) || (tmpGain > N_GAINS)) | |
134 | { | |
135 | cout <<" ERROR parameters out of range z = "<< tmpZ <<" x = "<< tmpX<< " gain = " << tmpGain<<" nSamples = " << tmpSamples <<endl; | |
136 | } | |
137 | else | |
138 | { | |
139 | // cout <<" all parameters in range" << endl; | |
140 | } | |
141 | ||
142 | // cout << "analyzing channelnr " << tmp <<" of event " << fPhosEventCount << endl; | |
143 | // cout << " z = " << currentChannel->fZ << " x = " << currentChannel->fX << " gain = " << currentChannel->fGain << " samples =" << currentChannel->fNSamples <<endl; | |
144 | tmp ++; | |
145 | ||
7ce40e5c | 146 | fPatternTestPtr->AddPattern(tmpRawPtr, currentChannel->fZ, currentChannel->fX, currentChannel->fGain, tmpSamples, fNPresamples); |
147 | int ret = fPatternTestPtr->ValidateAltroPattern(tmpRawPtr, tmpSamples); | |
b85c748e | 148 | |
149 | if(ret >= 0) | |
150 | { | |
151 | ||
7ce40e5c | 152 | fNTotalSamples += tmpSamples; |
b85c748e | 153 | fNTotalPatterns ++; |
154 | ||
155 | if(ret > 0) | |
156 | { | |
157 | fNWrongSamples += ret; | |
158 | fNWrongPatterns ++; | |
159 | ||
160 | if(fPhosEventCount%100 == 0) | |
161 | { | |
162 | /* | |
163 | cout << "warning: incorrect pattern found for event " << fPhosEventCount <<" X = " << currentChannel->fX <<" Z = " << currentChannel->fZ ; | |
164 | cout << "number of correct aptterns is " << fNTotalPatterns << "number of wrong patterns is " << fNWrongPatterns<<endl; | |
165 | float percent = 100*((float)fNWrongPatterns)/( float(fNTotalPatterns)); | |
166 | cout <<"The corrpution rate is " << percent << " percent " <<endl; | |
167 | cout <<" ERROR: incorrect parameters" << endl; | |
168 | */ | |
169 | } | |
170 | ||
171 | ||
172 | if(fPhosEventCount%100 == 0 && fPhosEventCount !=0) | |
173 | { | |
174 | fPatternTestPtr->countAllPatterns(fNSamples); | |
175 | fPatternTestPtr->PrintStatistics(); | |
176 | ||
177 | } | |
178 | } | |
179 | } | |
180 | else | |
181 | { | |
182 | cout <<" ERROR: incorrect parameters" << endl; | |
183 | } | |
184 | currentChannel = fShmPtr->NextChannel(); | |
185 | ||
186 | } | |
187 | } | |
188 | ||
189 | ||
190 | outBPtr = outputPtr; | |
191 | ||
192 | // mysize += sizeof(AliHLTPHOSRcuCellAccumulatedEnergyDataStruct); | |
193 | ||
194 | /* | |
195 | AliHLTComponentBlockData bd; | |
196 | FillBlockData( bd ); | |
197 | bd.fOffset = offset; | |
198 | bd.fSize = mysize; | |
199 | bd.fDataType = AliHLTPHOSDefinitions::fgkCellAccumulatedEnergyDataType; | |
200 | bd.fSpecification = 0xFFFFFFFF; | |
201 | outputBlocks.push_back( bd ); | |
202 | tSize += mysize; | |
203 | outBPtr += mysize; | |
204 | */ | |
205 | ||
206 | if( tSize > size ) | |
207 | { | |
208 | Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoEvent", "Too much data", | |
209 | "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu." | |
210 | , tSize, size ); | |
211 | return EMSGSIZE; | |
212 | } | |
213 | ||
214 | fPhosEventCount++; | |
215 | ||
216 | ||
217 | return 0; | |
218 | }//end DoEvent | |
219 | ||
220 | ||
221 | ||
222 | ||
223 | ||
224 | int | |
225 | AliHLTPHOSRcuAltroPatternTestComponent::DoInit(int argc, const char** argv ) | |
226 | { | |
227 | //See html documentation of base class | |
228 | cout << "AliHLTPHOSRcuAltroPatternTestComponent::DoInit, argc =" << argc << endl; | |
229 | char patternFilename[2000]; | |
230 | bool isSetPartternArg = false; | |
231 | fPrintInfo = kFALSE; | |
232 | int iResult=0; | |
233 | TString argument=""; | |
234 | iResult = ScanArguments(argc, argv); | |
235 | // fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ); | |
236 | ||
237 | if(iResult < 0) | |
238 | { | |
239 | return iResult; | |
240 | } | |
241 | ||
242 | if(fIsSetEquippmentID == kFALSE) | |
243 | { | |
244 | Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "Missing argument", | |
245 | "The argument equippmentID is not set: set it with a component argumet like this: -equippmentID <number>"); | |
246 | // iResult = -2; | |
247 | return -5; | |
248 | } | |
249 | ||
250 | for(int i = 0; i < argc; i++) | |
251 | { | |
252 | if(!strcmp("-patternfile", argv[i])) | |
253 | { | |
254 | if(argc < (i+1)) | |
255 | { | |
256 | Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "Missing argument", | |
257 | "The argument -patternfile requires that a filename follows: set it with a component argumet like this: -patternfile <filename>"); | |
258 | return -6; | |
259 | } | |
260 | else | |
261 | { | |
262 | sprintf(patternFilename, argv[i+1]); | |
263 | isSetPartternArg = true; | |
264 | } | |
265 | } | |
266 | } | |
267 | ||
268 | if(isSetPartternArg == false) | |
269 | { | |
270 | Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "Missing argument", | |
271 | "The argument patternfile is not set: set it with a component argumet like this: -patternfile <filename>"); | |
272 | return -7; | |
273 | ||
274 | } | |
2589c3a3 | 275 | else if(fUtilitiesPtr->CheckFile(patternFilename, "r") == false) |
b85c748e | 276 | { |
277 | char tmpMessage[1024]; | |
278 | sprintf(tmpMessage, "the file %s could not be found, please check that file exist and that you have read access to it", patternFilename); | |
279 | Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "File not found",tmpMessage); | |
280 | ||
281 | return -8; | |
282 | ||
283 | } | |
284 | else | |
285 | { | |
286 | int tmpPattern[ALTRO_MAX_SAMPLES]; | |
287 | ScanPatternFromFile(patternFilename, tmpPattern, ALTRO_MAX_SAMPLES) ; | |
288 | fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ, tmpPattern, ALTRO_MAX_SAMPLES); | |
289 | } | |
290 | ||
291 | // return iResult; | |
292 | return 0; | |
293 | } | |
294 | ||
295 | ||
296 | AliHLTComponent* | |
297 | AliHLTPHOSRcuAltroPatternTestComponent::Spawn() | |
298 | { | |
299 | //See html documentation of base class | |
300 | return new AliHLTPHOSRcuAltroPatternTestComponent; | |
301 | } | |
302 | ||
303 | ||
304 | void | |
6e587e00 | 305 | AliHLTPHOSRcuAltroPatternTestComponent::ScanPatternFromFile(const char *filename, int *pattern, const int /*length*/) const |
b85c748e | 306 | { |
307 | FILE *fp = fopen(filename, "r"); | |
308 | ||
309 | // int tmpPattern[ALTRO_MAX_SAMPLES]; | |
310 | int dummy = 0; | |
311 | ||
312 | for(int i=0; i<ALTRO_MAX_SAMPLES; i++) | |
313 | { | |
314 | fscanf(fp,"w 0x%X 0x%X\n", &dummy, &pattern[i]); | |
315 | // cout << tmpPattern[i] << endl; | |
316 | } | |
6e587e00 | 317 | |
b85c748e | 318 | |
319 | // fPatternTestPtr->SetAltroPattern(tmpPattern); | |
320 | } | |
321 | ||
322 | //w 0x6801 0x1 |