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