]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSDataCorruptor.cxx
Classes for online creation of root trees
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSDataCorruptor.cxx
CommitLineData
56673b84 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
4 * *
5 * Primary Author: Per Thomas Hille <perthi@fys.uio.no> *
6 * *
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 **************************************************************************/
15
f809259d 16#include "AliHLTPHOSDataCorruptor.h"
17#include "AliHLTPHOSPulseGenerator.h"
18
19#include "TRandom.h"
20
21#include <iostream>
22
23using namespace std;
24
25
26AliHLTPHOSDataCorruptor::AliHLTPHOSDataCorruptor():fPulseGeneratorPtr(0), fRandomGeneratorPtr(0)
27{
f2a83724 28 // cout << " AliHLTPHOSDataCorruptor::AliHLTPHOSDataCorruptor() creating new datacorruptor" << endl;
f809259d 29 fPulseGeneratorPtr = new AliHLTPHOSPulseGenerator(100, 0, 300, 2, 10);
30 fRandomGeneratorPtr = new TRandom();
31}
32
33
34AliHLTPHOSDataCorruptor::AliHLTPHOSDataCorruptor(const AliHLTPHOSDataCorruptor & ):fPulseGeneratorPtr(0), fRandomGeneratorPtr(0)
35{
36
37}
38
39
40AliHLTPHOSDataCorruptor::~AliHLTPHOSDataCorruptor()
41{
42 delete fPulseGeneratorPtr;
43}
44
45
46/**
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
52 */
53void
54AliHLTPHOSDataCorruptor::MakeCorruptedData(Double_t *dataArray, int N)
55{
56
57
58}
59
60
61void
62AliHLTPHOSDataCorruptor::MakeCorruptedDataTest(Double_t *dataArray, int N)
63{
64 // double testPulse[300];
65 // dataArray[300];
2f2c023b 66 int* quantisized = new int[N];
f809259d 67
68 fPulseGeneratorPtr->SetSampleFreq(10);
69 fPulseGeneratorPtr->SetAmplitude(100);
70 fPulseGeneratorPtr->SetTZero(0);
71 fPulseGeneratorPtr->MakePulse(dataArray, N);
72
73 cout <<endl <<endl;
74 cout << "AliHLTPHOSDataCorruptor::MakeCorruptedDataTest: printing data array before corruption" <<endl;
75
76 for(int i=0; i< N; i++)
77 {
78 cout << dataArray[i] <<"\t";
79 quantisized[i] = (int)(dataArray[i]);
80 }
81
82 cout << endl;
83 cout << "AliHLTPHOSDataCorruptor::MakeCorruptedDataTest: printing data after quantization" <<endl;
84
85 for(int i=0; i< N; i++)
86 {
87 cout << quantisized[i] <<"\t";
88 }
89 cout << endl;
90
91 int bit = fRandomGeneratorPtr->Integer(10);
92
93 cout << "AliHLTPHOSDataCorruptor::MakeCorruptedDataTest: printing data flipping sample 20, bit " << bit <<endl;
94
95 FlipBit(&quantisized[10], bit);
96
97 cout << endl;
98
99 for(int i=0; i< N; i++)
100 {
101 cout << quantisized[i] <<"\t";
102 }
103 cout << endl;
104 cout << endl;
2f2c023b 105 delete [] quantisized;
f809259d 106}
107
108
109/**
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
113 *impedance.
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) .
116*/
117void
118AliHLTPHOSDataCorruptor::FlipBit(int *sample, int n)
119{
120
121 int mask = 1 << n;
122 cout << "n = "<< n <<" mask = " << mask << endl;
123 cout << "before flip"<< *sample << endl;
124 *sample = *sample ^ mask;
125 cout <<"after flip" << *sample <<endl;
126
127}