1 /**************************************************************************
2 * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved. *
4 * Authors: Per Thomas Hille for the ALICE *
5 * offline/HLT Project. Contributors are mentioned in the code where *
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 **************************************************************************/
19 #include "AliHLTPHOSRcuAltroPatternTestComponent.h"
20 #include "AliHLTPHOSSharedMemoryInterface.h"
21 #include "AliHLTPHOSValidCellDataStruct.h"
22 #include "AliHLTPHOSRcuAltroPatternTest.h"
24 AliHLTPHOSRcuAltroPatternTestComponent gAliHLTPHOSRcuAltroPatternTestComponent;
26 AliHLTPHOSRcuAltroPatternTestComponent:: AliHLTPHOSRcuAltroPatternTestComponent() : AliHLTPHOSRcuProcessor(),
34 fShmPtr = new AliHLTPHOSSharedMemoryInterface();
38 AliHLTPHOSRcuAltroPatternTestComponent::~ AliHLTPHOSRcuAltroPatternTestComponent()
45 AliHLTPHOSRcuAltroPatternTestComponent::Deinit()
47 //See html documentation of base class
53 AliHLTPHOSRcuAltroPatternTestComponent::GetComponentID()
55 //See html documentation of base class
56 return "AltroPatternTester";
61 AliHLTPHOSRcuAltroPatternTestComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
63 //See html documentation of base class
64 const AliHLTComponentDataType* pType=fgkInputDataTypes;
67 list.push_back(*pType);
73 AliHLTComponentDataType
74 AliHLTPHOSRcuAltroPatternTestComponent::GetOutputDataType()
76 //See html documentation of base class
77 return AliHLTPHOSDefinitions::fgkCellEnergyDataType;
82 AliHLTPHOSRcuAltroPatternTestComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
84 //See html documentation of base class
91 int AliHLTPHOSRcuAltroPatternTestComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
92 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
93 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& /*outputBlocks */)
95 //See html documentation of base class
96 //cout << "AliHLTPHOSRcuAltroPatternTestComponent::DoEvent, processing event "<< fPhosEventCount << endl;
98 AliHLTPHOSValidCellDataStruct *currentChannel =0;
99 unsigned long ndx = 0;
100 // UInt_t offset = 0;
101 // UInt_t mysize = 0;
103 const AliHLTComponentBlockData* iter = NULL;
104 AliHLTPHOSRcuCellEnergyDataStruct *cellDataPtr;
105 AliHLTUInt8_t* outBPtr;
109 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
112 if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
117 cellDataPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)( iter->fPtr);
118 fShmPtr->SetMemory(cellDataPtr);
119 currentChannel = fShmPtr->NextChannel();
122 while(currentChannel != 0)
125 int tmpZ = currentChannel->fZ;
126 int tmpX = currentChannel->fX;
127 int tmpGain = currentChannel->fGain;
128 int tmpSamples = currentChannel->fNSamples;
131 if( (tmpZ > N_ZROWS_RCU) || (tmpX > N_XCOLUMNS_RCU) || (tmpGain > N_GAINS))
133 cout <<" ERROR parameters out of range z = "<< tmpZ <<" x = "<< tmpX<< " gain = " << tmpGain<<" nSamples = " << tmpSamples <<endl;
137 // cout <<" all parameters in range" << endl;
140 // cout << "analyzing channelnr " << tmp <<" of event " << fPhosEventCount << endl;
141 // cout << " z = " << currentChannel->fZ << " x = " << currentChannel->fX << " gain = " << currentChannel->fGain << " samples =" << currentChannel->fNSamples <<endl;
144 fPatternTestPtr->AddPattern(currentChannel->fData, currentChannel->fZ, currentChannel->fX, currentChannel->fGain, currentChannel->fNSamples, fNPresamples);
145 int ret = fPatternTestPtr->ValidateAltroPattern(currentChannel->fData, currentChannel->fNSamples);
150 fNTotalSamples += currentChannel->fNSamples;
155 fNWrongSamples += ret;
158 if(fPhosEventCount%100 == 0)
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;
170 if(fPhosEventCount%100 == 0 && fPhosEventCount !=0)
172 fPatternTestPtr->countAllPatterns(fNSamples);
173 fPatternTestPtr->PrintStatistics();
180 cout <<" ERROR: incorrect parameters" << endl;
182 currentChannel = fShmPtr->NextChannel();
190 // mysize += sizeof(AliHLTPHOSRcuCellAccumulatedEnergyDataStruct);
193 AliHLTComponentBlockData bd;
197 bd.fDataType = AliHLTPHOSDefinitions::fgkCellAccumulatedEnergyDataType;
198 bd.fSpecification = 0xFFFFFFFF;
199 outputBlocks.push_back( bd );
206 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoEvent", "Too much data",
207 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
223 AliHLTPHOSRcuAltroPatternTestComponent::DoInit(int argc, const char** argv )
225 //See html documentation of base class
226 cout << "AliHLTPHOSRcuAltroPatternTestComponent::DoInit, argc =" << argc << endl;
227 char patternFilename[2000];
228 bool isSetPartternArg = false;
232 iResult = ScanArguments(argc, argv);
233 // fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ);
240 if(fIsSetEquippmentID == kFALSE)
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>");
248 for(int i = 0; i < argc; i++)
250 if(!strcmp("-patternfile", argv[i]))
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>");
260 sprintf(patternFilename, argv[i+1]);
261 isSetPartternArg = true;
266 if(isSetPartternArg == false)
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>");
273 else if(CheckFile(patternFilename, "r") == false)
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);
284 int tmpPattern[ALTRO_MAX_SAMPLES];
285 ScanPatternFromFile(patternFilename, tmpPattern, ALTRO_MAX_SAMPLES) ;
286 fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ, tmpPattern, ALTRO_MAX_SAMPLES);
295 AliHLTPHOSRcuAltroPatternTestComponent::Spawn()
297 //See html documentation of base class
298 return new AliHLTPHOSRcuAltroPatternTestComponent;
303 AliHLTPHOSRcuAltroPatternTestComponent::ScanPatternFromFile(const char *filename, int *pattern, const int /*length*/) const
305 FILE *fp = fopen(filename, "r");
307 // int tmpPattern[ALTRO_MAX_SAMPLES];
310 for(int i=0; i<ALTRO_MAX_SAMPLES; i++)
312 fscanf(fp,"w 0x%X 0x%X\n", &dummy, &pattern[i]);
313 // cout << tmpPattern[i] << endl;
317 // fPatternTestPtr->SetAltroPattern(tmpPattern);