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