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