]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/monitorGDC.cxx
Dixed a crash when no proper files/data to display (Mikolaj)
[u/mrichter/AliRoot.git] / MONITOR / monitorGDC.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // this program performs local monitoring on a GDC by running the HLT code   //
21 //                                                                           //
22 // If an argument is given, this is taken as the name of a date file which   //
23 // is used instead of the local node.                                        //
24 // The program can be stopped by pressing CTRL-C.                            //
25 //                                                                           //
26 ///////////////////////////////////////////////////////////////////////////////
27
28 #include <TError.h>
29 #include <TSysEvtHandler.h>
30 #ifdef ALI_DATE
31 #include <TROOT.h>
32 #include <TSystem.h>
33 #include <TDatime.h>
34 #include "AliRawReaderDate.h"
35 #include "event.h"
36 #include "monitor.h"
37 /*
38 #include <AliHLTStandardIncludes.h>
39 #include <AliHLTTransform.h>
40 #include <AliHLTMemHandler.h>
41 #include <AliHLTTrackArray.h>
42 #include <AliHLTHoughMaxFinder.h>
43 #include <AliHLTHoughBaseTransformer.h>
44 #include <AliHLTHough.h>
45 #include <AliHLTBenchmark.h>
46 #include <AliHLTITSclusterer.h>
47 #include <AliHLTITSVertexerZ.h>
48 #include <AliHLTITStracker.h>
49 */
50 #include "AliESDEvent.h"
51 #include "AliESDVertex.h"
52 #include "AliTracker.h"
53 #include <AliKalmanTrack.h>
54 #include "AliITSgeomTGeo.h"
55 #include "AliITSgeom.h"
56 #include "AliMagF.h"
57 #include "AliMagFMaps.h"
58 #endif
59
60 //_____________________________________________________________________________
61 class AliGDCInterruptHandler : public TSignalHandler {
62 public:
63   AliGDCInterruptHandler();
64   Bool_t Notify() {fStop = kTRUE; return kTRUE;};
65   Bool_t Stop() const {return fStop;};
66 private:
67   Bool_t fStop;  // CTRL-C pressed
68 };
69
70 //_____________________________________________________________________________
71 AliGDCInterruptHandler::AliGDCInterruptHandler() : 
72   TSignalHandler(kSigInterrupt, kFALSE),
73   fStop(kFALSE)
74 {
75
76 }
77
78
79 //_____________________________________________________________________________
80 #ifdef ALI_DATE
81 int main(int argc, char** argv)
82 {
83   // set ROOT in batch mode
84   gROOT->SetBatch();   
85
86   // open a log file
87   FILE* file = fopen("monitorGDC.log", "w");
88
89   TDatime time;
90
91   // get data from a file or online from this node
92   Int_t status = 0;
93   if (argc > 1) {
94     status = monitorSetDataSource(argv[1]);
95   } else {
96     status = monitorSetDataSource(":");
97   }
98   if (status) ::Fatal("monitorSetDataSource", monitorDecodeError(status));
99
100   // monitor only a sample of physics events
101   char* table[] = {"Physics event", "yes", NULL};
102   status = monitorDeclareTable(table);
103   if (status) ::Fatal("monitorDeclareTable", monitorDecodeError(status));
104
105   // declare this monitoring program to DATE
106   status = monitorDeclareMp("GDC physics monitoring");
107   if (status) ::Fatal("monitorDeclareMp", monitorDecodeError(status));
108
109   // initialize HLT transformations
110   //  if (!AliHLTTransform::Init("./", kFALSE)) {
111   //    ::Fatal("AliHLTTransform::Init", "HLT initialization failed");
112   //  }
113
114   AliESDEvent *esd = new AliESDEvent;
115   esd->CreateStdContent();
116
117   //  AliITSgeom *geom = new AliITSgeom();
118   //  geom->ReadNewFile("$ALICE_ROOT/ITS/ITSgeometry_vPPRasymmFMD.det");
119   //  if (!geom) return 1;
120   //  Int_t sfield = 0;
121   //  switch ((Int_t)(AliHLTTransform::GetSolenoidField()+0.5)) {
122   //  case 2:
123   //    sfield = AliMagFMaps::k2kG;
124   //    break;
125   //  case 4:
126   //    sfield = AliMagFMaps::k4kG;
127   //    break;
128   //  case 5:
129   //    sfield = AliMagFMaps::k5kG;
130   //    break;
131   //  default:
132   //    ::Fatal("AliHLTTransform::GetSolenoidField", "Incorrect magnetic field");
133   //  }
134   AliMagF* field = new AliMagFMaps("Maps","Maps", 2, 1., 10., AliMagFMaps::k5kG);
135   AliTracker::SetFieldMap(field,kTRUE);
136
137   // Init PID
138   AliPID pid;
139
140   // create the signal handler
141   AliGDCInterruptHandler* handler = new AliGDCInterruptHandler;
142   gSystem->AddSignalHandler(handler);
143
144   // endless loop
145   void* ptr = NULL;
146   while (!handler->Stop()) {
147     // get the next event
148     status = monitorGetEventDynamic(&ptr);
149     if (status == (Int_t)MON_ERR_EOF) break;
150     if (status) ::Fatal("monitorGetEventDynamic", monitorDecodeError(status));
151
152     // if no new event
153     if (!ptr) {
154       gSystem->Sleep(1000);   // sleep for 1 second
155       continue;
156     }
157
158     AliRawReaderDate rawReader(ptr);
159     //    if ((rawReader.GetAttributes()[0] & 0x02) != 0) {
160
161     //      Int_t errorCode = rawReader.CheckData();
162     Int_t errorCode = 0;
163       if (errorCode && (errorCode != AliRawReader::kErrSize)) {
164         time.Set();
165         if (file) fprintf(file, "%s\n", time.AsString());
166         if (file) fprintf(file, "run: %d  event: %d %d\n", 
167                           rawReader.GetRunNumber(), 
168                           rawReader.GetEventId()[0], 
169                           rawReader.GetEventId()[1]);
170         fprintf(file, "ERROR: %d\n\n", errorCode);
171
172       } else {
173
174 //      AliHLTBenchmark *fBenchmark = new AliHLTBenchmark();
175 //      fBenchmark->Start("Overall timing");
176
177 //      // ITS clusterer and vertexer
178 //      fBenchmark->Start("ITS Clusterer");
179 //      AliHLTITSclusterer clusterer(0);
180 //      AliRawReader *itsrawreader=new AliRawReaderDate(ptr);
181 //      TTree* treeClusters = new TTree("TreeL3ITSclusters"," "); //make a tree
182 //      clusterer.Digits2Clusters(itsrawreader,treeClusters);
183 //      fBenchmark->Stop("ITS Clusterer");
184         
185 //      AliHLTITSVertexerZ vertexer;
186 //      AliESDVertex *vertex = vertexer.FindVertexForCurrentEvent(geom,treeClusters);
187 //      Double_t vtxPos[3];
188 //      Double_t vtxErr[3]={0.005,0.005,0.010};
189 //      vertex->GetXYZ(vtxPos);
190 //      //      vertex->GetSigmaXYZ(vtxErr);
191 //      esd->SetVertex(vertex);
192
193 //      // TPC Hough reconstruction
194 //      Float_t ptmin = 0.1*AliHLTTransform::GetSolenoidField();
195 //      Float_t zvertex = vtxPos[2];
196
197 //      // Run the Hough Transformer
198 //      fBenchmark->Start("Init");
199 //      AliHLTHough *hough1 = new AliHLTHough();
200
201 //      hough1->SetThreshold(4);
202 //      hough1->CalcTransformerParams(ptmin);
203 //      hough1->SetPeakThreshold(70,-1);
204 //      //      printf("Pointer is %x\n",ptr);
205 //      hough1->Init("./", kFALSE, 100, kFALSE,4,0,(Char_t*)ptr,zvertex);
206 //      hough1->SetAddHistograms();
207 //      fBenchmark->Stop("Init");
208
209 //      fBenchmark->Start("Init");
210 //      AliHLTHough *hough2 = new AliHLTHough();
211
212 //      hough2->SetThreshold(4);
213 //      hough2->CalcTransformerParams(ptmin);
214 //      hough2->SetPeakThreshold(70,-1);
215 //      //      printf("Pointer is %x\n",ptr);
216 //      hough2->Init("./", kFALSE, 100, kFALSE,4,0,(Char_t*)ptr,zvertex);
217 //      hough2->SetAddHistograms();
218 //      fBenchmark->Stop("Init");
219
220 //      Int_t nglobaltracks = 0;
221 //      /*
222 //      hough1->StartProcessInThread(0,17);
223 //      hough2->StartProcessInThread(18,35);
224
225 //      //      gSystem->Sleep(20000);
226 //      if(hough1->WaitForThreadFinish())
227 //        ::Fatal("AliHLTHough::WaitForThreadFinish"," Can not join the required thread! ");
228 //      if(hough2->WaitForThreadFinish())
229 //        ::Fatal("AliHLTHough::WaitForThreadFinish"," Can not join the required thread! ");
230
231 //      gSystem->MakeDirectory("hough1");
232 //      hough1->WriteTracks("./hough1");
233 //      gSystem->MakeDirectory("hough2");
234 //      hough2->WriteTracks("./hough2");
235 //      */
236
237 //      for(int slice=0; slice<=17; slice++)
238 //      {
239 //        //      cout<<"Processing slice "<<slice<<endl;
240 //        fBenchmark->Start("ReadData");
241 //        hough1->ReadData(slice,0);
242 //        fBenchmark->Stop("ReadData");
243 //        fBenchmark->Start("Transform");
244 //        hough1->Transform();
245 //        fBenchmark->Stop("Transform");
246 //        hough1->AddAllHistogramsRows();
247 //        hough1->FindTrackCandidatesRow();
248 //        fBenchmark->Start("AddTracks");
249 //        hough1->AddTracks();
250 //        fBenchmark->Stop("AddTracks");
251
252 //        //      AliHLTTrackArray* tracks = (AliHLTTrackArray*)hough1->GetTracks(0);
253 //        //      nglobaltracks += tracks->GetNTracks();
254 //      }
255 //      for(int slice=18; slice<=35; slice++)
256 //      {
257 //        //      cout<<"Processing slice "<<slice<<endl;
258 //        fBenchmark->Start("ReadData");
259 //        hough2->ReadData(slice,0);
260 //        fBenchmark->Stop("ReadData");
261 //        fBenchmark->Start("Transform");
262 //        hough2->Transform();
263 //        fBenchmark->Stop("Transform");
264 //        hough2->AddAllHistogramsRows();
265 //        hough2->FindTrackCandidatesRow();
266 //        fBenchmark->Start("AddTracks");
267 //        hough2->AddTracks();
268 //        fBenchmark->Stop("AddTracks");
269
270 //        //      AliHLTTrackArray* tracks = (AliHLTTrackArray*)hough2->GetTracks(0);
271 //        //      nglobaltracks += tracks->GetNTracks();
272 //      }
273
274 //      nglobaltracks += hough1->FillESD(esd);
275 //      nglobaltracks += hough2->FillESD(esd);
276
277 //      // ITS tracker
278 //      AliHLTITStracker itsTracker(0);
279 //      itsTracker.SetVertex(vtxPos,vtxErr);
280
281 //      itsTracker.LoadClusters(treeClusters);
282 //      itsTracker.Clusters2Tracks(esd);
283 //      itsTracker.UnloadClusters();
284
285 //      fBenchmark->Stop("Overall timing");
286 //      time.Set();
287 //      if (file) fprintf(file, "%s\n", time.AsString());
288 //      if (file) fprintf(file, "run: %d  event: %d %d\n", 
289 //                        rawReader.GetRunNumber(), 
290 //                        rawReader.GetEventId()[0], 
291 //                        rawReader.GetEventId()[1]);
292 //      if (errorCode) fprintf(file, "ERROR: %d\n", errorCode);
293
294 //      if (file) fprintf(file, "Hough Transformer found %d tracks\n",nglobaltracks);
295
296 //      hough1->DoBench("hough1");
297 //      hough2->DoBench("hough2");
298 //      fBenchmark->Analyze("overall");
299 //      if (file) {
300 //        FILE* bench = fopen("hough1.dat", "r");
301 //        while (bench && !feof(bench)) {
302 //          char buffer[256];
303 //          if (!fgets(buffer, 256, bench)) break;
304 //          fprintf(file, "%s", buffer);
305 //        }
306 //        fclose(bench);
307 //      }
308 //      if (file) {
309 //        FILE* bench = fopen("hough2.dat", "r");
310 //        while (bench && !feof(bench)) {
311 //          char buffer[256];
312 //          if (!fgets(buffer, 256, bench)) break;
313 //          fprintf(file, "%s", buffer);
314 //        }
315 //        fclose(bench);
316 //      }
317 //      if (file) {
318 //        FILE* bench = fopen("overall.dat", "r");
319 //        while (bench && !feof(bench)) {
320 //          char buffer[256];
321 //          if (!fgets(buffer, 256, bench)) break;
322 //          fprintf(file, "%s", buffer);
323 //        }
324 //        fclose(bench);
325 //        fprintf(file, "\n\n");
326 //      }
327
328 //      delete hough1;
329 //      delete hough2;
330
331 //      esd->Reset();
332       }
333     //    }
334
335     /*
336     // read run, event, detector, DDL numbers and data size
337     AliRawReaderDate rawReader(ptr);
338     time.Set();
339     printf("\n%s\n", time.AsString());
340     printf("run: %d  event: %d %d\n", rawReader.GetRunNumber(), 
341            rawReader.GetEventId()[0], rawReader.GetEventId()[1]);
342     while (rawReader.ReadMiniHeader()) {
343       printf(" detector: %d   DDL: %d  size: %d\n", 
344              rawReader.GetDetectorID(), rawReader.GetDDLID(), 
345              rawReader.GetDataSize());
346     }
347
348     */
349
350     gSystem->Sleep(100);   // sleep for 0.1 second
351     free(ptr);
352
353     gSystem->ProcessEvents();
354     if (file) fflush(file);
355
356   }
357
358   gSystem->RemoveSignalHandler(handler);
359   if (file) fclose(file);
360
361   return 0;
362 }
363
364 #else
365 int main(int /*argc*/, char** /*argv*/)
366 {
367   ::Fatal("main", "this program was compiled without DATE");
368
369   return 1;
370 }
371 #endif