Merging THbtp and HBTP in one library. Comiplation on Windows/Cygwin
[u/mrichter/AliRoot.git] / TRD / TRDVDRIFTda.cxx
CommitLineData
170c35f1 1/*
2
c5348551 3Contact: r.bailhache@gsi.de
25781e34 4Link: run 25909
5Run Type: PHYSICS STANDALONE
c5348551 6DA Type: MON
7Number of events needed: as many as possible
25781e34 8Input Files: raw files of the TRD
9Output Files: trdCalibrationv.root,to be exported to the DAQ FXS
10Trigger types used: PHYSICS_EVENT, for the time being
170c35f1 11
12*/
13
6ace5fe2 14#define RESULT_FILE "trdCalibrationv.root"
15
16
170c35f1 17extern "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>
170c35f1 33#include <TDirectory.h>
34#include <TSystem.h>
35#include <TFile.h>
25781e34 36#include "TROOT.h"
37#include "TPluginManager.h"
170c35f1 38//
39//AliRoot includes
40//
41#include "AliRawReader.h"
42#include "AliRawReaderDate.h"
80cb9622 43#include "AliTRDrawStreamTB.h"
170c35f1 44#include "AliCDBManager.h"
45
46//
47// TRD calibration algorithm includes
48//
170c35f1 49#include "AliTRDCalibraFillHisto.h"
50
51
52
53
54/* Main routine
55 Arguments:
56 1- monitoring data source
57*/
58int main(int argc, char **argv) {
59
25781e34 60 /* magic line from Rene */
61 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
62 "*",
63 "TStreamerInfo",
64 "RIO",
65 "TStreamerInfo()");
170c35f1 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 */
6ace5fe2 96 printf("TRD DA VDRIFT started\n");
170c35f1 97
98
99 /* init some counters */
100 int nevents_physics=0;
101 int nevents_total=0;
102
289cc637 103 //Instance of AliCDBManager: needed by AliTRDRawStreamV2
170c35f1 104 AliCDBManager *man = AliCDBManager::Instance();
105 man->SetDefaultStorage("local://$ALICE_ROOT");
106 man->SetRun(0);
107 //Instance of AliTRDCalibraFillHisto
108 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
170c35f1 109 // everythings are okey for vdrift
3a0f6479 110 Bool_t passvdrift = kTRUE; // if timebin okey
111 Int_t nbvdrift = 0; // number of events with entries for vdrift
170c35f1 112
162a3e73 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);
f222df8d 123
170c35f1 124
125 /* main loop (infinite) */
126 for(;;) {
127 //for(Int_t k = 0; k < 20; k++) {
128 struct eventHeaderStruct *event;
129 eventTypeType eventT;
6ace5fe2 130
170c35f1 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
25781e34 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);
170c35f1 152
153
154 /* use event - here, just write event id to result file */
155 eventT=event->eventType;
6ace5fe2 156
170c35f1 157 //
158 // vdrift calibration: run only for physics events
159 //
6ace5fe2 160 if ((eventT==PHYSICS_EVENT) && (passvdrift)) {
170c35f1 161 //if (eventT==PHYSICS_EVENT) {
170c35f1 162 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
80cb9622 163 AliTRDrawStreamTB *trdRawStream = new AliTRDrawStreamTB((AliRawReader *) rawReader);
3a0f6479 164 Int_t result = calibra->ProcessEventDAQ(trdRawStream,(Bool_t)nevents_physics);
165 if(!result) passvdrift = kFALSE;
166 else nbvdrift += (Int_t) result/2;
5750af0a 167
168
170c35f1 169 delete trdRawStream;
170 delete rawReader;
171 }
172
5750af0a 173 if(eventT==PHYSICS_EVENT){
174
175 nevents_physics++;
176
177 }
170c35f1 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
6ace5fe2 192
193 /* report progress */
194 printf("%d events processed and %d used\n",nevents_total,nbvdrift);
195
170c35f1 196 //
197 // Write a local file and put it on the FX
198 //
6ace5fe2 199 TFile *fileTRD = new TFile(RESULT_FILE,"recreate");
200
3a0f6479 201 if((nbvdrift > 0) && passvdrift){
6ace5fe2 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 //}
170c35f1 207 }
208 fileTRD->Close();
209 status=0;
6ace5fe2 210 // Export the file in any case to see if problems
211 if(daqDA_FES_storeFile(RESULT_FILE,RESULT_FILE)) status = -2;
212
170c35f1 213 delete fileTRD;
214
215 return status;
216}