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 **************************************************************************/
20 #include "AliHLTPHOSRcuAltroPatternTestComponent.h"
21 #include "AliHLTPHOSSharedMemoryInterface.h"
22 #include "AliHLTPHOSValidCellDataStruct.h"
23 #include "AliHLTPHOSRcuAltroPatternTest.h"
25 AliHLTPHOSRcuAltroPatternTestComponent gAliHLTPHOSRcuAltroPatternTestComponent;
27 AliHLTPHOSRcuAltroPatternTestComponent:: AliHLTPHOSRcuAltroPatternTestComponent() : AliHLTPHOSRcuProcessor(),
35 fShmPtr = new AliHLTPHOSSharedMemoryInterface();
39 AliHLTPHOSRcuAltroPatternTestComponent::~ AliHLTPHOSRcuAltroPatternTestComponent()
46 AliHLTPHOSRcuAltroPatternTestComponent::Deinit()
48 //See html documentation of base class
54 AliHLTPHOSRcuAltroPatternTestComponent::GetComponentID()
56 //See html documentation of base class
57 return "AltroPatternTester";
62 AliHLTPHOSRcuAltroPatternTestComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
64 //See html documentation of base class
65 const AliHLTComponentDataType* pType=fgkInputDataTypes;
68 list.push_back(*pType);
74 AliHLTComponentDataType
75 AliHLTPHOSRcuAltroPatternTestComponent::GetOutputDataType()
77 //See html documentation of base class
78 return AliHLTPHOSDefinitions::fgkCellEnergyDataType;
83 AliHLTPHOSRcuAltroPatternTestComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
85 //See html documentation of base class
92 int AliHLTPHOSRcuAltroPatternTestComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
93 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
94 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& /*outputBlocks */)
96 //See html documentation of base class
97 //cout << "AliHLTPHOSRcuAltroPatternTestComponent::DoEvent, processing event "<< fPhosEventCount << endl;
99 AliHLTPHOSValidCellDataStruct *currentChannel =0;
100 unsigned long ndx = 0;
101 // UInt_t offset = 0;
102 // UInt_t mysize = 0;
104 const AliHLTComponentBlockData* iter = NULL;
105 AliHLTPHOSRcuCellEnergyDataStruct *cellDataPtr;
106 AliHLTUInt8_t* outBPtr;
108 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
111 if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
116 cellDataPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)( iter->fPtr);
117 fShmPtr->SetMemory(cellDataPtr);
118 currentChannel = fShmPtr->NextChannel();
120 Int_t* tmpRawPtr = 0;
123 while(currentChannel != 0)
126 int tmpZ = currentChannel->fZ;
127 int tmpX = currentChannel->fX;
128 int tmpGain = currentChannel->fGain;
130 tmpRawPtr = fShmPtr->GetRawData(tmpSamples);
133 if( (tmpZ > N_ZROWS_RCU) || (tmpX > N_XCOLUMNS_RCU) || (tmpGain > N_GAINS))
135 cout <<" ERROR parameters out of range z = "<< tmpZ <<" x = "<< tmpX<< " gain = " << tmpGain<<" nSamples = " << tmpSamples <<endl;
139 // cout <<" all parameters in range" << endl;
142 // cout << "analyzing channelnr " << tmp <<" of event " << fPhosEventCount << endl;
143 // cout << " z = " << currentChannel->fZ << " x = " << currentChannel->fX << " gain = " << currentChannel->fGain << " samples =" << currentChannel->fNSamples <<endl;
146 fPatternTestPtr->AddPattern(tmpRawPtr, currentChannel->fZ, currentChannel->fX, currentChannel->fGain, tmpSamples, fNPresamples);
147 int ret = fPatternTestPtr->ValidateAltroPattern(tmpRawPtr, tmpSamples);
152 fNTotalSamples += tmpSamples;
157 fNWrongSamples += ret;
160 if(fPhosEventCount%100 == 0)
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;
172 if(fPhosEventCount%100 == 0 && fPhosEventCount !=0)
174 fPatternTestPtr->countAllPatterns(fNSamples);
175 fPatternTestPtr->PrintStatistics();
182 cout <<" ERROR: incorrect parameters" << endl;
184 currentChannel = fShmPtr->NextChannel();
192 // mysize += sizeof(AliHLTPHOSRcuCellAccumulatedEnergyDataStruct);
195 AliHLTComponentBlockData bd;
199 bd.fDataType = AliHLTPHOSDefinitions::fgkCellAccumulatedEnergyDataType;
200 bd.fSpecification = 0xFFFFFFFF;
201 outputBlocks.push_back( bd );
208 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoEvent", "Too much data",
209 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
225 AliHLTPHOSRcuAltroPatternTestComponent::DoInit(int argc, const char** argv )
227 //See html documentation of base class
228 cout << "AliHLTPHOSRcuAltroPatternTestComponent::DoInit, argc =" << argc << endl;
229 char patternFilename[2000];
230 bool isSetPartternArg = false;
234 iResult = ScanArguments(argc, argv);
235 // fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ);
242 if(fIsSetEquippmentID == kFALSE)
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>");
250 for(int i = 0; i < argc; i++)
252 if(!strcmp("-patternfile", argv[i]))
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>");
262 sprintf(patternFilename, argv[i+1]);
263 isSetPartternArg = true;
268 if(isSetPartternArg == false)
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>");
275 else if(fUtilitiesPtr->CheckFile(patternFilename, "r") == false)
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);
286 int tmpPattern[ALTRO_MAX_SAMPLES];
287 ScanPatternFromFile(patternFilename, tmpPattern, ALTRO_MAX_SAMPLES) ;
288 fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ, tmpPattern, ALTRO_MAX_SAMPLES);
297 AliHLTPHOSRcuAltroPatternTestComponent::Spawn()
299 //See html documentation of base class
300 return new AliHLTPHOSRcuAltroPatternTestComponent;
305 AliHLTPHOSRcuAltroPatternTestComponent::ScanPatternFromFile(const char *filename, int *pattern, const int /*length*/) const
307 FILE *fp = fopen(filename, "r");
309 // int tmpPattern[ALTRO_MAX_SAMPLES];
312 for(int i=0; i<ALTRO_MAX_SAMPLES; i++)
314 fscanf(fp,"w 0x%X 0x%X\n", &dummy, &pattern[i]);
315 // cout << tmpPattern[i] << endl;
319 // fPatternTestPtr->SetAltroPattern(tmpPattern);