Cleanup
[u/mrichter/AliRoot.git] / TRD / TRDda.cxx
CommitLineData
170c35f1 1/*
2
3
4TRDda.cxx - calibration algorithm to be run on monitoring server
5DAcase2.c
6
7AliTRDCalibraFillHisto - average pulse height/ vdrift calibration
8AliTRDCalibPadStatus - pad status calibration
9
10
11This program connects to the DAQ data source passed as argument
12and populates local "./result.txt" file with the ids of events received
13during the run.
14
15The program exits when being asked to shut down (daqDA_checkshutdown)
16or End of Run event.
17
18Messages on stdout are exported to DAQ log system.
19
20contact: alice-datesupport@cern.ch
21
22*/
23
24extern "C" {
25#include <daqDA.h>
26}
27
28#include "event.h"
29#include "monitor.h"
30#include <stdio.h>
31#include <stdlib.h>
32
33
34//
35//Root includes
36//
37#include <TObjArray.h>
38#include <TString.h>
39#include <TVectorF.h>
40#include <TROOT.h>
41#include <TDirectory.h>
42#include <TSystem.h>
43#include <TFile.h>
44//
45//AliRoot includes
46//
47#include "AliRawReader.h"
48#include "AliRawReaderDate.h"
49#include "AliTRDRawStream.h"
50#include "AliCDBManager.h"
51
52//
53// TRD calibration algorithm includes
54//
55#include "AliTRDCalibPadStatus.h"
56#include "AliTRDCalibraFillHisto.h"
57
58
59
60
61/* Main routine
62 Arguments:
63 1- monitoring data source
64*/
65int main(int argc, char **argv) {
66
67 int status;
68
69 if (argc!=2) {
70 printf("Wrong number of arguments\n");
71 return -1;
72 }
73
74
75 /* define data source : this is argument 1 */
76 status=monitorSetDataSource( argv[1] );
77 if (status!=0) {
78 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
79 return -1;
80 }
81
82
83 /* declare monitoring program */
84 status=monitorDeclareMp( __FILE__ );
85 if (status!=0) {
86 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
87 return -1;
88 }
89
90
91 /* define wait event timeout - 1s max */
92 monitorSetNowait();
93 monitorSetNoWaitNetworkTimeout(1000);
94
95
96 /* log start of process */
97 printf("DA example case2 monitoring program started\n");
98
99
100 /* init some counters */
101 int nevents_physics=0;
102 int nevents_total=0;
103
104 //Instance of AliCDBManager: needed by AliTRDRawStream
105 AliCDBManager *man = AliCDBManager::Instance();
106 man->SetDefaultStorage("local://$ALICE_ROOT");
107 man->SetRun(0);
108 //Instance of AliTRDCalibraFillHisto
109 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
110 //AliTRDCalibPadStatus
111 AliTRDCalibPadStatus calibpad = AliTRDCalibPadStatus();
112 // pad status on: no zero suppression (special runs)
113 Bool_t passpadstatus = kTRUE;
114 // everythings are okey for vdrift
3a0f6479 115 Bool_t passvdrift = kTRUE; // if timebin okey
116 Int_t nbvdrift = 0; // number of events with entries for vdrift
170c35f1 117
118
119 /* main loop (infinite) */
120 for(;;) {
121 //for(Int_t k = 0; k < 20; k++) {
122 struct eventHeaderStruct *event;
123 eventTypeType eventT;
124
125 /* check shutdown condition */
126 if (daqDA_checkShutdown()) {break;}
127
128 /* get next event (blocking call until timeout) */
129 status=monitorGetEventDynamic((void **)&event);
130 if (status==MON_ERR_EOF) {
131 printf ("End of File detected\n");
132 break; /* end of monitoring file has been reached */
133 }
134
135 if (status!=0) {
136 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
137 break;
138 }
139
140 /* retry if got no event */
141 if (event==NULL) {
142 continue;
143 }
144
145 printf(" physic event number %d will be processed\n",(Int_t) nevents_physics);
146
147
148 /* use event - here, just write event id to result file */
149 eventT=event->eventType;
150 //
151 // pad status calibration: we try a first time to see if zero suppressed or not
152 //
153 if(passpadstatus){
154 printf("pad status calibration\n");
155 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
156 AliTRDRawStream *trdRawStream = new AliTRDRawStream((AliRawReader *) rawReader);
3a0f6479 157 if(!calibpad.ProcessEvent(trdRawStream),(Bool_t)nevents_total)) passpadstatus = kFALSE;
170c35f1 158
159 delete trdRawStream;
160 delete rawReader;
161 }
162 //
163 // vdrift calibration: run only for physics events
164 //
3a0f6479 165 if ((eventT==PHYSICS_EVENT) && (!passpadstatus) && (passvdrift)) {
170c35f1 166 //if (eventT==PHYSICS_EVENT) {
167 printf("vdrift calibration\n");
168 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
169 AliTRDRawStream *trdRawStream = new AliTRDRawStream((AliRawReader *) rawReader);
3a0f6479 170 Int_t result = calibra->ProcessEventDAQ(trdRawStream,(Bool_t)nevents_physics);
171 if(!result) passvdrift = kFALSE;
172 else nbvdrift += (Int_t) result/2;
173
170c35f1 174
175 nevents_physics++;
176
177 delete trdRawStream;
178 delete rawReader;
179 }
180
181
182 nevents_total++;
183
184
185 /* free resources */
186 free(event);
187
188 /* exit when last event received, no need to wait for TERM signal */
189 if (eventT==END_OF_RUN) {
190 printf("EOR event detected\n");
191 break;
192 }
193 }
194
195 //
196 // Write a local file and put it on the FX
197 //
198 TFile *fileTRD = new TFile("trdCalibration.root","recreate");
199 Bool_t passwrite = kFALSE;
200 //
201 // pad status
202 //
203 if(passpadstatus){
204 // We do this at the shuttle maybe!
205 //calibpad.AnalyseHisto();
206 //AliTRDCalPadStatus *calPadStatus = calibpad.CreateCalPadStatus();
207 calibpad.Write("calibpadstatus");
208 passwrite = kTRUE;
209 }
210 //
211 // vdrift
212 //
3a0f6479 213 if((nbvdrift > 0) && passvdrift){
170c35f1 214 Double_t *stat = calibra->StatH((TH2 *)(calibra->GetPH2d()),1);
215 // write only of enough statistics
216 if(stat[6] < 0.20) {
217 calibra->GetPH2d()->Write();
218 passwrite = kTRUE;
219 }
220
221 }
222 fileTRD->Close();
223 status=0;
224 if(passwrite) {
225 if(daqDA_FES_storeFile("trdCalibration.root","trdCalibration.root")) status = -2;
226 }
227 delete fileTRD;
228
229 return status;
230}