]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/HMPIDda.cxx
New geometry with services (not ALL) and CRADLE support (for the glory of Fed)
[u/mrichter/AliRoot.git] / HMPID / HMPIDda.cxx
1 /*
2
3 HMPID DA for online calibration
4
5 Contact: Levente.Molnar@ba.infn.it, Giacomo.Volpe@ba.infn.it
6 Link: http://richpc1.ba.infn.it/~levente/Files4Public/ValidateHmpidDA/
7 Run Type: PEDESTAL -- but we select on the PHYSICS_EVENTS in th HMPIDda.cxx
8 DA Type: LDC
9 Number of events needed: 1000 events
10 Input Files: Raw pedestal file, no external config file
11 Output Files: 14 txt files including pedestal values
12 Trigger types used: PEDESTAL RUN (selecting on PHYSICS_EVENT)
13
14 */
15
16 extern "C" {
17 #include <daqDA.h>
18 }
19
20 #include "event.h"
21 #include "monitor.h"
22
23 #include <Riostream.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 //AliRoot
28 #include "AliHMPIDRawStream.h"
29 #include "AliHMPIDCalib.h"
30 #include "AliRawReaderDate.h"
31 #include "AliBitPacking.h"
32 #include "TMath.h"
33
34 //ROOT
35 #include "TFile.h"
36 #include "TSystem.h"
37 #include "TKey.h"
38 #include "TH2S.h"
39 #include "TObject.h"
40 #include "TBenchmark.h"
41 #include "TMath.h"
42 #include "TRandom.h"
43
44
45 int main(int argc, char **argv){ 
46
47   int status;
48
49   /* log start of process */
50   printf("HMPID DA program started\n");  
51
52   /* check that we got some arguments = list of files */
53   if (argc<2) {
54     printf("Wrong number of arguments\n");
55     return -1;
56   }
57
58   /* copy locally a file from daq detector config db
59   status=daqDA_DB_getFile("myconfig","./myconfig.txt");
60   if (status) {
61     printf("Failed to get config file : %d\n",status);
62     return -1;
63   }
64   and possibly use it */
65
66   /* report progress */
67   daqDA_progressReport(10);
68
69   
70   
71   /* define wait event timeout - 1s max */
72   monitorSetNowait();
73   monitorSetNoWaitNetworkTimeout(1000);
74
75   /* init the pedestal calculation */
76   AliHMPIDCalib *pCal=new AliHMPIDCalib();
77   
78   /* init event counter */
79   Int_t iEvtNcal=0;
80   ULong_t runNum=0;
81   
82   int n;
83   for (n=1;n<argc;n++) {
84
85     status=monitorSetDataSource( argv[n] );
86     if (status!=0) {
87       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
88       return -1;
89     }
90
91     /* report progress */
92     /* in this example, indexed on the number of files */
93     daqDA_progressReport(10+80*n/argc);
94
95     for(;;) { // infinite loop 
96       
97        /* check shutdown condition */
98     if (daqDA_checkShutdown()) {break;}
99     
100       struct eventHeaderStruct *event;
101       eventTypeType eventT;
102
103       /* get next event */
104       status=monitorGetEventDynamic((void **)&event);
105       if (status==MON_ERR_EOF)                                              /* end of monitoring file has been reached */
106       {
107         printf("End of monitoring file has been reached! \n");
108         break;
109         }
110       
111        
112       if (status!=0) {
113         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
114         return -1;
115       }
116
117       /* retry if got no event */
118       if (event==NULL) {
119         //break;
120         continue;
121       }
122
123       /* use event - here, just write event id to result file */
124       eventT=event->eventType;
125
126       if (eventT==PHYSICS_EVENT) {                                                //we use PHYSICS_EVENT for pedestal not CALIBRATION_EVENT
127         
128         runNum=(unsigned long)event->eventRunNb;                                  //assuming that only one run is processed at a time
129              
130         iEvtNcal++;
131         
132         AliRawReader *reader = new AliRawReaderDate((void*)event);
133         AliHMPIDRawStream stream(reader);
134         
135         while(stream.Next())
136           {
137              for(Int_t iPad=0;iPad<stream.GetNPads();iPad++) {
138              pCal->FillPedestal(stream.GetPadArray()[iPad],stream.GetChargeArray()[iPad]);
139            }
140            
141            for(Int_t iddl=0;iddl<AliHMPIDRawStream::kNDDL;iddl++){                                         
142               for(Int_t ierr=0; ierr < AliHMPIDRawStream::kSumErr; ierr++) {
143                  pCal->FillErrors(iddl,ierr,stream.GetErrors(iddl,ierr));
144                }
145             }
146           
147         }//Next()    
148         stream.Delete();            
149
150       }// if CALIBRATION_EVENT
151
152       /* exit when last event received, no need to wait for TERM signal */
153       if (eventT==END_OF_RUN) {
154         printf("EOR event detected\n");
155         break;    
156     
157       } // events loop   
158
159       free(event);
160     }
161
162   }//arg
163
164   /* write report */
165   printf("HMPID DA processed RUN #%s, with %d calibration events\n",getenv("DATE_RUN_NUMBER"),iEvtNcal);
166
167   if (!iEvtNcal) {
168     printf("No calibration events have been read. Exiting\n");
169     return -1;
170   }
171
172   /* report progress */
173   daqDA_progressReport(90);
174
175    
176   for(Int_t nDDL=0; nDDL < AliHMPIDCalib::kNDDL; nDDL++) {
177     
178     /* Calculate pedestal for the given ddl, if there is no ddl go t next */
179     if(!pCal->CalcPedestal(runNum,nDDL,Form("./HmpidPedDdl%02i.txt",nDDL),iEvtNcal)) continue;
180     if(!pCal->WriteErrors(runNum,nDDL,Form("./HmpidErrorsDdl%02i.txt",nDDL),iEvtNcal)) continue;
181     
182     /* store the result file on FES */
183     /*
184     status=daqDA_FES_storeFile(Form("./HmpidPedDdl%02i.txt",nDDL),Form("HMPID_DA_Pedestals_ddl=%02i",nDDL));
185     if (status) {
186       printf("Failed to export file : %d\n",status);
187       return -1;
188     }
189     */
190     status=daqDA_FES_storeFile(Form("./HmpidPedDdl%02i.txt",nDDL),Form("HMPID_DA_Pedestals_ddl=%02i",nDDL));
191     if (status) { printf("Failed to export file : %d\n",status); }
192     status=daqDA_FES_storeFile(Form("./HmpidErrorsDdl%02i.txt",nDDL),Form("HMPID_DA_Errors_ddl=%02i",nDDL));
193     if (status) { printf("Failed to export file : %d\n",status); }
194     
195   }//nDDL
196   delete pCal;
197   if (status) return -1;
198   
199   /* report progress */
200   daqDA_progressReport(100);
201   
202
203   return status;
204 }