]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSDataCorruptor.cxx
Added new files to build system
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSDataCorruptor.cxx
1 #include "AliHLTPHOSDataCorruptor.h"
2 #include "AliHLTPHOSPulseGenerator.h"
3
4 #include "TRandom.h"
5
6 #include <iostream>
7
8 using namespace std;
9
10
11 AliHLTPHOSDataCorruptor::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
19 AliHLTPHOSDataCorruptor::AliHLTPHOSDataCorruptor(const AliHLTPHOSDataCorruptor & ):fPulseGeneratorPtr(0), fRandomGeneratorPtr(0)
20 {
21
22 }
23
24
25 AliHLTPHOSDataCorruptor::~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  */
38 void
39 AliHLTPHOSDataCorruptor::MakeCorruptedData(Double_t *dataArray, int N)
40 {
41   
42
43 }
44
45
46 void
47 AliHLTPHOSDataCorruptor::MakeCorruptedDataTest(Double_t *dataArray, int N)
48 {
49   //  double testPulse[300];
50   //  dataArray[300];
51   int* quantisized = new int[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   delete [] quantisized;
91 }
92
93
94 /**
95  *Flipping a single bit in a sample from 0 if it is one, and 1 if it
96  *is zero. This emluates a situaion that can occur on the readout bus
97  *if the rcu driver is not able to drive the bus because of to low
98  *impedance.
99  *@param sample The samle the should have the bit(s) flipped
100  *@param n      The number of bits to flip, the highest number is 10 (most significant) . 
101 */
102 void 
103 AliHLTPHOSDataCorruptor::FlipBit(int *sample, int n)
104 {
105
106   int mask = 1 << n;
107   cout << "n = "<< n <<" mask = " << mask << endl;
108   cout << "before flip"<< *sample << endl;
109   *sample = *sample ^ mask;
110   cout <<"after flip" << *sample <<endl;
111
112 }