]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/monitorGDC.cxx
31734891f101a3962d28e63f4ece17eb1e601bf8
[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 DATE_SYS
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 #include <AliL3StandardIncludes.h>
38 #include <AliL3Transform.h>
39 #include <AliL3MemHandler.h>
40 #include <AliL3TrackArray.h>
41 #include <AliL3HoughMaxFinder.h>
42 #include <AliL3HoughBaseTransformer.h>
43 #include <AliL3Hough.h>
44 #include <AliL3Benchmark.h>
45 #endif
46
47
48 //_____________________________________________________________________________
49 class AliGDCInterruptHandler : public TSignalHandler {
50 public:
51   AliGDCInterruptHandler();
52   Bool_t Notify() {fStop = kTRUE; return kTRUE;};
53   Bool_t Stop() const {return fStop;};
54 private:
55   Bool_t fStop;  // CTRL-C pressed
56 };
57
58 //_____________________________________________________________________________
59 AliGDCInterruptHandler::AliGDCInterruptHandler() : 
60   TSignalHandler(kSigInterrupt, kFALSE) 
61 {
62   fStop = kFALSE;
63 };
64
65
66 //_____________________________________________________________________________
67 #ifdef DATE_SYS
68 int main(int argc, char** argv)
69 {
70   // set ROOT in batch mode
71   gROOT->SetBatch();   
72
73   // open a log file
74   FILE* file = fopen("monitorGDC.log", "w");
75
76   TDatime time;
77
78   // get data from a file or online from this node
79   Int_t status = 0;
80   if (argc > 1) {
81     status = monitorSetDataSource(argv[1]);
82   } else {
83     status = monitorSetDataSource(":");
84   }
85   if (status) ::Fatal("monitorSetDataSource", monitorDecodeError(status));
86
87   // monitor only a sample of physics events
88   char* table[] = {"Physics event", "yes", NULL};
89   status = monitorDeclareTable(table);
90   if (status) ::Fatal("monitorDeclareTable", monitorDecodeError(status));
91
92   // declare this monitoring program to DATE
93   status = monitorDeclareMp("GDC physics monitoring");
94   if (status) ::Fatal("monitorDeclareMp", monitorDecodeError(status));
95
96   // initialize HLT transformations
97   if (!AliL3Transform::Init("./", kFALSE)) {
98     ::Fatal("AliL3Transform::Init", "HLT initialization failed");
99   }
100
101   // create the signal handler
102   AliGDCInterruptHandler* handler = new AliGDCInterruptHandler;
103   gSystem->AddSignalHandler(handler);
104
105   // endless loop
106   void* ptr = NULL;
107   while (!handler->Stop()) {
108     // get the next event
109     status = monitorGetEventDynamic(&ptr);
110     if (status == (Int_t)MON_ERR_EOF) break;
111     if (status) ::Fatal("monitorGetEventDynamic", monitorDecodeError(status));
112
113     // if no new event
114     if (!ptr) {
115       gSystem->Sleep(1000);   // sleep for 1 second
116       continue;
117     }
118
119     AliRawReaderDate rawReader(ptr);
120     //    if ((rawReader.GetAttributes()[0] & 0x02) != 0) {
121
122     //      Int_t errorCode = rawReader.CheckData();
123     Int_t errorCode = 0;
124       if (errorCode && (errorCode != AliRawReader::kErrSize)) {
125         time.Set();
126         if (file) fprintf(file, "%s\n", time.AsString());
127         if (file) fprintf(file, "run: %d  event: %d %d\n", 
128                           rawReader.GetRunNumber(), 
129                           rawReader.GetEventId()[0], 
130                           rawReader.GetEventId()[1]);
131         fprintf(file, "ERROR: %d\n\n", errorCode);
132
133       } else {
134
135         AliL3Benchmark *fBenchmark = new AliL3Benchmark();
136         fBenchmark->Start("Overall timing");
137
138         // Run the Hough Transformer
139         fBenchmark->Start("Init");
140         AliL3Hough *hough1 = new AliL3Hough();
141
142         hough1->SetThreshold(4);
143         hough1->SetTransformerParams(76,140,0.4,-1);
144         hough1->SetPeakThreshold(70,-1);
145         //      printf("Pointer is %x\n",ptr);
146         hough1->Init("./", kFALSE, 100, kFALSE,4,0,(Char_t*)ptr,3.82147);
147         hough1->SetAddHistograms();
148         fBenchmark->Stop("Init");
149
150         fBenchmark->Start("Init");
151         AliL3Hough *hough2 = new AliL3Hough();
152
153         hough2->SetThreshold(4);
154         hough2->SetTransformerParams(76,140,0.4,-1);
155         hough2->SetPeakThreshold(70,-1);
156         //      printf("Pointer is %x\n",ptr);
157         hough2->Init("./", kFALSE, 100, kFALSE,4,0,(Char_t*)ptr,3.82147);
158         hough2->SetAddHistograms();
159         fBenchmark->Stop("Init");
160
161         Int_t n_global_tracks = 0;
162         hough1->StartProcessInThread(0,17);
163         hough2->StartProcessInThread(18,35);
164
165         //      gSystem->Sleep(20000);
166         if(hough1->WaitForThreadFinish())
167           ::Fatal("AliL3Hough::WaitForThreadFinish"," Can not join the required thread! ");
168         if(hough2->WaitForThreadFinish())
169           ::Fatal("AliL3Hough::WaitForThreadFinish"," Can not join the required thread! ");
170
171         gSystem->MakeDirectory("hough1");
172         hough1->WriteTracks("./hough1");
173         gSystem->MakeDirectory("hough2");
174         hough2->WriteTracks("./hough2");
175
176         /*
177         for(int slice=0; slice<=35; slice++)
178         {
179           //      cout<<"Processing slice "<<slice<<endl;
180           fBenchmark->Start("ReadData");
181           hough->ReadData(slice,0);
182           fBenchmark->Stop("ReadData");
183           fBenchmark->Start("Transform");
184           hough->Transform();
185           fBenchmark->Stop("Transform");
186           hough->AddAllHistogramsRows();
187           hough->FindTrackCandidatesRow();
188           fBenchmark->Start("AddTracks");
189           hough->AddTracks();
190           fBenchmark->Stop("AddTracks");
191
192           AliL3TrackArray* tracks = (AliL3TrackArray*)hough->GetTracks(0);
193           n_global_tracks += tracks->GetNTracks();
194         }
195         */
196         fBenchmark->Stop("Overall timing");
197         time.Set();
198         if (file) fprintf(file, "%s\n", time.AsString());
199         if (file) fprintf(file, "run: %d  event: %d %d\n", 
200                           rawReader.GetRunNumber(), 
201                           rawReader.GetEventId()[0], 
202                           rawReader.GetEventId()[1]);
203         if (errorCode) fprintf(file, "ERROR: %d\n", errorCode);
204
205         if (file) fprintf(file, "Hough Transformer found %d tracks\n",n_global_tracks);
206
207         hough1->DoBench("hough1");
208         hough2->DoBench("hough2");
209         fBenchmark->Analyze("overall");
210         if (file) {
211           FILE* bench = fopen("hough1.dat", "r");
212           while (bench && !feof(bench)) {
213             char buffer[256];
214             if (!fgets(buffer, 256, bench)) break;
215             fprintf(file, "%s", buffer);
216           }
217           fclose(bench);
218         }
219         if (file) {
220           FILE* bench = fopen("hough2.dat", "r");
221           while (bench && !feof(bench)) {
222             char buffer[256];
223             if (!fgets(buffer, 256, bench)) break;
224             fprintf(file, "%s", buffer);
225           }
226           fclose(bench);
227         }
228         if (file) {
229           FILE* bench = fopen("overall.dat", "r");
230           while (bench && !feof(bench)) {
231             char buffer[256];
232             if (!fgets(buffer, 256, bench)) break;
233             fprintf(file, "%s", buffer);
234           }
235           fclose(bench);
236           fprintf(file, "\n\n");
237         }
238
239         delete hough1;
240         delete hough2;
241       }
242     //    }
243
244     /*
245     // read run, event, detector, DDL numbers and data size
246     AliRawReaderDate rawReader(ptr);
247     time.Set();
248     printf("\n%s\n", time.AsString());
249     printf("run: %d  event: %d %d\n", rawReader.GetRunNumber(), 
250            rawReader.GetEventId()[0], rawReader.GetEventId()[1]);
251     while (rawReader.ReadMiniHeader()) {
252       printf(" detector: %d   DDL: %d  size: %d\n", 
253              rawReader.GetDetectorID(), rawReader.GetDDLID(), 
254              rawReader.GetDataSize());
255     }
256
257     */
258
259     gSystem->Sleep(100);   // sleep for 0.1 second
260     free(ptr);
261
262     gSystem->ProcessEvents();
263     if (file) fflush(file);
264
265   }
266
267   gSystem->RemoveSignalHandler(handler);
268   if (file) fclose(file);
269
270   return 0;
271 }
272
273 #else
274 int main(int /*argc*/, char** /*argv*/)
275 {
276   ::Fatal("main", "this program was compiled without DATE");
277
278   return 1;
279 }
280 #endif