Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-1999, 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 :
16 : /* $Id$ */
17 :
18 : /*
19 : * Class for reading TRU data from a bunch from a raw datastream.
20 : * Author: Henrik Qvigstad <henrik.qvigstad@cern.ch>
21 : * Author: Jussi Viinikainen <jussi.viinikainen@cern.ch> (adaptation to Run2 format)
22 : */
23 :
24 : #include "AliPHOSTRURawReader.h"
25 : #include "AliCaloRawStreamV3.h"
26 : #include "AliLog.h"
27 :
28 22 : ClassImp(AliPHOSTRURawReader)
29 :
30 :
31 : //________________________________________________________________
32 : AliPHOSTRURawReader::AliPHOSTRURawReader()
33 128 : : TObject(),
34 128 : fSignals(),
35 128 : fFlags(),
36 128 : fFlags2x2(),
37 128 : fActive(false),
38 128 : fHasSignal(false),
39 128 : fActiveTime(),
40 128 : fHasSignalTime(),
41 128 : fUse4x4Flags(false)
42 640 : {
43 : // default constructor
44 :
45 : // fSignals Initialization:
46 2304 : for(Int_t row = 0; row < fgkN2x2XPrTRURow; ++row) {
47 30720 : for(Int_t branch = 0; branch < fgkN2x2ZPrBranch; ++branch) {
48 3698688 : for(Int_t timeBin = 0; timeBin < fgkNTimeBins; ++timeBin) {
49 1835008 : fSignals[row][branch][timeBin] = fgkDefaultSignalValue;
50 1835008 : fFlags2x2[row][branch][timeBin] = kFALSE;
51 : }
52 : }
53 : }
54 :
55 : // fFlags Initialization
56 2048 : for(Int_t row = 0; row < fgkN4x4XPrTRURow; ++row){
57 25088 : for(Int_t branch = 0; branch < fgkN4x4ZPrBranch; ++branch){
58 3005184 : for(Int_t timeBin = 0; timeBin < fgkNTimeBins; ++timeBin){
59 1490944 : fFlags[row][branch][timeBin] = kFALSE;
60 : }
61 : }
62 : }
63 :
64 : // fActiveTime Initialization
65 33024 : for(Int_t timeBin = 0; timeBin < fgkNTimeBins; ++timeBin){
66 16384 : fActiveTime[timeBin] = kFALSE;
67 16384 : fHasSignalTime[timeBin] = kFALSE;
68 : }
69 256 : }
70 :
71 :
72 : //________________________________________________________________
73 : AliPHOSTRURawReader::~AliPHOSTRURawReader()
74 512 : {
75 : // destructor
76 512 : }
77 :
78 : //________________________________________________________________
79 : void AliPHOSTRURawReader::ReadFromStream(AliCaloRawStreamV3* rawStream)
80 : {
81 : // reads the trigger signal amplitudes and trigger flags from the rawStream
82 :
83 0 : const UShort_t * const signal = rawStream->GetSignals(); // stream of 10-bit words, buffered as 16-bit words
84 0 : const Int_t signalLength = rawStream->GetBunchLength(); // The length of the signal in time steps
85 0 : const Int_t index = rawStream->GetColumn(); // For some reason the index of the readout channel is given by GetColumn function
86 0 : Int_t timeBin = rawStream->GetStartTimeBin(); // Find the time bin of the first time step
87 0 : if (timeBin <0 || timeBin >= fgkNTimeBins) {
88 0 : AliError(Form("Wrong number of time bins: %d (<0 or >%d!)\n",timeBin,fgkNTimeBins));
89 0 : return;
90 : }
91 :
92 : Int_t channelIndex = index;
93 :
94 0 : if (channelIndex >= 2048)
95 0 : channelIndex-=2048; // branch 1: 0 <= z < 28
96 :
97 0 : fActive = kTRUE; // Set the TRU active
98 :
99 : /* Channels in TRU:
100 : *
101 : * There are 112 readout channels and 12 channels reserved for production flags
102 : * The channels are indexed as follows:
103 : *
104 : * Channels 0-111: channel data readout
105 : * Channels 112-123: production flags
106 : */
107 :
108 :
109 0 : if(channelIndex < fgkNReadoutChannels){ // Channel data
110 :
111 : /* Channel data:
112 : *
113 : * The channel data is read one channel at a time
114 : * The x and z indices corresponding to the channel are calculated from the channel index
115 : */
116 :
117 0 : fHasSignal = kTRUE;
118 0 : const Int_t xBin = 7 - channelIndex % 8; // x index in TRU internal 2x2 coordinate system
119 0 : const Int_t zBin = 13 - channelIndex / 8; // z index in TRU internal 2x2 coordinate system
120 :
121 : // Loop over all the time steps in the signal
122 0 : for(Int_t i = 0; i < signalLength; i++){
123 0 : if (timeBin > -1 && timeBin < fgkNTimeBins) {
124 0 : fSignals[xBin][zBin][timeBin] = signal[i];
125 0 : fActiveTime[timeBin] = kTRUE;
126 0 : fHasSignalTime[timeBin] = kTRUE;
127 0 : }
128 0 : timeBin--; // The time bins come in reverse order from raw data
129 : }
130 0 : } else { // Production flags
131 :
132 : /* Production flags:
133 : *
134 : * Production flags are supplied in channels 112 - 123
135 : * Each of the channels is 10 bit wide
136 : * The bits inside the channel (indexing starting from the first bit of channel 112) is as follows:
137 : *
138 : * Bits 0-111: Trigger flags for corresponding channel index
139 : * If using 4x4 algorithm, only 91 first bits are used of these
140 : * Bit 112: Marker for 4x4 algorithm (1 active, 0 not active)
141 : * Bit 113: Marker for 2x2 algorithm (1 active, 0 not active)
142 : * Bit 114: Global L0 OR of all patches in the TRU
143 : */
144 :
145 : Int_t channel, xBin, zBin;
146 0 : for(Int_t i = 0; i < signalLength; i++){
147 0 : fActiveTime[timeBin] = kTRUE;
148 :
149 : // If bit 112 is 1, we are considering 4x4 algorithm
150 0 : if(channelIndex == fgkFinalProductionChannel){
151 0 : if( (signal[i] & ( 1 << 2 )) > 0 ){ // Check the bit number 112
152 0 : fUse4x4Flags = kTRUE;
153 0 : }
154 : }
155 :
156 : // Assign the bits in the words to corresponding channels
157 0 : for(Int_t bitIndex = 0; bitIndex < fgkWordLength; bitIndex++){
158 :
159 : /* Find the correct channel number assuming that
160 : * channelIndex 112 = bits 0-9 corresponding trigger flags in channels 0-9
161 : * channelIndex 113 = bits 10-19 corresponding trigger flags in channels 10-19
162 : * and so on
163 : */
164 0 : channel = (channelIndex - fgkNReadoutChannels) * fgkWordLength + bitIndex;
165 :
166 : /*
167 : * Note: flags corresponding to 2x2 sums and 4x4 sums need to be filled
168 : * in different loops since the internal xz coordinates are different
169 : * for 2x2 case and 4x4 case. We do not know which data we are filling
170 : * at the time we do the filling. This information comes only in the
171 : * channel 123 in bit 112.
172 : */
173 :
174 0 : if(channel < fgkNReadoutChannels){ // Fill histogram for 2x2 trigger flags
175 0 : xBin = 7 - channel % 8; // x index in TRU internal 2x2 coordinate system
176 0 : zBin = 13 - channel / 8; // z index in TRU internal 2x2 coordinate system
177 :
178 : // check if the bit bitIndex is 1
179 0 : if( (signal[i] & ( 1 << bitIndex )) > 0 ){
180 0 : fFlags2x2[xBin][zBin][timeBin] = kTRUE;
181 0 : }
182 : }
183 :
184 0 : if(channel < fgkN4x4TriggerFlags){ // Fill histogram for 4x4 trigger flags
185 0 : xBin = channel % 7; // x index in TRU internal 4x4 coordinate system
186 0 : zBin = 12 - channel / 7; // z index in TRU internal 4x4 coordinate system
187 :
188 : // check if the bit bitIndex is 1
189 0 : if( (signal[i] & ( 1 << bitIndex )) > 0 ){
190 0 : fFlags[xBin][zBin][timeBin] = kTRUE;
191 0 : }
192 : }
193 : } // Bits in one word
194 0 : timeBin--; // The time bins come in reverse order from raw data
195 : } // Length of signal
196 : } // Production flags
197 :
198 0 : }
199 :
200 :
201 : //________________________________________________________________
202 : void AliPHOSTRURawReader::Reset()
203 : {
204 : // Reset to default values
205 :
206 0 : if( ! fActive )
207 : return;
208 :
209 0 : for(Int_t timeBin = 0; timeBin < fgkNTimeBins; ++timeBin) { // loop timeBins
210 0 : if( fActiveTime[timeBin] ) {
211 0 : for(Int_t xIdx = 0; xIdx < fgkN2x2XPrTRURow; ++xIdx) { // loop 2x2
212 0 : for(Int_t zIdx = 0; zIdx < fgkN2x2ZPrBranch; ++zIdx) {
213 0 : fSignals[xIdx][zIdx][timeBin] = fgkDefaultSignalValue;
214 0 : fFlags2x2[xIdx][zIdx][timeBin] = kFALSE;
215 : } // zIdx
216 : } // xIdx
217 0 : for(Int_t xIdx = 0; xIdx < fgkN4x4XPrTRURow; ++xIdx) { // loop 4x4
218 0 : for(Int_t zIdx = 0; zIdx < fgkN4x4ZPrBranch; ++zIdx) {
219 0 : fFlags[xIdx][zIdx][timeBin] = false;
220 : } // zIdx
221 : } // xIdx
222 0 : }// end if fActiveTime
223 0 : fActiveTime[timeBin] = false;
224 0 : fHasSignalTime[timeBin] = false;
225 : } // timeBin
226 :
227 0 : fActive = false;
228 0 : fHasSignal = false;
229 0 : }
230 :
231 : //___________________________________________________________________
232 : Bool_t AliPHOSTRURawReader::GetTriggerFlag(Int_t xIdx, Int_t zIdx, Int_t timeBin) const {
233 : // Getter for trigger flags
234 0 : if(fUse4x4Flags){
235 0 : return fFlags[xIdx][zIdx][timeBin];
236 : }
237 0 : return fFlags2x2[xIdx][zIdx][timeBin];
238 0 : }
|