]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerGUI.cxx
Commenting out the code relying on temporarily removed
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerGUI.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 /// \class AliMUONTriggerGUI
19 /// Graphical User Interface utility class for the MUON trigger detector
20 /// It creates, after initialisation with a data file, a sensitive map
21 /// of the trigger boards
22 /// \author Bogdan Vulpescu, LPC Clermont-Ferrand
23
24 #include "AliMUONTriggerGUI.h"
25 #include "AliMUONTriggerGUIboard.h"
26 #include "AliMUONTriggerGUIdimap.h"
27 #include "AliMUONTriggerGUIbdmap.h"
28
29 #include "AliMpSegmentation.h"
30 #include "AliMpVSegmentation.h"
31 #include "AliMpPad.h"
32 #include "AliMpIntPair.h"
33 #include "AliMUON.h"
34 #include "AliMpDEIterator.h"
35 #include "AliMUONGeometryTransformer.h"
36 #include "AliMUONTriggerCrateStore.h"
37 #include "AliMUONLocalTriggerBoard.h"
38 #include "AliMUONTriggerElectronics.h"
39 #include "AliMUONCalibrationData.h"
40
41 #include "AliRun.h"
42 #include "AliRunLoader.h"
43 #include "AliCDBManager.h"
44
45 #include <TSystem.h>
46 #include <TGLabel.h>
47 #include <TGFrame.h>
48 #include <TApplication.h>
49 #include <TGDimension.h>
50 #include <TString.h>
51 #include <TGMenu.h>
52 #include <TGTextEntry.h>
53 #include <TGButton.h>
54 #include <TFile.h>
55 #include <TGImageMap.h>
56 #include <TGTextBuffer.h>
57
58 /// \cond CLASSIMP
59 ClassImp(AliMUONTriggerGUI)
60 /// \endcond
61
62 //__________________________________________________________________________
63 AliMUONTriggerGUI::AliMUONTriggerGUI()
64   : TObject(),
65     fMain(0),
66     fImageMap(0),
67     fTxtBuffer1(0),
68     fTxtBuffer2(0),
69     fTxtCircuit(0),
70     fRunInput(0),
71     fError(0),
72     fControl(0),
73     fCircuit(0),
74     fSkipToEventTxt(0),
75     fFileName(0),
76     fPath(0),
77     fEvString(0),
78     fChamber(0),
79     fEvent(0),
80     fEventsPerRun(0),
81     fLoader(0),
82     fRunLoader(0),
83     fCDBManager(0),
84     fCalibrationData(0),
85     fBoardsInit(0),
86     fDiMap(0),
87     fTriggerProcessor(0),
88     fBoards(0)
89 {
90   /// main GUI frame of the trigger monitor
91
92   fChamber = 0;
93   fEvent   = 0;
94   fEventsPerRun = 0;
95   fRunLoader = 0;
96   fDiMap = 0;
97
98   fBoards = 0;
99   fFileName = new TString("");
100   fEvString = new TString("");
101   fPath = new TString("");
102
103   fTriggerProcessor = 0;
104
105   fCDBManager = AliCDBManager::Instance();
106   fCDBManager->SetDefaultStorage("local://$ALICE_ROOT");
107   fCalibrationData = new AliMUONCalibrationData(0);  // runnumber zero
108   
109   // Main frame
110
111   fMain = new TGMainFrame(gClient->GetRoot(), 750, 420);
112   fMain->Connect("CloseWindow()", "AliMUONTriggerGUI", this, "CloseWindow()");
113
114   // Menu bar
115   
116   TGMenuBar *menuBar = new TGMenuBar(fMain);
117   
118   // File menu
119
120   TGPopupMenu *menuFile = new TGPopupMenu(gClient->GetRoot());
121   //menuFile->AddLabel("");
122
123   menuFile->AddEntry("Run",     kMFILERUN);
124   menuFile->AddEntry("Control", kMFILECNTRL);
125   menuFile->AddEntry("Exit",    kMFILEEXIT);
126
127   menuFile->Connect("Activated(Int_t)", "AliMUONTriggerGUI", this, "HandleMenu(Int_t)");
128
129   // Circuit menu
130
131   TGPopupMenu *menuCircuit = new TGPopupMenu(gClient->GetRoot());
132   //menuCircuit->AddLabel("");
133
134   menuCircuit->AddEntry("Open",     kMCIRCUITOPEN);
135
136   menuCircuit->Connect("Activated(Int_t)", "AliMUONTriggerGUI", this, "HandleMenu(Int_t)");
137
138   // Digits map menu
139
140   TGPopupMenu *menuMap = new TGPopupMenu(gClient->GetRoot());
141   //menuMap->AddLabel("");
142
143   menuMap->AddEntry("Digits map",   kMMAPDIGITS);
144   menuMap->AddEntry("Reset digits", kMRESETDIGITS);
145
146   menuMap->Connect("Activated(Int_t)", "AliMUONTriggerGUI", this,
147                     "HandleMenu(Int_t)");
148
149   // Trigger menu
150
151   TGPopupMenu *menuTrigger = new TGPopupMenu(gClient->GetRoot());
152   //menuTrigger->AddLabel("");
153
154   menuTrigger->AddEntry("Trigger DSET",     kMTRIGGERDSET);
155
156   menuTrigger->Connect("Activated(Int_t)", "AliMUONTriggerGUI", this, "HandleMenu(Int_t)");
157
158   // Add menus to the menu bar
159
160   menuBar->AddPopup("File", menuFile, 
161                     new TGLayoutHints(kLHintsTop | kLHintsLeft, 5,5,2,2)
162                     );
163
164   menuBar->AddPopup("Maps", menuMap, 
165                     new TGLayoutHints(kLHintsTop | kLHintsLeft, 5,5,2,2)
166                     );
167
168   menuBar->AddPopup("Circuit", menuCircuit, 
169                     new TGLayoutHints(kLHintsTop | kLHintsLeft, 5,5,2,2)
170                     );
171
172   menuBar->AddPopup("Trigger", menuTrigger, 
173                     new TGLayoutHints(kLHintsTop | kLHintsLeft, 5,5,2,2)
174                     );
175
176   // Add menu bar to the main frame
177
178   fMain->AddFrame(menuBar,
179                   new TGLayoutHints(kLHintsTop | 
180                                     kLHintsLeft | 
181                                     kLHintsExpandX, 
182                                     0, 0, 1, 1)
183                   );
184  
185   // The image map
186
187   fImageMap = new TGImageMap(fMain,"$ALICE_ROOT/MUON/data/guimap.gif");
188   
189   fImageMap->Connect("RegionClicked(Int_t)", "AliMUONTriggerGUI", this, "OpenBoard(Int_t)");
190
191   fImageMap->SetToolTipText("Map of the local boards as seen from the I.P.");
192
193   // Add image map to the main frame
194
195   fMain->AddFrame(fImageMap);
196   fMain->SetWindowName("Map of the local boards as seen from the I.P.");
197
198   // Resize the main frame
199   
200   TGDimension size = fMain->GetDefaultSize();
201   fMain->Resize(size);
202
203   fMain->MapSubwindows();
204
205   fMain->MapWindow();
206
207   fBoardsInit = kFALSE;
208
209   //HandleMenu(kMFILERUN);  // temporary
210
211   //InitBoards();
212   //Init();
213   
214 }
215
216 //__________________________________________________________________________
217 void AliMUONTriggerGUI::HandleMenu(Int_t id)
218 {
219   /// handles entry numbers in the available menus (EMenuIdentifiers)
220
221   TGCompositeFrame *runInput1, *runInput2, *runInput3;
222   TGCompositeFrame *control1, *control2, *circuit1, *circuit2;
223   TGLabel *runL1, *runL2, *circuitL1;
224   TGTextEntry *runText1, *runText2, *circuitText1;
225   TGTextButton *runApply, *runCancel; 
226   TGTextButton *controlClose, *nextEvent, *previousEvent, *skipToEvent;
227   TGTextButton *circuitCancel, *circuitOpen;
228
229   //Int_t trigInfo[kNBoards*6] = {-1};
230   //Int_t nLocalTrigger = 0;
231
232   TString error = TString("");
233   if (id != kMFILEEXIT && id != kMFILERUN && fRunLoader == 0) {
234     error.Append("Run not initialized (Menu: File/Run)");
235     DoErrorGUI(error.Data());
236     return;
237   }
238
239   switch (id) {
240
241   case kMFILEEXIT:
242
243     printf("\nBye. \n");
244     CloseWindow();
245     break;
246     
247   case kMFILERUN:
248     
249     // input main frame
250
251     fRunInput = new TGTransientFrame(gClient->GetRoot(), fMain, 400, 200);
252     fRunInput->Connect("CloseWindow()", "AliMUONTriggerGUI", this, "CloseRunInput()");
253     fRunInput->DontCallClose(); // to avoid double deletions.
254
255     // use hierarchical cleaning
256     fRunInput->SetCleanup(kDeepCleanup);
257
258     fRunInput->SetWindowName("Input file and event number");
259
260     // input galice and event number frames
261
262     runInput1 = new TGCompositeFrame(fRunInput, 400, 200, kHorizontalFrame);
263     runInput2 = new TGCompositeFrame(fRunInput, 400, 200, kHorizontalFrame);
264
265     // .. with labels
266
267     runL1 = new TGLabel(runInput1, new TGString("Path to gAlice:"));
268     runL2 = new TGLabel(runInput2, new TGString("Event number:"));
269
270     // galice text entry
271
272     runText1 = new TGTextEntry(runInput1, fTxtBuffer1 = new TGTextBuffer(100));
273
274     //fPath->Append("dset");                 // temporary
275     //fTxtBuffer1->AddText(0,fPath->Data());  // temporary
276
277     runText1->SetToolTipText("Enter the path to galice.root");
278     runText1->Resize(300, runText1->GetDefaultHeight());
279
280     // event number text entry
281
282     runText2 = new TGTextEntry(runInput2, fTxtBuffer2 = new TGTextBuffer(5));
283
284     fEvString->Form("%d",0);               
285     fTxtBuffer2->AddText(0,fEvString->Data());
286
287     runText2->SetToolTipText("Enter the first event number to start with");
288     runText2->Resize(300, runText2->GetDefaultHeight());
289
290     // add to galice frame
291
292     runInput1->AddFrame(runL1,
293                          new TGLayoutHints(kLHintsLeft | 
294                                            kLHintsCenterY, 
295                                            3, 5, 0, 0)
296                         );
297
298     runInput1->AddFrame(runText1, 
299                         new TGLayoutHints(kLHintsRight | 
300                                           kLHintsCenterY, 
301                                           0, 2, 0, 0)
302                         );
303
304     // add to event number frame
305
306     runInput2->AddFrame(runL2,
307                          new TGLayoutHints(kLHintsLeft | 
308                                            kLHintsCenterY, 
309                                            3, 5, 0, 0)
310                         );
311
312     runInput2->AddFrame(runText2, 
313                         new TGLayoutHints(kLHintsRight | 
314                                           kLHintsCenterY, 
315                                           0, 2, 0, 0)
316                         );
317
318     // add input frames to main input frame
319
320     fRunInput->AddFrame(runInput1, 
321                         new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0));
322     
323     fRunInput->AddFrame(runInput2, 
324                         new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0));
325     
326     // frame with buttons
327
328     runInput3 = new TGCompositeFrame(fRunInput, 400, 200, kHorizontalFrame);
329
330     // buttons
331
332     runApply = new TGTextButton(runInput3, "Apply", 1);
333     runApply->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoRunApply()");
334     runApply->SetToolTipText("Apply changes");
335
336     runCancel = new TGTextButton(runInput3, "Cancel", 2);
337     runCancel->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoRunCancel()");    runCancel->SetToolTipText("Cancel changes");
338
339     // add buttons
340
341     runInput3->AddFrame(runApply, 
342                          new TGLayoutHints(kLHintsTop | 
343                                            kLHintsLeft, 
344                                            3, 3, 2, 2)
345                         );
346     
347     runInput3->AddFrame(runCancel, 
348                          new TGLayoutHints(kLHintsTop | 
349                                            kLHintsLeft, 
350                                            3, 3, 2, 2)
351                         );
352     
353     // add to the main input frame
354
355     fRunInput->AddFrame(runInput3, 
356                         new TGLayoutHints(kLHintsTop | 
357                                           kLHintsExpandX, 
358                                           2, 2, 3, 0)
359                         );
360     
361     fRunInput->MapSubwindows();
362     fRunInput->Resize();
363     fRunInput->MapWindow();
364
365     //DoRunApply();   // temporary
366
367     break;
368     
369   case kMFILECNTRL:
370
371     // control main frame
372
373     fControl = new TGTransientFrame(gClient->GetRoot(), fMain, 50, 50);
374     fControl->Connect("CloseWindow()", "AliMUONTriggerGUI", this, "CloseControl()");
375     fControl->DontCallClose(); // to avoid double deletions.
376   
377     // use hierarchical cleaning
378     fControl->SetCleanup(kDeepCleanup);
379   
380     fControl->SetWindowName("Run controls");
381
382     // frame to hold buttons
383
384     control1 = new TGCompositeFrame(fControl, 50, 50, kVerticalFrame);
385   
386     // buttons
387
388     controlClose = new TGTextButton(control1, "Close", 1);
389     controlClose->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoControlClose()");
390     //controlClose->Resize(300, controlClose->GetDefaultHeight());  
391
392     nextEvent = new TGTextButton(control1, "Next event", 2);
393     nextEvent->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoNextEvent()");
394
395     previousEvent = new TGTextButton(control1, "Previous event", 3);
396     previousEvent->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoPreviousEvent()");
397   
398     // frame to hold event skip
399
400     control2 = new TGCompositeFrame(fControl, 50, 50, kHorizontalFrame);
401   
402     // skip to event text field
403
404     fSkipToEventTxt = new TGTextEntry(control2, fTxtBuffer2 = new TGTextBuffer(5));
405
406     fTxtBuffer2->AddText(0,fEvString->Data());
407
408     // skip to event button
409
410     skipToEvent = new TGTextButton(control2, "Skip to event", 1);
411     skipToEvent->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoSkipToEvent()");
412
413     // add to event skip frame
414
415     control2->AddFrame(fSkipToEventTxt, 
416                        new TGLayoutHints(kLHintsTop | 
417                                          kLHintsRight, 
418                                          10, 10, 5, 5)
419                        );
420   
421     control2->AddFrame(skipToEvent, 
422                        new TGLayoutHints(kLHintsTop | 
423                                          kLHintsRight, 
424                                          10, 10, 5, 5)
425                        );
426   
427     // add buttons
428   
429     control1->AddFrame(controlClose, 
430                  new TGLayoutHints(kLHintsBottom | 
431                                    kLHintsExpandX, 
432                                    10, 10, 5, 5)
433                  );
434   
435     control1->AddFrame(nextEvent, 
436                  new TGLayoutHints(kLHintsBottom | 
437                                    kLHintsExpandX, 
438                                    10, 10, 5, 5)
439                  );
440   
441     control1->AddFrame(previousEvent, 
442                  new TGLayoutHints(kLHintsBottom | 
443                                    kLHintsExpandX, 
444                                    10, 10, 5, 5)
445                  );
446   
447     // add to the main frame
448
449     fControl->AddFrame(control1,
450                        new TGLayoutHints(kLHintsBottom |
451                                          kLHintsLeft | 
452                                          kLHintsCenterY, 
453                                          3, 5, 0, 0)
454                        );
455     
456     fControl->AddFrame(control2,
457                        new TGLayoutHints(kLHintsTop | 
458                                          kLHintsCenterX, 
459                                          3, 5, 0, 0)
460                        );
461     
462     fControl->MapSubwindows();
463     fControl->Resize();
464     fControl->MapWindow();
465    
466     break;
467
468   case kMMAPDIGITS:
469     
470     if (fDiMap == 0) {
471       fDiMap = new AliMUONTriggerGUIdimap(fLoader,fBoards,gClient->GetRoot(), fMain, 400, 200);
472     } else if (!fDiMap->IsOn()) {
473       fDiMap = new AliMUONTriggerGUIdimap(fLoader,fBoards,gClient->GetRoot(), fMain, 400, 200);
474     }
475
476     break;
477     
478   case kMRESETDIGITS:
479     
480     Int_t number, over, pos;
481     for (Int_t ib = 0; ib < kNBoards; ib++) {
482       AliMUONTriggerGUIboard *board = GetBoard(ib);
483       board->ClearXDigits();
484       board->ClearYDigits();
485       // extended y-strips
486       number = board->GetNumber();
487       pos    = board->GetPosition();
488       over   = board->GetYOver();
489       for (Int_t io = 1; io <= over; io++) {
490         if (io == pos) continue;
491         board = GetBoard(number+io-pos);
492         board->ClearYDigits();
493       }
494     }
495
496     break;
497     
498   case kMCIRCUITOPEN:
499
500     fCircuit = new TGTransientFrame(gClient->GetRoot(), fMain, 50, 50);
501     fCircuit->Connect("CloseWindow()", "AliMUONTriggerGUI", this, "CloseCircuit()");
502     fCircuit->DontCallClose(); // to avoid double deletions.
503   
504     // use hierarchical cleaning
505     fCircuit->SetCleanup(kDeepCleanup);
506   
507     fCircuit->SetWindowName("Board circuit");
508
509     // sub-frames
510
511     circuit1 = new TGCompositeFrame(fCircuit, 400, 200, kHorizontalFrame);
512     circuit2 = new TGCompositeFrame(fCircuit, 400, 200, kHorizontalFrame);
513
514     // labels
515
516     circuitL1 = new TGLabel(circuit1, new TGString("Circuit number:"));
517     
518     // text entry
519     
520     circuitText1 = new TGTextEntry(circuit1, fTxtCircuit = new TGTextBuffer(10));
521     // buttons
522
523     circuitCancel = new TGTextButton(circuit2, "Cancel", 1);
524     circuitCancel->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoCircuitCancel()");
525     //circuitCancel->Resize(100, circuitCancel->GetDefaultHeight());  
526
527     circuitOpen = new TGTextButton(circuit2, "Open", 2);
528     circuitOpen->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoCircuitOpen()");
529     //circuitOpen->Resize(100, circuitOpen->GetDefaultHeight());  
530
531     // adding
532
533     circuit1->AddFrame(circuitL1,
534                        new TGLayoutHints(kLHintsLeft | 
535                                          kLHintsCenterY, 
536                                          5, 5, 2, 2)
537                        );
538     
539     circuit1->AddFrame(circuitText1, 
540                        new TGLayoutHints(kLHintsRight | 
541                                          kLHintsCenterY, 
542                                          0, 2, 2, 2)
543                        );
544     
545     circuit2->AddFrame(circuitCancel, 
546                  new TGLayoutHints(kLHintsBottom | 
547                                    kLHintsCenterY, 
548                                    5, 5, 2, 2)
549                  );
550   
551     circuit2->AddFrame(circuitOpen, 
552                  new TGLayoutHints(kLHintsBottom | 
553                                    kLHintsCenterY, 
554                                    5, 5, 2, 2)
555                  );
556   
557     fCircuit->AddFrame(circuit1, 
558                        new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0));
559     
560     fCircuit->AddFrame(circuit2, 
561                        new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0));
562     
563     fCircuit->MapSubwindows();
564     fCircuit->Resize();
565     fCircuit->MapWindow();
566
567     break;
568
569   case kMTRIGGERDSET:
570     /*
571     cout << "Trigger with boards digits....." << endl;
572     fTriggerProcessor->FeedBoardsGUI(Boards());
573
574     nLocalTrigger = fTriggerProcessor->TriggerGUI(trigInfo,kTRUE);
575
576     cout << "Trigger done with " << nLocalTrigger << " local decisions !" << endl;
577
578     for (Int_t ilo = 0; ilo < nLocalTrigger; ilo++) {
579
580       cout << "Local decision " << ilo << endl;
581       cout << "Circuit = "  << trigInfo[6*ilo+0] << endl;
582       cout << "LoStripX = " << trigInfo[6*ilo+1] << endl;
583       cout << "LoStripY = " << trigInfo[6*ilo+2] << endl;
584       cout << "LoDev = "    << trigInfo[6*ilo+3] << endl;
585       cout << "LoLpt = "    << trigInfo[6*ilo+4] << endl;
586       cout << "LoHpt = "    << trigInfo[6*ilo+5] << endl;
587       cout                                       << endl;
588     }
589     */
590     break;
591
592   default:
593     printf("Menu item %d selected\n", id);
594     break;
595     
596   }
597
598 }
599
600 //__________________________________________________________________________
601 void AliMUONTriggerGUI::CloseRunInput() const
602 {
603   /// close the run input frame
604
605   delete fRunInput;
606
607 }
608
609 //__________________________________________________________________________
610 void AliMUONTriggerGUI::CloseError() const
611 {
612   /// close the error frame
613
614   delete fError;
615
616 }
617
618 //__________________________________________________________________________
619 void AliMUONTriggerGUI::CloseControl() const
620 {
621   /// close the event control frame
622
623   delete fControl;
624
625   //gSystem->Exec("cd $PWD/mtrun; aliroot -b -q mtsim.C");
626
627 }
628
629 //__________________________________________________________________________
630 void AliMUONTriggerGUI::CloseCircuit() const
631 {
632   /// close the circuit frame
633
634   delete fCircuit;
635
636 }
637
638 //__________________________________________________________________________
639 void AliMUONTriggerGUI::CloseWindow() 
640 {
641   /// close the main frame and exit aplication
642
643   delete fRunLoader;
644   printf("\n"); 
645   gApplication->Terminate(); 
646
647 }
648
649 //__________________________________________________________________________
650 void AliMUONTriggerGUI::DoRunApply()
651 {
652   /// apply changes in the run control frame
653
654   printf("Input 1 = %s \n",fTxtBuffer1->GetString());
655
656   TString es = TString(fTxtBuffer2->GetString());
657   fEvent = es.Atoi();
658
659   printf("Input 2 = %s event = %d \n",fTxtBuffer2->GetString(),fEvent);
660
661   TString error = TString("");;
662
663   fPath->Form("%s",fTxtBuffer1->GetString());
664   fFileName->Form("%s",fTxtBuffer1->GetString());
665   printf("File location: %s \n",fFileName->Data());
666
667   if (gSystem->AccessPathName(fFileName->Data()) || !fFileName->EndsWith(".root")) {
668
669     error.Append("No galice file: ");
670     error.Append(fFileName->Data());
671     DoErrorGUI(error.Data());
672
673   } else {
674
675     TFile *ftest = new TFile(fFileName->Data(),"READ");
676     AliRun *galice = (AliRun*)ftest->Get("gAlice");
677     if (galice == 0) {
678
679       ftest->Close();
680       delete ftest;
681       
682       error.Append("No gAlice in file: ");
683       error.Append(fFileName->Data());
684       DoErrorGUI(error.Data());
685
686       return;
687
688     } else {
689       ftest->Close();
690       delete ftest;
691     }
692
693     if (fRunLoader) delete fRunLoader;
694
695     fRunLoader = AliRunLoader::Open(fFileName->Data(),"MUONFolder","READ");
696
697     if (fRunLoader == 0x0) {
698
699       DoErrorGUI("No run loader !");
700
701     } else {
702       
703       fRunLoader->LoadgAlice();
704       gAlice = fRunLoader->GetAliRun();
705       fEventsPerRun = gAlice->GetEventsPerRun();
706       
707       fLoader = fRunLoader->GetLoader("MUONLoader");
708       fLoader->LoadDigits("READ");
709       fRunLoader->GetEvent(fEvent);
710            
711       fRunInput->SendCloseMessage();
712       
713       if (!fBoardsInit) {
714         InitBoards();
715       }
716       
717       if (fDiMap) {
718         if (fDiMap->IsOn()) {
719           fDiMap->SetLoader(fLoader);
720         }
721       }
722       
723       //fTriggerProcessor = new AliMUONTriggerElectronics(fCalibrationData);
724     }
725
726   }
727
728 }
729
730 //__________________________________________________________________________
731 void AliMUONTriggerGUI::DoRunCancel()
732 {
733   /// cancel the changes in the run control frame
734
735   printf("Input 1 = %s \n",fTxtBuffer1->GetString());
736
737   TString es = TString(fTxtBuffer2->GetString());
738   fEvent = es.Atoi();
739
740   printf("Input 2 = %s event = %d \n",fTxtBuffer2->GetString(),fEvent);
741
742   fRunInput->SendCloseMessage();
743
744 }
745
746 //__________________________________________________________________________
747 void AliMUONTriggerGUI::DoErrorGUI(const Char_t *wt)
748 {
749   /// show an error message in a new frame
750
751   fError = new TGTransientFrame(gClient->GetRoot(), fMain, 50, 50);
752   fError->Connect("CloseWindow()", "AliMUONTriggerGUI", this, "CloseError()");
753   fError->DontCallClose(); // to avoid double deletions.
754   
755   // use hierarchical cleaning
756   fError->SetCleanup(kDeepCleanup);
757   
758   fError->SetWindowName("Error !");
759
760   TGCompositeFrame *fW = new TGCompositeFrame(fError, 50, 50, kVerticalFrame);
761   
762   TGTextButton *fErrorOK = new TGTextButton(fW, "&Ok", 1);
763   fErrorOK->Connect("Clicked()", "AliMUONTriggerGUI", this, "DoErrorOK()");
764   
765   fW->AddFrame(fErrorOK, 
766                new TGLayoutHints(kLHintsBottom | 
767                                  kLHintsCenterX, 
768                                  5, 5, 5, 5)
769                );
770   
771   TGLabel *fWL = new TGLabel(fW, new TGString(wt));
772   
773   fW->AddFrame(fWL,
774                new TGLayoutHints(kLHintsTop | 
775                                  kLHintsCenterX, 
776                                  5, 5, 5, 5)
777                );
778   
779   fError->AddFrame(fW,
780                    new TGLayoutHints(kLHintsLeft | 
781                                      kLHintsCenterY, 
782                                      5, 5, 5, 5)
783                    );
784   
785   fError->MapSubwindows();
786   fError->Resize();
787   fError->MapWindow();
788    
789 }
790
791 //__________________________________________________________________________
792 void AliMUONTriggerGUI::DoNextEvent()
793 {
794   /// load next event from the file
795
796   TString error = TString("");
797
798   if (fEvent < (fEventsPerRun-1)) {
799     fEvent++;
800     fRunLoader->GetEvent(fEvent);
801
802     fEvString->Form("%d",fEvent);               
803     fTxtBuffer2->RemoveText(0,5);
804     fTxtBuffer2->AddText(0,fEvString->Data());
805     fSkipToEventTxt->SetFocus();
806
807   } else {
808     error.Form("Only %d event(s) in the run !",fEventsPerRun);
809     DoErrorGUI(error.Data());
810   }
811
812 }
813
814 //__________________________________________________________________________
815 void AliMUONTriggerGUI::DoPreviousEvent()
816 {
817   /// load previous event from the input file
818
819   TString error = TString("");
820
821   if (fEvent > 0) {
822     fEvent--;
823     fRunLoader->GetEvent(fEvent);
824
825     fEvString->Form("%d",fEvent);               
826     fTxtBuffer2->RemoveText(0,5);
827     fTxtBuffer2->AddText(0,fEvString->Data());
828     fSkipToEventTxt->SetFocus();
829
830   } else {
831     error.Form("Already at event 0 !");
832     DoErrorGUI(error.Data());
833   }
834
835 }
836
837 //__________________________________________________________________________
838 void AliMUONTriggerGUI::DoSkipToEvent()
839 {
840   /// skip to event -input- from the input file
841
842   TString error = TString("");
843
844   TString es = TString(fTxtBuffer2->GetString());
845   fEvent = es.Atoi();
846
847   if (fEvent < 0 || fEvent > (fEventsPerRun-1)) {
848     error.Form("Event number out of range !");
849     DoErrorGUI(error.Data());
850   } else {
851     fRunLoader->GetEvent(fEvent);
852     /*
853     fRunLoader->LoadKinematics();
854
855     AliStack* stack = gAlice->Stack();
856     Int_t nParticles = stack->GetNtrack();
857     Int_t nPrimaries = stack->GetNprimary();
858     
859     TParticle *part;
860     Int_t nMuons = 0;
861     Int_t pdgCode;
862     Double_t px, py, pz, theta, phi;
863     for (Int_t i = 0; i < nPrimaries; i++) {
864       part = stack->Particle(i);
865       if (!part) continue;
866       if (TMath::Abs(part->GetPdgCode()) == 13) {
867         nMuons++;
868         pdgCode = part->GetPdgCode();
869         px = part->Px();
870         py = part->Py();
871         pz = part->Pz();
872         theta = part->Theta();
873         phi = part->Phi();
874         printf("Kine %d px %f py %f pz %f th %f ph %f \n",pdgCode,px,py,pz,theta,phi); 
875       }
876     }
877     */    
878   }
879
880 }
881
882 //__________________________________________________________________________
883 void AliMUONTriggerGUI::DoErrorOK()
884 {
885   /// close the error frame
886
887   fError->SendCloseMessage();
888
889 }
890
891 //__________________________________________________________________________
892 void AliMUONTriggerGUI::DoControlClose()
893 {
894   /// close the event control frame
895
896   fControl->SendCloseMessage();
897
898 }
899
900 //__________________________________________________________________________
901 void AliMUONTriggerGUI::DoCircuitCancel()
902 {
903   /// close the circuit frame
904
905   fCircuit->SendCloseMessage();
906
907 }
908
909 //__________________________________________________________________________
910 void AliMUONTriggerGUI::DoCircuitOpen()
911 {
912   /// open a circuit
913
914   TString cs = TString(fTxtCircuit->GetString());
915   Int_t icirc = cs.Atoi();
916
917   AliMUONTriggerGUIboard *board;
918
919   for (Int_t ib = 0; ib < kNBoards; ib++) {
920
921     board = GetBoard(ib);
922
923     if (board->GetIdCircuit() == icirc) {
924
925       OpenBoard(ib);
926
927       if (fDiMap) {
928         if (fDiMap->IsOn()) {
929           fDiMap->SelectBoard(ib);
930         }
931       }
932       
933       fCircuit->SendCloseMessage();
934       return;
935     }
936
937   }
938
939 }
940
941 //__________________________________________________________________________
942 AliMUONTriggerGUIboard* AliMUONTriggerGUI::GetBoard(Int_t id) const
943 {
944   /// return board with "id"
945
946   if (fBoards == 0) return 0;
947   void * b = fBoards->UncheckedAt(id);
948   if (b == 0) return 0;
949
950   return (AliMUONTriggerGUIboard*)b;
951
952 }
953
954 //__________________________________________________________________________
955 void AliMUONTriggerGUI::OpenBoard(Int_t id)
956 {
957   /// open board with "id" in a new frame
958    
959   AliMUONTriggerGUIboard *board = GetBoard(id);
960   UShort_t status = board->GetStatus();
961   board->SetOpen(kTRUE);
962
963   AliMUONTriggerGUIbdmap *bf;
964   Char_t text[200];
965
966   bf = new AliMUONTriggerGUIbdmap(gClient->GetRoot(), fMain, 400, 200);
967
968   if (status & kGood) {
969     sprintf(text,"%s (Circuit %4d) status : working",
970             board->GetBoardName(),board->GetIdCircuit());
971   }
972
973   if (status & kWithProblems) {
974     sprintf(text,"%s (Circuit %4d)  status : has problems...",
975             board->GetBoardName(),board->GetIdCircuit());
976   }
977
978   if (status & kNotWorking) {
979     sprintf(text,"%s (Circuit %4d)  status : not working",
980             board->GetBoardName(),board->GetIdCircuit());
981   }
982
983   if (status & kUnknown) {
984     sprintf(text,"%s (Circuit %4d)  status : unknown",
985             board->GetBoardName(),board->GetIdCircuit());
986   }
987
988   bf->SetName(text);
989   bf->SetBoard(Boards(),id);
990   bf->SetLoader(fLoader);
991   bf->Init();
992
993   bf->Show();
994
995   if (fDiMap) {
996     if (fDiMap->IsOn()) {
997       fDiMap->SelectBoard(id);
998     }
999   }
1000
1001 }
1002
1003 //__________________________________________________________________________
1004 void AliMUONTriggerGUI::Init()
1005 {
1006   /// initialize the main GUI frame
1007   
1008   if (!fBoardsInit) {
1009     InitBoards();
1010   }
1011
1012   /*
1013   AliMUONTriggerGUIboard *board;
1014   for (Int_t ib = 0; ib < kNBoards; ib++) {
1015     board = GetBoard(ib);
1016     board->Dump();
1017   }
1018   */
1019 }
1020
1021 //__________________________________________________________________________
1022 void AliMUONTriggerGUI::InitBoards()
1023 {
1024   /// create board objects and define the sensitive regions in the image map
1025   
1026   fBoardsInit = kTRUE;
1027
1028   AliMUONTriggerCrateStore* crateManager = new AliMUONTriggerCrateStore();
1029   crateManager->ReadFromFile();
1030
1031   Int_t nPixelX = 700;
1032   Int_t nPixelY = 676;
1033
1034   Int_t nPixelBorderX = 40;  // to guess...
1035   Int_t nPixelBorderY = 40;  // to guess...
1036
1037   Float_t boardsX = 2*257.00;  // cm
1038   Float_t boardsY = 2*306.61;  // cm
1039
1040   FILE *fmap;
1041
1042   Int_t side, col, line, nbx, detElemId = 0;
1043   UShort_t status = 1;
1044   Float_t xCenter, yCenter, zCenter, xWidth, yWidth;
1045   Float_t xc, yc;
1046   Char_t name[8], text[200];
1047   Int_t x, y;
1048   UInt_t w, h;
1049   Int_t xp[5];
1050   Int_t yp[5];
1051   TString mapspath = gSystem->Getenv("ALICE_ROOT");
1052   mapspath.Append("/MUON/data");
1053
1054   TGRegion *reg;
1055   AliMUONTriggerGUIboard *board;
1056
1057   // regions for the image map
1058
1059   sprintf(text,"%s/guimapp11.txt",mapspath.Data());
1060   fmap = fopen(text,"r");
1061
1062   for (Int_t ib = 0; ib < kNBoards; ib++) {
1063
1064     fscanf(fmap,"%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",&side,&col,&line,&nbx,&xCenter,&yCenter,&xWidth,&yWidth,&zCenter,&name[0]);
1065
1066     //printf("%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",side,col,line,nbx,xCenter,yCenter,xWidth,yWidth,zCenter,name);
1067
1068     board = new AliMUONTriggerGUIboard(ib,name);
1069
1070     status = 1;
1071     board->SetStatus(status);
1072
1073     // calculate detElemId%100
1074     // side=0 left
1075     // side=1 right
1076     // ALICE SC
1077     if (side == 0)              detElemId = 14 - line;
1078     if (side == 1 && line <  5) detElemId = 13 + line;
1079     if (side == 1 && line >= 5) detElemId = line - 5;
1080     
1081     board->SetDetElemId(detElemId);
1082
1083     Boards()->Add(board);
1084
1085     xc = xCenter;
1086     yc = yCenter;
1087
1088     x = (Int_t)(nPixelX/2 + xc * (nPixelX - 2*nPixelBorderX)/boardsX);
1089     y = (Int_t)(nPixelY/2 - yc * (nPixelY - 2*nPixelBorderY)/boardsY);
1090
1091     if (x < 0) x = 0;
1092     if (y < 0) y = 0;
1093
1094     w = (UInt_t)(xWidth*(nPixelX-2*nPixelBorderX)/boardsX);
1095     h = (UInt_t)(yWidth*(nPixelY-2*nPixelBorderY)/boardsY);
1096     
1097     xp[0] = x-w/2;
1098     xp[1] = x+w/2;
1099     xp[2] = x+w/2;
1100     xp[3] = x-w/2;
1101     xp[4] = x-w/2;
1102     
1103     yp[0] = y-h/2;
1104     yp[1] = y-h/2;
1105     yp[2] = y+h/2;
1106     yp[3] = y+h/2;
1107     yp[4] = y-h/2;
1108
1109     reg = new TGRegion(5,xp,yp);
1110     fImageMap->AddRegion(*reg, ib);
1111
1112     if (status & kGood) {
1113       sprintf(text,"%s working",name);
1114     }
1115     if (status & kWithProblems) {
1116       sprintf(text,"%s has problems...",name);
1117     }
1118     if (status & kNotWorking) {
1119       sprintf(text,"%s not working",name);
1120     }
1121     if (status & kUnknown) {
1122       sprintf(text,"%s status unknown",name);
1123     }
1124     
1125     //fImageMap->SetToolTipText(ib, text);
1126     
1127   }
1128
1129   fclose(fmap);
1130   
1131   // MT position and dimension in board
1132   
1133   for (Int_t imt = 0; imt < kNMT; imt++) {
1134
1135     sprintf(text,"%s/guimapp%2d.txt",mapspath.Data(),11+imt);
1136
1137     fmap = fopen(text,"r");
1138
1139     for (Int_t ib = 0; ib < kNBoards; ib++) {
1140
1141       fscanf(fmap,"%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",&side,&col,&line,&nbx,&xCenter,&yCenter,&xWidth,&yWidth,&zCenter,&name[0]);
1142
1143       board = GetBoard(ib);
1144       board->SetDimensions(imt,xCenter,yCenter,zCenter,xWidth,yWidth);
1145
1146     }
1147
1148     fclose(fmap);
1149
1150   }
1151
1152   // MT x-strips indices and circuit number
1153   Int_t ix, iy1, iy2, sIx, sIy1, cathode, icirc;
1154   sprintf(text,"%s/guimapix11.txt",mapspath.Data());
1155
1156   fmap = fopen(text,"r");
1157   
1158   for (Int_t ib = 0; ib < kNBoards; ib++) {
1159     
1160     fscanf(fmap,"%d   %d   %d   %d   %d   %d   %d   %s   \n",&side,&col,&line,&nbx,&ix,&iy1,&iy2,&name[0]);
1161     
1162     board = GetBoard(ib);
1163     board->SetXSindex(ix,iy1,iy2);
1164
1165     // set the circuit number
1166     detElemId = board->GetDetElemId();
1167     detElemId += 100 * 11;
1168     cathode = 0;
1169     sIx  = board->GetXSix();
1170     sIy1 = board->GetXSiy1();
1171     const AliMpVSegmentation* seg = 
1172       AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
1173     
1174     AliMpPad pad = seg->PadByIndices(AliMpIntPair(sIx,sIy1),kTRUE);
1175     AliMpIntPair location = pad.GetLocation(0);
1176
1177     Int_t nboard = location.GetFirst();
1178     AliMUONLocalTriggerBoard* b = crateManager->LocalBoard(nboard);
1179     icirc = b->GetNumber();
1180     board->SetBoardName((Char_t*)b->GetName());
1181     board->SetIdCircuit(icirc);
1182
1183     TString crateName = b->GetCrate();
1184     
1185     sprintf(text,"%s (crate %s circuit %3d, number %3d)",board->GetBoardName(),crateName.Data(),icirc,ib);
1186     fImageMap->SetToolTipText(ib, text);
1187         
1188   }
1189   
1190   fclose(fmap);
1191
1192   // MT y-strips indices
1193   Int_t ix1, ix2, iy;
1194
1195   sprintf(text,"%s/guimapiy11.txt",mapspath.Data());
1196   
1197   fmap = fopen(text,"r");
1198   
1199   for (Int_t ib = 0; ib < kNBoards; ib++) {
1200     
1201     fscanf(fmap,"%d   %d   %d   %d   %d   %d   %d   %s   \n",&side,&col,&line,&nbx,&ix1,&ix2,&iy,&name[0]);
1202     
1203     board = GetBoard(ib);
1204     board->SetYSindex(ix1,ix2,iy);
1205     
1206   }
1207   
1208   fclose(fmap);
1209
1210   // Extended y-strips over neighbouring boards
1211
1212   sprintf(text,"%s/guimapp11.txt",mapspath.Data());
1213   
1214   fmap = fopen(text,"r");
1215   
1216   for (Int_t ib = 0; ib < kNBoards; ib++) {
1217     
1218     fscanf(fmap,"%d   %d   %d   %d   %f   %f   %f   %f   %f   %s   \n",&side,&col,&line,&nbx,&xCenter,&yCenter,&xWidth,&yWidth,&zCenter,&name[0]);
1219     
1220     board = GetBoard(ib);
1221
1222     board->SetPosition(nbx);
1223     
1224     if ((col == 2 || col == 3) && (line >= 4 && line <= 6)) {
1225       board->SetYOver(4);
1226     } else
1227       
1228     if (col == 1 && (line == 4 || line == 6)) {
1229       board->SetYOver(3);
1230     } else
1231         
1232     if (col == 7 || line == 1 || line == 9) {
1233       board->SetYOver(1);
1234     } else
1235           
1236     {
1237       board->SetYOver(2);
1238     }
1239     
1240   }
1241   
1242   fclose(fmap);
1243
1244   // Set coordinates of strips boxes
1245
1246   for (Int_t ib = 0; ib < kNBoards; ib++) {
1247     
1248     board = GetBoard(ib);
1249     SetStripBoxes(board);
1250
1251   }
1252
1253 }
1254
1255 //__________________________________________________________________________
1256 void AliMUONTriggerGUI::SetStripBoxes(AliMUONTriggerGUIboard *board) 
1257 {
1258   /// set coordinates of strip boxes
1259
1260   gAlice = fRunLoader->GetAliRun();
1261   AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
1262   const AliMUONGeometryTransformer* kGeomTransformer = pMUON->GetGeometryTransformer();
1263
1264   const AliMpVSegmentation* seg;
1265   AliMpPad pad;
1266   AliMpDEIterator it;
1267
1268   Int_t chamber, detElemId, maxX, maxY, ic;
1269   Float_t xpmin, xpmax, ypmin, ypmax;
1270   Float_t xg1, xg2, yg1, yg2, zg1;
1271   Float_t xlocal1, xlocal2, ylocal1, ylocal2;
1272   Float_t xCenter, yCenter, xWidth, yWidth;
1273
1274   for (Int_t i = 0; i < kNMT; i++) {
1275
1276     chamber = 11+i;
1277
1278     xCenter = board->GetXCenter(i);
1279     yCenter = board->GetYCenter(i);
1280     xWidth  = board->GetXWidth(i);
1281     yWidth  = board->GetYWidth(i);
1282
1283     for ( it.First(chamber-1); ! it.IsDone(); it.Next() ) {
1284     
1285       detElemId = it.CurrentDEId();
1286     
1287       if (detElemId%100 != board->GetDetElemId()) continue;
1288
1289       /*---------- y-pads ic = 2 ----------*/
1290       ic = 2;
1291       
1292       seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(ic-1));
1293
1294       maxX = seg->MaxPadIndexX();
1295       maxY = seg->MaxPadIndexY();
1296       
1297       for (Int_t ix = 0; ix <= maxX; ix++) {
1298         for (Int_t iy = 0; iy <= maxY; iy++) {
1299           
1300           pad = seg->PadByIndices(AliMpIntPair(ix,iy),kFALSE);
1301           
1302           if (!pad.IsValid()) continue;
1303           
1304           // get the pad position and dimensions
1305           xlocal1 = pad.Position().X();
1306           ylocal1 = pad.Position().Y();
1307           xlocal2 = pad.Dimensions().X();
1308           ylocal2 = pad.Dimensions().Y();
1309           
1310           kGeomTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
1311           // (no transformation for pad dimensions)
1312           xg2 = xlocal2;
1313           yg2 = ylocal2;
1314           
1315           // transform in the monitor coordinate system
1316           //xpmin = -(xg1+xg2);
1317           //xpmax = -(xg1-xg2);
1318           //ypmin = -(yg2-yg1);
1319           //ypmax = +(yg2+yg1);
1320           // ALICE SC
1321           xpmin = +(xg1-xg2);
1322           xpmax = +(xg1+xg2);
1323           ypmin = -(yg2-yg1);
1324           ypmax = +(yg2+yg1);
1325           
1326           xpmin -= xCenter;
1327           xpmax -= xCenter;
1328           ypmin -= yCenter;
1329           ypmax -= yCenter;
1330           
1331           Int_t iX1, iX2, iY, ixDig;
1332           iX1 = board->GetYSix1();
1333           iX2 = board->GetYSix2();
1334           iY  = board->GetYSiy();
1335           if (ix >= iX1 && ix <= iX2 && iy == iY) {
1336             
1337             ypmin = -0.5*yWidth;
1338             ypmax = +0.5*yWidth;
1339
1340             ixDig = ix - iX1;
1341
1342             board->SetYDigBox(i,ixDig,(Double_t)xpmin,(Double_t)ypmin,
1343                                       (Double_t)xpmax,(Double_t)ypmax);
1344
1345           }
1346
1347         }  // end maxY
1348       }  // end maxX
1349
1350       /*---------- x-pads ic = 1 ----------*/
1351       ic = 1;
1352       
1353       seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(ic-1));
1354
1355       maxX = seg->MaxPadIndexX();
1356       maxY = seg->MaxPadIndexY();
1357             
1358       for (Int_t ix = 0; ix <= maxX; ix++) {
1359         for (Int_t iy = 0; iy <= maxY; iy++) {
1360           
1361           pad = seg->PadByIndices(AliMpIntPair(ix,iy),kFALSE);
1362           
1363           if (!pad.IsValid()) continue;
1364           
1365           // get the pad position and dimensions
1366           xlocal1 = pad.Position().X();
1367           ylocal1 = pad.Position().Y();
1368           xlocal2 = pad.Dimensions().X();
1369           ylocal2 = pad.Dimensions().Y();
1370           
1371           kGeomTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
1372           // (no transformation for pad dimensions)
1373           xg2 = xlocal2;
1374           yg2 = ylocal2;
1375           
1376           // transform in the monitor coordinate system
1377           //xpmin = -(xg1+xg2);
1378           //xpmax = -(xg1-xg2);
1379           //ypmin = -(yg2-yg1);
1380           //ypmax = +(yg2+yg1);
1381           // ALICE SC
1382           xpmin = +(xg1+xg2);
1383           xpmax = +(xg1-xg2);
1384           ypmin = -(yg2-yg1);
1385           ypmax = +(yg2+yg1);
1386           
1387           xpmin -= xCenter;
1388           xpmax -= xCenter;
1389           ypmin -= yCenter;
1390           ypmax -= yCenter;
1391
1392           Int_t iX, iY1, iY2, iyDig;
1393           iX  = board->GetXSix();
1394           iY1 = board->GetXSiy1();
1395           iY2 = board->GetXSiy2();
1396           if (ix == iX && iy >= iY1 && iy <= iY2) {
1397
1398             iyDig = iy - iY1;
1399
1400             board->SetXDigBox(i,iyDig,(Double_t)xpmin,(Double_t)ypmin,
1401                                       (Double_t)xpmax,(Double_t)ypmax);
1402
1403           }
1404
1405         }  // end maxY
1406       }  // end maxX
1407
1408     }  // end detElemId
1409
1410   }  // end kNMT loop
1411         
1412 }
1413