]>
Commit | Line | Data |
---|---|---|
c810e10b | 1 | /* |
2 | ||
3 | DAcase2.c | |
4 | ||
5 | This program connects to the DAQ data source passed as argument | |
6 | and populates local "./result.txt" file with the ids of events received | |
7 | during the run. | |
8 | ||
9 | The program exits when being asked to shut down (daqDA_checkshutdown) | |
10 | or End of Run event. | |
11 | ||
12 | Messages on stdout are exported to DAQ log system. | |
13 | ||
14 | contact: alice-datesupport@cern.ch | |
15 | ||
16 | */ | |
17 | ||
18 | ||
19 | #include "event.h" | |
20 | #include "monitor.h" | |
21 | extern "C" { | |
22 | #include "daqDA.h" | |
23 | } | |
24 | ||
25 | #include <stdio.h> | |
26 | #include <stdlib.h> | |
27 | ||
28 | #include <TSystem.h> | |
29 | ||
30 | #include "AliRawReader.h" | |
31 | #include "AliRawReaderDate.h" | |
4d005f39 | 32 | #include "AliPHOSDA1.h" |
c810e10b | 33 | #include "AliPHOSRawDecoderv1.h" |
34 | #include "AliCaloAltroMapping.h" | |
35 | ||
36 | ||
37 | /* Main routine | |
38 | Arguments: | |
39 | 1- monitoring data source | |
40 | */ | |
41 | int main(int argc, char **argv) { | |
42 | ||
43 | int status; | |
44 | ||
45 | if (argc!=2) { | |
46 | printf("Wrong number of arguments\n"); | |
47 | return -1; | |
48 | } | |
49 | ||
50 | ||
51 | /* open result file */ | |
52 | FILE *fp=NULL; | |
53 | fp=fopen("./result.txt","a"); | |
54 | if (fp==NULL) { | |
55 | printf("Failed to open file\n"); | |
56 | return -1; | |
57 | } | |
58 | ||
59 | /* Open mapping files */ | |
60 | AliAltroMapping *mapping[4]; | |
61 | TString path = gSystem->Getenv("ALICE_ROOT"); | |
62 | path += "/PHOS/mapping/RCU"; | |
63 | TString path2; | |
64 | for(Int_t i = 0; i < 4; i++) { | |
65 | path2 = path; | |
66 | path2 += i; | |
67 | path2 += ".data"; | |
68 | mapping[i] = new AliCaloAltroMapping(path2.Data()); | |
69 | } | |
70 | ||
71 | ||
72 | /* define data source : this is argument 1 */ | |
73 | status=monitorSetDataSource( argv[1] ); | |
74 | if (status!=0) { | |
75 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
76 | return -1; | |
77 | } | |
78 | ||
79 | ||
80 | /* declare monitoring program */ | |
81 | status=monitorDeclareMp( __FILE__ ); | |
82 | if (status!=0) { | |
83 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
84 | return -1; | |
85 | } | |
86 | ||
87 | ||
88 | /* define wait event timeout - 1s max */ | |
89 | monitorSetNowait(); | |
90 | monitorSetNoWaitNetworkTimeout(1000); | |
91 | ||
92 | ||
93 | /* log start of process */ | |
94 | printf("DA example case2 monitoring program started\n"); | |
95 | ||
96 | ||
97 | /* init some counters */ | |
98 | int nevents_physics=0; | |
99 | int nevents_total=0; | |
100 | ||
101 | AliRawReader *rawReader = NULL; | |
102 | ||
103 | AliPHOSDA1 da1(2); // DA1 (Calibration DA) for module2 | |
104 | ||
105 | Float_t e[64][56][2]; | |
106 | Float_t t[64][56][2]; | |
107 | ||
108 | Int_t gain = -1; | |
109 | Int_t X = -1; | |
110 | Int_t Z = -1; | |
111 | ||
112 | /* main loop (infinite) */ | |
113 | for(;;) { | |
114 | struct eventHeaderStruct *event; | |
115 | eventTypeType eventT; | |
116 | ||
117 | /* check shutdown condition */ | |
118 | if (daqDA_checkShutdown()) {break;} | |
119 | ||
120 | /* get next event (blocking call until timeout) */ | |
121 | status=monitorGetEventDynamic((void **)&event); | |
122 | if (status==MON_ERR_EOF) { | |
123 | printf ("End of File detected\n"); | |
124 | break; /* end of monitoring file has been reached */ | |
125 | } | |
126 | ||
127 | if (status!=0) { | |
128 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
129 | break; | |
130 | } | |
131 | ||
132 | /* retry if got no event */ | |
133 | if (event==NULL) { | |
134 | continue; | |
135 | } | |
136 | ||
137 | ||
138 | /* use event - here, just write event id to result file */ | |
139 | eventT=event->eventType; | |
140 | ||
141 | if (eventT==PHYSICS_EVENT) { | |
142 | fprintf(fp,"Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u\n", | |
143 | (unsigned long)event->eventRunNb, | |
144 | (unsigned long)event->eventSize, | |
145 | EVENT_ID_GET_BUNCH_CROSSING(event->eventId), | |
146 | EVENT_ID_GET_ORBIT(event->eventId), | |
147 | EVENT_ID_GET_PERIOD(event->eventId) | |
148 | ); | |
149 | ||
150 | for(Int_t iX=0; iX<64; iX++) { | |
151 | for(Int_t iZ=0; iZ<56; iZ++) { | |
152 | for(Int_t iGain=0; iGain<2; iGain++) { | |
153 | e[iX][iZ][iGain] = 0.; | |
154 | t[iX][iZ][iGain] = 0.; | |
155 | } | |
156 | } | |
157 | } | |
158 | ||
159 | rawReader = new AliRawReaderDate((void*)event); | |
160 | AliPHOSRawDecoderv1 dc(rawReader,mapping); | |
161 | dc.SubtractPedestals(kTRUE); | |
162 | dc.SetOldRCUFormat(kTRUE); | |
163 | ||
164 | while(dc.NextDigit()) { | |
165 | ||
166 | X = dc.GetRow() - 1; | |
167 | Z = dc.GetColumn() - 1; | |
168 | ||
169 | if(dc.IsLowGain()) gain = 0; | |
170 | else | |
171 | gain = 1; | |
172 | ||
173 | e[X][Z][gain] = dc.GetEnergy(); | |
174 | t[X][Z][gain] = dc.GetTime(); | |
175 | ||
176 | } | |
177 | ||
178 | da1.FillHistograms(e,t); | |
179 | //da1.UpdateHistoFile(); | |
180 | ||
181 | delete rawReader; | |
182 | nevents_physics++; | |
183 | } | |
184 | ||
185 | nevents_total++; | |
186 | ||
187 | /* free resources */ | |
188 | free(event); | |
189 | ||
190 | /* exit when last event received, no need to wait for TERM signal */ | |
191 | if (eventT==END_OF_RUN) { | |
192 | printf("EOR event detected\n"); | |
193 | break; | |
194 | } | |
195 | } | |
196 | ||
197 | for(Int_t i = 0; i < 4; i++) delete mapping[i]; | |
198 | ||
199 | /* write report */ | |
200 | fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total); | |
201 | ||
202 | /* close result file */ | |
203 | fclose(fp); | |
204 | ||
205 | ||
206 | return status; | |
207 | } |