]>
Commit | Line | Data |
---|---|---|
170c35f1 | 1 | /* |
2 | ||
3 | ||
4 | TRDda.cxx - calibration algorithm to be run on monitoring server | |
5 | DAcase2.c | |
6 | ||
7 | AliTRDCalibraFillHisto - average pulse height/ vdrift calibration | |
8 | AliTRDCalibPadStatus - pad status calibration | |
9 | ||
10 | ||
11 | This program connects to the DAQ data source passed as argument | |
12 | and populates local "./result.txt" file with the ids of events received | |
13 | during the run. | |
14 | ||
15 | The program exits when being asked to shut down (daqDA_checkshutdown) | |
16 | or End of Run event. | |
17 | ||
18 | Messages on stdout are exported to DAQ log system. | |
19 | ||
20 | contact: alice-datesupport@cern.ch | |
21 | ||
22 | */ | |
23 | ||
24 | extern "C" { | |
25 | #include <daqDA.h> | |
26 | } | |
27 | ||
28 | #include "event.h" | |
29 | #include "monitor.h" | |
30 | #include <stdio.h> | |
31 | #include <stdlib.h> | |
32 | ||
33 | ||
34 | // | |
35 | //Root includes | |
36 | // | |
37 | #include <TObjArray.h> | |
38 | #include <TString.h> | |
39 | #include <TVectorF.h> | |
40 | #include <TROOT.h> | |
41 | #include <TDirectory.h> | |
42 | #include <TSystem.h> | |
43 | #include <TFile.h> | |
44 | // | |
45 | //AliRoot includes | |
46 | // | |
47 | #include "AliRawReader.h" | |
48 | #include "AliRawReaderDate.h" | |
49 | #include "AliTRDRawStream.h" | |
50 | #include "AliCDBManager.h" | |
51 | ||
52 | // | |
53 | // TRD calibration algorithm includes | |
54 | // | |
55 | #include "AliTRDCalibPadStatus.h" | |
56 | #include "AliTRDCalibraFillHisto.h" | |
57 | ||
58 | ||
59 | ||
60 | ||
61 | /* Main routine | |
62 | Arguments: | |
63 | 1- monitoring data source | |
64 | */ | |
65 | int main(int argc, char **argv) { | |
66 | ||
67 | int status; | |
68 | ||
69 | if (argc!=2) { | |
70 | printf("Wrong number of arguments\n"); | |
71 | return -1; | |
72 | } | |
73 | ||
74 | ||
75 | /* define data source : this is argument 1 */ | |
76 | status=monitorSetDataSource( argv[1] ); | |
77 | if (status!=0) { | |
78 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
79 | return -1; | |
80 | } | |
81 | ||
82 | ||
83 | /* declare monitoring program */ | |
84 | status=monitorDeclareMp( __FILE__ ); | |
85 | if (status!=0) { | |
86 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
87 | return -1; | |
88 | } | |
89 | ||
90 | ||
91 | /* define wait event timeout - 1s max */ | |
92 | monitorSetNowait(); | |
93 | monitorSetNoWaitNetworkTimeout(1000); | |
94 | ||
95 | ||
96 | /* log start of process */ | |
97 | printf("DA example case2 monitoring program started\n"); | |
98 | ||
99 | ||
100 | /* init some counters */ | |
101 | int nevents_physics=0; | |
102 | int nevents_total=0; | |
103 | ||
104 | //Instance of AliCDBManager: needed by AliTRDRawStream | |
105 | AliCDBManager *man = AliCDBManager::Instance(); | |
106 | man->SetDefaultStorage("local://$ALICE_ROOT"); | |
107 | man->SetRun(0); | |
108 | //Instance of AliTRDCalibraFillHisto | |
109 | AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance(); | |
110 | //AliTRDCalibPadStatus | |
111 | AliTRDCalibPadStatus calibpad = AliTRDCalibPadStatus(); | |
112 | // pad status on: no zero suppression (special runs) | |
113 | Bool_t passpadstatus = kTRUE; | |
114 | // everythings are okey for vdrift | |
115 | Bool_t passvdrift = kFALSE; | |
116 | ||
117 | ||
118 | /* main loop (infinite) */ | |
119 | for(;;) { | |
120 | //for(Int_t k = 0; k < 20; k++) { | |
121 | struct eventHeaderStruct *event; | |
122 | eventTypeType eventT; | |
123 | ||
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 | ||
144 | printf(" physic event number %d will be processed\n",(Int_t) nevents_physics); | |
145 | ||
146 | ||
147 | /* use event - here, just write event id to result file */ | |
148 | eventT=event->eventType; | |
149 | // | |
150 | // pad status calibration: we try a first time to see if zero suppressed or not | |
151 | // | |
152 | if(passpadstatus){ | |
153 | printf("pad status calibration\n"); | |
154 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); | |
155 | AliTRDRawStream *trdRawStream = new AliTRDRawStream((AliRawReader *) rawReader); | |
156 | if(!calibpad.ProcessEvent(trdRawStream)) passpadstatus = kFALSE; | |
157 | ||
158 | delete trdRawStream; | |
159 | delete rawReader; | |
160 | } | |
161 | // | |
162 | // vdrift calibration: run only for physics events | |
163 | // | |
164 | if ((eventT==PHYSICS_EVENT) && (!passpadstatus)) { | |
165 | //if (eventT==PHYSICS_EVENT) { | |
166 | printf("vdrift calibration\n"); | |
167 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); | |
168 | AliTRDRawStream *trdRawStream = new AliTRDRawStream((AliRawReader *) rawReader); | |
169 | if(calibra->ProcessEventDAQ(trdRawStream)) passvdrift = kTRUE; | |
170 | ||
171 | nevents_physics++; | |
172 | ||
173 | delete trdRawStream; | |
174 | delete rawReader; | |
175 | } | |
176 | ||
177 | ||
178 | nevents_total++; | |
179 | ||
180 | ||
181 | /* free resources */ | |
182 | free(event); | |
183 | ||
184 | /* exit when last event received, no need to wait for TERM signal */ | |
185 | if (eventT==END_OF_RUN) { | |
186 | printf("EOR event detected\n"); | |
187 | break; | |
188 | } | |
189 | } | |
190 | ||
191 | // | |
192 | // Write a local file and put it on the FX | |
193 | // | |
194 | TFile *fileTRD = new TFile("trdCalibration.root","recreate"); | |
195 | Bool_t passwrite = kFALSE; | |
196 | // | |
197 | // pad status | |
198 | // | |
199 | if(passpadstatus){ | |
200 | // We do this at the shuttle maybe! | |
201 | //calibpad.AnalyseHisto(); | |
202 | //AliTRDCalPadStatus *calPadStatus = calibpad.CreateCalPadStatus(); | |
203 | calibpad.Write("calibpadstatus"); | |
204 | passwrite = kTRUE; | |
205 | } | |
206 | // | |
207 | // vdrift | |
208 | // | |
209 | if((nevents_physics > 0) && passvdrift){ | |
210 | Double_t *stat = calibra->StatH((TH2 *)(calibra->GetPH2d()),1); | |
211 | // write only of enough statistics | |
212 | if(stat[6] < 0.20) { | |
213 | calibra->GetPH2d()->Write(); | |
214 | passwrite = kTRUE; | |
215 | } | |
216 | ||
217 | } | |
218 | fileTRD->Close(); | |
219 | status=0; | |
220 | if(passwrite) { | |
221 | if(daqDA_FES_storeFile("trdCalibration.root","trdCalibration.root")) status = -2; | |
222 | } | |
223 | delete fileTRD; | |
224 | ||
225 | return status; | |
226 | } |