]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/PHOSda.cxx
Comments are added
[u/mrichter/AliRoot.git] / PHOS / PHOSda.cxx
CommitLineData
8a0fbb82 1/*
2
3DAcase2.c
4
5This program connects to the DAQ data source passed as argument
6and populates local "./result.txt" file with the ids of events received
7during the run.
8
9The program exits when being asked to shut down (daqDA_checkshutdown)
10or End of Run event.
11
12Messages on stdout are exported to DAQ log system.
13
14contact: alice-datesupport@cern.ch
15
16*/
17
18
19#include "event.h"
20#include "monitor.h"
ae66f382 21extern "C" {
8a0fbb82 22#include "daqDA.h"
ae66f382 23}
8a0fbb82 24
25#include <stdio.h>
26#include <stdlib.h>
27
9c86e3c0 28#include "AliRawReader.h"
29#include "AliRawReaderDate.h"
30#include "AliPHOSCalibHistoProducer.h"
8a0fbb82 31
32
33/* Main routine
34 Arguments:
35 1- monitoring data source
36*/
37int main(int argc, char **argv) {
38
39 int status;
40
41 if (argc!=2) {
42 printf("Wrong number of arguments\n");
43 return -1;
44 }
45
8a0fbb82 46
47 /* open result file */
48 FILE *fp=NULL;
49 fp=fopen("./result.txt","a");
50 if (fp==NULL) {
51 printf("Failed to open file\n");
52 return -1;
53 }
54
55
56 /* define data source : this is argument 1 */
57 status=monitorSetDataSource( argv[1] );
58 if (status!=0) {
59 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
60 return -1;
61 }
62
63
64 /* declare monitoring program */
65 status=monitorDeclareMp( __FILE__ );
66 if (status!=0) {
67 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
68 return -1;
69 }
70
71
72 /* define wait event timeout - 1s max */
73 monitorSetNowait();
74 monitorSetNoWaitNetworkTimeout(1000);
75
76
77 /* log start of process */
78 printf("DA example case2 monitoring program started\n");
79
80
81 /* init some counters */
82 int nevents_physics=0;
83 int nevents_total=0;
84
9c86e3c0 85 AliPHOSCalibHistoProducer hp;
86 hp.SetOldRCUFormat(kTRUE);
87 hp.SetUpdatingRate(500);
8a0fbb82 88
89 /* main loop (infinite) */
90 for(;;) {
91 struct eventHeaderStruct *event;
92 eventTypeType eventT;
93
94 /* check shutdown condition */
95 if (daqDA_checkShutdown()) {break;}
96
97 /* get next event (blocking call until timeout) */
98 status=monitorGetEventDynamic((void **)&event);
99 if (status==MON_ERR_EOF) {
100 printf ("End of File detected\n");
101 break; /* end of monitoring file has been reached */
102 }
103
104 if (status!=0) {
105 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
106 break;
107 }
108
109 /* retry if got no event */
110 if (event==NULL) {
111 continue;
112 }
113
114
115 /* use event - here, just write event id to result file */
116 eventT=event->eventType;
117
118 if (eventT==PHYSICS_EVENT) {
119 fprintf(fp,"Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u\n",
120 (unsigned long)event->eventRunNb,
121 (unsigned long)event->eventSize,
122 EVENT_ID_GET_BUNCH_CROSSING(event->eventId),
123 EVENT_ID_GET_ORBIT(event->eventId),
124 EVENT_ID_GET_PERIOD(event->eventId)
125 );
9c86e3c0 126
127 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
128
129 hp.SetRawReader(rawReader);
130 hp.Run();
131
8a0fbb82 132 nevents_physics++;
133 }
134 nevents_total++;
135
136
137 /* free resources */
138 free(event);
139
140 /* exit when last event received, no need to wait for TERM signal */
141 if (eventT==END_OF_RUN) {
142 printf("EOR event detected\n");
143 break;
144 }
145 }
146
147
148 /* write report */
149 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
150
151 /* close result file */
152 fclose(fp);
153
154
155 return status;
156}