]>
Commit | Line | Data |
---|---|---|
8484394b | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
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 | /* $Id$ */ | |
16 | ||
17 | // Storing digits in a binary file | |
18 | // according to the DDL mapping | |
19 | // Author: B. Cheynis | |
20 | ||
21 | #include <Riostream.h> | |
22 | #include <TObjArray.h> | |
23 | #include <TMath.h> | |
24 | ||
25 | #include "AliLog.h" | |
26 | #include "AliRawDataHeaderSim.h" | |
27 | #include "AliADBuffer.h" | |
28 | #include "AliADdigit.h" | |
29 | #include "AliADConst.h" | |
30 | ||
31 | ClassImp(AliADBuffer) | |
32 | ||
33 | //_____________________________________________________________________________ | |
34 | AliADBuffer::AliADBuffer():TObject(), | |
35 | fRemainingWord(0), | |
36 | f() | |
37 | { | |
38 | // | |
39 | // default constructor | |
40 | // | |
41 | } | |
42 | //_____________________________________________________________________________ | |
43 | AliADBuffer::AliADBuffer(const char* fileName):TObject(), | |
44 | fRemainingWord(0), | |
45 | f() | |
46 | { | |
47 | // Constructor | |
48 | f = new AliFstream(fileName); | |
49 | AliRawDataHeaderSim header; | |
50 | f->WriteBuffer((char*)(&header), sizeof(header)); | |
51 | ||
52 | } | |
53 | ||
54 | //_____________________________________________________________________________ | |
55 | AliADBuffer::~AliADBuffer(){ | |
56 | // Destructor, it closes the IO stream | |
57 | AliRawDataHeaderSim header; | |
58 | header.fSize = f->Tellp(); | |
59 | header.SetAttribute(0); // valid data | |
60 | f->Seekp(0); | |
61 | f->WriteBuffer((char*)(&header), sizeof(header)); | |
62 | delete f; | |
63 | } | |
64 | ||
65 | //_____________________________________________________________________________ | |
66 | void AliADBuffer::WriteTriggerInfo(UInt_t trigger) { | |
67 | // The method writes AD trigger information | |
68 | // This info is contained in the first two | |
69 | // raw-data words following the raw-data header (CDH). | |
70 | ||
71 | f->WriteBuffer((char*)(&trigger),sizeof(trigger)); | |
72 | ||
73 | // By default all the inputs are unmasked... Hopefully | |
74 | UInt_t triggerMask = 0xffff; | |
75 | f->WriteBuffer((char*)(&triggerMask),sizeof(triggerMask)); | |
76 | } | |
77 | ||
78 | //_____________________________________________________________________________ | |
79 | void AliADBuffer::WriteTriggerScalers() { | |
80 | // The method writes the AD trigger scalers | |
81 | // For the moment there is no way to simulate | |
82 | // this, so we fill the necessary 16 words with 0 | |
83 | ||
84 | // First the general trigger scalers (16 of them) | |
85 | for(Int_t i = 0; i < 16; i++) { | |
86 | UInt_t data = 0; | |
87 | f->WriteBuffer((char*)&data,sizeof(data)); | |
88 | } | |
89 | } | |
90 | ||
91 | //_____________________________________________________________________________ | |
92 | void AliADBuffer::WriteBunchNumbers() { | |
93 | // The method writes the Bunch Numbers corresponding | |
94 | // to the 10 Minimum Bias events | |
95 | // For the moment there is no way to simulate | |
96 | // this, so we fill the necessary 10 words with 0 | |
97 | ||
98 | // First the bunch crossing numbers | |
99 | // for these 10 events | |
100 | ||
101 | for(Int_t i = 0; i < 10; i++) { | |
102 | UInt_t data = 0; | |
103 | f->WriteBuffer((char*)&data,sizeof(data)); | |
104 | } | |
105 | ||
106 | } | |
107 | ||
108 | //_____________________________________________________________________________ | |
109 | void AliADBuffer::WriteChannel(Int_t channel, Short_t *adc, Bool_t integrator){ | |
110 | // It writes AD charge information into a raw data file. | |
111 | // Being called by Digits2Raw | |
112 | ||
9a065522 | 113 | UInt_t data = 0; |
8484394b | 114 | for(Int_t i = 0; i < kNClocks; ++i) { |
115 | if (adc[i] > 1023) { | |
116 | AliWarning(Form("ADC (channel=%d) saturated: %d. Truncating to 1023",channel,adc[i])); | |
117 | adc[i] = 1023; | |
118 | } | |
119 | } | |
9a065522 | 120 | |
121 | if(channel%2 == 0) { | |
122 | for(Int_t i = 0; i < (kNClocks/2); ++i) { | |
123 | data = (adc[2*i] & 0x3ff); | |
124 | data |= ((integrator & 0x1) << 10); | |
125 | ||
126 | data |= ((adc[2*i+1] & 0x3ff) << 16); | |
127 | data |= ((!integrator & 0x1) << 26); | |
128 | ||
8484394b | 129 | f->WriteBuffer((char*)&data,sizeof(data)); |
130 | } | |
9a065522 | 131 | fRemainingWord = (adc[kNClocks-1] & 0x3ff); |
132 | fRemainingWord |= ((integrator & 0x1) << 10); | |
133 | } | |
134 | else { | |
135 | data = fRemainingWord; | |
136 | data |= ((adc[0] & 0x3ff) << 16); | |
137 | data |= ((integrator & 0x1) << 26); | |
138 | f->WriteBuffer((char*)&data,sizeof(data)); | |
139 | ||
140 | for(Int_t i = 1; i <= (kNClocks/2); ++i) { | |
141 | data = (adc[2*i-1] & 0x3ff); | |
142 | data |= ((!integrator & 0x1) << 10); | |
143 | ||
144 | data |= ((adc[2*i] & 0x3ff) << 16); | |
145 | data |= ((integrator & 0x1) << 26); | |
146 | ||
147 | f->WriteBuffer((char*)&data,sizeof(data)); | |
148 | } | |
149 | } | |
8484394b | 150 | |
151 | } | |
152 | ||
153 | //_____________________________________________________________________________ | |
154 | void AliADBuffer::WriteBeamFlags() { | |
155 | ||
156 | //void AliADBuffer::WriteBeamFlags(Bool_t *bbFlag, Bool_t *bgFlag) { | |
157 | // The method writes information about | |
158 | // the Beam-Beam and Beam-Gas flags i.e. | |
159 | // 10 shorts for the 4 channels | |
160 | // of half a CIU card | |
161 | ||
162 | // Beam-beam and beam-gas flags are available | |
163 | // only for the triggered event-of-interest (sample index = 10) | |
164 | // As soon as trigger simulation would become more complex | |
165 | // and would allow to simulate neighbouring samples, this code | |
166 | // should be extended in order to fill all (or fraction) of the | |
167 | // flags | |
168 | /*/ | |
169 | UShort_t data = 0; | |
170 | ||
171 | for(Int_t iEvOfInt = 0; iEvOfInt < kNClocks; iEvOfInt=iEvOfInt+2) { | |
172 | for(Int_t iChannel = 0; iChannel < 4; iChannel++) { | |
173 | data = 0; | |
174 | if (bbFlag[iChannel]) data |= ((bbFlag[iChannel] & 0x1) << 2*iChannel); | |
175 | if (bgFlag[iChannel]) data |= ((bgFlag[iChannel] & 0x1) << 2*iChannel+1); | |
176 | ||
177 | if(iEvOfInt < (kNClocks - 1)) { | |
178 | if (bbFlag[iChannel]) data |= ((bbFlag[iChannel] & 0x1) << 8 + 2*iChannel); | |
179 | if (bgFlag[iChannel]) data |= ((bgFlag[iChannel] & 0x1) << 8 + 2*iChannel+1); | |
180 | } | |
181 | f->WriteBuffer((char*)&data,sizeof(data)); | |
182 | } | |
183 | } | |
184 | data = 0; | |
185 | f->WriteBuffer((char*)&data,sizeof(data));//Empty short in the end | |
186 | /*/ | |
9a065522 | 187 | for(Int_t i = 0; i < 6; i++) { |
188 | UInt_t data = 0; | |
8484394b | 189 | f->WriteBuffer((char*)&data,sizeof(data)); |
190 | } | |
191 | } | |
192 | ||
193 | //_____________________________________________________________________________ | |
194 | void AliADBuffer::WriteMBInfo() { | |
195 | // The method writes information about | |
196 | // the 10 previous minimum-bias events | |
197 | // i.e. channels charge for each of these | |
198 | // 10 events (4*10 shorts for the 4 channels | |
199 | // of half a CIU card) | |
200 | ||
9a065522 | 201 | for(Int_t i = 0; i < 20; i++) { |
202 | UInt_t data = 0; | |
8484394b | 203 | f->WriteBuffer((char*)&data,sizeof(data)); |
204 | } | |
205 | } | |
206 | ||
207 | ||
208 | //_____________________________________________________________________________ | |
209 | void AliADBuffer::WriteMBFlags() { | |
210 | // The method writes information about | |
211 | // the Minimum Bias flags | |
212 | // 5 16-bits words for the 4 channels | |
213 | // of half a CIU card + one empty 16-bit | |
214 | ||
215 | ||
9a065522 | 216 | for(Int_t i = 0; i < 3; i++) { |
217 | UInt_t data = 0; | |
218 | f->WriteBuffer((char*)&data,sizeof(data)); | |
219 | } | |
8484394b | 220 | } |
221 | ||
222 | //_____________________________________________________________________________ | |
223 | void AliADBuffer::WriteBeamScalers() { | |
224 | // The method writes the AD beam scalers | |
225 | // For the moment there is no way to simulate | |
226 | // this, so we fill the necessary words with 0 | |
227 | ||
228 | // Beam-beam and beam-gas scalers for | |
229 | // 4 individual channel (4x4 words) | |
230 | // (64-bit + 64-bit)*4 = 32bit * 16 | |
231 | ||
232 | for(Int_t i = 0; i < 16; i++) { | |
233 | UInt_t data = 0; | |
234 | f->WriteBuffer((char*)&data,sizeof(data)); | |
235 | } | |
236 | } | |
237 | ||
238 | ||
239 | ||
240 | //_____________________________________________________________________________ | |
241 | void AliADBuffer::WriteTiming(Float_t time, Float_t width) { | |
242 | // It writes the timing information into a raw data file. | |
243 | // Being called by Digits2Raw | |
244 | ||
245 | // Writes the timing information | |
246 | UInt_t data = TMath::Nint(time) & 0xfff; | |
247 | data |= (TMath::Nint(width) & 0x7f) << 12; | |
248 | f->WriteBuffer((char*)&data,sizeof(data)); | |
249 | } |