4 // Small script to test consistency of writing and reading raw data.
12 gRandom->SetSeed(12345);
14 Int_t channelWidth = 128;
15 Float_t shapingTime = 5;
16 UInt_t maxAdc = (1 << 10);
17 UInt_t threshold = 0; // (1 << 8);
18 TArrayI outData(sampleRate * channelWidth);
20 Float_t lastTotalCharge = 0;
22 for (Int_t channel = 0; channel < channelWidth; channel++) {
23 Float_t totalCharge = gRandom->Uniform(0, 1);
25 for (Int_t sample = 0; sample < sampleRate; sample++) {
26 Float_t time = Float_t(sample) / sampleRate + 1./sampleRate;
27 Float_t charge = (totalCharge + (lastTotalCharge - totalCharge)
28 * TMath::Exp(-shapingTime * time));
29 UInt_t adc = channel; // UInt_t(maxAdc * charge);
30 outData[channel * sampleRate + sample] = adc;
31 if (adc > threshold) ok++;
33 lastTotalCharge = totalCharge;
35 std::cout << "Total of " << outData.fN << " samples of which "
36 << ok << " of them are above threshold (" << threshold
40 AliAltroBuffer buffer("FMD_4096.ddl", new AliFMDAltroMapping());
41 buffer.WriteDataHeader(kTRUE, kFALSE);
42 buffer.WriteChannel(0, 0, 0, outData.fN, outData.fArray, threshold);
44 buffer.WriteDataHeader(kFALSE, kFALSE);
47 AliRawReader* reader = new AliRawReaderFile(-1);
49 std::cerr << "Failed to make AliRawReader" << endl;
52 AliFMDRawStream input(reader); // , sampleRate);
53 reader->Select(12); // AliFMDParameters::kBaseDDL >> 8);
57 UShort_t detector = 1; // Must be one here
58 UShort_t oldDetector = 0;
59 // Loop over data in file
72 AliFMDParameters* pars = AliFMDParameters::Instance();
73 TArrayI inputData(sampleRate * channelWidth);
76 isGood = input.ReadChannel(ddl, hwaddr, last, data);
79 std::cout << Form("Read channel %p 0x%x of size %d", ddl, hwaddr, last)
81 UShort_t det, sec, str;
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;
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;
94 // Loop over the `timebins', and make the digits
95 for (size_t i = 0; i < last; 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;
107 Int_t channel = input.Strip();
108 Int_t sample = input.Sample();
109 inputData[channel * sampleRate + sample] = input.Count();
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;
121 std::cout << "Read " << count << " values" << std::endl;
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;
136 //____________________________________________________________________