]>
Commit | Line | Data |
---|---|---|
8a0fbb82 | 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" | |
ae66f382 | 21 | extern "C" { |
8a0fbb82 | 22 | #include "daqDA.h" |
ae66f382 | 23 | } |
8a0fbb82 | 24 | |
25 | #include <stdio.h> | |
26 | #include <stdlib.h> | |
27 | ||
78794642 | 28 | #include <TSystem.h> |
29 | ||
9c86e3c0 | 30 | #include "AliRawReader.h" |
31 | #include "AliRawReaderDate.h" | |
32 | #include "AliPHOSCalibHistoProducer.h" | |
e5b0061a | 33 | #include "AliPHOSRawDecoder.h" |
78794642 | 34 | #include "AliCaloAltroMapping.h" |
8a0fbb82 | 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 | ||
8a0fbb82 | 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 | } | |
78794642 | 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 | } | |
8a0fbb82 | 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 | ||
e5b0061a | 101 | AliRawReader *rawReader = NULL; |
102 | ||
103 | AliPHOSCalibHistoProducer hp(200,0.,200.); | |
9c86e3c0 | 104 | hp.SetOldRCUFormat(kTRUE); |
e5b0061a | 105 | hp.SetUpdatingRate(200000); |
8a0fbb82 | 106 | |
107 | /* main loop (infinite) */ | |
108 | for(;;) { | |
109 | struct eventHeaderStruct *event; | |
110 | eventTypeType eventT; | |
111 | ||
112 | /* check shutdown condition */ | |
113 | if (daqDA_checkShutdown()) {break;} | |
114 | ||
115 | /* get next event (blocking call until timeout) */ | |
116 | status=monitorGetEventDynamic((void **)&event); | |
117 | if (status==MON_ERR_EOF) { | |
118 | printf ("End of File detected\n"); | |
119 | break; /* end of monitoring file has been reached */ | |
120 | } | |
121 | ||
122 | if (status!=0) { | |
123 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
124 | break; | |
125 | } | |
126 | ||
127 | /* retry if got no event */ | |
128 | if (event==NULL) { | |
129 | continue; | |
130 | } | |
131 | ||
132 | ||
133 | /* use event - here, just write event id to result file */ | |
134 | eventT=event->eventType; | |
135 | ||
136 | if (eventT==PHYSICS_EVENT) { | |
137 | fprintf(fp,"Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u\n", | |
138 | (unsigned long)event->eventRunNb, | |
139 | (unsigned long)event->eventSize, | |
140 | EVENT_ID_GET_BUNCH_CROSSING(event->eventId), | |
141 | EVENT_ID_GET_ORBIT(event->eventId), | |
142 | EVENT_ID_GET_PERIOD(event->eventId) | |
143 | ); | |
9c86e3c0 | 144 | |
e5b0061a | 145 | rawReader = new AliRawReaderDate((void*)event); |
78794642 | 146 | AliPHOSRawDecoder dc(rawReader,mapping); |
e5b0061a | 147 | dc.SubtractPedestals(kTRUE); |
148 | hp.SetRawDecoder(&dc); | |
9c86e3c0 | 149 | hp.Run(); |
78794642 | 150 | |
151 | delete rawReader; | |
9c86e3c0 | 152 | |
8a0fbb82 | 153 | nevents_physics++; |
154 | } | |
155 | nevents_total++; | |
156 | ||
8a0fbb82 | 157 | /* free resources */ |
158 | free(event); | |
159 | ||
160 | /* exit when last event received, no need to wait for TERM signal */ | |
161 | if (eventT==END_OF_RUN) { | |
162 | printf("EOR event detected\n"); | |
163 | break; | |
164 | } | |
165 | } | |
166 | ||
78794642 | 167 | for(Int_t i = 0; i < 4; i++) delete mapping[i]; |
8a0fbb82 | 168 | |
169 | /* write report */ | |
170 | fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total); | |
171 | ||
172 | /* close result file */ | |
173 | fclose(fp); | |
174 | ||
175 | ||
176 | return status; | |
177 | } |