]>
Commit | Line | Data |
---|---|---|
d389af40 | 1 | // |
a1f80595 | 2 | // $Id$ |
3 | // | |
d389af40 | 4 | // Small script to test consistency of writing and reading raw data. |
5 | // | |
9b48326f | 6 | /** Check raw data I/O |
7 | @ingroup simple_script | |
8 | */ | |
d389af40 | 9 | void |
10 | RawTest() | |
11 | { | |
12 | gRandom->SetSeed(12345); | |
13 | Int_t sampleRate = 3; | |
14 | Int_t channelWidth = 128; | |
15 | Float_t shapingTime = 5; | |
16 | UInt_t maxAdc = (1 << 10); | |
17 | UInt_t threshold = (1 << 8); | |
18 | TArrayI outData(sampleRate * channelWidth); | |
19 | ||
20 | Float_t lastTotalCharge = 0; | |
21 | Int_t ok = 0; | |
22 | for (Int_t channel = 0; channel < channelWidth; channel++) { | |
23 | Float_t totalCharge = gRandom->Uniform(0, 1); | |
24 | ||
25 | for (Int_t sample = 0; sample < sampleRate; sample++) { | |
26 | Float_t time = Float_t(sample) / sampleRate; | |
27 | Float_t charge = (totalCharge + (lastTotalCharge - totalCharge) | |
28 | * TMath::Exp(-shapingTime * time)); | |
29 | UInt_t adc = UInt_t(maxAdc * charge); | |
30 | outData[channel * sampleRate + sample] = adc; | |
31 | if (adc > threshold) ok++; | |
32 | } | |
33 | lastTotalCharge = totalCharge; | |
34 | } | |
35 | std::cout << "Total of " << outData.fN << " samples of which " | |
36 | << ok << " of them are above threshold (" << threshold | |
37 | << ")" << std::endl; | |
38 | ||
39 | { | |
40 | AliAltroBuffer buffer("FMD_4096.ddl", 1); | |
41 | buffer.WriteDataHeader(kTRUE, kFALSE); | |
42 | buffer.WriteChannel(0, 0, 0, outData.fN, outData.fArray, threshold); | |
43 | buffer.Flush(); | |
44 | buffer.WriteDataHeader(kFALSE, kFALSE); | |
45 | } | |
46 | ||
47 | AliRawReader* reader = new AliRawReaderFile(-1); | |
48 | if (!reader) { | |
49 | std::cerr << "Failed to make AliRawReader" << endl; | |
50 | return 0; | |
51 | } | |
52 | AliFMDRawStream input(reader, sampleRate); | |
1e8f773e | 53 | reader->Select(AliFMDParameters::kBaseDDL >> 8); |
d389af40 | 54 | |
55 | Int_t oldDDL = -1; | |
56 | Int_t count = 0; | |
57 | UShort_t detector = 1; // Must be one here | |
58 | UShort_t oldDetector = 0; | |
59 | // Loop over data in file | |
60 | Bool_t next = kTRUE; | |
61 | ||
62 | // local Cache | |
63 | TArrayI counts(10); | |
64 | counts.Reset(-1); | |
65 | Int_t offset = 0; | |
66 | ||
67 | TArrayI inputData(sampleRate * channelWidth); | |
68 | while (next) { | |
69 | next = input.Next(); | |
70 | ||
71 | if (!next) break; | |
72 | ||
73 | Int_t channel = input.Strip(); | |
74 | Int_t sample = input.Sample(); | |
75 | inputData[channel * sampleRate + sample] = input.Count(); | |
76 | count++; | |
77 | ||
78 | Int_t in = inputData[channel * sampleRate + sample]; | |
79 | Int_t out = outData[channel * sampleRate + sample]; | |
80 | std::cout << "[\t" << channel << ",\t" << sample << "]\t" | |
81 | << out << "\t" << in << std::flush; | |
82 | if (out >= threshold && in != out) std::cout << "\tBad" << std::flush; | |
83 | std::cout << std::endl; | |
84 | } | |
85 | ||
86 | std::cout << "Read " << count << " values" << std::endl; | |
87 | #if 1 | |
88 | for (Int_t channel = channelWidth - 1; channel > 0; channel--) { | |
89 | for (Int_t sample = sampleRate - 1; sample > 0; sample--) { | |
90 | Int_t in = inputData[channel * sampleRate + sample]; | |
91 | Int_t out = outData[channel * sampleRate + sample]; | |
92 | std::cout << "[\t" << channel << ",\t" << sample << "]\t" | |
93 | << out << "\t" << in << std::flush; | |
94 | if (out >= threshold && in != out) std::cout << "\tBad" << std::flush; | |
95 | std::cout << std::endl; | |
96 | } | |
97 | } | |
98 | #endif | |
99 | } | |
100 | ||
a1f80595 | 101 | //____________________________________________________________________ |
102 | // | |
103 | // EOF | |
104 | // | |
d389af40 | 105 | |
106 | ||
107 | ||
108 | ||
109 | ||
110 | ||
111 | ||
112 |