]> git.uio.no Git - u/mrichter/AliRoot.git/blame - VZERO/AliVZEROBuffer.cxx
- fixing use of centrality class
[u/mrichter/AliRoot.git] / VZERO / AliVZEROBuffer.cxx
CommitLineData
af095430 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
d983817d 21// Author: B. Cheynis
af095430 22
23#include <Riostream.h>
24#include <TObjArray.h>
b6fd9c4a 25#include <TMath.h>
26
726d762c 27#include "AliLog.h"
f7ee745b 28#include "AliRawDataHeaderSim.h"
af095430 29#include "AliVZEROBuffer.h"
b6fd9c4a 30#include "AliVZEROdigit.h"
af095430 31
32ClassImp(AliVZEROBuffer)
0b2bea8b 33
34//_____________________________________________________________________________
35AliVZEROBuffer::AliVZEROBuffer():TObject(),
b6fd9c4a 36 fRemainingWord(0),
726d762c 37 f()
0b2bea8b 38{
39 //
40 // default constructor
41 //
42}
af095430 43//_____________________________________________________________________________
0b2bea8b 44AliVZEROBuffer::AliVZEROBuffer(const char* fileName):TObject(),
b6fd9c4a 45 fRemainingWord(0),
726d762c 46 f()
0b2bea8b 47{
af095430 48 // Constructor
08f92f14 49 f = new AliFstream(fileName);
af095430 50 // fout=new TFile(fileName,"recreate");
51 // tree=new TTree("tree","Values");
f7ee745b 52 AliRawDataHeaderSim header;
08f92f14 53 f->WriteBuffer((char*)(&header), sizeof(header));
0b2bea8b 54
af095430 55}
56
57//_____________________________________________________________________________
58AliVZEROBuffer::~AliVZEROBuffer(){
59 // Destructor, it closes the IO stream
f7ee745b 60 AliRawDataHeaderSim header;
08f92f14 61 header.fSize = f->Tellp();
d983817d 62 header.SetAttribute(0); // valid data
08f92f14 63 f->Seekp(0);
64 f->WriteBuffer((char*)(&header), sizeof(header));
65 delete f;
af095430 66 //delete tree;
67 //delete fout;
68}
69
af095430 70//_____________________________________________________________________________
726d762c 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//_____________________________________________________________________________
98512c02 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
af095430 88
98512c02 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}
726d762c 112
98512c02 113//_____________________________________________________________________________
b6fd9c4a 114void AliVZEROBuffer::WriteChannel(Int_t channel, Short_t *adc, Bool_t integrator){
98512c02 115 // It writes VZERO charge information into a raw data file.
116 // Being called by Digits2Raw
117
118 UInt_t data = 0;
b6fd9c4a 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 }
98512c02 125
b6fd9c4a 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);
726d762c 138 }
b6fd9c4a 139 else {
140 data = fRemainingWord;
141 data |= ((adc[0] & 0x3ff) << 16);
142 data |= ((integrator & 0x1) << 26);
143 f->WriteBuffer((char*)&data,sizeof(data));
726d762c 144
b6fd9c4a 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 }
98512c02 155
726d762c 156}
157
158//_____________________________________________________________________________
b6fd9c4a 159void AliVZEROBuffer::WriteBeamFlags(Bool_t *bbFlag, Bool_t *bgFlag) {
98512c02 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
726d762c 164
b6fd9c4a 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++) {
726d762c 172 UInt_t data = 0;
173 f->WriteBuffer((char*)&data,sizeof(data));
174 }
b6fd9c4a 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
98512c02 188}
726d762c 189
98512c02 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++) {
726d762c 200 UInt_t data = 0;
201 f->WriteBuffer((char*)&data,sizeof(data));
202 }
203}
204
98512c02 205
726d762c 206//_____________________________________________________________________________
98512c02 207void AliVZEROBuffer::WriteMBFlags() {
726d762c 208 // The method writes information about
98512c02 209 // the Minimum Bias flags
210 // 3 32-bits words for the 4 channels
211 // of half a CIU card
726d762c 212
98512c02 213
214 for(Int_t i = 0; i < 3; i++) {
726d762c 215 UInt_t data = 0;
216 f->WriteBuffer((char*)&data,sizeof(data));
217 }
98512c02 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
726d762c 225
98512c02 226 // Beam-beam and beam-gas scalers for
227 // 4 individual channel (4x4 words)
228
229 for(Int_t i = 0; i < 16; i++) {
726d762c 230 UInt_t data = 0;
231 f->WriteBuffer((char*)&data,sizeof(data));
232 }
af095430 233}
98512c02 234
235//_____________________________________________________________________________
b6fd9c4a 236void AliVZEROBuffer::WriteTiming(Float_t time, Float_t width) {
98512c02 237 // It writes the timing information into a raw data file.
238 // Being called by Digits2Raw
239
98512c02 240 // Writes the timing information
b6fd9c4a 241 UInt_t data = TMath::Nint(time/(25.0/256.0)) & 0xfff;
242 data |= (TMath::Nint(width/(25./64.)) & 0x7f) << 12;
98512c02 243 f->WriteBuffer((char*)&data,sizeof(data));
244}