]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/HMPIDda.cxx
Tools for experts for cross-checkings
[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, EXTERNAL config file: HmpidSigmaCut.txt on both HMPID LDCs
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 "fstream.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 //AliRoot
29 #include "AliHMPIDRawStream.h"
30 #include "AliHMPIDCalib.h"
31 #include "AliRawReaderDate.h"
32 #include "AliBitPacking.h"
33
34 //ROOT
35 #include "TFile.h"
36 #include "TROOT.h"
37 #include "TObject.h"
38
39
40 int main(int argc, char **argv){ 
41
42   int status;
43
44   /* log start of process */
45   printf("HMPID DA program started\n");  
46 /*
47   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
48                                         "*",
49                                         "TStreamerInfo",
50                                         "RIO",
51                                         "TStreamerInfo()");
52   */
53   /* check that we got some arguments = list of files */
54   if (argc<2) {
55     printf("Wrong number of arguments\n");
56     return -1;
57   }
58
59   /* copy locally a file from daq detector config db
60   status=daqDA_DB_getFile("myconfig","./myconfig.txt");
61   if (status) {
62     printf("Failed to get config file : %d\n",status);
63     return -1;
64   }
65   and possibly use it */
66
67   /* report progress */
68   daqDA_progressReport(10);
69
70   
71   
72   /* define wait event timeout - 1s max */
73   monitorSetNowait();
74   monitorSetNoWaitNetworkTimeout(1000);
75
76   /* init the pedestal calculation */
77   AliHMPIDCalib *pCal=new AliHMPIDCalib();
78   /* Set the number of sigma cuts inside the file HmpidSigmaCut.txt on BOTH LDCs! */
79   /* If the file is NOT present then the default cut 3 will be used!*/
80   pCal->SetSigCutFromFile("HmpidSigmaCut.txt");
81   /* ONLY set this option to kTRUE if you want to create the ADC dsitributions for all 161280 pads!!!!*/  
82   /* kTRUE is not suggested for production mode b/c of the memory consumption! */
83   pCal->SetWriteHistoPads(kFALSE);               //use this option for default production useage!!!
84   //pCal->SetWriteHistoPads(kTRUE);              //only for expert debug
85   //pCal->SetWriteHistoPads(kTRUE,kTRUE,13);     //DO NOT USE THIS OPTION!
86   
87   /* init event counter */
88   Int_t firstEvt=0;
89   Int_t iEvtNcal=firstEvt;                      //Start from 1 not 0!                                                 
90   ULong_t runNum=0;
91   ULong_t ldcId=0;
92
93   int n;
94   for (n=1;n<argc;n++) {
95
96     status=monitorSetDataSource( argv[n] );
97     if (status!=0) {
98       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
99       return -1;
100     }
101
102     /* report progress */
103     /* in this example, indexed on the number of files */
104     daqDA_progressReport(10+80*n/argc);
105
106     for(;;) { // infinite loop 
107       
108        /* check shutdown condition */
109     if (daqDA_checkShutdown()) {break;}
110     
111       struct eventHeaderStruct *event;
112       eventTypeType eventT;
113
114       /* get next event */
115       status=monitorGetEventDynamic((void **)&event);
116       if (status==MON_ERR_EOF)                                              /* end of monitoring file has been reached */
117       {
118         printf("End of monitoring file has been reached! \n");
119         break;
120         }
121       
122        
123       if (status!=0) {
124         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
125         return -1;
126       }
127
128       /* retry if got no event */
129       if (event==NULL) {
130         //break;
131         continue;
132       }
133
134       /* use event - here, just write event id to result file */
135       eventT=event->eventType;
136
137       if (eventT==PHYSICS_EVENT) {                                                //we use PHYSICS_EVENT for pedestal not CALIBRATION_EVENT
138         
139         runNum=(unsigned long)event->eventRunNb;                                  //assuming that only one run is processed at a time
140         ldcId=(unsigned long)event->eventLdcId;
141         if(iEvtNcal==firstEvt && pCal->GetWritePads()==kTRUE) pCal->InitFile((Int_t)ldcId);    //The number for iEvtNcal should be the same as for the first value
142         iEvtNcal++;        
143         AliRawReader *reader = new AliRawReaderDate((void*)event);
144         AliHMPIDRawStream stream(reader);
145         while(stream.Next())
146           {
147              for(Int_t iPad=0;iPad<stream.GetNPads();iPad++) {
148              pCal->FillPedestal(stream.GetPadArray()[iPad],stream.GetChargeArray()[iPad]);
149               } //pads
150           }//while -- loop on det load in one event
151           
152          for(Int_t iddl=0;iddl<stream.GetNDDL();iddl++){   
153                  pCal->FillDDLCnt(iddl,stream.GetnDDLInStream()[iddl],stream.GetnDDLOutStream()[iddl]);                     
154            for(Int_t ierr=0; ierr < stream.GetNErrors(); ierr++) {
155                pCal->FillErrors(iddl,ierr,stream.GetErrors(iddl,ierr));
156                }
157           }//err   
158           
159         pCal->SetRunParams(runNum,stream.GetTimeStamp(),stream.GetLDCNumber());   //Get the last TimeStam read and the LDC ID
160         stream.Delete();            
161       }// if CALIBRATION_EVENT
162
163       /* exit when last event received, no need to wait for TERM signal */
164       if (eventT==END_OF_RUN) {
165         printf("EOR event detected\n");
166         break;    
167     
168       } // events loop   
169
170       free(event);
171     }
172
173   }//arg
174
175   /* write report */
176   printf("HMPID DA processed RUN #%s on LDC#%d, with %d calibration events\n",getenv("DATE_RUN_NUMBER"),ldcId,iEvtNcal);
177
178   if (!iEvtNcal) {
179     printf("No calibration events have been read. Exiting\n");
180     return -1;
181   }
182
183   /* report progress */
184   daqDA_progressReport(90);
185  
186   for(Int_t nDDL=0; nDDL < AliHMPIDRawStream::kNDDL; nDDL++) {
187     
188     /* Calculate pedestal for the given ddl, if there is no ddl go t next */
189     if(!pCal->CalcPedestal(nDDL,Form("./HmpidPedDdl%02i.txt",nDDL),iEvtNcal)) continue;
190     if(!pCal->WriteErrors(nDDL,Form("./HmpidErrorsDdl%02i.txt",nDDL),iEvtNcal)) continue;
191     
192     /* store the result file on FES */
193    
194     status=daqDA_FES_storeFile(Form("./HmpidPedDdl%02i.txt",nDDL),Form("HMPID_DA_Pedestals_ddl=%02i",nDDL));
195     if (status) { printf("Failed to export file : %d\n",status); }
196     status=daqDA_FES_storeFile(Form("./HmpidErrorsDdl%02i.txt",nDDL),Form("HMPID_DA_Errors_ddl=%02i",nDDL));
197     if (status) { printf("Failed to export file : %d\n",status); }
198     
199   }//nDDL
200
201   if(pCal->GetWritePads()==kTRUE) {
202       pCal->CloseFile((Int_t)ldcId);  
203       status=daqDA_FES_storeFile(Form("HmpidPadsOnLdc%2d.root",ldcId),Form("HMPID_PADS_ON_LDC=%2d",ldcId));
204     }
205   
206   delete pCal;  
207   if (status) return -1;
208   
209   /* report progress */
210   daqDA_progressReport(100);
211   
212   
213   return status;
214 }