]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/TRDda.cxx
7d5f8dbee1d10371395701be9e6669725a6af0d8
[u/mrichter/AliRoot.git] / TRD / TRDda.cxx
1 /*
2
3
4 TRDda.cxx - calibration algorithm to be run on monitoring server
5 DAcase2.c
6
7 AliTRDCalibraFillHisto - average pulse height/ vdrift calibration
8 AliTRDCalibPadStatus - pad status calibration
9
10
11 This program connects to the DAQ data source passed as argument
12 and populates local "./result.txt" file with the ids of events received
13 during the run.
14
15 The program exits when being asked to shut down (daqDA_checkshutdown)
16 or End of Run event.
17
18 Messages on stdout are exported to DAQ log system.
19
20 contact: alice-datesupport@cern.ch
21
22 */
23
24 extern "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 */
65 int 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
115   Bool_t passvdrift  = kTRUE;    // if timebin okey
116   Int_t  nbvdrift    = 0;     // number of events with entries for vdrift
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(" event number %d (physic event number %d) will be processed\n",(Int_t) nevents_total,(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);
157       if(!calibpad.ProcessEvent(trdRawStream,(Bool_t)nevents_total)) passpadstatus = kFALSE;
158       
159       delete trdRawStream;
160       delete rawReader;
161     }
162     //
163     // vdrift calibration: run only for physics events
164     //
165     if ((eventT==PHYSICS_EVENT) && (!passpadstatus)  && (passvdrift)) {
166       //if (eventT==PHYSICS_EVENT) {
167       printf("vdrift calibration\n");
168       AliRawReader *rawReader = new AliRawReaderDate((void*)event);
169       AliTRDRawStream *trdRawStream = new AliTRDRawStream((AliRawReader *) rawReader);
170       Int_t result = calibra->ProcessEventDAQ(trdRawStream,(Bool_t)nevents_physics);
171       if(!result) passvdrift = kFALSE;
172       else nbvdrift += (Int_t) result/2;
173              
174       
175       delete trdRawStream;
176       delete rawReader;
177     } 
178    
179     if(eventT==PHYSICS_EVENT){
180  
181       nevents_physics++;
182      
183     }
184     
185     nevents_total++;
186
187
188     /* free resources */
189     free(event);
190     
191     /* exit when last event received, no need to wait for TERM signal */
192     if (eventT==END_OF_RUN) {
193       printf("EOR event detected\n");
194       break;
195     }
196   }
197
198   //
199   // Write a local file and put it on the FX 
200   //
201   TFile  *fileTRD     = new TFile("trdCalibration.root","recreate");
202   Bool_t passwrite   = kFALSE;
203   //
204   // pad status
205   //
206   if(passpadstatus){
207     // We do this at the shuttle maybe!
208     //calibpad.AnalyseHisto();
209     //AliTRDCalPadStatus *calPadStatus = calibpad.CreateCalPadStatus();
210     calibpad.Write("calibpadstatus");
211     passwrite  = kTRUE; 
212   }
213   //
214   // vdrift
215   //
216   if((nbvdrift > 0) && passvdrift){
217     Double_t *stat = calibra->StatH((TH2 *)(calibra->GetPH2d()),1);
218     // write only of enough statistics
219     if((stat[6] < 0.20) && (stat[5] > 3000.0)) {
220       calibra->GetPH2d()->Write();
221       passwrite = kTRUE;
222     }
223     
224   }
225   fileTRD->Close();
226   status=0;
227   if(passwrite) {
228     if(daqDA_FES_storeFile("trdCalibration.root","trdCalibration.root")) status = -2;
229   }
230   delete fileTRD;  
231
232   return status;
233 }