]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/PHOSda.cxx
Zero version of PHOS DA (case2.c example from DAQ DA framework)
[u/mrichter/AliRoot.git] / PHOS / PHOSda.cxx
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 #include "daqDA.h"
22
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 // #include "AliRawReader.h"
27 // #include "AliRawReaderDate.h"
28
29
30 /* Main routine
31       Arguments: 
32       1- monitoring data source
33 */
34 int main(int argc, char **argv) {
35
36   int status;
37   
38   if (argc!=2) {
39     printf("Wrong number of arguments\n");
40     return -1;
41   }
42
43 //   AliRawReader* rawReader = new AliRawReaderDate(argv[1]);
44
45   /* open result file */
46   FILE *fp=NULL;
47   fp=fopen("./result.txt","a");
48   if (fp==NULL) {
49     printf("Failed to open file\n");
50     return -1;
51   }
52   
53
54   /* define data source : this is argument 1 */  
55   status=monitorSetDataSource( argv[1] );
56   if (status!=0) {
57     printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
58     return -1;
59   }
60
61
62   /* declare monitoring program */
63   status=monitorDeclareMp( __FILE__ );
64   if (status!=0) {
65     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
66     return -1;
67   }
68
69
70   /* define wait event timeout - 1s max */
71   monitorSetNowait();
72   monitorSetNoWaitNetworkTimeout(1000);
73   
74
75   /* log start of process */
76   printf("DA example case2 monitoring program started\n");  
77
78
79   /* init some counters */
80   int nevents_physics=0;
81   int nevents_total=0;
82
83   
84   /* main loop (infinite) */
85   for(;;) {
86     struct eventHeaderStruct *event;
87     eventTypeType eventT;
88   
89     /* check shutdown condition */
90     if (daqDA_checkShutdown()) {break;}
91     
92     /* get next event (blocking call until timeout) */
93     status=monitorGetEventDynamic((void **)&event);
94     if (status==MON_ERR_EOF) {
95       printf ("End of File detected\n");
96       break; /* end of monitoring file has been reached */
97     }
98     
99     if (status!=0) {
100       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
101       break;
102     }
103
104     /* retry if got no event */
105     if (event==NULL) {
106       continue;
107     }
108
109
110     /* use event - here, just write event id to result file */
111     eventT=event->eventType;
112     
113     if (eventT==PHYSICS_EVENT) {
114       fprintf(fp,"Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u\n",
115           (unsigned long)event->eventRunNb,
116         (unsigned long)event->eventSize,
117         EVENT_ID_GET_BUNCH_CROSSING(event->eventId),
118         EVENT_ID_GET_ORBIT(event->eventId),
119         EVENT_ID_GET_PERIOD(event->eventId)
120       );
121       nevents_physics++;
122     }
123     nevents_total++;
124
125
126     /* free resources */
127     free(event);
128     
129     /* exit when last event received, no need to wait for TERM signal */
130     if (eventT==END_OF_RUN) {
131       printf("EOR event detected\n");
132       break;
133     }
134   }
135
136
137   /* write report */
138   fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
139
140   /* close result file */
141   fclose(fp);
142
143
144   return status;
145 }