]>
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); | |
2aeec17d | 13 | Int_t sampleRate = 4; |
d389af40 | 14 | Int_t channelWidth = 128; |
15 | Float_t shapingTime = 5; | |
16 | UInt_t maxAdc = (1 << 10); | |
2aeec17d | 17 | UInt_t threshold = 0; // (1 << 8); |
d389af40 | 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++) { | |
2aeec17d | 26 | Float_t time = Float_t(sample) / sampleRate + 1./sampleRate; |
d389af40 | 27 | Float_t charge = (totalCharge + (lastTotalCharge - totalCharge) |
28 | * TMath::Exp(-shapingTime * time)); | |
2aeec17d | 29 | UInt_t adc = channel; // UInt_t(maxAdc * charge); |
d389af40 | 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 | { | |
2aeec17d | 40 | AliAltroBuffer buffer("FMD_4096.ddl", new AliFMDAltroMapping()); |
d389af40 | 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 | } | |
2aeec17d | 52 | AliFMDRawStream input(reader); // , sampleRate); |
53 | reader->Select(12); // 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; | |
2aeec17d | 66 | UInt_t ddl = 0; |
67 | UInt_t rate = 0; | |
68 | UInt_t last = 0; | |
69 | UInt_t hwaddr = 0; | |
70 | UShort_t data[2048]; | |
d389af40 | 71 | |
2aeec17d | 72 | AliFMDParameters* pars = AliFMDParameters::Instance(); |
d389af40 | 73 | TArrayI inputData(sampleRate * channelWidth); |
2aeec17d | 74 | Bool_t isGood = true; |
d389af40 | 75 | while (next) { |
2aeec17d | 76 | isGood = input.ReadChannel(ddl, hwaddr, last, data); |
77 | ddl = 0; | |
78 | ||
79 | std::cout << Form("Read channel %p 0x%x of size %d", ddl, hwaddr, last) | |
80 | << std::endl; | |
81 | UShort_t det, sec, str; | |
82 | Char_t ring; | |
83 | if (!pars->Hardware2Detector(ddl, hwaddr, det, ring, sec, str)) { | |
84 | std::cerr << Form("Failed to get detector id from DDL %d " | |
85 | "and hardware address 0x%x", ddl, hwaddr) << std::endl; | |
86 | continue; | |
87 | } | |
88 | rate = pars->GetSampleRate(det, ring, sec, str); | |
89 | Int_t stripMin = pars->GetMinStrip(det, ring, sec, str); | |
90 | Int_t stripMax = pars->GetMaxStrip(det, ring, sec, str); | |
91 | std::cout << Form("DDL 0x%04x, address 0x%03x maps to FMD%d%c[%2d,%3d]", | |
92 | ddl, hwaddr, det, ring, sec, str) << std::endl; | |
93 | ||
94 | // Loop over the `timebins', and make the digits | |
95 | for (size_t i = 0; i < last; i++) { | |
96 | Int_t in = data[i]; | |
97 | Int_t out = outData[channel * sampleRate + sample]; | |
98 | std::cout << "[\t" << channel << ",\t" << sample << "]\t" | |
99 | << out << "\t" << in << std::flush; | |
100 | if (out >= threshold && in != out) std::cout << "\tBad" << std::flush; | |
101 | } | |
102 | #if 0 | |
d389af40 | 103 | next = input.Next(); |
104 | ||
105 | if (!next) break; | |
106 | ||
107 | Int_t channel = input.Strip(); | |
108 | Int_t sample = input.Sample(); | |
109 | inputData[channel * sampleRate + sample] = input.Count(); | |
110 | count++; | |
111 | ||
112 | Int_t in = inputData[channel * sampleRate + sample]; | |
113 | Int_t out = outData[channel * sampleRate + sample]; | |
114 | std::cout << "[\t" << channel << ",\t" << sample << "]\t" | |
115 | << out << "\t" << in << std::flush; | |
116 | if (out >= threshold && in != out) std::cout << "\tBad" << std::flush; | |
117 | std::cout << std::endl; | |
2aeec17d | 118 | #endif |
d389af40 | 119 | } |
120 | ||
121 | std::cout << "Read " << count << " values" << std::endl; | |
2aeec17d | 122 | #if 0 |
d389af40 | 123 | for (Int_t channel = channelWidth - 1; channel > 0; channel--) { |
124 | for (Int_t sample = sampleRate - 1; sample > 0; sample--) { | |
125 | Int_t in = inputData[channel * sampleRate + sample]; | |
126 | Int_t out = outData[channel * sampleRate + sample]; | |
127 | std::cout << "[\t" << channel << ",\t" << sample << "]\t" | |
128 | << out << "\t" << in << std::flush; | |
129 | if (out >= threshold && in != out) std::cout << "\tBad" << std::flush; | |
130 | std::cout << std::endl; | |
131 | } | |
132 | } | |
133 | #endif | |
134 | } | |
135 | ||
a1f80595 | 136 | //____________________________________________________________________ |
137 | // | |
138 | // EOF | |
139 | // | |
d389af40 | 140 | |
141 | ||
142 | ||
143 | ||
144 | ||
145 | ||
146 | ||
147 |