1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
19 * Class for reading TRU data from a bunch from a raw datastream.
20 * Author: Henrik Qvigstad <henrik.qvigstad@cern.ch>
23 #include "AliPHOSTRURawReader.h"
25 #include "AliCaloRawStreamV3.h"
26 #include <bitset> // std::bitset
28 ClassImp(AliPHOSTRURawReader)
31 //________________________________________________________________
32 AliPHOSTRURawReader::AliPHOSTRURawReader()
42 // default constructor
44 // fSignals Initialization:
45 for(Int_t row = 0; row < kN2x2XPrTRURow; ++row) {
46 for(Int_t branch = 0; branch < kN2x2ZPrBranch; ++branch) {
47 for(Int_t timeBin = 0; timeBin < kNTimeBins; ++timeBin) {
48 fSignals[row][branch][timeBin] = kDefaultSignalValue;
53 // fFlags Initialization
54 for(Int_t row = 0; row < kN4x4XPrTRURow; ++row){
55 for(Int_t branch = 0; branch < kN4x4ZPrBranch; ++branch){
56 for(Int_t timeBin = 0; timeBin < kNTimeBins; ++timeBin){
57 fFlags[row][branch][timeBin] = kFALSE;
62 // fActiveTime Initialization
63 for(Int_t timeBin = 0; timeBin < kNTimeBins; ++timeBin){
64 fActiveTime[timeBin] = kFALSE;
65 fHasSignalTime[timeBin] = kFALSE;
70 //________________________________________________________________
71 AliPHOSTRURawReader::~AliPHOSTRURawReader()
76 //________________________________________________________________
77 void AliPHOSTRURawReader::ReadFromStream(AliCaloRawStreamV3* rawStream)
79 // reads the trigger signal amplitudes and trigger flags from the rawStream
81 const UShort_t * const signal = rawStream->GetSignals(); // stream of 10-bit words, buffered as 16-bit words
82 const Int_t signalLength = rawStream->GetBunchLength();
83 const Int_t timeBin = rawStream->GetHWAddress() & 0x7f; // , i.e. & '01111111', strips the first 7 bits ([0:6]) and interprits it as a int
85 // TODO: this may need to be an error
86 if(signalLength != 16 && signalLength != 16+112)
87 Warning("ReadFromStream", " signalLength: !16 && !16+112, reader logic may not be valid.");
91 fActiveTime[timeBin] = kTRUE;
93 /* There are 91 4x4 Sliding Window signal sum trigger flags.
94 * We read the trigger location information from first 12 10-bit words of the signal
95 * (these are buffered to 12 16-bit words in the rawstream object)
96 * , but only 10 of the 10-bit words are used for trigger location within the TRU.
97 * The flags are found in word_2[0] to word_11[9].
98 * We read the information as following. */
100 for(Int_t wIdx = 2; wIdx < 12; ++wIdx) { // words
101 const std::bitset<10> word(signal[wIdx]); // @param word represent a 10-bit word
102 for(Int_t bIdx = 0; bIdx < 10; ++bIdx) { // bits
103 //const Int_t index = 119 - (wIdx*10 + (9-bi)); // index used in TRU documentation,
104 const Int_t index = (110 - wIdx*10) + bIdx; // equivalent
105 if( index < 91 ) { // we are only interrested in these words/bits
106 const Int_t xIdx = index % 7; // x index in TRU internal 2x2 coordinate system
107 const Int_t zIdx = index / 7; // z index in TRU internal 2x2 coordinate system
108 // fFlags[xIdx][zIdx][time] = (signal[wIdx] & (0x01 * 2**i)) != 1;
109 fFlags[xIdx][zIdx][timeBin] = (bool) word[bIdx];
116 /* The 2x2 trigger signal sum may follow.
117 * If so, it is found in the following 112 10-bit words
118 * (, 16-bit words in buffer.)
119 * We read the signal as following.
122 if( 16+112 == signalLength) {
124 fHasSignalTime[timeBin] = kTRUE;
125 for (Int_t idx = 0; idx < 112; idx++)
127 const Int_t xIdx = 7 - idx % 8; // x index in TRU
128 const Int_t zIdx = 13 - idx / 8; // z index in TRU
129 const Int_t wIdx = idx + 16; // word index in signal array
130 fSignals[xIdx][zIdx][timeBin] = signal[wIdx];
136 //________________________________________________________________
137 void AliPHOSTRURawReader::Reset()
139 // Reset to default values
144 for(Int_t timeBin = 0; timeBin < kNTimeBins; ++timeBin) { // loop timeBins
145 if( fActiveTime[timeBin] ) {
146 for(Int_t xIdx = 0; xIdx < kN2x2XPrTRURow; ++xIdx) { // loop 2x2
147 for(Int_t zIdx = 0; zIdx < kN2x2ZPrBranch; ++zIdx) {
148 fSignals[xIdx][zIdx][timeBin] = kDefaultSignalValue;
151 for(Int_t xIdx = 0; xIdx < kN4x4XPrTRURow; ++xIdx) { // loop 4x4
152 for(Int_t zIdx = 0; zIdx < kN4x4ZPrBranch; ++zIdx) {
153 fFlags[xIdx][zIdx][timeBin] = false;
156 }// end if fActiveTime
157 fActiveTime[timeBin] = false;
158 fHasSignalTime[timeBin] = false;