1 //////////////////////////////////////////////////////////////////////////////
2 // This program can be run in two modes. //
4 // 1. With the DAQ DA framework on. In Makefile: -DDA_OFF flag outcommented.//
5 // Call this program with the name of the executable followed by the //
6 // data files to process. //
8 // 2. Without the DAQ DA framework on. In Makefile: with -DDA_OFF flag. //
9 // Call this program with the name of the executable followed by the //
10 // runNr and the data files to process. //
12 //////////////////////////////////////////////////////////////////////////////
19 #include "AliRawReaderDate.h"
20 #include "AliITSRawStreamSPD.h"
21 #include "AliITSOnlineSPDscan.h"
22 #include "AliITSOnlineSPDscanSingle.h"
23 #include "AliITSOnlineSPDscanMultiple.h"
24 #include "AliITSOnlineSPDscanMeanTh.h"
25 #include "AliITSOnlineSPDscanAnalyzer.h"
30 #include <TPluginManager.h>
33 int main(int argc, char **argv) {
35 printf("Wrong number of arguments\n");
39 char *saveDirNoisy = "./calibResults/Noisy"; // hard wired for now!!!
41 char *saveDirNoisyToFXS = "./calibResults/NoisyToFXS"; // hard wired for now!!!
43 char *saveDirParameters = "./calibResults/Parameters"; // hard wired for now!!!
44 char *saveDirRef = "./calibResults/Reference"; // hard wired for now!!!
46 // This line is needed in case of a stand-alone application w/o
47 // $ROOTSYS/etc/system.rootrc file
48 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
54 // turn off annoying warning messages
56 AliLog::Instance()->SetModuleDebugLevel("ROOT", -2);
59 enum calib_types{MINTH,MEANTH,DAC,UNIMA,NOISE,DELAY};
62 // ********* STEP 1: Produce scan container files. ***********************************
66 int runNr = atoi(getenv("DATE_RUN_NUMBER"));
68 int runNr = atoi(argv[1]);
73 AliITSOnlineSPDscan *scanObj[20];
75 for (UInt_t eqId=0; eqId<20; eqId++) {
77 bScanInit[eqId]=kFALSE;
79 // header data variables
81 Bool_t halfStaveScanned[20][6];
83 Bool_t dataFormat[20];
85 Bool_t chipPresent[20][6][10];
94 UInt_t dacHigh[20][6];
97 // current scan step flag
98 Int_t currentStep[20];
99 for (UInt_t eqId=0; eqId<20; eqId++) currentStep[eqId] = 9999;
101 // loop over run segments
102 for (int segNr=startSeg; segNr<argc; segNr++) {
107 /* define data source : this is argument 1 */
108 status=monitorSetDataSource( argv[segNr] );
110 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
113 /* declare monitoring program */
114 status=monitorDeclareMp("ITS_SPD_CAL");
116 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
119 /* define wait event timeout - 1s max */
121 monitorSetNoWaitNetworkTimeout(1000);
124 struct eventHeaderStruct *event;
125 eventTypeType eventT;
129 /* main loop (infinite) */
132 /* check shutdown condition */
133 if (daqDA_checkShutdown()) {break;}
134 /* get next event (blocking call until timeout) */
135 status=monitorGetEventDynamic((void **)&event);
136 if (status==MON_ERR_EOF) {
137 printf ("End of File detected\n");
138 break; /* end of monitoring file has been reached */
141 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
144 /* retry if got no event */
146 printf("event==NULL\n");
150 eventT=event->eventType;
151 if (event->eventType == PHYSICS_EVENT){
155 // printf("eventNr %d\n",eventNr);
157 AliRawReader *reader = new AliRawReaderDate((void*)event);
158 AliITSRawStreamSPD *str = new AliITSRawStreamSPD(reader);
161 for (UInt_t eqId=0; eqId<20; eqId++) {
164 reader->Select("ITSSPD",eqId,eqId);
166 // Hit Event flags, specific for one event
167 Bool_t hitEventHSIncremented[6];
168 Bool_t hitEventChipIncremented[6][10];
169 for (UInt_t hs=0; hs<6; hs++) {
170 hitEventHSIncremented[hs] = kFALSE;
171 for (UInt_t chip=0; chip<10; chip++) {
172 hitEventChipIncremented[hs][chip] = kFALSE;
176 if (str->ReadCalibHeader()) {
177 // first check the type:
178 if (bScanInit[eqId] && type[eqId]!=str->GetHtype()) {
179 printf("Calib header problem. Type changed (%d -> %d)!\n",type[eqId],str->GetHtype());
183 routerNr[eqId] = str->GetHrouterNr();
184 type[eqId] = str->GetHtype();
185 dataFormat[eqId] = str->GetHdataFormat();
186 triggers[eqId] = str->GetHtriggers();
187 dacStart[eqId] = str->GetHdacStart();
188 dacEnd[eqId] = str->GetHdacEnd();
189 dacStep[eqId] = str->GetHdacStep();
190 dacId[eqId] = str->GetHdacId();
191 rowStart[eqId] = str->GetHrowStart();
192 rowEnd[eqId] = str->GetHrowEnd();
193 rowValue[eqId] = str->GetHrowValue();
194 dacValue[eqId] = str->GetHdacValue();
195 for (UInt_t hs=0; hs<6; hs++) {
196 halfStaveScanned[eqId][hs]=str->GetHhalfStaveScanned(hs);
197 dacHigh[eqId][hs] = str->GetHdacHigh(hs);
198 dacLow[eqId][hs] = str->GetHdacLow(hs);
199 TPAmp[eqId][hs] = str->GetHTPAmp(hs);
200 for (UInt_t chip=0; chip<10; chip++) {
201 chipPresent[eqId][hs][chip] = str->GetHchipPresent(hs,chip);
205 currentStep[eqId] = (dacValue[eqId]-dacStart[eqId])/dacStep[eqId];
206 if (type[eqId]==DELAY) {
207 currentStep[eqId]=currentStep[eqId]*2;
208 dacValue[eqId]=dacValue[eqId]*2;
209 if (dacHigh[eqId][0]==128) { // misc_ctrl value
210 currentStep[eqId]=currentStep[eqId]+1;
211 dacValue[eqId]=dacValue[eqId]+1;
216 if (routerNr[eqId]!=eqId) {
217 printf("Router nr problem? Router nr %d != EqID %d\n",routerNr[eqId],eqId);
220 if (!bScanInit[eqId]) {
221 // initialize container object
222 Char_t fileName[200];
223 sprintf(fileName,"%s/SPDcal_run_%d_eq_%d.root",saveDirRef,runNr,eqId);
224 switch (type[eqId]) {
227 scanObj[eqId] = new AliITSOnlineSPDscanSingle(fileName);
228 ((AliITSOnlineSPDscanSingle*)scanObj[eqId])->ClearThis();
229 bScanInit[eqId]=kTRUE;
234 scanObj[eqId] = new AliITSOnlineSPDscanMultiple(fileName);
235 scanObj[eqId]->ClearThis();
236 bScanInit[eqId]=kTRUE;
239 scanObj[eqId] = new AliITSOnlineSPDscanMeanTh(fileName);
240 scanObj[eqId]->ClearThis();
241 bScanInit[eqId]=kTRUE;
244 printf("Unknown scan type: %d.\n",type[eqId]);
246 // some multiple scan data
247 if (type[eqId]==MINTH || type[eqId]==MEANTH || type[eqId]==DAC || type[eqId]==DELAY) {
248 ((AliITSOnlineSPDscanMultiple*)scanObj[eqId])->SetDacId(dacId[eqId]);
251 scanObj[eqId]->SetRunNr((UInt_t)runNr);
252 scanObj[eqId]->SetRouterNr(routerNr[eqId]);
253 for (UInt_t hs=0; hs<6; hs++) {
254 scanObj[eqId]->SetHalfStaveScanned(hs,halfStaveScanned[eqId][hs]);
256 scanObj[eqId]->SetType(type[eqId]);
257 scanObj[eqId]->SetDataFormat(dataFormat[eqId]);
258 for (Int_t hs=0; hs<6; hs++) {
260 // remove later when the chip present is set correctly !!!!!!!!!!!!!!!!!!!!!!!!!!!
261 Bool_t halfStavePresent = str->GetHalfStavePresent(hs);
262 // remove later when the chip present is set correctly !!!!!!!!!!!!!!!!!!!!!!!!!!!
264 for (UInt_t chip=0; chip<10; chip++) {
265 scanObj[eqId]->SetChipPresent(hs,chip,chipPresent[eqId][hs][chip]);
267 // remove later when the chip present is set correctly !!!!!!!!!!!!!!!!!!!!!!!!!!!
268 if (halfStavePresent) scanObj[eqId]->SetChipPresent(hs,chip,kTRUE);
269 // remove later when the chip present is set correctly !!!!!!!!!!!!!!!!!!!!!!!!!!!
273 scanObj[eqId]->SetRowStart(rowStart[eqId]);
274 scanObj[eqId]->SetRowEnd(rowEnd[eqId]);
275 scanObj[eqId]->SetDacStart(dacStart[eqId]);
276 scanObj[eqId]->SetDacEnd(dacEnd[eqId]);
277 scanObj[eqId]->SetDacStep(dacStep[eqId]);
280 if (type[eqId]==MINTH) {
281 scanObj[eqId]->SetTriggers(currentStep[eqId],triggers[eqId]);
283 if (type[eqId]==UNIMA || type[eqId]==NOISE) {
284 if (currentStep[eqId]==9999) printf("SPDcalibratorStep1 (eq %d): single step\n",eqId);
287 if (type[eqId]==MINTH || type[eqId]==MEANTH || type[eqId]==DAC || type[eqId]==DELAY) {
288 ((AliITSOnlineSPDscanMultiple*)scanObj[eqId])->SetDacValue(currentStep[eqId],dacValue[eqId]);
289 if (type[eqId]==DELAY) {
290 printf("SPDcalibratorStep1 (eq %d): DAC %d/%d , step %d\n",eqId,dacValue[eqId]/2,dacHigh[eqId][0],currentStep[eqId]);
293 printf("SPDcalibratorStep1 (eq %d): DAC %d , step %d\n",eqId,dacValue[eqId],currentStep[eqId]);
296 if (type[eqId]==MEANTH) {
297 for (Int_t hs=0; hs<6; hs++) {
298 ((AliITSOnlineSPDscanMeanTh*)scanObj[eqId])->SetDacLow(currentStep[eqId],hs,dacLow[eqId][hs]);
299 ((AliITSOnlineSPDscanMeanTh*)scanObj[eqId])->SetDacHigh(currentStep[eqId],hs,dacHigh[eqId][hs]);
300 ((AliITSOnlineSPDscanMeanTh*)scanObj[eqId])->SetTPAmp(currentStep[eqId],hs,TPAmp[eqId][hs]);
307 if (bScanInit[eqId]) {
308 while (str->Next()) {
309 UInt_t hs = str->GetHalfStaveNr();
310 UInt_t chip = str->GetChipAddr();
312 if (type[eqId]!=MINTH || dacHigh[eqId][0]==chip) { // dachigh[0] holds chip scanned for minth
314 scanObj[eqId]->IncrementHits(currentStep[eqId],hs,chip,str->GetChipCol(),str->GetChipRow());
316 if (!hitEventHSIncremented[hs]) {
317 scanObj[eqId]->IncrementHitEventsTot(currentStep[eqId],hs);
318 hitEventHSIncremented[hs]=kTRUE;
321 if (!hitEventChipIncremented[hs][chip]) {
322 scanObj[eqId]->IncrementHitEvents(currentStep[eqId],hs,chip);
323 hitEventChipIncremented[hs][chip]=kTRUE;
329 if (type[eqId]!=MINTH) { // for minth, triggers are set from header info
330 scanObj[eqId]->IncrementTriggers(currentStep[eqId]);
347 status = monitorLogout();
349 printf("monitorLogout() failed : %s\n",monitorDecodeError(status));
354 daqDA_progressReport((unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 ));
356 printf("progress: %d\n",(unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 ));
361 // clean up scan objects
362 for (UInt_t eqId=0; eqId<20; eqId++) {
363 if (scanObj[eqId]!=NULL) delete scanObj[eqId];
370 // ********* STEP 2: Analyze scan container files. ***********************************
372 // clear noisyToFXS dir:
374 sprintf(command,"cd %s; rm -f *",saveDirNoisyToFXS);
378 AliITSOnlineSPDscanAnalyzer *analyzer;
380 // *** *** *** start loop over equipments (eq_id)
381 for (int eqId=0; eqId<20; eqId++) {
383 Char_t fileName[200];
384 sprintf(fileName,"%s/SPDcal_run_%d_eq_%d.root",saveDirRef,runNr,eqId);
385 analyzer = new AliITSOnlineSPDscanAnalyzer(fileName);
387 Int_t type = analyzer->GetType();
388 Int_t dacId = analyzer->GetDacId();
391 printf("SPD calibrator Step2: eqId %d, type %d, dacId %d\n",eqId,type,dacId);
393 else printf("SPD calibrator Step2: eqId %d type %d\n",eqId,type);
401 else if (type==NOISE) {
402 if (analyzer->ProcessNoisyPixels(saveDirNoisy)) {
403 for (UInt_t module=0; module<240; module++) {
404 if (analyzer->SaveDeadNoisyPixels(module,saveDirNoisy)) {
407 sprintf(command,"cp %s/SPD_DeadNoisy_%d.root %s/.",saveDirNoisy,module,saveDirNoisyToFXS);
414 // else if (type==DAC && dacId==42) {
415 // Char_t ofileName[100];
416 // sprintf(ofileName,"%s/delay_eq_%d.txt",saveDirParameters,eqId);
418 // ofile.open (ofileName);
419 // for (UInt_t hs=0; hs<6; hs++) {
420 // for (UInt_t chipNr=0; chipNr<10; chipNr++) {
421 // ofile << analyzer->GetDelay(hs,chipNr);
429 // sprintf(id,"SPD_delay_%d",eqId);
430 // Int_t status = daqDA_FES_storeFile(ofileName,id);
432 // printf("Failed to export file %s , status %d\n",ofileName,status);
436 else if (type==MINTH || (type==DAC && dacId==39)) {
437 Char_t ofileName[100];
438 sprintf(ofileName,"%s/minth_eq_%d.txt",saveDirParameters,eqId);
440 ofile.open (ofileName);
441 for (UInt_t hs=0; hs<6; hs++) {
442 for (UInt_t chipNr=0; chipNr<10; chipNr++) {
443 ofile << analyzer->GetMinTh(hs,chipNr);
451 sprintf(id,"SPD_minth_%d",eqId);
452 Int_t status = daqDA_FES_storeFile(ofileName,id);
454 printf("Failed to export file %s , status %d\n",ofileName,status);
458 else if (type==DELAY) {
459 Char_t ofileName[100];
460 sprintf(ofileName,"%s/delay_eq_%d.txt",saveDirParameters,eqId);
462 ofile.open (ofileName);
463 for (UInt_t hs=0; hs<6; hs++) {
464 for (UInt_t chipNr=0; chipNr<10; chipNr++) {
465 UInt_t clockCycle = analyzer->GetDelay(hs,chipNr);
466 UInt_t delayCtrl = clockCycle/2;
467 UInt_t miscCtrl = 192;
468 if (clockCycle%2==1) miscCtrl = 128;
469 ofile << delayCtrl << "/" << miscCtrl;
477 sprintf(id,"SPD_delay_%d",eqId);
478 Int_t status = daqDA_FES_storeFile(ofileName,id);
480 printf("Failed to export file %s , status %d\n",ofileName,status);
489 daqDA_progressReport((unsigned int)(50+(eqId+1)*2.5));
491 printf("progress: %d\n",(unsigned int)(50+(eqId+1)*2.5));
495 // *** *** *** end loop over equipments (eq_id)
499 // send a tared file of all new noisy maps
500 sprintf(command,"cd %s; tar -cf noisy.tar *",saveDirNoisyToFXS);
501 printf("\n\n%s\n\n",command);
503 Char_t fileName[200];
504 sprintf(fileName,"%s/noisy.tar",saveDirNoisyToFXS);
506 sprintf(id,"SPD_noisy");
507 Int_t status = daqDA_FES_storeFile(fileName,id);
509 printf("Failed to export file %s , status %d\n",fileName,status);