Line data Source code
1 : /**************************************************************************
2 : * This file is property of and copyright by the ALICE HLT Project *
3 : * All rights reserved. *
4 : * *
5 : * Primary Authors: Markus Fasel *
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 : #include "AliHLTEMCALSTURawDigitMaker.h"
16 : #include "AliCaloConstants.h"
17 : #include "AliCaloRawAnalyzerFactory.h"
18 : #include "AliCaloRawAnalyzerFakeALTRO.h"
19 : #include "AliCaloRawStreamV3.h"
20 : #include "AliDAQ.h"
21 : #include "AliEMCALTriggerSTUDCSConfig.h"
22 : #include "AliEMCALTriggerData.h"
23 : #include "AliEMCALTriggerRawDigit.h"
24 : #include "AliEMCALTriggerSTURawStream.h"
25 : #include "AliHLTEMCALGeometry.h"
26 : #include "AliRawEquipmentHeader.h"
27 : #include "AliRawEvent.h"
28 : #include "AliRawReader.h"
29 : #include "AliRawVEquipment.h"
30 :
31 6 : ClassImp(AliHLTEMCALSTURawDigitMaker)
32 :
33 : AliHLTEMCALSTURawDigitMaker::AliHLTEMCALSTURawDigitMaker() :
34 0 : TObject(),
35 0 : AliHLTLogging(),
36 0 : fkGeometryPtr(NULL),
37 0 : fDCSConfigSTU(NULL),
38 0 : fTriggerData(NULL),
39 0 : fNRawDigits(0)
40 0 : {
41 0 : fDCSConfigSTU = new AliEMCALTriggerSTUDCSConfig;
42 0 : fTriggerData = new AliEMCALTriggerData;
43 0 : for (Int_t i=0; i<fgkNRawDigits; i++) fRawDigitIndex[i] = -1;
44 0 : }
45 :
46 0 : AliHLTEMCALSTURawDigitMaker::~AliHLTEMCALSTURawDigitMaker() {
47 0 : if(fDCSConfigSTU) delete fDCSConfigSTU;
48 0 : if(fTriggerData) delete fTriggerData;
49 0 : }
50 :
51 : void AliHLTEMCALSTURawDigitMaker::ProcessSTUStream(AliEMCALTriggerSTURawStream *stustream, Int_t detector){
52 :
53 : HLTDebug("Start post processing the raw digit maker");
54 0 : Int_t idx;
55 :
56 : AliHLTCaloTriggerRawDigitDataStruct *hltdig(NULL);
57 :
58 :
59 0 : if (stustream && stustream->ReadPayLoad()) {
60 0 : fTriggerData->SetL1DataDecoded(1);
61 :
62 0 : for (int i = 0; i < 2; i++) {
63 0 : fTriggerData->SetL1GammaThreshold(i, stustream->GetL1GammaThreshold(i));
64 0 : fTriggerData->SetL1JetThreshold( i, stustream->GetL1JetThreshold(i) );
65 : }
66 :
67 0 : Int_t v0[2] = { static_cast<Int_t>(stustream->GetV0A()), static_cast<Int_t>(stustream->GetV0C())};
68 :
69 : // Modify DCS config from STU payload content
70 0 : for(Int_t i = 0; i < 3; i++){
71 0 : for(Int_t j = 0; j < 2; j++){
72 0 : fDCSConfigSTU->SetG(i, j, stustream->GetG(i, j));
73 0 : fDCSConfigSTU->SetJ(i, j, stustream->GetJ(i, j));
74 : }
75 : }
76 0 : fDCSConfigSTU->SetRawData(stustream->GetRawData());
77 0 : fDCSConfigSTU->SetRegion(stustream->GetRegionEnable());
78 0 : fDCSConfigSTU->SetFw(stustream->GetFwVersion());
79 :
80 0 : fTriggerData->SetL1FrameMask(stustream->GetFrameReceived());
81 0 : fTriggerData->SetL1V0(v0);
82 0 : Int_t type[15] =
83 0 : {
84 0 : static_cast<Int_t>(stustream->GetG(0, 0)),
85 0 : static_cast<Int_t>(stustream->GetG(1, 0)),
86 0 : static_cast<Int_t>(stustream->GetG(2, 0)),
87 0 : static_cast<Int_t>(stustream->GetJ(0, 0)),
88 0 : static_cast<Int_t>(stustream->GetJ(1, 0)),
89 0 : static_cast<Int_t>(stustream->GetJ(2, 0)),
90 0 : static_cast<Int_t>(stustream->GetG(0, 1)),
91 0 : static_cast<Int_t>(stustream->GetG(1, 1)),
92 0 : static_cast<Int_t>(stustream->GetG(2, 1)),
93 0 : static_cast<Int_t>(stustream->GetJ(0, 1)),
94 0 : static_cast<Int_t>(stustream->GetJ(1, 1)),
95 0 : static_cast<Int_t>(stustream->GetJ(2, 1)),
96 0 : static_cast<Int_t>(stustream->GetRawData()),
97 0 : static_cast<Int_t>(stustream->GetRegionEnable()),
98 0 : static_cast<Int_t>(stustream->GetFwVersion())
99 : };
100 0 : fTriggerData->SetL1TriggerType(type);
101 :
102 0 : fTriggerData->SetL1RawData(stustream->GetRawData());
103 :
104 0 : Int_t iTRU, jTRU, x, y, jADC;
105 :
106 0 : TVector2 sizeL1gsubr, sizeL1gpatch, sizeL1jsubr, sizeL1jpatch;
107 0 : fDCSConfigSTU->GetSegmentation(sizeL1gsubr, sizeL1gpatch, sizeL1jsubr, sizeL1jpatch);
108 :
109 0 : if (stustream->GetRawData()) {
110 : HLTDebug("| STU => TRU raw data are there!\n");
111 :
112 : //Int_t nTRU = fkGeometryPtr->GetGeometryPtr()->GetNTotalTRU();
113 0 : Int_t nTRU = detector == 0 ? 32 : 14;
114 0 : for (Int_t i = 0; i < nTRU; i++) {
115 0 : iTRU = fkGeometryPtr->GetGeometryPtr()->GetTRUIndexFromSTUIndex(i, detector);
116 :
117 0 : UInt_t adc[96]; for (Int_t j = 0; j < 96; j++) adc[j] = 0;
118 :
119 0 : stustream->GetADC(i, adc);
120 :
121 0 : for (Int_t j = 0; j < 96; j++) {
122 0 : if (adc[j] <= 0) continue;
123 : HLTDebug("| STU => TRU# %2d raw data: ADC# %2d: %d\n", iTRU, j, adc[j]);
124 0 : if(fkGeometryPtr->GetGeometryPtr()->GetTriggerMappingVersion() == 1){
125 0 : fkGeometryPtr->GetGeometryPtr()->GetAbsFastORIndexFromTRU(iTRU, j, idx);
126 : } else {
127 0 : fkGeometryPtr->GetGeometryPtr()->GetTRUFromSTU(i, j, jTRU, jADC, detector);
128 : //printf("Detector %d, iTRU %d (%d), jTRU %d, iADC %d, jADC %d\n", detector, i, iTRU, jTRU, j, jADC);
129 0 : fkGeometryPtr->GetGeometryPtr()->GetAbsFastORIndexFromTRU(jTRU, jADC, idx);
130 : }
131 :
132 0 : SetL1TimeSum(GetRawDigit(idx), adc[j]);
133 : }
134 0 : }
135 0 : }
136 :
137 : // List of patches in EMCal coordinate system
138 :
139 0 : for (Int_t i = 0; i < stustream->GetNL0GammaPatch(); i++) {
140 0 : stustream->GetL0GammaPatch(i, iTRU, x);
141 :
142 : //if(iTRU >= 32) iTRU -= 32;
143 0 : iTRU = fkGeometryPtr->GetGeometryPtr()->GetTRUIndexFromSTUIndex(iTRU, detector);
144 :
145 : const Int_t sizePatchL0 = 4;
146 :
147 : HLTDebug("| STU => Found L0 patch id: %2d in TRU# %2d\n", x, iTRU);
148 :
149 0 : Int_t idFastOR[4];
150 0 : for (Int_t j = 0; j < 4; j++) idFastOR[j] = -1;
151 :
152 0 : if (fkGeometryPtr->GetGeometryPtr()->GetFastORIndexFromL0Index(iTRU, x, idFastOR, sizePatchL0)) {
153 0 : idx = idFastOR[1];
154 :
155 0 : Int_t px, py;
156 0 : if (fkGeometryPtr->GetGeometryPtr()->GetPositionInEMCALFromAbsFastORIndex(idx, px, py)){
157 : HLTDebug("| STU => Add L0 patch at (%2d , %2d)\n", px, py);
158 0 : SetTriggerBit(GetRawDigit(idx), kL0, 1);
159 : }
160 0 : }
161 0 : }
162 :
163 0 : Int_t vx, vy, lphi;
164 0 : for (int ithr = 0; ithr < 2; ithr++) {
165 0 : for (Int_t i = 0; i < stustream->GetNL1GammaPatch(ithr); i++) {
166 0 : if (stustream->GetL1GammaPatch(i, ithr, iTRU, x, y)) { // col (0..23), row (0..3)
167 :
168 0 : if (fkGeometryPtr->GetGeometryPtr()->GetTriggerMappingVersion() == 1) {
169 : // Run 1
170 0 : iTRU = fkGeometryPtr->GetGeometryPtr()->GetTRUIndexFromSTUIndex(iTRU, detector);
171 :
172 : HLTDebug("| STU => Found L1 gamma patch at (%2d , %2d) in TRU# %2d\n", x, y, iTRU);
173 :
174 0 : vx = 23 - x;
175 0 : vy = y + 4 * int(iTRU / 2); // Position in EMCal frame
176 :
177 0 : if (iTRU % 2) vx += 24; // C side
178 :
179 0 : vx = vx - int(sizeL1gsubr.X()) * int(sizeL1gpatch.X()) + 1;
180 : lphi = 64;
181 0 : if (vx >= 0 && vy < lphi) {
182 0 : if (fkGeometryPtr->GetGeometryPtr()->GetAbsFastORIndexFromPositionInEMCAL(vx, vy, idx)) {
183 : HLTDebug("| STU => Add L1 gamma [%d] patch at (%2d , %2d)\n", ithr, vx, vy);
184 0 : SetTriggerBit(GetRawDigit(idx), kL1GammaHigh + ithr, 1);
185 : }
186 : }
187 : } else {
188 : // Run 2
189 0 : fkGeometryPtr->GetGeometryPtr()->GetTRUFromSTU(iTRU, x, y, jTRU, vx, vy, detector);
190 0 : fkGeometryPtr->GetGeometryPtr()->GetAbsFastORIndexFromPositionInTRU(jTRU, vx, vy, idx);
191 0 : SetTriggerBit(GetRawDigit(idx), kL1GammaHigh + ithr, 1);
192 : }
193 : }
194 : }
195 :
196 0 : for (Int_t i = 0; i < stustream->GetNL1JetPatch(ithr); i++) {
197 0 : if (stustream->GetL1JetPatch(i, ithr, x, y)) { // col (0,15), row (0,11)
198 : HLTDebug("| STU => Found L1 jet [%d] patch at (%2d , %2d)\n", ithr, x, y);
199 :
200 0 : if (fkGeometryPtr->GetGeometryPtr()->GetTriggerMappingVersion() == 1) {
201 0 : vx = 11 - y - int(sizeL1jpatch.X()) + 1;
202 0 : vy = 15 - x - int(sizeL1jpatch.Y()) + 1;
203 0 : }
204 : else {
205 0 : vx = y;
206 0 : vy = x;
207 : }
208 0 : vx *= int(sizeL1jsubr.X());
209 0 : vy *= int(sizeL1jsubr.Y());
210 :
211 0 : if (vx >= 0 && vy >= 0) {
212 0 : if (fkGeometryPtr->GetGeometryPtr()->GetAbsFastORIndexFromPositionInEMCAL(vx, vy, idx)) {
213 : HLTDebug("| STU => Add L1 jet patch at (%2d , %2d)\n", vx, vy);
214 0 : SetTriggerBit(GetRawDigit(idx), kL1JetHigh + ithr, 1);
215 : }
216 : }
217 : }
218 : }
219 : }
220 :
221 0 : if (detector == 1) {
222 0 : UInt_t sregion[36] = {0};
223 0 : stustream->GetPHOSSubregion(sregion);
224 0 : for (int isr=0;isr<36;isr++) {
225 0 : if (fkGeometryPtr->GetGeometryPtr()->GetAbsFastORIndexFromPHOSSubregion(isr, idx)) {
226 0 : SetL1SubRegion(GetRawDigit(idx), sregion[isr]);
227 : }
228 : }
229 0 : }
230 0 : }
231 :
232 : /*
233 : for(int idig = 0; idig < fNRawDigits; idig++){
234 : PrintRawDigit(fRawDigitBuffer[idig]);
235 : }
236 : */
237 0 : }
238 :
239 : Int_t AliHLTEMCALSTURawDigitMaker::WriteRawDigitsBuffer(AliHLTCaloTriggerRawDigitDataStruct *bufferptr, AliHLTUInt32_t &availableSize) const {
240 : Int_t outputsize = 0;
241 0 : for(Int_t idig = 0; idig < fNRawDigits; idig++){
242 0 : if(availableSize < sizeof(AliHLTCaloTriggerRawDigitDataStruct)){
243 0 : HLTWarning("Buffer exceeded after %d digits", idig);
244 0 : break;
245 : }
246 0 : if (fRawDigitBuffer[idig].fID < 0 || fRawDigitBuffer[idig].fID >= fgkNRawDigits)
247 : {
248 0 : HLTWarning("Invalid TRU Index in Output %d", fRawDigitBuffer[idig].fID);
249 : continue;
250 : }
251 0 : *bufferptr = fRawDigitBuffer[idig];
252 0 : bufferptr++;
253 0 : outputsize += sizeof(AliHLTCaloTriggerRawDigitDataStruct);
254 0 : availableSize -= sizeof(AliHLTCaloTriggerRawDigitDataStruct);
255 0 : }
256 0 : return outputsize;
257 : }
258 :
259 : void AliHLTEMCALSTURawDigitMaker::Reset() {
260 0 : for (Int_t i = 0; i < fgkNRawDigits; i++) fRawDigitIndex[i] = -1;
261 0 : fNRawDigits = 0;
262 0 : fTriggerData->Reset();
263 0 : }
264 :
265 : AliHLTCaloTriggerRawDigitDataStruct &AliHLTEMCALSTURawDigitMaker::GetRawDigit(Int_t index){
266 0 : if (index < 0){
267 0 : HLTWarning("Invalid STU Index %d", index);
268 0 : AliHLTCaloTriggerRawDigitDataStruct &dig = fRawDigitBuffer[fgkNRawDigits - 1];
269 0 : InitializeRawDigit(dig);
270 : return dig;
271 : }
272 0 : if(fRawDigitIndex[index] >= 0){
273 0 : return fRawDigitBuffer[fRawDigitIndex[index]];
274 : }
275 :
276 0 : fRawDigitIndex[index] = fNRawDigits;
277 0 : AliHLTCaloTriggerRawDigitDataStruct &dig = fRawDigitBuffer[fNRawDigits];
278 0 : InitializeRawDigit(dig);
279 0 : SetRawDigitID(dig, index);
280 0 : fNRawDigits++;
281 : return dig;
282 0 : }
|