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