]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/TPCda.cxx
Initialisation.
[u/mrichter/AliRoot.git] / TPC / TPCda.cxx
1 /*
2
3
4 TPCda.cxx - calibration algorithm to be run on GDC
5 DAcase2.c
6
7 AliTPCCalibPulser   - pulser signal calibration
8 AliTPCCalibPedestal - pedestal and noise calibration
9 AliTPCCalibCE       - CE time and amplitude calibration
10
11
12 contact: marian.ivanov@cern.ch
13
14
15 This program connects to the DAQ data source passed as argument
16 and populates local "./result.txt" file with the ids of events received
17 during the run.
18
19 The program exits when being asked to shut down (daqDA_checkshutdown)
20 or End of Run event.
21
22 Messages on stdout are exported to DAQ log system.
23
24 contact: alice-datesupport@cern.ch
25
26 */
27
28 extern "C" {
29 #include <daqDA.h>
30 }
31
32 #include "event.h"
33 #include "monitor.h"
34 #include <stdio.h>
35 #include <stdlib.h>
36
37
38 //
39 //Root includes
40 //
41 #include <TObjArray.h>
42 #include <TH1F.h>
43 #include <TH1D.h>
44 #include <TH2F.h>
45 #include <TH2S.h>
46 #include <TH1S.h>
47 #include <TString.h>
48 #include <TVectorF.h>
49 #include <TMath.h>
50 #include <TF1.h>
51 #include <TRandom.h>
52 #include <TROOT.h>
53 #include <TDirectory.h>
54 #include <TSystem.h>
55 #include <TFile.h>
56 //
57 //AliRoot includes
58 //
59 #include "AliRawReader.h"
60 #include "AliRawReaderDate.h"
61 #include "AliTPCRawStream.h"
62 #include "AliTPCROC.h"
63 #include "AliTPCCalROC.h"
64 #include "AliTPCCalPad.h"
65 #include "AliMathBase.h"
66 #include "TTreeStream.h"
67 //
68 // TPC calibration algorithm includes
69 //
70 #include "AliTPCCalibPedestal.h"
71 #include "AliTPCCalibPulser.h"
72
73
74
75
76 /* Main routine
77       Arguments: 
78       1- monitoring data source
79 */
80 int main(int argc, char **argv) {
81
82   int status;
83   AliTPCCalibPulser   calibSignal;     // pulser calibration 
84   AliTPCCalibPedestal calibPedestal;   // pedestal and nosie calibration
85
86   if (argc!=2) {
87     printf("Wrong number of arguments\n");
88     return -1;
89   }
90
91
92   /* open result file */
93   FILE *fp=NULL;
94   fp=fopen("./result.txt","a");
95   if (fp==NULL) {
96     printf("Failed to open file\n");
97     return -1;
98   }
99   
100
101   /* define data source : this is argument 1 */  
102   status=monitorSetDataSource( argv[1] );
103   if (status!=0) {
104     printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
105     return -1;
106   }
107
108
109   /* declare monitoring program */
110   status=monitorDeclareMp( __FILE__ );
111   if (status!=0) {
112     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
113     return -1;
114   }
115
116
117   /* define wait event timeout - 1s max */
118   monitorSetNowait();
119   monitorSetNoWaitNetworkTimeout(1000);
120   
121
122   /* log start of process */
123   printf("DA example case2 monitoring program started\n");  
124
125
126   /* init some counters */
127   int nevents_physics=0;
128   int nevents_total=0;
129
130   
131   /* main loop (infinite) */
132   for(;;) {
133     struct eventHeaderStruct *event;
134     eventTypeType eventT;
135   
136     /* check shutdown condition */
137     if (daqDA_checkShutdown()) {break;}
138     
139     /* get next event (blocking call until timeout) */
140     status=monitorGetEventDynamic((void **)&event);
141     if (status==MON_ERR_EOF) {
142       printf ("End of File detected\n");
143       break; /* end of monitoring file has been reached */
144     }
145     
146     if (status!=0) {
147       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
148       break;
149     }
150
151     /* retry if got no event */
152     if (event==NULL) {
153       continue;
154     }
155
156
157     /* use event - here, just write event id to result file */
158     eventT=event->eventType;
159     //
160     //  PULSER calibration
161     //
162     //    if (eventT==PULSER_EVENT){   // i don't know the ID
163     {
164       AliRawReader *rawReader = new AliRawReaderDate((void*)event);
165       calibSignal.ProcessEvent(rawReader);
166       delete rawReader;
167     }
168     //}
169     //
170     //  Pedestal calibration calibration
171     //
172     //    if (eventT==BLACK_EVENT){   // i don't know the ID
173     {
174       AliRawReader *rawReader = new AliRawReaderDate((void*)event);
175       calibPedestal.ProcessEvent(rawReader);
176       delete rawReader;
177     }
178     //}
179     
180
181     if (eventT==PHYSICS_EVENT) {
182       fprintf(fp,"Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u\n",
183         (unsigned long)event->eventRunNb,
184         (unsigned long)event->eventSize,
185         EVENT_ID_GET_BUNCH_CROSSING(event->eventId),
186         EVENT_ID_GET_ORBIT(event->eventId),
187         EVENT_ID_GET_PERIOD(event->eventId)
188       );
189       nevents_physics++;
190     }
191     nevents_total++;
192
193
194     /* free resources */
195     free(event);
196     
197     /* exit when last event received, no need to wait for TERM signal */
198     if (eventT==END_OF_RUN) {
199       printf("EOR event detected\n");
200       calibPedestal.Analyse();
201       calibSignal.Analyse();
202       break;
203     }
204   }
205
206   TFile * fileTPC = new TFile ("tpcCalibration.root","recreate");
207   calibPedestal.Write("calibPedestal");
208   calibSignal.Write("calibSignal");
209   delete fileTPC;
210   //
211   //
212   /* write report */
213   fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
214
215   /* close result file */
216   fclose(fp);
217
218
219   return status;
220 }