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