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