]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZEROBuffer.cxx
Small optimizations
[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 "AliRawDataHeader.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   AliRawDataHeader header;
53   f->WriteBuffer((char*)(&header), sizeof(header));
54
55 }
56
57 //_____________________________________________________________________________
58 AliVZEROBuffer::~AliVZEROBuffer(){
59   // Destructor, it closes the IO stream
60   AliRawDataHeader 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::WriteChannel(Int_t cell,Int_t ADC, Int_t Time){
105   // It writes VZERO digits as a raw data file. 
106   // Being called by AliVZERODDL.C
107
108   UInt_t data = 0;
109   // Information about previous 10 interaction
110   // Not available in the simulation...
111   for(Int_t i = 0; i < 5; i++)
112     f->WriteBuffer((char*)&data,sizeof(data));
113
114   // Now write the ADC charge for this channel
115   if (ADC < 0 || ADC > 1023) {
116     AliInfo(Form("ADC saturated: %d. Truncating to 1023",ADC));
117     ADC = 1023;
118   }
119   data = ADC | 0x400; // 'Interaction' flag
120   f->WriteBuffer((char*)&data,sizeof(data));
121
122   data = 0;
123   // Information about following 10 interaction
124   // Not available in the simulation...
125   for(Int_t i = 0; i < 5; i++)
126     f->WriteBuffer((char*)&data,sizeof(data));
127
128   // Now write the timing information
129   data = Time & 0xfff;
130   // The signal width is not available the digits!
131   // To be added soon
132   // data |= (width & 0x7f) << 12;
133   f->WriteBuffer((char*)&data,sizeof(data));
134 }
135
136 //_____________________________________________________________________________
137 void AliVZEROBuffer::WriteScalers() {
138   // The method writes the VZERO trigger scalers
139   // For the moment there is no way to simulate
140   // this, so we fill the necessary words with 0
141
142   // First the general trigger scalers (16 of them)
143   for(Int_t i = 0; i < 16; i++) {
144     UInt_t data = 0;
145     f->WriteBuffer((char*)&data,sizeof(data));
146   }
147
148   // Then beam-beam and beam-gas scalers for
149   // each individual channel (4x64 words)
150   for(Int_t i = 0; i < 256; i++) {
151     UInt_t data = 0;
152     f->WriteBuffer((char*)&data,sizeof(data));
153   }
154 }
155
156 //_____________________________________________________________________________
157 void AliVZEROBuffer::WriteMBInfo() {
158   // The method writes information about
159   // the 10 previous minimum-bias events
160
161   // First the bunch crossing numbers
162   // for these 10 events
163   for(Int_t i = 0; i < 10; i++) {
164     UInt_t data = 0;
165     f->WriteBuffer((char*)&data,sizeof(data));
166   }
167
168   // Then channels charge for each of these
169   // 10 events (5 words/channel)
170   for(Int_t i = 0; i < 320; i++) {
171     UInt_t data = 0;
172     f->WriteBuffer((char*)&data,sizeof(data));
173   }
174 }