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