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 **************************************************************************/
22 #include "AliHLTPHOSRcuAltroPatternTestComponent.h"
23 #include "AliHLTPHOSSharedMemoryInterface.h"
24 #include "AliHLTPHOSValidCellDataStruct.h"
25 #include "AliHLTPHOSRcuAltroPatternTest.h"
27 AliHLTPHOSRcuAltroPatternTestComponent gAliHLTPHOSRcuAltroPatternTestComponent;
29 AliHLTPHOSRcuAltroPatternTestComponent:: AliHLTPHOSRcuAltroPatternTestComponent() : AliHLTPHOSRcuProcessor(),
38 fShmPtr = new AliHLTPHOSSharedMemoryInterface();
42 AliHLTPHOSRcuAltroPatternTestComponent::~ AliHLTPHOSRcuAltroPatternTestComponent()
49 AliHLTPHOSRcuAltroPatternTestComponent::Deinit()
51 //See html documentation of base class
57 AliHLTPHOSRcuAltroPatternTestComponent::GetComponentID()
59 //See html documentation of base class
60 return "AltroPatternTester";
65 AliHLTPHOSRcuAltroPatternTestComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
67 //See html documentation of base class
68 const AliHLTComponentDataType* pType=fgkInputDataTypes;
71 list.push_back(*pType);
77 AliHLTComponentDataType
78 AliHLTPHOSRcuAltroPatternTestComponent::GetOutputDataType()
80 //See html documentation of base class
81 return AliHLTPHOSDefinitions::fgkCellEnergyDataType;
86 AliHLTPHOSRcuAltroPatternTestComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
88 //See html documentation of base class
95 int AliHLTPHOSRcuAltroPatternTestComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
96 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
97 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& /*outputBlocks */)
99 //See html documentation of base class
100 //cout << "AliHLTPHOSRcuAltroPatternTestComponent::DoEvent, processing event "<< fPhosEventCount << endl;
102 AliHLTPHOSValidCellDataStruct *currentChannel =0;
103 unsigned long ndx = 0;
104 // UInt_t offset = 0;
105 // UInt_t mysize = 0;
107 const AliHLTComponentBlockData* iter = NULL;
108 AliHLTPHOSRcuCellEnergyDataStruct *cellDataPtr;
109 AliHLTUInt8_t* outBPtr;
111 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
114 if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
119 cellDataPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)( iter->fPtr);
120 fShmPtr->SetMemory(cellDataPtr);
121 currentChannel = fShmPtr->NextChannel();
123 Int_t* tmpRawPtr = 0;
126 while(currentChannel != 0)
129 int tmpZ = currentChannel->fZ;
130 int tmpX = currentChannel->fX;
131 int tmpGain = currentChannel->fGain;
133 tmpRawPtr = fShmPtr->GetRawData(tmpSamples);
136 if( (tmpZ > NZROWSRCU) || (tmpX > NXCOLUMNSRCU) || (tmpGain > NGAINS))
138 cout <<" ERROR parameters out of range z = "<< tmpZ <<" x = "<< tmpX<< " gain = " << tmpGain<<" nSamples = " << tmpSamples <<endl;
142 // cout <<" all parameters in range" << endl;
145 // cout << "analyzing channelnr " << tmp <<" of event " << fPhosEventCount << endl;
146 // cout << " z = " << currentChannel->fZ << " x = " << currentChannel->fX << " gain = " << currentChannel->fGain << " samples =" << currentChannel->fNSamples <<endl;
149 fPatternTestPtr->AddPattern(tmpRawPtr, currentChannel->fZ, currentChannel->fX, currentChannel->fGain, tmpSamples, fNPresamples);
150 int ret = fPatternTestPtr->ValidateAltroPattern(tmpRawPtr, tmpSamples);
155 fNTotalSamples += tmpSamples;
160 fNWrongSamples += ret;
163 if(fPhosEventCount%100 == 0)
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;
175 if(fPhosEventCount%100 == 0 && fPhosEventCount !=0)
177 fPatternTestPtr->countAllPatterns(fNSamples);
178 fPatternTestPtr->PrintStatistics();
185 cout <<" ERROR: incorrect parameters" << endl;
187 currentChannel = fShmPtr->NextChannel();
195 // mysize += sizeof(AliHLTPHOSRcuCellAccumulatedEnergyDataStruct);
198 AliHLTComponentBlockData bd;
202 bd.fDataType = AliHLTPHOSDefinitions::fgkCellAccumulatedEnergyDataType;
203 bd.fSpecification = 0xFFFFFFFF;
204 outputBlocks.push_back( bd );
211 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoEvent", "Too much data",
212 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
228 AliHLTPHOSRcuAltroPatternTestComponent::DoInit(int argc, const char** argv )
230 //See html documentation of base class
231 cout << "AliHLTPHOSRcuAltroPatternTestComponent::DoInit, argc =" << argc << endl;
232 char patternFilename[2000];
233 bool isSetPartternArg = false;
237 iResult = ScanArguments(argc, argv);
238 // fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ);
245 if(fIsSetEquippmentID == kFALSE)
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>");
253 for(int i = 0; i < argc; i++)
255 if(!strcmp("-patternfile", argv[i]))
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>");
265 sprintf(patternFilename, "%s", argv[i+1]);
266 isSetPartternArg = true;
269 if(!strcmp("-nsamples", argv[i]))
271 fNSamples = atoi(argv[i+1]);
275 if(isSetPartternArg == false)
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>");
282 else if(fUtilitiesPtr->CheckFile(patternFilename, "r") == false)
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);
293 int tmpPattern[ALTROMAXSAMPLES];
294 ScanPatternFromFile(patternFilename, tmpPattern, ALTROMAXSAMPLES) ;
295 fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ, tmpPattern, ALTROMAXSAMPLES);
304 AliHLTPHOSRcuAltroPatternTestComponent::Spawn()
306 //See html documentation of base class
307 return new AliHLTPHOSRcuAltroPatternTestComponent;
312 AliHLTPHOSRcuAltroPatternTestComponent::ScanPatternFromFile(const char *filename, int *pattern, const int /*length*/) const
314 FILE *fp = fopen(filename, "r");
316 // int tmpPattern[ALTRO_MAX_SAMPLES];
319 for(int i=0; i<ALTROMAXSAMPLES; i++)
321 res = fscanf(fp,"w 0x%X 0x%X\n", &dummy, &pattern[i]);
322 // cout << tmpPattern[i] << endl;
326 // fPatternTestPtr->SetAltroPattern(tmpPattern);