]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/TRDVDRIFTda.cxx
make the script working
[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"
fd50bb14 45#include "AliLog.h"
27b46d95 46
1785640c 47//
48//AMORE
49//
50#include <AmoreDA.h>
170c35f1 51
52//
53// TRD calibration algorithm includes
54//
170c35f1 55#include "AliTRDCalibraFillHisto.h"
56
1785640c 57//functions, implementation below
58//void SendToAmoreDB(TObject *o, unsigned long32 runNb);
170c35f1 59
60
61/* Main routine
62 Arguments:
63 1- monitoring data source
64*/
65int main(int argc, char **argv) {
66
25781e34 67 /* magic line from Rene */
68 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
69 "*",
70 "TStreamerInfo",
71 "RIO",
72 "TStreamerInfo()");
170c35f1 73 int status;
74
75 if (argc!=2) {
76 printf("Wrong number of arguments\n");
77 return -1;
78 }
79
80
81 /* define data source : this is argument 1 */
82 status=monitorSetDataSource( argv[1] );
83 if (status!=0) {
84 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
85 return -1;
86 }
87
88
89 /* declare monitoring program */
90 status=monitorDeclareMp( __FILE__ );
91 if (status!=0) {
92 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
93 return -1;
94 }
95
96
97 /* define wait event timeout - 1s max */
98 monitorSetNowait();
99 monitorSetNoWaitNetworkTimeout(1000);
100
101
102 /* log start of process */
6ace5fe2 103 printf("TRD DA VDRIFT started\n");
170c35f1 104
105
106 /* init some counters */
1785640c 107 int nevents_physics=0;
108 int nevents_total=0;
109 //unsigned long32 runNb=0; //run number
170c35f1 110
09ea3770 111 //Instance of AliCDBManager: needed by AliTRDrawFastStream
27b46d95 112 //AliCDBManager *man = AliCDBManager::Instance();
162637e4 113 //man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
27b46d95 114 //man->SetRun(0);
170c35f1 115 //Instance of AliTRDCalibraFillHisto
116 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
6aafa7ea 117 calibra->SetNumberClustersProcent(0.9);
1785640c 118
170c35f1 119 // everythings are okey for vdrift
3a0f6479 120 Bool_t passvdrift = kTRUE; // if timebin okey
121 Int_t nbvdrift = 0; // number of events with entries for vdrift
170c35f1 122
162a3e73 123 // setting
fd50bb14 124 //AliTRDrawFastStream::DisableSkipData();
125 AliLog::SetGlobalLogLevel(AliLog::kFatal);
09ea3770 126
170c35f1 127 /* main loop (infinite) */
128 for(;;) {
129 //for(Int_t k = 0; k < 20; k++) {
130 struct eventHeaderStruct *event;
131 eventTypeType eventT;
6ace5fe2 132
170c35f1 133 /* check shutdown condition */
134 if (daqDA_checkShutdown()) {break;}
135
136 /* get next event (blocking call until timeout) */
137 status=monitorGetEventDynamic((void **)&event);
138 if (status==MON_ERR_EOF) {
139 printf ("End of File detected\n");
140 break; /* end of monitoring file has been reached */
141 }
142
143 if (status!=0) {
144 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
145 break;
146 }
147
148 /* retry if got no event */
149 if (event==NULL) {
150 continue;
151 }
152
1785640c 153 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);
154
155
170c35f1 156
170c35f1 157 /* use event - here, just write event id to result file */
158 eventT=event->eventType;
6ace5fe2 159
170c35f1 160 //
161 // vdrift calibration: run only for physics events
162 //
6ace5fe2 163 if ((eventT==PHYSICS_EVENT) && (passvdrift)) {
170c35f1 164 //if (eventT==PHYSICS_EVENT) {
170c35f1 165 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
5ac2a9f9 166 rawReader->Select("TRD");
1785640c 167
8df1f8f5 168 Int_t result = calibra->ProcessEventDAQ((AliRawReader *)rawReader);
3a0f6479 169 if(!result) passvdrift = kFALSE;
170 else nbvdrift += (Int_t) result/2;
5750af0a 171
1785640c 172
170c35f1 173 delete rawReader;
5ac2a9f9 174
170c35f1 175 }
1785640c 176
177 // get the run number
178 //runNb = event->eventRunNb;
170c35f1 179
5750af0a 180 if(eventT==PHYSICS_EVENT){
181
1785640c 182 nevents_physics++;
5750af0a 183
184 }
170c35f1 185
1785640c 186 /*
187 if( ((Int_t)nevents_physics)%100 == 0 ) {
188 SendToAmoreDB(&calibra);
189 }
190 */
191
192
193 nevents_total++;
170c35f1 194
195
196 /* free resources */
197 free(event);
198
199 /* exit when last event received, no need to wait for TERM signal */
200 if (eventT==END_OF_RUN) {
201 printf("EOR event detected\n");
202 break;
203 }
204 }
205
6ace5fe2 206
207 /* report progress */
1785640c 208 printf("%d events processed and %d used\n",nevents_total,nbvdrift);
6ace5fe2 209
170c35f1 210 //
211 // Write a local file and put it on the FX
212 //
6ace5fe2 213 TFile *fileTRD = new TFile(RESULT_FILE,"recreate");
214
3a0f6479 215 if((nbvdrift > 0) && passvdrift){
6ace5fe2 216 //Double_t *stat = calibra->StatH((TH2 *)(calibra->GetPH2d()),1);
217 //if((stat[6] < 0.20) && (stat[5] > 3000.0)) {
218 // write the histogram in any case to see if problems
219 calibra->GetPH2d()->Write();
220 //}
170c35f1 221 }
222 fileTRD->Close();
223 status=0;
6ace5fe2 224 // Export the file in any case to see if problems
5f518e55 225 if(daqDA_FES_storeFile(RESULT_FILE,FILE_ID)) status = -2;
6ace5fe2 226
170c35f1 227 delete fileTRD;
228
229 return status;
1ac4bb35 230}
0ca1720e 231
09ea3770 232/*
233 void SendToAmoreDB(TObject *o)
234 {
235 //AMORE
236 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
237 gSystem->Setenv("AMORE_DA_NAME","TRD-dataQA");
238
239 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
240 Int_t statusDA=0;
241 statusDA+=amoreDA.Send("DataQA-VDRIFT",o);
242 if ( statusDA!=0 )
243 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
244 // reset env var
245 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
246 }
247*/
068b874f 248
249