Updated to use new mapping scheme, new CaloRawStreamV3, reading of the ZS parameters...
[u/mrichter/AliRoot.git] / PHOS / PHOSBCMda.cxx
CommitLineData
0bbeb14b 1/*
2contact: Boris.Polishchuk@cern.ch
3link: http://aliceinfo.cern.ch/static/phpBB3/viewtopic.php?f=4&t=17
4reference run: /castor/cern.ch/alice/phos/2007/10/02/13/07000008232001.10.root
6ab90476 5run type: LED
0bbeb14b 6DA type: MON
7number of events needed: 1000
6ab90476 8number of events needed: 1000
9input files: Mod0RCU0.data Mod0RCU1.data Mod0RCU2.data Mod0RCU3.data Mod1RCU0.data Mod1RCU1.data Mod1RCU2.data Mod1RCU3.data Mod2RCU0.data Mod2RCU1.data Mod2RCU2.data Mod2RCU3.data Mod3RCU0.data Mod3RCU1.data Mod3RCU2.data Mod3RCU3.data Mod4RCU0.data Mod4RCU1.data Mod4RCU2.data Mod4RCU3.data
0bbeb14b 10Output files: PHOS_Module2_BCM.root
6ab90476 11Trigger types used: CALIBRATION_EVENT
0bbeb14b 12*/
13
14
15#include "event.h"
16#include "monitor.h"
17extern "C" {
18#include "daqDA.h"
19}
20
21#include <stdio.h>
22#include <stdlib.h>
23
24#include <TSystem.h>
25#include <TROOT.h>
26#include <TPluginManager.h>
27
28#include "AliRawReader.h"
29#include "AliRawReaderDate.h"
30#include "AliPHOSDA2.h"
8083e819 31#include "AliPHOSRawFitterv1.h"
0bbeb14b 32#include "AliCaloAltroMapping.h"
8083e819 33#include "AliCaloRawStreamV3.h"
6ab90476 34#include "AliLog.h"
0bbeb14b 35
36
37/* Main routine
38 Arguments:
39 1- monitoring data source
40*/
41int main(int argc, char **argv) {
42
43 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
44 "*",
45 "TStreamerInfo",
46 "RIO",
47 "TStreamerInfo()");
48
6ab90476 49 AliLog::SetGlobalDebugLevel(0) ;
50 AliLog::SetGlobalLogLevel(AliLog::kFatal);
51
0bbeb14b 52 int status;
53
54 if (argc!=2) {
55 printf("Wrong number of arguments\n");
56 return -1;
57 }
58
6ab90476 59 short offset, threshold;
0bbeb14b 60
61 /* Retrieve mapping files from DAQ DB */
6ab90476 62 const char* mapFiles[20] = {
63 "Mod0RCU0.data",
64 "Mod0RCU1.data",
65 "Mod0RCU2.data",
66 "Mod0RCU3.data",
67 "Mod1RCU0.data",
68 "Mod1RCU1.data",
69 "Mod1RCU2.data",
70 "Mod1RCU3.data",
71 "Mod2RCU0.data",
72 "Mod2RCU1.data",
73 "Mod2RCU2.data",
74 "Mod2RCU3.data",
75 "Mod3RCU0.data",
76 "Mod3RCU1.data",
77 "Mod3RCU2.data",
78 "Mod3RCU3.data",
79 "Mod4RCU0.data",
80 "Mod4RCU1.data",
81 "Mod4RCU2.data",
82 "Mod4RCU3.data"
83 };
84
85 for(Int_t iFile=0; iFile<20; iFile++) {
0bbeb14b 86 int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
6ab90476 87 if(failed) {
0bbeb14b 88 printf("Cannot retrieve file %s from DAQ DB. Exit.\n",mapFiles[iFile]);
89 return -1;
90 }
91 }
92
93 /* Open mapping files */
6ab90476 94 AliAltroMapping *mapping[20];
0bbeb14b 95 TString path = "./";
6ab90476 96
97 path += "Mod";
0bbeb14b 98 TString path2;
6ab90476 99 TString path3;
100 Int_t iMap = 0;
101
102 for(Int_t iMod = 0; iMod < 5; iMod++) {
0bbeb14b 103 path2 = path;
6ab90476 104 path2 += iMod;
105 path2 += "RCU";
106
107 for(Int_t iRCU=0; iRCU<4; iRCU++) {
108 path3 = path2;
109 path3 += iRCU;
110 path3 += ".data";
111 mapping[iMap] = new AliCaloAltroMapping(path3.Data());
112 iMap++;
113 }
114 }
0bbeb14b 115
116 /* define data source : this is argument 1 */
117 status=monitorSetDataSource( argv[1] );
118 if (status!=0) {
119 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
120 return -1;
121 }
122
123
124 /* declare monitoring program */
125 status=monitorDeclareMp( __FILE__ );
126 if (status!=0) {
127 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
128 return -1;
129 }
130
131
132 /* define wait event timeout - 1s max */
133 monitorSetNowait();
134 monitorSetNoWaitNetworkTimeout(1000);
135
136
137 /* log start of process */
138 printf("DA2 (bad channels search) started.\n");
139
140
141 /* init some counters */
142 int nevents_physics=0;
143 int nevents_total=0;
144
145 AliRawReader *rawReader = NULL;
146
7708b003 147 AliPHOSDA2* da2 = new AliPHOSDA2(2); // DA2 ("Checking for bad channels") for module2
0bbeb14b 148
149 Float_t q[64][56][2];
150
8083e819 151 Int_t cellX = -1;
152 Int_t cellZ = -1;
153 Int_t nBunches = 0;
154 Int_t nFired = -1;
155 Int_t sigStart, sigLength;
6ab90476 156 Int_t caloFlag;
0bbeb14b 157
158 /* main loop (infinite) */
159 for(;;) {
160 struct eventHeaderStruct *event;
161 eventTypeType eventT;
162
163 /* check shutdown condition */
164 if (daqDA_checkShutdown()) {break;}
165
166 /* get next event (blocking call until timeout) */
167 status=monitorGetEventDynamic((void **)&event);
168 if (status==MON_ERR_EOF) {
169 printf ("End of File detected\n");
170 break; /* end of monitoring file has been reached */
171 }
172
173 if (status!=0) {
174 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
175 break;
176 }
177
178 /* retry if got no event */
179 if (event==NULL) {
180 continue;
181 }
182
183
184 /* use event - here, just write event id to result file */
185 eventT=event->eventType;
186
187 if (eventT==PHYSICS_EVENT || eventT==CALIBRATION_EVENT) {
188
189 for(Int_t iX=0; iX<64; iX++) {
190 for(Int_t iZ=0; iZ<56; iZ++) {
191 for(Int_t iGain=0; iGain<2; iGain++) {
192 q[iX][iZ][iGain] = 0.;
193 }
194 }
195 }
196
7708b003 197 nFired = 0;
198
0bbeb14b 199 rawReader = new AliRawReaderDate((void*)event);
8083e819 200 AliCaloRawStreamV3 stream(rawReader,"PHOS",mapping);
6ab90476 201 AliPHOSRawFitterv1 fitter;
8083e819 202 fitter.SubtractPedestals(kTRUE); // assume that data is non-ZS
0bbeb14b 203
8083e819 204 while (stream.NextDDL()) {
205 while (stream.NextChannel()) {
206
6ab90476 207 /* Retrieve ZS parameters from data*/
208 short value = stream.GetAltroCFG1();
209 bool ZeroSuppressionEnabled = (value >> 15) & 0x1;
210 bool AutomaticBaselineSubtraction = (value >> 14) & 0x1;
211 if(ZeroSuppressionEnabled) {
212 offset = (value >> 10) & 0xf;
213 threshold = value & 0x3ff;
214 fitter.SubtractPedestals(kFALSE);
215 fitter.SetAmpOffset(offset);
216 fitter.SetAmpThreshold(threshold);
217 }
218
8083e819 219 cellX = stream.GetCellX();
220 cellZ = stream.GetCellZ();
221 caloFlag = stream.GetCaloFlag(); // 0=LG, 1=HG, 2=TRU
6ab90476 222
223 if(caloFlag!=0 && caloFlag!=1) continue; //TRU data!
224
8083e819 225 // In case of oscillating signals with ZS, a channel can have several bunches
226 nBunches = 0;
227 while (stream.NextBunch()) {
228 nBunches++;
6ab90476 229 sigStart = stream.GetStartTimeBin();
230 sigLength = stream.GetBunchLength();
231 fitter.SetChannelGeo(stream.GetModule(),cellX,cellZ,caloFlag);
232 fitter.Eval(stream.GetSignals(),sigStart,sigLength);
233 q[cellX][cellZ][caloFlag] = fitter.GetSignalQuality();
234 printf("q[%d][%d][%d] = %.3f\n",cellX,cellZ,caloFlag,q[cellX][cellZ][caloFlag]);
8083e819 235 } // End of NextBunch()
236
6ab90476 237 if(caloFlag==1 && fitter.GetEnergy()>40)
8083e819 238 nFired++;
239 }
0bbeb14b 240 }
6ab90476 241
7708b003 242 da2->FillQualityHistograms(q);
243 da2->FillFiredCellsHistogram(nFired);
0bbeb14b 244 //da1.UpdateHistoFile();
245
246 delete rawReader;
247 nevents_physics++;
248 }
249
250 nevents_total++;
251
252 /* free resources */
253 free(event);
254
255 /* exit when last event received, no need to wait for TERM signal */
256 if (eventT==END_OF_RUN) {
257 printf("EOR event detected\n");
258 break;
259 }
260 }
261
6ab90476 262 for(Int_t i = 0; i < 20; i++) delete mapping[i];
7708b003 263
264 /* Be sure that all histograms are saved */
265 delete da2;
0bbeb14b 266
267 /* Store output files to the File Exchange Server */
7708b003 268 daqDA_FES_storeFile("PHOS_Module2_BCM.root","BAD_CHANNELS");
0bbeb14b 269
270 return status;
271}