2 *********************************************************
4 this file provides the detector algorithm for HMPID. *
5 *********************************************************
14 #include <Riostream.h>
19 //#include "AliHMPIDRawStream.h"
20 #include "AliRawReaderDate.h"
21 #include "AliBitPacking.h"
29 #include "TBenchmark.h"
33 int main(int argc, char **argv){
37 /* log start of process */
38 printf("HMPID DA program started\n");
40 /* check that we got some arguments = list of files */
42 printf("Wrong number of arguments\n");
46 /* copy locally a file from daq detector config db
47 status=daqDA_DB_getFile("myconfig","./myconfig.txt");
49 printf("Failed to get config file : %d\n",status);
52 and possibly use it */
55 daqDA_progressReport(10);
58 /* init some counters */
59 Float_t SummQ[14][48][11][25], SummQ2[14][48][11][25];
61 for(Int_t ddl=0;ddl<=13;ddl++) {
62 isDDLOn[ddl] = kFALSE;
63 for(Int_t row=1;row<=24;row++)
64 for(Int_t dil=1;dil<=10;dil++)
65 for(Int_t adr=0;adr<=47;adr++)
67 SummQ[ddl][adr][dil][row]=0;
68 SummQ2[ddl][adr][dil][row]=0;
72 /* init event counter */
76 for (n=1;n<argc;n++) {
78 status=monitorSetDataSource( argv[n] );
80 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
85 /* in this example, indexed on the number of files */
86 daqDA_progressReport(10+80*n/argc);
88 for(;;) { // infinite loop
89 struct eventHeaderStruct *event;
93 status=monitorGetEventDynamic((void **)&event);
94 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
96 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
100 /* retry if got no event */
105 /* use event - here, just write event id to result file */
106 eventT=event->eventType;
108 if (eventT==CALIBRATION_EVENT) {
112 AliRawReader *pRR = new AliRawReaderDate((void*)event);
114 pRR->Select("HMPID");//select only one DDL files
116 UInt_t RawDataWord=0;
118 while(pRR->ReadNextInt(RawDataWord)) //raw records loop (in selected DDL files)
120 Int_t ddl = pRR->GetDDLID();
122 Int_t a = AliBitPacking::UnpackWord(RawDataWord,12,17); assert(0<=a&&a<=47); // 1098 7654 3210 9876 5432 1098 7654 3210 DILOGIC address (0..47)
123 Int_t d = AliBitPacking::UnpackWord(RawDataWord,18,21); assert(1<=d&&d<=10); // 3322 2222 2222 1111 1111 1000 0000 0000 DILOGIC number (1..10)
124 Int_t r = AliBitPacking::UnpackWord(RawDataWord,22,26); assert(1<=r&&r<=24); // Row number (1..24)
126 Int_t q = AliBitPacking::UnpackWord(RawDataWord, 0,11); assert(0<=q&&q<=4095); // 0000 0rrr rrdd ddaa aaaa qqqq qqqq qqqq Qdc (0..4095)
128 SummQ[ddl][a][d][r]+=q;
129 SummQ2[ddl][a][d][r]+=(q*q);
130 isDDLOn[ddl] = kTRUE;
135 }// if CALIBRATION_EVENT
137 /* exit when last event received, no need to wait for TERM signal */
138 if (eventT==END_OF_RUN) {
139 printf("EOR event detected\n");
150 printf("Run #%s, received %d calibration events\n",getenv("DATE_RUN_NUMBER"),iEvtNcal);
153 printf("No calibration events have been read. Exiting\n");
157 /* report progress */
158 daqDA_progressReport(90);
160 for(Int_t ddl=0; ddl < 14; ddl++) {
161 if (!isDDLOn[ddl]) continue;
164 out.open(Form("./HmpidPedDdl%02i.txt",ddl));
166 for(Int_t row=1; row < 25; row++)
167 for(Int_t dil=1; dil < 11; dil++)
168 for(Int_t adr=0; adr < 48; adr++) {
170 Float_t mean = SummQ[ddl][adr][dil][row]/iEvtNcal;
171 Float_t sigma = TMath::Sqrt(SummQ2[ddl][adr][dil][row]/iEvtNcal - (SummQ[ddl][adr][dil][row]/iEvtNcal)*(SummQ[ddl][adr][dil][row]/iEvtNcal));
172 Int_t inhard=((Int_t(mean))<<9)+Int_t(mean+3*sigma);
174 out << Form("%2i %2i %2i %5.2f %5.2f %x\n",row,dil,adr,mean,sigma,inhard);
177 /* store the result file on FES */
178 status=daqDA_FES_storeFile(Form("./HmpidPedDdl%02i.txt",ddl),Form("HMPID_DA_Pedestals_ddl=%02i",ddl));
180 printf("Failed to export file : %d\n",status);
186 /* report progress */
187 daqDA_progressReport(100);