1 /**************************************************************************
2 * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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
23 #include <Riostream.h>
24 #include <TObjArray.h>
28 #include "AliRawDataHeaderSim.h"
29 #include "AliVZEROBuffer.h"
30 #include "AliVZEROdigit.h"
32 ClassImp(AliVZEROBuffer)
34 //_____________________________________________________________________________
35 AliVZEROBuffer::AliVZEROBuffer():TObject(),
40 // default constructor
43 //_____________________________________________________________________________
44 AliVZEROBuffer::AliVZEROBuffer(const char* fileName):TObject(),
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));
57 //_____________________________________________________________________________
58 AliVZEROBuffer::~AliVZEROBuffer(){
59 // Destructor, it closes the IO stream
60 AliRawDataHeaderSim header;
61 header.fSize = f->Tellp();
62 header.SetAttribute(0); // valid data
64 f->WriteBuffer((char*)(&header), sizeof(header));
70 //_____________________________________________________________________________
71 void 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).
76 f->WriteBuffer((char*)(&trigger),sizeof(trigger));
78 // By default all the inputs are unmasked... Hopefully
79 UInt_t triggerMask = 0xffff;
80 f->WriteBuffer((char*)(&triggerMask),sizeof(triggerMask));
83 //_____________________________________________________________________________
84 void 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
89 // First the general trigger scalers (16 of them)
90 for(Int_t i = 0; i < 16; i++) {
92 f->WriteBuffer((char*)&data,sizeof(data));
96 //_____________________________________________________________________________
97 void 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
103 // First the bunch crossing numbers
104 // for these 10 events
106 for(Int_t i = 0; i < 10; i++) {
108 f->WriteBuffer((char*)&data,sizeof(data));
113 //_____________________________________________________________________________
114 void 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
119 for(Int_t i = 0; i < AliVZEROdigit::kNClocks; ++i) {
121 AliWarning(Form("ADC (channel=%d) saturated: %d. Truncating to 1023",channel,adc[i]));
127 for(Int_t i = 0; i < (AliVZEROdigit::kNClocks/2); ++i) {
128 data = (adc[2*i] & 0x3ff);
129 data |= ((integrator & 0x1) << 10);
131 data |= ((adc[2*i+1] & 0x3ff) << 16);
132 data |= ((!integrator & 0x1) << 26);
134 f->WriteBuffer((char*)&data,sizeof(data));
136 fRemainingWord = (adc[AliVZEROdigit::kNClocks-1] & 0x3ff);
137 fRemainingWord |= ((integrator & 0x1) << 10);
140 data = fRemainingWord;
141 data |= ((adc[0] & 0x3ff) << 16);
142 data |= ((integrator & 0x1) << 26);
143 f->WriteBuffer((char*)&data,sizeof(data));
145 for(Int_t i = 1; i <= (AliVZEROdigit::kNClocks/2); ++i) {
146 data = (adc[2*i-1] & 0x3ff);
147 data |= ((!integrator & 0x1) << 10);
149 data |= ((adc[2*i] & 0x3ff) << 16);
150 data |= ((integrator & 0x1) << 26);
152 f->WriteBuffer((char*)&data,sizeof(data));
158 //_____________________________________________________________________________
159 void 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
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
171 for(Int_t i = 0; i < 2; i++) {
173 f->WriteBuffer((char*)&data,sizeof(data));
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));
181 f->WriteBuffer((char*)&data,sizeof(data));
183 for(Int_t i = 0; i < 3; i++) {
185 f->WriteBuffer((char*)&data,sizeof(data));
191 //_____________________________________________________________________________
192 void 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)
199 for(Int_t i = 0; i < 20; i++) {
201 f->WriteBuffer((char*)&data,sizeof(data));
206 //_____________________________________________________________________________
207 void 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
214 for(Int_t i = 0; i < 3; i++) {
216 f->WriteBuffer((char*)&data,sizeof(data));
220 //_____________________________________________________________________________
221 void 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
226 // Beam-beam and beam-gas scalers for
227 // 4 individual channel (4x4 words)
229 for(Int_t i = 0; i < 16; i++) {
231 f->WriteBuffer((char*)&data,sizeof(data));
235 //_____________________________________________________________________________
236 void AliVZEROBuffer::WriteTiming(Float_t time, Float_t width) {
237 // It writes the timing information into a raw data file.
238 // Being called by Digits2Raw
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));