1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
5 * Primary Author: Per Thomas Hille <perthi@fys.uio.no> *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 #include "AliHLTPHOSDataCorruptor.h"
17 #include "AliHLTPHOSPulseGenerator.h"
26 AliHLTPHOSDataCorruptor::AliHLTPHOSDataCorruptor():fPulseGeneratorPtr(0), fRandomGeneratorPtr(0)
28 // cout << " AliHLTPHOSDataCorruptor::AliHLTPHOSDataCorruptor() creating new datacorruptor" << endl;
29 fPulseGeneratorPtr = new AliHLTPHOSPulseGenerator(100, 0, 300, 2, 10);
30 fRandomGeneratorPtr = new TRandom();
34 AliHLTPHOSDataCorruptor::AliHLTPHOSDataCorruptor(const AliHLTPHOSDataCorruptor & ):fPulseGeneratorPtr(0), fRandomGeneratorPtr(0)
40 AliHLTPHOSDataCorruptor::~AliHLTPHOSDataCorruptor()
42 delete fPulseGeneratorPtr;
47 * Takes as input good data from an altro and makes
48 * bad data from it by flipping bits in individual samples, adding noise
49 * add a double pulse.. etc
50 * @param dataArray data that should be corrupted
51 * @param N the number of samples in the array
54 AliHLTPHOSDataCorruptor::MakeCorruptedData(Double_t *dataArray, int N)
62 AliHLTPHOSDataCorruptor::MakeCorruptedDataTest(Double_t *dataArray, int N)
64 // double testPulse[300];
66 int* quantisized = new int[N];
68 fPulseGeneratorPtr->SetSampleFreq(10);
69 fPulseGeneratorPtr->SetAmplitude(100);
70 fPulseGeneratorPtr->SetTZero(0);
71 fPulseGeneratorPtr->MakePulse(dataArray, N);
74 cout << "AliHLTPHOSDataCorruptor::MakeCorruptedDataTest: printing data array before corruption" <<endl;
76 for(int i=0; i< N; i++)
78 cout << dataArray[i] <<"\t";
79 quantisized[i] = (int)(dataArray[i]);
83 cout << "AliHLTPHOSDataCorruptor::MakeCorruptedDataTest: printing data after quantization" <<endl;
85 for(int i=0; i< N; i++)
87 cout << quantisized[i] <<"\t";
91 int bit = fRandomGeneratorPtr->Integer(10);
93 cout << "AliHLTPHOSDataCorruptor::MakeCorruptedDataTest: printing data flipping sample 20, bit " << bit <<endl;
95 FlipBit(&quantisized[10], bit);
99 for(int i=0; i< N; i++)
101 cout << quantisized[i] <<"\t";
105 delete [] quantisized;
110 *Flipping a single bit in a sample from 0 if it is one, and 1 if it
111 *is zero. This emluates a situaion that can occur on the readout bus
112 *if the rcu driver is not able to drive the bus because of to low
114 *@param sample The samle the should have the bit(s) flipped
115 *@param n The number of bits to flip, the highest number is 10 (most significant) .
118 AliHLTPHOSDataCorruptor::FlipBit(int *sample, int n)
122 cout << "n = "<< n <<" mask = " << mask << endl;
123 cout << "before flip"<< *sample << endl;
124 *sample = *sample ^ mask;
125 cout <<"after flip" << *sample <<endl;