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