]>
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 | ||
113 | UShort_t data = 0; | |
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 | } | |
120 | ||
121 | for(Int_t i = 0; i < (kNClocks); ++i) { | |
122 | data = (adc[i] & 0x3ff); | |
123 | data |= ((integrator & 0x1) << 10); | |
124 | f->WriteBuffer((char*)&data,sizeof(data)); | |
125 | } | |
126 | ||
127 | } | |
128 | ||
129 | //_____________________________________________________________________________ | |
130 | void AliADBuffer::WriteBeamFlags() { | |
131 | ||
132 | //void AliADBuffer::WriteBeamFlags(Bool_t *bbFlag, Bool_t *bgFlag) { | |
133 | // The method writes information about | |
134 | // the Beam-Beam and Beam-Gas flags i.e. | |
135 | // 10 shorts for the 4 channels | |
136 | // of half a CIU card | |
137 | ||
138 | // Beam-beam and beam-gas flags are available | |
139 | // only for the triggered event-of-interest (sample index = 10) | |
140 | // As soon as trigger simulation would become more complex | |
141 | // and would allow to simulate neighbouring samples, this code | |
142 | // should be extended in order to fill all (or fraction) of the | |
143 | // flags | |
144 | /*/ | |
145 | UShort_t data = 0; | |
146 | ||
147 | for(Int_t iEvOfInt = 0; iEvOfInt < kNClocks; iEvOfInt=iEvOfInt+2) { | |
148 | for(Int_t iChannel = 0; iChannel < 4; iChannel++) { | |
149 | data = 0; | |
150 | if (bbFlag[iChannel]) data |= ((bbFlag[iChannel] & 0x1) << 2*iChannel); | |
151 | if (bgFlag[iChannel]) data |= ((bgFlag[iChannel] & 0x1) << 2*iChannel+1); | |
152 | ||
153 | if(iEvOfInt < (kNClocks - 1)) { | |
154 | if (bbFlag[iChannel]) data |= ((bbFlag[iChannel] & 0x1) << 8 + 2*iChannel); | |
155 | if (bgFlag[iChannel]) data |= ((bgFlag[iChannel] & 0x1) << 8 + 2*iChannel+1); | |
156 | } | |
157 | f->WriteBuffer((char*)&data,sizeof(data)); | |
158 | } | |
159 | } | |
160 | data = 0; | |
161 | f->WriteBuffer((char*)&data,sizeof(data));//Empty short in the end | |
162 | /*/ | |
163 | for(Int_t i = 0; i < 12; i++) { | |
164 | UShort_t data = 0; | |
165 | f->WriteBuffer((char*)&data,sizeof(data)); | |
166 | } | |
167 | } | |
168 | ||
169 | //_____________________________________________________________________________ | |
170 | void AliADBuffer::WriteMBInfo() { | |
171 | // The method writes information about | |
172 | // the 10 previous minimum-bias events | |
173 | // i.e. channels charge for each of these | |
174 | // 10 events (4*10 shorts for the 4 channels | |
175 | // of half a CIU card) | |
176 | ||
177 | for(Int_t i = 0; i < 40; i++) { | |
178 | UShort_t data = 0; | |
179 | f->WriteBuffer((char*)&data,sizeof(data)); | |
180 | } | |
181 | } | |
182 | ||
183 | ||
184 | //_____________________________________________________________________________ | |
185 | void AliADBuffer::WriteMBFlags() { | |
186 | // The method writes information about | |
187 | // the Minimum Bias flags | |
188 | // 5 16-bits words for the 4 channels | |
189 | // of half a CIU card + one empty 16-bit | |
190 | ||
191 | ||
192 | for(Int_t i = 0; i < 6; i++) { | |
193 | UShort_t data = 0; | |
194 | f->WriteBuffer((char*)&data,sizeof(data)); | |
195 | } | |
196 | } | |
197 | ||
198 | //_____________________________________________________________________________ | |
199 | void AliADBuffer::WriteBeamScalers() { | |
200 | // The method writes the AD beam scalers | |
201 | // For the moment there is no way to simulate | |
202 | // this, so we fill the necessary words with 0 | |
203 | ||
204 | // Beam-beam and beam-gas scalers for | |
205 | // 4 individual channel (4x4 words) | |
206 | // (64-bit + 64-bit)*4 = 32bit * 16 | |
207 | ||
208 | for(Int_t i = 0; i < 16; i++) { | |
209 | UInt_t data = 0; | |
210 | f->WriteBuffer((char*)&data,sizeof(data)); | |
211 | } | |
212 | } | |
213 | ||
214 | ||
215 | ||
216 | //_____________________________________________________________________________ | |
217 | void AliADBuffer::WriteTiming(Float_t time, Float_t width) { | |
218 | // It writes the timing information into a raw data file. | |
219 | // Being called by Digits2Raw | |
220 | ||
221 | // Writes the timing information | |
222 | UInt_t data = TMath::Nint(time) & 0xfff; | |
223 | data |= (TMath::Nint(width) & 0x7f) << 12; | |
224 | f->WriteBuffer((char*)&data,sizeof(data)); | |
225 | } |