Avoid nasty crash if user forget to initialize reconstruction setup
[u/mrichter/AliRoot.git] / TRD / TRDVDRIFTda.cxx
CommitLineData
170c35f1 1/*
2
c5348551 3Contact: r.bailhache@gsi.de
27b46d95 4Link:
5Reference run: 25909
25781e34 6Run Type: PHYSICS STANDALONE
c5348551 7DA Type: MON
27b46d95 8Number of events needed: many
9Input Files: TRD raw files
10Output Files: trdCalibrationv.root
11Trigger types used: PHYSICS_EVENT
170c35f1 12
13*/
14
5f518e55 15#define RESULT_FILE "trdVdrift.root"
16#define FILE_ID "VDRIFT"
6ace5fe2 17
18
170c35f1 19extern "C" {
20#include <daqDA.h>
21}
22
23#include "event.h"
24#include "monitor.h"
25#include <stdio.h>
26#include <stdlib.h>
27
28
29//
30//Root includes
31//
32#include <TObjArray.h>
33#include <TString.h>
34#include <TVectorF.h>
170c35f1 35#include <TDirectory.h>
36#include <TSystem.h>
37#include <TFile.h>
25781e34 38#include "TROOT.h"
39#include "TPluginManager.h"
170c35f1 40//
41//AliRoot includes
42//
43#include "AliRawReader.h"
44#include "AliRawReaderDate.h"
987ba9a3 45#include "AliTRDrawStream.h"
5ac2a9f9 46#include "AliTRDrawStreamBase.h"
27b46d95 47
1785640c 48//
49//AMORE
50//
51#include <AmoreDA.h>
170c35f1 52
53//
54// TRD calibration algorithm includes
55//
170c35f1 56#include "AliTRDCalibraFillHisto.h"
57
1785640c 58//functions, implementation below
59//void SendToAmoreDB(TObject *o, unsigned long32 runNb);
170c35f1 60
61
62/* Main routine
63 Arguments:
64 1- monitoring data source
65*/
66int main(int argc, char **argv) {
67
25781e34 68 /* magic line from Rene */
69 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
70 "*",
71 "TStreamerInfo",
72 "RIO",
73 "TStreamerInfo()");
170c35f1 74 int status;
75
76 if (argc!=2) {
77 printf("Wrong number of arguments\n");
78 return -1;
79 }
80
81
82 /* define data source : this is argument 1 */
83 status=monitorSetDataSource( argv[1] );
84 if (status!=0) {
85 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
86 return -1;
87 }
88
89
90 /* declare monitoring program */
91 status=monitorDeclareMp( __FILE__ );
92 if (status!=0) {
93 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
94 return -1;
95 }
96
97
98 /* define wait event timeout - 1s max */
99 monitorSetNowait();
100 monitorSetNoWaitNetworkTimeout(1000);
101
102
103 /* log start of process */
6ace5fe2 104 printf("TRD DA VDRIFT started\n");
170c35f1 105
106
107 /* init some counters */
1785640c 108 int nevents_physics=0;
109 int nevents_total=0;
110 //unsigned long32 runNb=0; //run number
170c35f1 111
f3667dfd 112 //Instance of AliCDBManager: needed by AliTRDrawStream
27b46d95 113 //AliCDBManager *man = AliCDBManager::Instance();
162637e4 114 //man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
27b46d95 115 //man->SetRun(0);
170c35f1 116 //Instance of AliTRDCalibraFillHisto
117 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
6aafa7ea 118 calibra->SetNumberClustersProcent(0.9);
1785640c 119
170c35f1 120 // everythings are okey for vdrift
3a0f6479 121 Bool_t passvdrift = kTRUE; // if timebin okey
122 Int_t nbvdrift = 0; // number of events with entries for vdrift
170c35f1 123
162a3e73 124 // setting
987ba9a3 125 // AliTRDrawStream::SetNoDebug();
0ca1720e 126 AliTRDrawStream::DisableSkipData();
987ba9a3 127 AliTRDrawStream::SetNoErrorWarning();
128 //AliTRDrawStream::SetForceCleanDataOnly();
0ca1720e 129 //AliTRDrawStream::AllowCorruptedData();
130 //AliTRDrawStream::DisableStackNumberChecker();
131 //AliTRDrawStream::DisableStackLinkNumberChecker();
987ba9a3 132 //AliTRDrawStream::SetSkipCDH();
133 //AliTRDrawStream::SetExtraWordsFix();
134 //AliTRDrawStream::EnableDebugStream();
135 //AliTRDrawStream::SetDumpHead(320);
136 //AliTRDrawStream::SetDumpHead(80);
f222df8d 137
170c35f1 138
139 /* main loop (infinite) */
140 for(;;) {
141 //for(Int_t k = 0; k < 20; k++) {
142 struct eventHeaderStruct *event;
143 eventTypeType eventT;
6ace5fe2 144
170c35f1 145 /* check shutdown condition */
146 if (daqDA_checkShutdown()) {break;}
147
148 /* get next event (blocking call until timeout) */
149 status=monitorGetEventDynamic((void **)&event);
150 if (status==MON_ERR_EOF) {
151 printf ("End of File detected\n");
152 break; /* end of monitoring file has been reached */
153 }
154
155 if (status!=0) {
156 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
157 break;
158 }
159
160 /* retry if got no event */
161 if (event==NULL) {
162 continue;
163 }
164
1785640c 165 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);
166
167
170c35f1 168
170c35f1 169 /* use event - here, just write event id to result file */
170 eventT=event->eventType;
6ace5fe2 171
170c35f1 172 //
173 // vdrift calibration: run only for physics events
174 //
6ace5fe2 175 if ((eventT==PHYSICS_EVENT) && (passvdrift)) {
170c35f1 176 //if (eventT==PHYSICS_EVENT) {
170c35f1 177 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
5ac2a9f9 178 rawReader->Select("TRD");
1785640c 179
180 Int_t result = calibra->ProcessEventDAQ2((AliTRDrawReader *) rawReader);
3a0f6479 181 if(!result) passvdrift = kFALSE;
182 else nbvdrift += (Int_t) result/2;
5750af0a 183
1785640c 184
170c35f1 185 delete rawReader;
5ac2a9f9 186
170c35f1 187 }
1785640c 188
189 // get the run number
190 //runNb = event->eventRunNb;
170c35f1 191
5750af0a 192 if(eventT==PHYSICS_EVENT){
193
1785640c 194 nevents_physics++;
5750af0a 195
196 }
170c35f1 197
1785640c 198 /*
199 if( ((Int_t)nevents_physics)%100 == 0 ) {
200 SendToAmoreDB(&calibra);
201 }
202 */
203
204
205 nevents_total++;
170c35f1 206
207
208 /* free resources */
209 free(event);
210
211 /* exit when last event received, no need to wait for TERM signal */
212 if (eventT==END_OF_RUN) {
213 printf("EOR event detected\n");
214 break;
215 }
216 }
217
6ace5fe2 218
219 /* report progress */
1785640c 220 printf("%d events processed and %d used\n",nevents_total,nbvdrift);
6ace5fe2 221
170c35f1 222 //
223 // Write a local file and put it on the FX
224 //
6ace5fe2 225 TFile *fileTRD = new TFile(RESULT_FILE,"recreate");
226
3a0f6479 227 if((nbvdrift > 0) && passvdrift){
6ace5fe2 228 //Double_t *stat = calibra->StatH((TH2 *)(calibra->GetPH2d()),1);
229 //if((stat[6] < 0.20) && (stat[5] > 3000.0)) {
230 // write the histogram in any case to see if problems
231 calibra->GetPH2d()->Write();
232 //}
170c35f1 233 }
234 fileTRD->Close();
235 status=0;
6ace5fe2 236 // Export the file in any case to see if problems
5f518e55 237 if(daqDA_FES_storeFile(RESULT_FILE,FILE_ID)) status = -2;
6ace5fe2 238
170c35f1 239 delete fileTRD;
240
241 return status;
1785640c 242
243 /*
244 void SendToAmoreDB(TObject *o)
245 {
246 //AMORE
247 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
248 gSystem->Setenv("AMORE_DA_NAME","TRD-dataQA");
249
250 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
251 Int_t statusDA=0;
252 statusDA+=amoreDA.Send("DataQA-VDRIFT",o);
253 if ( statusDA!=0 )
254 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
255 // reset env var
256 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
257 }
258 */
259
1ac4bb35 260}
0ca1720e 261
1785640c 262