]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSDataCorruptor.cxx
Class to make corrupted data from good data, neccessary in order
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSDataCorruptor.cxx
CommitLineData
f809259d 1#include "AliHLTPHOSDataCorruptor.h"
2#include "AliHLTPHOSPulseGenerator.h"
3
4#include "TRandom.h"
5
6#include <iostream>
7
8using namespace std;
9
10
11AliHLTPHOSDataCorruptor::AliHLTPHOSDataCorruptor():fPulseGeneratorPtr(0), fRandomGeneratorPtr(0)
12{
13 cout << " AliHLTPHOSDataCorruptor::AliHLTPHOSDataCorruptor() creating new datacorruptor" << endl;
14 fPulseGeneratorPtr = new AliHLTPHOSPulseGenerator(100, 0, 300, 2, 10);
15 fRandomGeneratorPtr = new TRandom();
16}
17
18
19AliHLTPHOSDataCorruptor::AliHLTPHOSDataCorruptor(const AliHLTPHOSDataCorruptor & ):fPulseGeneratorPtr(0), fRandomGeneratorPtr(0)
20{
21
22}
23
24
25AliHLTPHOSDataCorruptor::~AliHLTPHOSDataCorruptor()
26{
27 delete fPulseGeneratorPtr;
28}
29
30
31/**
32 * Takes as input good data from an altro and makes
33 * bad data from it by flipping bits in individual samples, adding noise
34 * add a double pulse.. etc
35 * @param dataArray data that should be corrupted
36 * @param N the number of samples in the array
37 */
38void
39AliHLTPHOSDataCorruptor::MakeCorruptedData(Double_t *dataArray, int N)
40{
41
42
43}
44
45
46void
47AliHLTPHOSDataCorruptor::MakeCorruptedDataTest(Double_t *dataArray, int N)
48{
49 // double testPulse[300];
50 // dataArray[300];
51 int quantisized[N];
52
53 fPulseGeneratorPtr->SetSampleFreq(10);
54 fPulseGeneratorPtr->SetAmplitude(100);
55 fPulseGeneratorPtr->SetTZero(0);
56 fPulseGeneratorPtr->MakePulse(dataArray, N);
57
58 cout <<endl <<endl;
59 cout << "AliHLTPHOSDataCorruptor::MakeCorruptedDataTest: printing data array before corruption" <<endl;
60
61 for(int i=0; i< N; i++)
62 {
63 cout << dataArray[i] <<"\t";
64 quantisized[i] = (int)(dataArray[i]);
65 }
66
67 cout << endl;
68 cout << "AliHLTPHOSDataCorruptor::MakeCorruptedDataTest: printing data after quantization" <<endl;
69
70 for(int i=0; i< N; i++)
71 {
72 cout << quantisized[i] <<"\t";
73 }
74 cout << endl;
75
76 int bit = fRandomGeneratorPtr->Integer(10);
77
78 cout << "AliHLTPHOSDataCorruptor::MakeCorruptedDataTest: printing data flipping sample 20, bit " << bit <<endl;
79
80 FlipBit(&quantisized[10], bit);
81
82 cout << endl;
83
84 for(int i=0; i< N; i++)
85 {
86 cout << quantisized[i] <<"\t";
87 }
88 cout << endl;
89 cout << endl;
90}
91
92
93/**
94 *Flipping a single bit in a sample from 0 if it is one, and 1 if it
95 *is zero. This emluates a situaion that can occur on the readout bus
96 *if the rcu driver is not able to drive the bus because of to low
97 *impedance.
98 *@param sample The samle the should have the bit(s) flipped
99 *@param n The number of bits to flip, the highest number is 10 (most significant) .
100*/
101void
102AliHLTPHOSDataCorruptor::FlipBit(int *sample, int n)
103{
104
105 int mask = 1 << n;
106 cout << "n = "<< n <<" mask = " << mask << endl;
107 cout << "before flip"<< *sample << endl;
108 *sample = *sample ^ mask;
109 cout <<"after flip" << *sample <<endl;
110
111}