]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/PHOSda.cxx
First working version (histograms with energy deposition in crystals)
[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 #include "AliPHOSCalibHistoProducer.h"
29
30
31 /* Main routine
32       Arguments: 
33       1- monitoring data source
34 */
35 int main(int argc, char **argv) {
36
37   int status;
38   
39   if (argc!=2) {
40     printf("Wrong number of arguments\n");
41     return -1;
42   }
43
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   AliPHOSCalibHistoProducer hp;
84   hp.SetOldRCUFormat(kTRUE);
85   hp.SetUpdatingRate(500);
86   
87   /* main loop (infinite) */
88   for(;;) {
89     struct eventHeaderStruct *event;
90     eventTypeType eventT;
91   
92     /* check shutdown condition */
93     if (daqDA_checkShutdown()) {break;}
94     
95     /* get next event (blocking call until timeout) */
96     status=monitorGetEventDynamic((void **)&event);
97     if (status==MON_ERR_EOF) {
98       printf ("End of File detected\n");
99       break; /* end of monitoring file has been reached */
100     }
101     
102     if (status!=0) {
103       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
104       break;
105     }
106
107     /* retry if got no event */
108     if (event==NULL) {
109       continue;
110     }
111
112
113     /* use event - here, just write event id to result file */
114     eventT=event->eventType;
115     
116     if (eventT==PHYSICS_EVENT) {
117       fprintf(fp,"Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u\n",
118           (unsigned long)event->eventRunNb,
119         (unsigned long)event->eventSize,
120         EVENT_ID_GET_BUNCH_CROSSING(event->eventId),
121         EVENT_ID_GET_ORBIT(event->eventId),
122         EVENT_ID_GET_PERIOD(event->eventId)
123       );
124       
125       AliRawReader *rawReader = new AliRawReaderDate((void*)event);
126
127       hp.SetRawReader(rawReader);
128       hp.Run();
129       
130       nevents_physics++;
131     }
132     nevents_total++;
133
134
135     /* free resources */
136     free(event);
137     
138     /* exit when last event received, no need to wait for TERM signal */
139     if (eventT==END_OF_RUN) {
140       printf("EOR event detected\n");
141       break;
142     }
143   }
144
145
146   /* write report */
147   fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
148
149   /* close result file */
150   fclose(fp);
151
152
153   return status;
154 }