]>
Commit | Line | Data |
---|---|---|
6f14ad73 | 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 | |
ef7257c6 | 19 | #include "AliHMPIDRawStream.h" |
21f61e25 | 20 | #include "AliHMPIDCalib.h" |
6f14ad73 | 21 | #include "AliRawReaderDate.h" |
22 | #include "AliBitPacking.h" | |
23 | #include "TMath.h" | |
24 | ||
25 | //ROOT | |
26 | #include "TFile.h" | |
21f61e25 | 27 | #include "TSystem.h" |
6f14ad73 | 28 | #include "TKey.h" |
29 | #include "TH2S.h" | |
30 | #include "TObject.h" | |
31 | #include "TBenchmark.h" | |
32 | #include "TMath.h" | |
33 | #include "TRandom.h" | |
21f61e25 | 34 | |
6f14ad73 | 35 | |
36 | int main(int argc, char **argv){ | |
37 | ||
38 | int status; | |
39 | ||
1e7f6589 | 40 | /* log start of process */ |
41 | printf("HMPID DA program started\n"); | |
42 | ||
6f14ad73 | 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 | ||
1e7f6589 | 49 | /* copy locally a file from daq detector config db |
6f14ad73 | 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 | } | |
1e7f6589 | 55 | and possibly use it */ |
6f14ad73 | 56 | |
57 | /* report progress */ | |
58 | daqDA_progressReport(10); | |
59 | ||
60 | ||
21f61e25 | 61 | /* init the pedestal calculation */ |
62 | AliHMPIDCalib *pCal=new AliHMPIDCalib(); | |
21f61e25 | 63 | |
1e7f6589 | 64 | /* init event counter */ |
6f14ad73 | 65 | Int_t iEvtNcal=0; |
66 | ||
3e60bb92 | 67 | Int_t cnt=0; |
68 | ||
1e7f6589 | 69 | int n; |
70 | for (n=1;n<argc;n++) { | |
6f14ad73 | 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 | ||
1e7f6589 | 82 | for(;;) { // infinite loop |
6f14ad73 | 83 | struct eventHeaderStruct *event; |
84 | eventTypeType eventT; | |
85 | ||
86 | /* get next event */ | |
87 | status=monitorGetEventDynamic((void **)&event); | |
3e60bb92 | 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 | ||
6f14ad73 | 95 | if (status!=0) { |
96 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
ef7257c6 | 97 | return -1; |
6f14ad73 | 98 | } |
99 | ||
100 | /* retry if got no event */ | |
101 | if (event==NULL) { | |
3e60bb92 | 102 | //break; |
103 | continue; | |
6f14ad73 | 104 | } |
105 | ||
106 | /* use event - here, just write event id to result file */ | |
107 | eventT=event->eventType; | |
108 | ||
21f61e25 | 109 | if (eventT==PHYSICS_EVENT) { //we use PHYSICS_EVENT for pedestal not CALIBRATION_EVENT |
6f14ad73 | 110 | |
111 | iEvtNcal++; | |
3e60bb92 | 112 | |
ef7257c6 | 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"); | |
6f14ad73 | 119 | |
ef7257c6 | 120 | AliHMPIDRawStream stream(reader); |
121 | ||
122 | while(stream.Next()) { | |
3e60bb92 | 123 | Int_t nDDL=stream.GetDDLNumber(); |
21f61e25 | 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++){ | |
3e60bb92 | 127 | pCal->FillPedestal(nDDL,row,dil,pad,stream.GetCharge(nDDL,row,dil,pad)); |
21f61e25 | 128 | }//pad |
129 | }//dil | |
130 | }//row | |
ef7257c6 | 131 | } //raw data loop |
6f14ad73 | 132 | |
ef7257c6 | 133 | delete reader; |
6f14ad73 | 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 | ||
1e7f6589 | 144 | free(event); |
145 | } | |
6f14ad73 | 146 | |
3e60bb92 | 147 | }//arg |
6f14ad73 | 148 | |
1e7f6589 | 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"); | |
6f14ad73 | 154 | return -1; |
155 | } | |
156 | ||
157 | /* report progress */ | |
1e7f6589 | 158 | daqDA_progressReport(90); |
6f14ad73 | 159 | |
3e60bb92 | 160 | for(Int_t nDDL=0; nDDL < AliHMPIDCalib::kNDDL; nDDL++) { |
21f61e25 | 161 | |
162 | /* Calculate pedestal for the given ddl, if there is no ddl go t next */ | |
3e60bb92 | 163 | if(!pCal->CalcPedestal(nDDL,Form("./HmpidPedDdl%02i.txt",nDDL),iEvtNcal)) continue; |
21f61e25 | 164 | |
1e7f6589 | 165 | /* store the result file on FES */ |
3e60bb92 | 166 | |
167 | status=daqDA_FES_storeFile(Form("./HmpidPedDdl%02i.txt",nDDL),Form("HMPID_DA_Pedestals_ddl=%02i",nDDL)); | |
1e7f6589 | 168 | if (status) { |
169 | printf("Failed to export file : %d\n",status); | |
170 | return -1; | |
171 | } | |
3e60bb92 | 172 | |
173 | }//nDDL | |
174 | ||
1e7f6589 | 175 | /* report progress */ |
176 | daqDA_progressReport(100); | |
6f14ad73 | 177 | |
1e7f6589 | 178 | return status; |
6f14ad73 | 179 | } |