LCOV - code coverage report
Current view: top level - MUON/MUONgraphics - AliMUONPainterDataSourceItem.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 138 0.7 %
Date: 2016-06-14 17:26:59 Functions: 1 22 4.5 %

          Line data    Source code
       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             : #include "AliMUONPainterDataSourceItem.h"
      19             : 
      20             : #include "AliMUONPainterEnv.h"
      21             : #include "AliMUONPainterHelper.h"
      22             : #include "AliMUONPainterDataRegistry.h"
      23             : #include "AliMUONVTrackerDataMaker.h"
      24             : #include "AliMUONVTrackerData.h"
      25             : #include "AliLog.h"
      26             : #include <TFile.h>
      27             : #include <TGFileDialog.h>
      28             : #include <TGLabel.h>
      29             : #include <TGButton.h>
      30             : #include <TSystem.h>
      31             : #include <TThread.h>
      32             : #include <Riostream.h>
      33             : 
      34             : ///\class AliMUONPainterDataSourceItem
      35             : ///
      36             : /// Widget to show one data source, and allow to run/stop/rewind/remove it
      37             : ///
      38             : /// WARNING : the thread business is not really working yet (AliRawReaders are
      39             : /// not really thread-safe for the moment). So please use a single raw data
      40             : /// source at a time, otherwise you'll get a crash !
      41             : ///
      42             : ///\author Laurent Aphecetche, Subatech
      43             : 
      44             : ///\cond CLASSIMP
      45          12 : ClassImp(AliMUONPainterDataSourceItem)
      46             : ///\endcond
      47             : 
      48             : namespace
      49             : {
      50             :   void* RunFunction(void* args)
      51             :   {
      52           0 :     Long_t* params = (Long_t*)(args);
      53             :     
      54           0 :     AliMUONPainterDataSourceItem* calling = reinterpret_cast<AliMUONPainterDataSourceItem*>(params[0]);
      55           0 :     AliMUONVTrackerDataMaker* reader = reinterpret_cast<AliMUONVTrackerDataMaker*> (params[1]);
      56             :     
      57             :     Bool_t ok(kTRUE);
      58             :     
      59           0 :     while ( ok ) 
      60             :     {
      61           0 :       ok = reader->NextEvent();
      62           0 :       if ( reader->IsZombie() ) 
      63             :       {
      64           0 :         AliMUONPainterDataRegistry::Instance()->DeleteZombies();
      65           0 :         return 0x0;
      66             :       }
      67           0 :       if ( !reader->IsRunning() ) gSystem->Sleep(1000);
      68             :     }
      69             :     
      70           0 :     calling->Rewind();
      71             :     
      72           0 :     return 0x0;
      73           0 :   }
      74             : }
      75             : 
      76             : //_____________________________________________________________________________
      77             : AliMUONPainterDataSourceItem::AliMUONPainterDataSourceItem(const TGWindow* p,
      78             :                                                            UInt_t w, UInt_t h,
      79             :                                                            AliMUONVTrackerDataMaker* maker)
      80           0 : : TGCompositeFrame(p,w,h,kHorizontalFrame),
      81           0 :   fDataMaker(maker),
      82           0 :   fSourceName(new TGLabel(this,maker->Data()->Name())),
      83           0 :   fSource(new TGLabel(this,maker->Source().Data())),
      84           0 :   fNumberOfEvents(new TGLabel(this,Form("%10d",0))),
      85           0 :   fRun(0x0),
      86           0 :   fStop(0x0),
      87           0 :   fRewind(0x0),
      88           0 :   fRemove(new TGTextButton(this,"Remove")),
      89           0 :   fSave(new TGTextButton(this,"Save")),
      90           0 :   fSaveAs(new TGTextButton(this,"Save As...")),
      91           0 :   fThread(0x0),
      92           0 :   fShouldReset(kFALSE)
      93           0 : {
      94             :     /// ctor
      95             :  
      96           0 :     SetCleanup(kDeepCleanup);
      97             :     
      98           0 :     Update();
      99             :     
     100           0 :     AddFrame(fSourceName, new TGLayoutHints(kLHintsNormal | kLHintsCenterY,5,5,5,5));
     101           0 :     AddFrame(fSource,new TGLayoutHints(kLHintsExpandX | kLHintsCenterY,5,5,5,5));
     102           0 :     AddFrame(fNumberOfEvents,new TGLayoutHints(kLHintsNormal | kLHintsCenterY,5,5,5,5));
     103             : 
     104           0 :     if ( fDataMaker->IsRunnable() ) 
     105             :     {
     106           0 :       fRun = new TGTextButton(this,"Run");
     107           0 :       fStop = new TGTextButton(this,"Stop");
     108           0 :       fRewind = new TGTextButton(this,"Rewind");
     109             :       
     110           0 :       fRun->SetEnabled(!maker->Data()->IsSingleEvent());
     111           0 :       fRun->Connect("Clicked()",
     112             :                     "AliMUONPainterDataSourceItem",
     113             :                     this,
     114             :                     "Run()");
     115             :       
     116           0 :       fStop->SetEnabled(kFALSE);
     117           0 :       fStop->Connect("Clicked()",
     118             :                      "AliMUONPainterDataSourceItem",
     119             :                      this,
     120             :                      "Stop()");
     121             :       
     122           0 :       fRewind->SetEnabled(kFALSE);
     123           0 :       fRewind->Connect("Clicked()",
     124             :                        "AliMUONPainterDataSourceItem",
     125             :                        this,
     126             :                        "Rewind()");
     127             :       
     128           0 :       AddFrame(fRun,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
     129           0 :       AddFrame(fStop,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));
     130           0 :       AddFrame(fRewind,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));    
     131             :     }
     132             : 
     133           0 :     AddFrame(fRemove,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));    
     134             : 
     135           0 :     AddFrame(fSave,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));    
     136             : 
     137           0 :     AddFrame(fSaveAs,new TGLayoutHints(kLHintsCenterY | kLHintsCenterY,5,5,5,5));    
     138             : 
     139           0 :     maker->Data()->Connect("NumberOfEventsChanged()",
     140             :                             "AliMUONPainterDataSourceItem",
     141             :                             this,
     142             :                             "Update()");
     143             :     
     144           0 :     fRemove->Connect("Clicked()",
     145             :                      "AliMUONPainterDataSourceItem",
     146             :                      this,
     147             :                      "Remove()");
     148             :     
     149           0 :     fSave->Connect("Clicked()",
     150             :                    "AliMUONPainterDataSourceItem",
     151             :                    this,
     152             :                    "Save()");
     153             : 
     154           0 :     fSaveAs->Connect("Clicked()",
     155             :                    "AliMUONPainterDataSourceItem",
     156             :                    this,
     157             :                    "SaveWithDialog()");
     158             :     
     159           0 :     Resize();
     160           0 : }
     161             : 
     162             : //_____________________________________________________________________________
     163           0 : AliMUONPainterDataSourceItem::~AliMUONPainterDataSourceItem()
     164           0 : {
     165             :   /// dtor
     166           0 :   TThread::Delete(fThread);
     167           0 :   delete fThread;
     168           0 : }
     169             : 
     170             : 
     171             : //_____________________________________________________________________________
     172             : void 
     173             : AliMUONPainterDataSourceItem::EnableRun() 
     174             : { 
     175             :   /// Enable run button
     176           0 :   if ( fRun ) 
     177             :   {
     178           0 :     fRun->SetEnabled(kTRUE); 
     179           0 :   }
     180           0 : }
     181             :   
     182             : //_____________________________________________________________________________
     183             : void 
     184             : AliMUONPainterDataSourceItem::DisableRun() 
     185             : { 
     186             :   /// Disable run button
     187           0 :   if ( fRun )
     188             :   {
     189           0 :     fRun->SetEnabled(kFALSE); 
     190           0 :   }
     191           0 : }
     192             : 
     193             : //_____________________________________________________________________________
     194             : void
     195             : AliMUONPainterDataSourceItem::Remove()
     196             : {
     197             :   /// Remove
     198             :   
     199           0 :   MakeZombie();
     200           0 :   AliMUONPainterDataRegistry::Instance()->Unregister(fDataMaker);
     201           0 : }
     202             : 
     203             : //_____________________________________________________________________________
     204             : void
     205             : AliMUONPainterDataSourceItem::Reset()
     206             : {
     207             :   /// Reset the data
     208           0 :   fDataMaker->Data()->Clear();
     209           0 : }
     210             : 
     211             : //_____________________________________________________________________________
     212             : void
     213             : AliMUONPainterDataSourceItem::Rewind()
     214             : {
     215             :   /// Rewind button was clicked
     216             :   
     217           0 :   fRewind->SetEnabled(kTRUE);
     218             :   
     219           0 :   Stop();
     220             :   
     221           0 :   TThread::Delete(fThread);
     222           0 :   delete fThread;
     223           0 :   fThread = 0x0;
     224             :   
     225           0 :   if ( fRun && fStop && fRewind ) 
     226             :   {
     227           0 :     fRun->SetEnabled(kTRUE);
     228           0 :     fStop->SetEnabled(kFALSE);
     229           0 :     fRewind->SetEnabled(kFALSE);
     230           0 :   }
     231             :   
     232           0 :   fDataMaker->Rewind();
     233             :   
     234           0 :   fShouldReset = kTRUE;
     235           0 : }
     236             : 
     237             : //_____________________________________________________________________________
     238             : void
     239             : AliMUONPainterDataSourceItem::Run()
     240             : {
     241             :   /// Run button was clicked
     242             :   
     243           0 :   StartRunning();
     244             :   
     245           0 :   if ( fShouldReset ) 
     246             :   {
     247           0 :     Reset();
     248           0 :     fShouldReset = kFALSE;
     249           0 :   }
     250             :   
     251           0 :   fRemove->SetEnabled(kFALSE);
     252             :   
     253           0 :   if (!fThread)
     254             :   {
     255           0 :     fParams[0] = (Long_t)(this);
     256           0 :     fParams[1] = (Long_t)(fDataMaker);
     257           0 :     fThread = new TThread(RunFunction,(void*)(&fParams[0]));
     258           0 :     fThread->Run();
     259           0 :   }
     260             :   
     261           0 :   fDataMaker->SetRunning(kTRUE);
     262             :   
     263           0 :   if ( fRun && fStop )
     264             :   {
     265           0 :     fRun->SetEnabled(kFALSE);
     266           0 :     fStop->SetEnabled(kTRUE);
     267           0 :   }
     268           0 : }
     269             : 
     270             : //_____________________________________________________________________________
     271             : void
     272             : AliMUONPainterDataSourceItem::Save(const char* filename)
     273             : {
     274             :   /// Save the data maker
     275             :   
     276           0 :   TFile* f = TFile::Open(filename,"RECREATE");
     277             :   
     278           0 :   fDataMaker->Write();
     279             :   
     280           0 :   f->Write();
     281           0 :   f->Close();
     282             :   
     283           0 :   delete f;
     284           0 : }
     285             : 
     286             : //_____________________________________________________________________________
     287             : void
     288             : AliMUONPainterDataSourceItem::Save()
     289             : {
     290             :   /// Save the data maker (filename is fixed)
     291             :   
     292           0 :   TString dname(fDataMaker->Data()->GetName());
     293           0 :   dname.ToLower();
     294             :   
     295           0 :   TString outputDir(AliMUONPainterHelper::Instance()->Env()->String("LastSaveDir","."));
     296             : 
     297           0 :   TString filename(Form("%s/mchview.%s.root",gSystem->ExpandPathName(outputDir.Data()),dname.Data()));
     298             :   
     299           0 :   Save(filename.Data());
     300           0 : }
     301             : 
     302             : //_____________________________________________________________________________
     303             : void
     304             : AliMUONPainterDataSourceItem::SaveWithDialog()
     305             : {
     306             :   /// Save the data maker (filename given by dialog)
     307             :   
     308           0 :   TGFileInfo fileInfo;
     309             :   
     310             : //  fileInfo.fFileTypes = fgkFileTypes;
     311             :   
     312           0 :   delete[] fileInfo.fIniDir;
     313             :   
     314           0 :   AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
     315             :   
     316           0 :   fileInfo.fIniDir = StrDup(env->String("LastSaveDir","."));
     317             :   
     318           0 :   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
     319             :                    kFDSave,&fileInfo);
     320             :   
     321           0 :   env->Set("LastSaveDir",fileInfo.fIniDir);
     322           0 :   env->Save();  
     323             :   
     324           0 :   Save(fileInfo.fFilename);  
     325           0 : }
     326             : 
     327             : //_____________________________________________________________________________
     328             : void
     329             : AliMUONPainterDataSourceItem::Stop()
     330             : {
     331             :   /// Stop button was clicked
     332             :   
     333           0 :   StopRunning();
     334             :   
     335           0 :   fDataMaker->SetRunning(kFALSE);
     336             :   
     337           0 :   if ( fStop && fRun ) 
     338             :   {
     339           0 :     fStop->SetEnabled(kFALSE);
     340           0 :     fRun->SetEnabled(kTRUE);
     341           0 :   }
     342             :   
     343           0 :   fRemove->SetEnabled(kTRUE);
     344           0 : }
     345             : 
     346             : //_____________________________________________________________________________
     347             : void
     348             : AliMUONPainterDataSourceItem::Update()
     349             : {
     350             :   /// Update ourselves
     351             :   
     352           0 :   fNumberOfEvents->SetText(Form("%10d",fDataMaker->Data()->NumberOfEvents(-1)));
     353           0 : }
     354             : 
     355             : //_____________________________________________________________________________
     356             : void
     357             : AliMUONPainterDataSourceItem::StartRunning()
     358             : {
     359             :   /// Signal we start to run
     360           0 :   Emit("StartRunning()");
     361           0 : }  
     362             : 
     363             : //_____________________________________________________________________________
     364             : void
     365             : AliMUONPainterDataSourceItem::StopRunning()
     366             : {
     367             :   /// Signal we stop to run
     368           0 :   Emit("StopRunning()");
     369           0 : }

Generated by: LCOV version 1.11