]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/TRDVDRIFTda.cxx
Modifications in the calibration/preprocessor for new raw data version
[u/mrichter/AliRoot.git] / TRD / TRDVDRIFTda.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 #define RESULT_FILE "trdCalibrationv.root"
25
26
27 extern "C" {
28 #include <daqDA.h>
29 }
30
31 #include "event.h"
32 #include "monitor.h"
33 #include <stdio.h>
34 #include <stdlib.h>
35
36
37 //
38 //Root includes
39 //
40 #include <TObjArray.h>
41 #include <TString.h>
42 #include <TVectorF.h>
43 #include <TROOT.h>
44 #include <TDirectory.h>
45 #include <TSystem.h>
46 #include <TFile.h>
47 //
48 //AliRoot includes
49 //
50 #include "AliRawReader.h"
51 #include "AliRawReaderDate.h"
52 #include "AliTRDRawStreamV2.h"
53 #include "AliCDBManager.h"
54
55 //
56 // TRD calibration algorithm includes
57 //
58 #include "AliTRDCalibraFillHisto.h"
59
60
61
62
63 /* Main routine
64       Arguments: 
65       1- monitoring data source
66 */
67 int main(int argc, char **argv) {
68
69   int status;
70
71   if (argc!=2) {
72     printf("Wrong number of arguments\n");
73     return -1;
74   }
75
76
77   /* define data source : this is argument 1 */  
78   status=monitorSetDataSource( argv[1] );
79   if (status!=0) {
80     printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
81     return -1;
82   }
83
84
85   /* declare monitoring program */
86   status=monitorDeclareMp( __FILE__ );
87   if (status!=0) {
88     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
89     return -1;
90   }
91
92
93   /* define wait event timeout - 1s max */
94   monitorSetNowait();
95   monitorSetNoWaitNetworkTimeout(1000);
96   
97
98   /* log start of process */
99   printf("TRD DA VDRIFT started\n");  
100
101
102   /* init some counters */
103   int nevents_physics=0;
104   int nevents_total=0;
105
106   //Instance of AliCDBManager: needed by AliTRDRawStreamV2
107   AliCDBManager *man = AliCDBManager::Instance();
108   man->SetDefaultStorage("local://$ALICE_ROOT");
109   man->SetRun(0);
110   //Instance of AliTRDCalibraFillHisto
111   AliTRDCalibraFillHisto *calibra      = AliTRDCalibraFillHisto::Instance();
112   // everythings are okey for vdrift
113   Bool_t passvdrift  = kTRUE;    // if timebin okey
114   Int_t  nbvdrift    = 0;     // number of events with entries for vdrift
115
116   
117   /* main loop (infinite) */
118   for(;;) {
119   //for(Int_t k = 0; k < 20; k++) {
120     struct eventHeaderStruct *event;
121     eventTypeType eventT;
122
123     /* check shutdown condition */
124     if (daqDA_checkShutdown()) {break;}
125     
126     /* get next event (blocking call until timeout) */
127     status=monitorGetEventDynamic((void **)&event);
128     if (status==MON_ERR_EOF) {
129       printf ("End of File detected\n");
130       break; /* end of monitoring file has been reached */
131     }
132     
133     if (status!=0) {
134       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
135       break;
136     }
137
138     /* retry if got no event */
139     if (event==NULL) {
140       continue;
141     }
142
143     if( ((Int_t)nevents_total)%100 == 0 ) printf(" event number %d (physic event number %d) will be processed\n",(Int_t) nevents_total,(Int_t) nevents_physics);  
144
145
146     /* use event - here, just write event id to result file */
147     eventT=event->eventType;
148     
149     //
150     // vdrift calibration: run only for physics events
151     //
152     if ((eventT==PHYSICS_EVENT) && (passvdrift)) {
153       //if (eventT==PHYSICS_EVENT) {
154       AliRawReader *rawReader = new AliRawReaderDate((void*)event);
155       AliTRDRawStreamV2 *trdRawStream = new AliTRDRawStreamV2((AliRawReader *) rawReader);
156       Int_t result = calibra->ProcessEventDAQ(trdRawStream,(Bool_t)nevents_physics);
157       if(!result) passvdrift = kFALSE;
158       else nbvdrift += (Int_t) result/2;
159              
160       
161       delete trdRawStream;
162       delete rawReader;
163     } 
164    
165     if(eventT==PHYSICS_EVENT){
166  
167       nevents_physics++;
168      
169     }
170     
171     nevents_total++;
172
173
174     /* free resources */
175     free(event);
176     
177     /* exit when last event received, no need to wait for TERM signal */
178     if (eventT==END_OF_RUN) {
179       printf("EOR event detected\n");
180       break;
181     }
182   }
183
184
185   /* report progress */
186   printf("%d events processed and %d used\n",nevents_total,nbvdrift);
187   
188   //
189   // Write a local file and put it on the FX 
190   //
191   TFile  *fileTRD     = new TFile(RESULT_FILE,"recreate");
192  
193   if((nbvdrift > 0) && passvdrift){
194     //Double_t *stat = calibra->StatH((TH2 *)(calibra->GetPH2d()),1);
195     //if((stat[6] < 0.20) && (stat[5] > 3000.0)) {
196     // write the histogram in any case to see if problems
197     calibra->GetPH2d()->Write();
198     //}
199   }
200   fileTRD->Close();
201   status=0;
202   // Export the file in any case to see if problems
203   if(daqDA_FES_storeFile(RESULT_FILE,RESULT_FILE)) status = -2;
204   
205   delete fileTRD;  
206
207   return status;
208 }