]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROBuffer.cxx
added comments to satisfy coding conventions
[u/mrichter/AliRoot.git] / VZERO / AliVZEROBuffer.cxx
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 "AliLog.h"
26 #include "AliRawDataHeaderSim.h"
27 #include "AliVZEROBuffer.h"
28
29 //#include "TFile.h"
30 //#include "TTree.h"
31
32 ClassImp(AliVZEROBuffer)
33
34 //_____________________________________________________________________________
35 AliVZEROBuffer::AliVZEROBuffer():TObject(),
36     fVerbose(0),
37     f()
38 {
39   //
40   // default constructor
41   //
42 }
43 //_____________________________________________________________________________
44 AliVZEROBuffer::AliVZEROBuffer(const char* fileName):TObject(),
45     fVerbose(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 //_____________________________________________________________________________
58 AliVZEROBuffer::~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 //_____________________________________________________________________________
71 AliVZEROBuffer::AliVZEROBuffer(const AliVZEROBuffer &source):TObject(source),
72    fVerbose(0),
73    f()
74
75 {
76   // Copy Constructor
77   this->fVerbose=source.fVerbose;
78   return;
79 }
80
81 //_____________________________________________________________________________
82 AliVZEROBuffer& AliVZEROBuffer::operator=(const AliVZEROBuffer &source)
83
84 {
85   //Assigment operator
86   this->fVerbose=source.fVerbose;
87   return *this;
88 }
89
90 //_____________________________________________________________________________
91 void AliVZEROBuffer::WriteTriggerInfo(UInt_t trigger) {
92   // The method writes VZERO trigger information
93   // This info is contained in the first two
94   // raw-data words following the raw-data header (CDH).
95
96   f->WriteBuffer((char*)(&trigger),sizeof(trigger));
97
98   // By default all the inputs are unmasked... Hopefully
99   UInt_t triggerMask = 0xffff;
100   f->WriteBuffer((char*)(&triggerMask),sizeof(triggerMask));
101 }
102
103 //_____________________________________________________________________________
104 void AliVZEROBuffer::WriteTriggerScalers() {
105   // The method writes the VZERO trigger scalers
106   // For the moment there is no way to simulate
107   // this, so we fill the necessary 16 words with 0
108
109   // First the general trigger scalers (16 of them)
110   for(Int_t i = 0; i < 16; i++) {
111       UInt_t data = 0;
112       f->WriteBuffer((char*)&data,sizeof(data));
113   }
114 }
115
116 //_____________________________________________________________________________
117 void AliVZEROBuffer::WriteBunchNumbers() {
118   // The method writes the Bunch Numbers corresponding 
119   // to the 10 Minimum Bias events
120   // For the moment there is no way to simulate
121   // this, so we fill the necessary 10 words with 0
122
123   // First the bunch crossing numbers
124   // for these 10 events
125   
126   for(Int_t i = 0; i < 10; i++) {
127       UInt_t data = 0;
128       f->WriteBuffer((char*)&data,sizeof(data));
129   }
130
131 }
132
133 //_____________________________________________________________________________
134 void AliVZEROBuffer::WriteChannel(Int_t cell, UInt_t ADC, Float_t /*Time*/, Bool_t integrator){
135   // It writes VZERO charge information into a raw data file. 
136   // Being called by Digits2Raw
137   
138   UInt_t data = 0;
139   
140   if (/*ADC < 0 || */ ADC > 1023) {
141       AliInfo(Form("ADC saturated: %d. Truncating to 1023",ADC));
142       ADC = 1023;
143   }
144
145   if(cell%2 == 0)  
146   // Information about previous 10 interaction 
147   // Not available in the simulation...
148   // Even cell number -- skip  5 words
149     { for(Int_t i = 0; i < 5; i++)
150          { data = 0; 
151            f->WriteBuffer((char*)&data,sizeof(data)); }      
152       data = ADC & 0x3ff;
153       data |= (integrator & 0x1) << 10; 
154       f->WriteBuffer((char*)&data,sizeof(data)); }
155   else
156   // Information about previous 10 interaction 
157   // Odd cell number -- skip 4 words and shift ADC by 16 bits 
158     { for(Int_t i = 0; i < 4; i++)
159          { data = 0;
160            f->WriteBuffer((char*)&data,sizeof(data)); }            
161       data = (ADC & 0x3ff) << 16;
162       data |= (integrator & 0x1) << 26;
163       f->WriteBuffer((char*)&data,sizeof(data)); }
164     
165   data = 0;
166   // Information about following 10 interaction
167   // Not available in the simulation...
168   for(Int_t i = 0; i < 5; i++)
169       f->WriteBuffer((char*)&data,sizeof(data));     
170 }
171
172 //_____________________________________________________________________________
173 void AliVZEROBuffer::WriteBeamFlags() {
174   // The method writes information about
175   // the Beam-Beam and Beam-Gas flags i.e. 
176   // 6  words for the 4 channels 
177   // of half a CIU card
178
179
180   for(Int_t i = 0; i < 6; i++) {
181     UInt_t data = 0;
182     f->WriteBuffer((char*)&data,sizeof(data));
183   }
184 }
185
186
187 //_____________________________________________________________________________
188 void AliVZEROBuffer::WriteMBInfo() {
189   // The method writes information about
190   // the 10 previous minimum-bias events
191   // i.e. channels charge for each of these
192   // 10 events (20 words for the 4 channels 
193   // of half a CIU card)
194     
195   for(Int_t i = 0; i < 20; i++) {
196     UInt_t data = 0;
197     f->WriteBuffer((char*)&data,sizeof(data));
198   }
199 }
200
201
202 //_____________________________________________________________________________
203 void AliVZEROBuffer::WriteMBFlags() {
204   // The method writes information about
205   // the Minimum Bias flags
206   // 3 32-bits words for the 4 channels 
207   // of half a CIU card
208
209
210   for(Int_t i = 0; i < 3; i++) {
211     UInt_t data = 0;
212     f->WriteBuffer((char*)&data,sizeof(data));
213   }
214 }
215
216 //_____________________________________________________________________________
217 void AliVZEROBuffer::WriteBeamScalers() {
218   // The method writes the VZERO beam scalers
219   // For the moment there is no way to simulate
220   // this, so we fill the necessary words with 0
221
222   // Beam-beam and beam-gas scalers for
223   // 4 individual channel (4x4 words)
224   
225   for(Int_t i = 0; i < 16; i++) {
226     UInt_t data = 0;
227     f->WriteBuffer((char*)&data,sizeof(data));
228   }
229 }
230
231 //_____________________________________________________________________________
232 void AliVZEROBuffer::WriteTiming(Int_t /*cell*/, UInt_t /* ADC*/, Float_t Time){
233   // It writes the timing information into a raw data file. 
234   // Being called by Digits2Raw
235
236   UInt_t data = 0;
237   Int_t  coarse1, coarse2, fine;
238
239   // Writes the timing information
240 //  data = Time & 0xfff;
241   
242   coarse1 = int( Time/25.0 );
243   coarse2 = int( (Time - 25*coarse1)/(25.0/8.0) );
244   fine    = int( (Time - 25*coarse1 -(25.0/8.0)*coarse2)/(25.0/256.0) );
245   
246   data  = (coarse1 & 0xf) << 8;
247   data |= (coarse2 & 0x7) << 5;  
248   data |= (fine & 0x1f);   
249   
250   // The signal width is not available the digits!
251   // To be added soon
252   // data |= (width & 0x7f) << 12;
253   f->WriteBuffer((char*)&data,sizeof(data));
254 }