]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PMD/PMDda.cxx
macro to generate gain and ped files
[u/mrichter/AliRoot.git] / PMD / PMDda.cxx
CommitLineData
24e8f6b2 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*/
17extern "C" {
18#include <daqDA.h>
19}
20
21#include "event.h"
22#include "monitor.h"
23//#include "daqDA.h"
24
25#include <Riostream.h>
26#include <stdio.h>
27#include <stdlib.h>
28
29//AliRoot
30#include "AliRawReaderDate.h"
31#include "AliPMDCalibPedestal.h"
32
33//ROOT
34#include "TFile.h"
35#include "TH1F.h"
36#include "TBenchmark.h"
37
38
39/* Main routine
40 Arguments:
41 1- monitoring data source
42*/
43int main(int argc, char **argv) {
44
45 AliPMDCalibPedestal calibped;
46
47 TH1F::AddDirectory(0);
48
49
50 // decoding the events
51
52 int status;
53
54 if (argc!=2) {
55 printf("Wrong number of arguments\n");
56 return -1;
57 }
58
59 /* open result file */
60 FILE *fp=NULL;
61 fp=fopen("./result.txt","a");
62 if (fp==NULL) {
63 printf("Failed to open file\n");
64 return -1;
65 }
66
67 /* define data source : this is argument 1 */
68 status=monitorSetDataSource( argv[1] );
69 if (status!=0) {
70 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
71 return -1;
72 }
73
74 /* declare monitoring program */
75 status=monitorDeclareMp( __FILE__ );
76 if (status!=0) {
77 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
78 return -1;
79 }
80
81 /* define wait event timeout - 1s max */
82 monitorSetNowait();
83 monitorSetNoWaitNetworkTimeout(1000);
84
85 /* log start of process */
86 printf("DA example case2 monitoring program started\n");
87
88 /* init some counters */
89 int nevents_physics=0;
90 int nevents_total=0;
91
92 struct eventHeaderStruct *event;
93 eventTypeType eventT;
94 Int_t iev=0;
95
96 /* main loop (infinite) */
97 for(;;) {
98
99 /* check shutdown condition */
100 if (daqDA_checkShutdown()) {break;}
101
102 /* get next event (blocking call until timeout) */
103 status=monitorGetEventDynamic((void **)&event);
104 if (status==MON_ERR_EOF) {
105 printf ("End of File detected\n");
106 break; /* end of monitoring file has been reached */
107 }
108
109 if (status!=0) {
110 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
111 break;
112 }
113
114 /* retry if got no event */
115 if (event==NULL) {
116 continue;
117 }
118
119 iev++;
120
121 /* use event - here, just write event id to result file */
122 eventT=event->eventType;
123 switch (event->eventType){
124
125 /* START OF RUN */
126 case START_OF_RUN:
127 break;
128 /* END START OF RUN */
129
130 /* END OF RUN */
131 case END_OF_RUN:
132 break;
133
134 case PHYSICS_EVENT:
135 printf(" event number = %i \n",iev);
136 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
137 calibped.ProcessEvent(rawReader);
138
139 delete rawReader;
140 rawReader = 0x0;
141
142 }
143
144 /* free resources */
145 free(event);
146
147 /* exit when last event received, no need to wait for TERM signal */
148 if (eventT==END_OF_RUN) {
149 printf("EOR event detected\n");
150 calibped.Analyse();
151
152
153
154 break;
155 }
156 }
157
158 //write the Run level file
159 TFile * fileRun = new TFile ("outPMDdaRun.root","RECREATE");
160 TBenchmark *bench = new TBenchmark();
161 bench->Start("PMD");
162 bench->Stop("PMD");
163 bench->Print("PMD");
164 fileRun->Close();
165
166 /* write report */
167 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
168
169 /* close result file */
170 fclose(fp);
171
172
173 return status;
174}