]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/HMPIDda.cxx
Bug in area evaluation for reconstruction of ring. Important for PbPb events (high...
[u/mrichter/AliRoot.git] / HMPID / HMPIDda.cxx
1 /*
2 *********************************************************
3 Author:                                                 *
4 this file provides the detector algorithm for HMPID.    *
5 *********************************************************
6 */
7 extern "C" {
8 #include <daqDA.h>
9 }
10
11 #include "event.h"
12 #include "monitor.h"
13
14 #include <Riostream.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17
18 //AliRoot
19 #include "AliHMPIDRawStream.h"
20 #include "AliHMPIDCalib.h"
21 #include "AliRawReaderDate.h"
22 #include "AliBitPacking.h"
23 #include "TMath.h"
24
25 //ROOT
26 #include "TFile.h"
27 #include "TSystem.h"
28 #include "TKey.h"
29 #include "TH2S.h"
30 #include "TObject.h"
31 #include "TBenchmark.h"
32 #include "TMath.h"
33 #include "TRandom.h"
34
35
36 int main(int argc, char **argv){ 
37
38   int status;
39
40   /* log start of process */
41   printf("HMPID DA program started\n");  
42
43   /* check that we got some arguments = list of files */
44   if (argc<2) {
45     printf("Wrong number of arguments\n");
46     return -1;
47   }
48
49   /* copy locally a file from daq detector config db
50   status=daqDA_DB_getFile("myconfig","./myconfig.txt");
51   if (status) {
52     printf("Failed to get config file : %d\n",status);
53     return -1;
54   }
55   and possibly use it */
56
57   /* report progress */
58   daqDA_progressReport(10);
59
60
61   /* init the pedestal calculation */
62   AliHMPIDCalib *pCal=new AliHMPIDCalib();
63   
64   /* init event counter */
65   Int_t iEvtNcal=0;
66
67   Int_t cnt=0;
68   
69   int n;
70   for (n=1;n<argc;n++) {
71
72     status=monitorSetDataSource( argv[n] );
73     if (status!=0) {
74       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
75       return -1;
76     }
77
78     /* report progress */
79     /* in this example, indexed on the number of files */
80     daqDA_progressReport(10+80*n/argc);
81
82     for(;;) { // infinite loop 
83       struct eventHeaderStruct *event;
84       eventTypeType eventT;
85
86       /* get next event */
87       status=monitorGetEventDynamic((void **)&event);
88       if (status==MON_ERR_EOF)                                              /* end of monitoring file has been reached */
89       {
90         printf("End of monitoring file has been reached! \n");
91         break;
92         }
93       
94        
95       if (status!=0) {
96         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
97         return -1;
98       }
99
100       /* retry if got no event */
101       if (event==NULL) {
102         //break;
103         continue;
104       }
105
106       /* use event - here, just write event id to result file */
107       eventT=event->eventType;
108
109       if (eventT==PHYSICS_EVENT) {                                                //we use PHYSICS_EVENT for pedestal not CALIBRATION_EVENT
110         
111         iEvtNcal++;
112         
113         AliRawReader *reader = new AliRawReaderDate((void*)event);
114
115         // Temporary there. Shall be removed as soon as the equipment ID is set correctly
116         // For the moment ddl.map file contains one line which maps
117         // the observed eqID=225 to the first HMPID DDL with ID=1536
118         //      reader->LoadEquipmentIdsMap("ddl.map");
119         
120         AliHMPIDRawStream stream(reader);
121
122         while(stream.Next()) {
123           Int_t nDDL=stream.GetDDLNumber();
124             for(Int_t row = 1; row <=AliHMPIDRawStream::kNRows; row++){
125               for(Int_t dil = 1; dil <=AliHMPIDRawStream::kNDILOGICAdd; dil++){
126                 for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
127                   pCal->FillPedestal(nDDL,row,dil,pad,stream.GetCharge(nDDL,row,dil,pad));
128                 }//pad
129               }//dil
130             }//row
131         } //raw data loop
132         
133         delete reader;
134
135       }// if CALIBRATION_EVENT
136
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");
140         break;    
141     
142       } // events loop   
143
144       free(event);
145     }
146
147   }//arg
148
149   /* write report */
150   printf("Run #%s, received %d calibration events\n",getenv("DATE_RUN_NUMBER"),iEvtNcal);
151
152   if (!iEvtNcal) {
153     printf("No calibration events have been read. Exiting\n");
154     return -1;
155   }
156
157   /* report progress */
158   daqDA_progressReport(90);
159
160   for(Int_t nDDL=0; nDDL < AliHMPIDCalib::kNDDL; nDDL++) {
161     
162     /* Calculate pedestal for the given ddl, if there is no ddl go t next */
163     if(!pCal->CalcPedestal(nDDL,Form("./HmpidPedDdl%02i.txt",nDDL),iEvtNcal)) continue;
164     
165     /* store the result file on FES */
166     
167     status=daqDA_FES_storeFile(Form("./HmpidPedDdl%02i.txt",nDDL),Form("HMPID_DA_Pedestals_ddl=%02i",nDDL));
168     if (status) {
169       printf("Failed to export file : %d\n",status);
170       return -1;
171     }
172     
173   }//nDDL
174   
175   /* report progress */
176   daqDA_progressReport(100);
177
178   return status;
179 }