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