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;
110 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
113 if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
118 cellDataPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)( iter->fPtr);
119 fShmPtr->SetMemory(cellDataPtr);
120 currentChannel = fShmPtr->NextChannel();
122 Int_t* tmpRawPtr = 0;
125 while(currentChannel != 0)
128 int tmpZ = currentChannel->fZ;
129 int tmpX = currentChannel->fX;
130 int tmpGain = currentChannel->fGain;
132 tmpRawPtr = fShmPtr->GetRawData(tmpSamples);
135 if( (tmpZ > N_ZROWS_RCU) || (tmpX > N_XCOLUMNS_RCU) || (tmpGain > N_GAINS))
137 cout <<" ERROR parameters out of range z = "<< tmpZ <<" x = "<< tmpX<< " gain = " << tmpGain<<" nSamples = " << tmpSamples <<endl;
141 // cout <<" all parameters in range" << endl;
144 // cout << "analyzing channelnr " << tmp <<" of event " << fPhosEventCount << endl;
145 // cout << " z = " << currentChannel->fZ << " x = " << currentChannel->fX << " gain = " << currentChannel->fGain << " samples =" << currentChannel->fNSamples <<endl;
148 fPatternTestPtr->AddPattern(tmpRawPtr, currentChannel->fZ, currentChannel->fX, currentChannel->fGain, tmpSamples, fNPresamples);
149 int ret = fPatternTestPtr->ValidateAltroPattern(tmpRawPtr, tmpSamples);
154 fNTotalSamples += tmpSamples;
159 fNWrongSamples += ret;
162 if(fPhosEventCount%100 == 0)
165 cout << "warning: incorrect pattern found for event " << fPhosEventCount <<" X = " << currentChannel->fX <<" Z = " << currentChannel->fZ ;
166 cout << "number of correct aptterns is " << fNTotalPatterns << "number of wrong patterns is " << fNWrongPatterns<<endl;
167 float percent = 100*((float)fNWrongPatterns)/( float(fNTotalPatterns));
168 cout <<"The corrpution rate is " << percent << " percent " <<endl;
169 cout <<" ERROR: incorrect parameters" << endl;
174 if(fPhosEventCount%100 == 0 && fPhosEventCount !=0)
176 fPatternTestPtr->countAllPatterns(fNSamples);
177 fPatternTestPtr->PrintStatistics();
184 cout <<" ERROR: incorrect parameters" << endl;
186 currentChannel = fShmPtr->NextChannel();
194 // mysize += sizeof(AliHLTPHOSRcuCellAccumulatedEnergyDataStruct);
197 AliHLTComponentBlockData bd;
201 bd.fDataType = AliHLTPHOSDefinitions::fgkCellAccumulatedEnergyDataType;
202 bd.fSpecification = 0xFFFFFFFF;
203 outputBlocks.push_back( bd );
210 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoEvent", "Too much data",
211 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
227 AliHLTPHOSRcuAltroPatternTestComponent::DoInit(int argc, const char** argv )
229 //See html documentation of base class
230 cout << "AliHLTPHOSRcuAltroPatternTestComponent::DoInit, argc =" << argc << endl;
231 char patternFilename[2000];
232 bool isSetPartternArg = false;
236 iResult = ScanArguments(argc, argv);
237 // fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ);
244 if(fIsSetEquippmentID == kFALSE)
246 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "Missing argument",
247 "The argument equippmentID is not set: set it with a component argumet like this: -equippmentID <number>");
252 for(int i = 0; i < argc; i++)
254 if(!strcmp("-patternfile", argv[i]))
258 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "Missing argument",
259 "The argument -patternfile requires that a filename follows: set it with a component argumet like this: -patternfile <filename>");
264 sprintf(patternFilename, argv[i+1]);
265 isSetPartternArg = true;
270 if(isSetPartternArg == false)
272 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "Missing argument",
273 "The argument patternfile is not set: set it with a component argumet like this: -patternfile <filename>");
277 else if(fUtilitiesPtr->CheckFile(patternFilename, "r") == false)
279 char tmpMessage[1024];
280 sprintf(tmpMessage, "the file %s could not be found, please check that file exist and that you have read access to it", patternFilename);
281 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuAltroPatternTestComponent::DoInit( int argc, const char** argv )", "File not found",tmpMessage);
288 int tmpPattern[ALTRO_MAX_SAMPLES];
289 ScanPatternFromFile(patternFilename, tmpPattern, ALTRO_MAX_SAMPLES) ;
290 fPatternTestPtr = new AliHLTPHOSRcuAltroPatternTest(fModuleID, fRcuX, fRcuZ, tmpPattern, ALTRO_MAX_SAMPLES);
299 AliHLTPHOSRcuAltroPatternTestComponent::Spawn()
301 //See html documentation of base class
302 return new AliHLTPHOSRcuAltroPatternTestComponent;
307 AliHLTPHOSRcuAltroPatternTestComponent::ScanPatternFromFile(const char *filename, int *pattern, const int /*length*/) const
309 FILE *fp = fopen(filename, "r");
311 // int tmpPattern[ALTRO_MAX_SAMPLES];
314 for(int i=0; i<ALTRO_MAX_SAMPLES; i++)
316 fscanf(fp,"w 0x%X 0x%X\n", &dummy, &pattern[i]);
317 // cout << tmpPattern[i] << endl;
321 // fPatternTestPtr->SetAltroPattern(tmpPattern);