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
21 #include <Riostream.h>
22 #include <TObjArray.h>
26 #include "AliRawDataHeaderSim.h"
27 #include "AliADBuffer.h"
28 #include "AliADdigit.h"
29 #include "AliADConst.h"
33 //_____________________________________________________________________________
34 AliADBuffer::AliADBuffer():TObject(),
39 // default constructor
42 //_____________________________________________________________________________
43 AliADBuffer::AliADBuffer(const char* fileName):TObject(),
48 f = new AliFstream(fileName);
49 AliRawDataHeaderSim header;
50 f->WriteBuffer((char*)(&header), sizeof(header));
54 //_____________________________________________________________________________
55 AliADBuffer::~AliADBuffer(){
56 // Destructor, it closes the IO stream
57 AliRawDataHeaderSim header;
58 header.fSize = f->Tellp();
59 header.SetAttribute(0); // valid data
61 f->WriteBuffer((char*)(&header), sizeof(header));
65 //_____________________________________________________________________________
66 void AliADBuffer::WriteTriggerInfo(UInt_t trigger) {
67 // The method writes AD trigger information
68 // This info is contained in the first two
69 // raw-data words following the raw-data header (CDH).
71 f->WriteBuffer((char*)(&trigger),sizeof(trigger));
73 // By default all the inputs are unmasked... Hopefully
74 UInt_t triggerMask = 0xffff;
75 f->WriteBuffer((char*)(&triggerMask),sizeof(triggerMask));
78 //_____________________________________________________________________________
79 void AliADBuffer::WriteTriggerScalers() {
80 // The method writes the AD trigger scalers
81 // For the moment there is no way to simulate
82 // this, so we fill the necessary 16 words with 0
84 // First the general trigger scalers (16 of them)
85 for(Int_t i = 0; i < 16; i++) {
87 f->WriteBuffer((char*)&data,sizeof(data));
91 //_____________________________________________________________________________
92 void AliADBuffer::WriteBunchNumbers() {
93 // The method writes the Bunch Numbers corresponding
94 // to the 10 Minimum Bias events
95 // For the moment there is no way to simulate
96 // this, so we fill the necessary 10 words with 0
98 // First the bunch crossing numbers
99 // for these 10 events
101 for(Int_t i = 0; i < 10; i++) {
103 f->WriteBuffer((char*)&data,sizeof(data));
108 //_____________________________________________________________________________
109 void AliADBuffer::WriteChannel(Int_t channel, Short_t *adc, Bool_t integrator){
110 // It writes AD charge information into a raw data file.
111 // Being called by Digits2Raw
114 for(Int_t i = 0; i < kNClocks; ++i) {
116 AliWarning(Form("ADC (channel=%d) saturated: %d. Truncating to 1023",channel,adc[i]));
122 for(Int_t i = 0; i < (kNClocks/2); ++i) {
123 data = (adc[2*i] & 0x3ff);
124 data |= ((integrator & 0x1) << 10);
126 data |= ((adc[2*i+1] & 0x3ff) << 16);
127 data |= ((!integrator & 0x1) << 26);
129 f->WriteBuffer((char*)&data,sizeof(data));
131 fRemainingWord = (adc[kNClocks-1] & 0x3ff);
132 fRemainingWord |= ((integrator & 0x1) << 10);
135 data = fRemainingWord;
136 data |= ((adc[0] & 0x3ff) << 16);
137 data |= ((integrator & 0x1) << 26);
138 f->WriteBuffer((char*)&data,sizeof(data));
140 for(Int_t i = 1; i <= (kNClocks/2); ++i) {
141 data = (adc[2*i-1] & 0x3ff);
142 data |= ((!integrator & 0x1) << 10);
144 data |= ((adc[2*i] & 0x3ff) << 16);
145 data |= ((integrator & 0x1) << 26);
147 f->WriteBuffer((char*)&data,sizeof(data));
153 //_____________________________________________________________________________
154 void AliADBuffer::WriteBeamFlags() {
156 //void AliADBuffer::WriteBeamFlags(Bool_t *bbFlag, Bool_t *bgFlag) {
157 // The method writes information about
158 // the Beam-Beam and Beam-Gas flags i.e.
159 // 10 shorts for the 4 channels
160 // of half a CIU card
162 // Beam-beam and beam-gas flags are available
163 // only for the triggered event-of-interest (sample index = 10)
164 // As soon as trigger simulation would become more complex
165 // and would allow to simulate neighbouring samples, this code
166 // should be extended in order to fill all (or fraction) of the
171 for(Int_t iEvOfInt = 0; iEvOfInt < kNClocks; iEvOfInt=iEvOfInt+2) {
172 for(Int_t iChannel = 0; iChannel < 4; iChannel++) {
174 if (bbFlag[iChannel]) data |= ((bbFlag[iChannel] & 0x1) << 2*iChannel);
175 if (bgFlag[iChannel]) data |= ((bgFlag[iChannel] & 0x1) << 2*iChannel+1);
177 if(iEvOfInt < (kNClocks - 1)) {
178 if (bbFlag[iChannel]) data |= ((bbFlag[iChannel] & 0x1) << 8 + 2*iChannel);
179 if (bgFlag[iChannel]) data |= ((bgFlag[iChannel] & 0x1) << 8 + 2*iChannel+1);
181 f->WriteBuffer((char*)&data,sizeof(data));
185 f->WriteBuffer((char*)&data,sizeof(data));//Empty short in the end
187 for(Int_t i = 0; i < 6; i++) {
189 f->WriteBuffer((char*)&data,sizeof(data));
193 //_____________________________________________________________________________
194 void AliADBuffer::WriteMBInfo() {
195 // The method writes information about
196 // the 10 previous minimum-bias events
197 // i.e. channels charge for each of these
198 // 10 events (4*10 shorts for the 4 channels
199 // of half a CIU card)
201 for(Int_t i = 0; i < 20; i++) {
203 f->WriteBuffer((char*)&data,sizeof(data));
208 //_____________________________________________________________________________
209 void AliADBuffer::WriteMBFlags() {
210 // The method writes information about
211 // the Minimum Bias flags
212 // 5 16-bits words for the 4 channels
213 // of half a CIU card + one empty 16-bit
216 for(Int_t i = 0; i < 3; i++) {
218 f->WriteBuffer((char*)&data,sizeof(data));
222 //_____________________________________________________________________________
223 void AliADBuffer::WriteBeamScalers() {
224 // The method writes the AD beam scalers
225 // For the moment there is no way to simulate
226 // this, so we fill the necessary words with 0
228 // Beam-beam and beam-gas scalers for
229 // 4 individual channel (4x4 words)
230 // (64-bit + 64-bit)*4 = 32bit * 16
232 for(Int_t i = 0; i < 16; i++) {
234 f->WriteBuffer((char*)&data,sizeof(data));
240 //_____________________________________________________________________________
241 void AliADBuffer::WriteTiming(Float_t time, Float_t width) {
242 // It writes the timing information into a raw data file.
243 // Being called by Digits2Raw
245 // Writes the timing information
246 UInt_t data = TMath::Nint(time) & 0xfff;
247 data |= (TMath::Nint(width) & 0x7f) << 12;
248 f->WriteBuffer((char*)&data,sizeof(data));