LCOV - code coverage report
Current view: top level - MUON/MUONgraphics - AliMUONPainterDataSourceFrame.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 417 0.2 %
Date: 2016-06-14 17:26:59 Functions: 1 31 3.2 %

          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 "AliMUONPainterDataSourceFrame.h"
      19             : 
      20             : #include "AliCDBEntry.h"
      21             : #include "AliCDBManager.h"
      22             : #include "AliCDBStorage.h"
      23             : #include "AliLog.h"
      24             : #include "AliMUONChamberPainter.h"
      25             : #include "AliMUONMchViewApplication.h"
      26             : #include "AliMUONPainterDataRegistry.h"
      27             : #include "AliMUONPainterDataSourceItem.h"
      28             : #include "AliMUONPainterEnv.h"
      29             : #include "AliMUONPainterHelper.h"
      30             : #include "AliMUONPainterMatrix.h"
      31             : #include "AliMUONPainterRegistry.h"
      32             : #include "AliMUONRecoParam.h"
      33             : #include "AliMUONTrackerConditionDataMaker.h"
      34             : #include "AliMUONTrackerDataMaker.h"
      35             : #include "AliMUONTrackerDataSourceTypes.h"
      36             : #include "AliMUONVTrackerData.h"
      37             : #include "AliRawReader.h"
      38             : #include "Riostream.h"
      39             : #include <cstdlib>
      40             : #include <TCanvas.h>
      41             : #include <TGButton.h>
      42             : #include <TGComboBox.h>
      43             : #include <TGFileDialog.h>
      44             : #include <TGNumberEntry.h>
      45             : #include <TGrid.h>
      46             : #include <TGTextEntry.h>
      47             : #include <TMath.h>
      48             : #include <TObjArray.h>
      49             : #include <TObjString.h>
      50             : #include <TRegexp.h>
      51             : #include <TString.h>
      52             : #include <TSystem.h>
      53             : 
      54             : ///\class AliMUONPainterDataSourceFrame
      55             : ///
      56             : /// A complete frame to select and display various data sources to
      57             : /// be displayed : either raw data or OCDB data.
      58             : /// Later on we might add digits and clusters for instance.
      59             : ///
      60             : ///\author Laurent Aphecetche, Subatech
      61             : 
      62             : ///\cond CLASSIMP
      63          12 : ClassImp(AliMUONPainterDataSourceFrame)
      64             : ///\endcond
      65             : 
      66             : //_____________________________________________________________________________
      67             : AliMUONPainterDataSourceFrame::AliMUONPainterDataSourceFrame(const TGWindow* p, UInt_t w, UInt_t h)
      68           0 : : TGCompositeFrame(p,w,h,kVerticalFrame),
      69           0 :   fRecentSourceSelector(new TGGroupFrame(this,"Recent sources",kHorizontalFrame)),
      70           0 :   fRawSelector(new TGGroupFrame(this,"Raw file URI",kHorizontalFrame)),
      71           0 :   fRawSelector2(new TGCompositeFrame(fRawSelector,w,h,kVerticalFrame)),
      72           0 :   fRawSelector21(new TGCompositeFrame(fRawSelector2,w,h,kHorizontalFrame)),
      73           0 :   fRawSelector22(new TGCompositeFrame(fRawSelector2,w,h,kHorizontalFrame)),
      74           0 :   fRawSelector24(new TGCompositeFrame(fRawSelector2,w,h,kHorizontalFrame)),
      75           0 :   fRawSelector23(new TGCompositeFrame(fRawSelector2,w,h,kHorizontalFrame)),
      76           0 :   fCalibrateNoGain(new TGCheckButton(fRawSelector22,"Ped sub")),
      77           0 :   fHistogramButton(new TGCheckButton(fRawSelector23,"Histogram")),
      78           0 :   fHistoMin(new TGNumberEntry(fRawSelector23,0)),
      79           0 :   fHistoMax(new TGNumberEntry(fRawSelector23,4096)),
      80           0 :   fEventRangeButton(new TGCheckButton(fRawSelector23,"Event range")),
      81           0 :   fEventMin(new TGNumberEntry(fRawSelector23,-1,10)),
      82           0 :   fEventMax(new TGNumberEntry(fRawSelector23,-1,10)),
      83           0 :   fRawOCDBPath(0x0),
      84           0 :   fOCDBSelector(new TGGroupFrame(this,"OCDB Path",kHorizontalFrame)),
      85           0 :   fDataReaders(new TGGroupFrame(this,"Data sources")),
      86           0 :   fFilePath(new TGTextEntry(fRawSelector21,"")),
      87           0 :   fOCDBPath(0x0),
      88           0 :   fRunSelector(new TGNumberEntry(fOCDBSelector,0,10)),
      89           0 :   fOCDBTypes(new TGComboBox(fOCDBSelector)),
      90           0 :   fRecentSources(new TGComboBox(fRecentSourceSelector)),
      91           0 :   fCreateRecentButton(new TGTextButton(fRecentSourceSelector,"Create data source")),
      92           0 :   fItems(new TObjArray),
      93           0 :   fACFSelector(new TGGroupFrame(this,"ASCII Calib File",kHorizontalFrame)),
      94           0 :   fACFPath(new TGTextEntry(fACFSelector,"")),
      95           0 :   fACFTypes(new TGComboBox(fACFSelector))
      96           0 : {
      97             :   /// Ctor
      98             : 
      99           0 :   AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
     100           0 :   TString uri = storage->GetURI();
     101             : 
     102           0 :   fRawOCDBPath = new TGTextEntry(fRawSelector24,uri.Data());
     103           0 :   fOCDBPath = new TGTextEntry(fOCDBSelector,uri.Data());
     104             : 
     105           0 :   AliMUONPainterDataRegistry* reg = AliMUONPainterDataRegistry::Instance();
     106             : 
     107           0 :   reg->Connect("DataMakerWasRegistered(AliMUONVTrackerDataMaker*)",
     108             :                "AliMUONPainterDataSourceFrame",
     109             :                this,
     110             :                "DataMakerWasRegistered(AliMUONVTrackerDataMaker*)");
     111             : 
     112           0 :   reg->Connect("DataMakerWasUnregistered(AliMUONVTrackerDataMaker*)",
     113             :                "AliMUONPainterDataSourceFrame",
     114             :                this,
     115             :                "DataMakerWasUnregistered(AliMUONVTrackerDataMaker*)");
     116             : 
     117           0 :   fItems->SetOwner(kFALSE);
     118             : 
     119             :   /// Recent source selection
     120             : 
     121           0 :   fCreateRecentButton->Connect("Clicked()",
     122             :                               "AliMUONPainterDataSourceFrame",
     123             :                               this,
     124             :                               "OpenRecentSource()");
     125             : 
     126           0 :   fRecentSourceSelector->AddFrame(fRecentSources,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
     127           0 :   fRecentSourceSelector->AddFrame(fCreateRecentButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
     128             : 
     129           0 :   fRecentSources->SetEnabled(kFALSE);
     130           0 :   fCreateRecentButton->SetEnabled(kFALSE);
     131             : 
     132           0 :   for ( Int_t i = 0; i < Env()->NumberOfDataSources(); ++i )
     133             :   {
     134           0 :     AddRecentSource(Env()->DataSourceDescriptor(i));
     135             :   }
     136             : 
     137           0 :   fRecentSources->Resize(100,20);
     138             : 
     139             :   /// Raw file selection
     140             : 
     141           0 :   TGButton* openButton = new TGPictureButton(fRawSelector21,
     142           0 :                                              gClient->GetPicture("fileopen.xpm"));
     143           0 :   openButton->SetToolTipText("Click to open file dialog");
     144             : 
     145           0 :   fRawSelector2->AddFrame(fRawSelector21, new TGLayoutHints(kLHintsExpandX,5,5,5,5));
     146           0 :   fRawSelector2->AddFrame(fRawSelector22, new TGLayoutHints(kLHintsExpandX,5,5,5,5));
     147           0 :   fRawSelector2->AddFrame(fRawSelector24, new TGLayoutHints(kLHintsTop,5,5,5,5));
     148           0 :   fRawSelector2->AddFrame(fRawSelector23, new TGLayoutHints(kLHintsExpandX,5,5,5,5));
     149             : 
     150           0 :   fRawSelector21->AddFrame(openButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
     151           0 :   fRawSelector21->AddFrame(fFilePath, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
     152             : 
     153           0 :   fRawSelector22->AddFrame(fCalibrateNoGain, new TGLayoutHints(kLHintsTop,5,5,5,5));
     154             : 
     155           0 :   fRawSelector24->AddFrame(fRawOCDBPath, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
     156           0 :   fRawOCDBPath->SetEnabled(kFALSE);
     157             : 
     158           0 :   fRawSelector23->AddFrame(fHistogramButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
     159           0 :   fHistogramButton->Connect("Clicked()","AliMUONPainterDataSourceFrame",this,"HistogramButtonClicked()");
     160           0 :   fHistoMin->SetState(kFALSE);
     161           0 :   fHistoMax->SetState(kFALSE);
     162           0 :   fRawSelector23->AddFrame(fHistoMin,new TGLayoutHints(kLHintsTop,5,5,5,5));
     163           0 :   fRawSelector23->AddFrame(fHistoMax,new TGLayoutHints(kLHintsTop,5,5,5,5));
     164             : 
     165             : 
     166           0 :   fRawSelector23->AddFrame(fEventRangeButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
     167           0 :   fEventRangeButton->Connect("Clicked()","AliMUONPainterDataSourceFrame",this,"EventRangeButtonClicked()");
     168           0 :   fEventMin->SetState(kFALSE);
     169           0 :   fEventMax->SetState(kFALSE);
     170             : 
     171           0 :   fEventMin->SetFormat(TGNumberFormat::kNESInteger);
     172           0 :   fEventMax->SetFormat(TGNumberFormat::kNESInteger);
     173             : 
     174           0 :   fRawSelector23->AddFrame(fEventMin,new TGLayoutHints(kLHintsTop,5,5,5,5));
     175           0 :   fRawSelector23->AddFrame(fEventMax,new TGLayoutHints(kLHintsTop,5,5,5,5));
     176             : 
     177           0 :   TGButton* createRawButton = new TGTextButton(fRawSelector,"Create data source");
     178             : 
     179           0 :   fRawSelector->AddFrame(fRawSelector2, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
     180           0 :   fRawSelector->AddFrame(createRawButton, new TGLayoutHints(kLHintsCenterY,5,5,5,5));
     181             : 
     182           0 :   fCalibrateNoGain->Connect("Clicked()","AliMUONPainterDataSourceFrame",this,"CalibrateButtonClicked()");
     183             : 
     184           0 :   openButton->Connect("Clicked()",
     185             :                       "AliMUONPainterDataSourceFrame",
     186             :                       this,
     187             :                       "OpenFileDialog()");
     188             : 
     189           0 :   createRawButton->Connect("Clicked()",
     190             :                            "AliMUONPainterDataSourceFrame",
     191             :                            this,
     192             :                            "CreateRawDataSource()");
     193             : 
     194             :   /// OCDB selection
     195             : 
     196           0 :   fOCDBTypes->AddEntry(AliMUONTrackerDataSourceTypes::ShortNameForConfig(),7);
     197           0 :   fOCDBTypes->AddEntry(AliMUONTrackerDataSourceTypes::ShortNameForOccupancy(),4);
     198           0 :   fOCDBTypes->AddEntry(AliMUONTrackerDataSourceTypes::ShortNameForHV(),3);
     199           0 :   fOCDBTypes->AddEntry(AliMUONTrackerDataSourceTypes::ShortNameForPedestals(),0);
     200           0 :   fOCDBTypes->AddEntry(AliMUONTrackerDataSourceTypes::ShortNameForStatus(),5);
     201           0 :   fOCDBTypes->AddEntry(AliMUONTrackerDataSourceTypes::ShortNameForStatusMap(),6);
     202           0 :   fOCDBTypes->AddEntry(AliMUONTrackerDataSourceTypes::ShortNameForRejectList(),8);
     203           0 :   fOCDBTypes->AddEntry(AliMUONTrackerDataSourceTypes::ShortNameForLV(),9);
     204           0 :   fOCDBTypes->Select(0);
     205           0 :   fOCDBTypes->Resize(80,20);
     206             : 
     207           0 :   TGButton* createOCDBButton = new TGTextButton(fOCDBSelector,"Create data source");
     208           0 :   createOCDBButton->Connect("Clicked()",
     209             :                             "AliMUONPainterDataSourceFrame",
     210             :                             this,
     211             :                             "CreateOCDBDataSource()");
     212             : 
     213             :   const char* ocdbToolTip = "Use URL style for either alien or local OCDB (foo://bar). For example :\n"
     214             :   "alien://folder=/alice/data.../OCDB\n"
     215             :   "or\nlocal:///home/user/aliroot (mind the 3 slashes there !)";
     216             : 
     217           0 :   fRawOCDBPath->SetToolTipText(ocdbToolTip);
     218           0 :   fOCDBPath->SetToolTipText(ocdbToolTip);
     219             : 
     220           0 :   fOCDBSelector->AddFrame(fOCDBPath,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
     221           0 :   fOCDBSelector->AddFrame(fRunSelector,new TGLayoutHints(kLHintsTop,5,5,5,5));
     222           0 :   fOCDBSelector->AddFrame(fOCDBTypes,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
     223           0 :   fOCDBSelector->AddFrame(createOCDBButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
     224             : 
     225             : 
     226             :   /// ASCII calibration file selection
     227             : 
     228           0 :   TGButton* openButtonACF = new TGPictureButton(fACFSelector,
     229           0 :                                                 gClient->GetPicture("fileopen.xpm"));
     230           0 :   openButtonACF->SetToolTipText("Click to open file dialog");
     231             : 
     232           0 :   fACFTypes->AddEntry(AliMUONTrackerDataSourceTypes::ShortNameForConfig(),7);
     233           0 :   fACFTypes->AddEntry(AliMUONTrackerDataSourceTypes::ShortNameForOccupancy(),4);
     234           0 :   fACFTypes->AddEntry(AliMUONTrackerDataSourceTypes::ShortNameForPedestals(),0);
     235           0 :   fACFTypes->Select(0);
     236           0 :   fACFTypes->Resize(100,20);
     237             : 
     238           0 :   fACFSelector->AddFrame(openButtonACF,new TGLayoutHints(kLHintsTop,5,5,5,5));
     239           0 :   fACFSelector->AddFrame(fACFPath, new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
     240           0 :   fACFSelector->AddFrame(fACFTypes,new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5));
     241             : 
     242           0 :   TGButton* createACFButton = new TGTextButton(fACFSelector,"Create data source");
     243           0 :   createACFButton->Connect("Clicked()",
     244             :                            "AliMUONPainterDataSourceFrame",
     245             :                            this,
     246             :                            "CreateACFDataSource()");
     247             : 
     248           0 :   openButtonACF->Connect("Clicked()",
     249             :                          "AliMUONPainterDataSourceFrame",
     250             :                          this,
     251             :                          "OpenFileDialogACF()");
     252             : 
     253           0 :   fACFSelector->AddFrame(createACFButton,new TGLayoutHints(kLHintsTop,5,5,5,5));
     254             : 
     255           0 :   AddFrame(fRecentSourceSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
     256             : 
     257           0 :   AddFrame(fRawSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
     258             : 
     259           0 :   AddFrame(fOCDBSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
     260             : 
     261           0 :   AddFrame(fACFSelector,new TGLayoutHints(kLHintsExpandX,10,10,10,10));
     262             : 
     263           0 :   AddFrame(fDataReaders, new TGLayoutHints(kLHintsExpandX,10,10,10,10));
     264             : 
     265           0 : }
     266             : 
     267             : //_____________________________________________________________________________
     268           0 : AliMUONPainterDataSourceFrame::~AliMUONPainterDataSourceFrame()
     269           0 : {
     270             :   /// dtor
     271             : 
     272           0 :   delete fItems;
     273           0 : }
     274             : 
     275             : //_____________________________________________________________________________
     276             : void
     277             : AliMUONPainterDataSourceFrame::AddRecentSource(const char* name)
     278             : {
     279             :   /// Add a source to the list of recently used sources
     280             : 
     281           0 :   TGListBox* lb = fRecentSources->GetListBox();
     282             : 
     283           0 :   for ( Int_t i = 0; i < lb->GetNumberOfEntries(); ++i )
     284             :   {
     285           0 :     TGTextLBEntry* t = (TGTextLBEntry*)lb->GetEntry(i);
     286           0 :     TString s(t->GetText()->GetString());
     287           0 :     if ( s == name )
     288             :     {
     289           0 :       return;
     290             :     }
     291           0 :   }
     292             : 
     293           0 :   fRecentSources->SetEnabled(kTRUE);
     294           0 :   fCreateRecentButton->SetEnabled(kTRUE);
     295             : 
     296           0 :   fRecentSources->AddEntry(name,lb->GetNumberOfEntries());
     297           0 :   fRecentSources->MapSubwindows();
     298           0 :   fRecentSources->Layout();
     299           0 : }
     300             : 
     301             : //_____________________________________________________________________________
     302             : void
     303             : AliMUONPainterDataSourceFrame::CalibrateButtonClicked()
     304             : {
     305             :   /// Calibrate button was clicked.
     306             : 
     307           0 :   if ( fCalibrateNoGain->IsOn() )
     308             :   {
     309           0 :     fRawOCDBPath->SetEnabled(kTRUE);
     310           0 :     fRawOCDBPath->SetFocus();
     311           0 :   }
     312             :   else
     313             :   {
     314           0 :     fRawOCDBPath->SetEnabled(kFALSE);
     315             :   }
     316           0 : }
     317             : 
     318             : //_____________________________________________________________________________
     319             : void
     320             : AliMUONPainterDataSourceFrame::CreateACFDataSource()
     321             : {
     322             :   /// Create an ACF data source (using information from the widgets)
     323             : 
     324           0 :   TString acfPath = fACFPath->GetText();
     325           0 :   TGTextLBEntry* t = static_cast<TGTextLBEntry*>(fACFTypes->GetSelectedEntry());
     326           0 :   TString type = t->GetText()->GetString();
     327             : 
     328           0 :   CreateACFDataSource(acfPath,type);
     329             : 
     330           0 :   fACFPath->SetText("");
     331           0 : }
     332             : 
     333             : //_____________________________________________________________________________
     334             : void
     335             : AliMUONPainterDataSourceFrame::CreateACFDataSource(const TString& acfPath, const TString& type)
     336             : {
     337             :   /// Create an ACF data source for a given (path,type)
     338             : 
     339           0 :   AliMUONVTrackerDataMaker* reader = new AliMUONTrackerConditionDataMaker(acfPath.Data(),
     340           0 :                                                                           type.Data());
     341             : 
     342           0 :   RegisterDataSource(reader,Form("FILE;%s;%s",acfPath.Data(),type.Data()));
     343           0 : }
     344             : 
     345             : //_____________________________________________________________________________
     346             : void
     347             : AliMUONPainterDataSourceFrame::CreateACFDataSource(const TString& uri)
     348             : {
     349             :   /// Create an ACF data source, given it's URI
     350             : 
     351           0 :   TObjArray* a = uri.Tokenize(";");
     352           0 :   TString acfPath = static_cast<TObjString*>(a->At(1))->String();
     353           0 :   TString type = static_cast<TObjString*>(a->At(2))->String();
     354             : 
     355           0 :   CreateACFDataSource(acfPath,type);
     356             : 
     357           0 :   delete a;
     358           0 : }
     359             : 
     360             : //_____________________________________________________________________________
     361             : AliMUONPainterMatrix*
     362             : AliMUONPainterDataSourceFrame::CreateFullTracker(AliMUONVTrackerData* data,
     363             :                                                  Int_t dim,
     364             :                                                  Double_t xmin, Double_t xmax,
     365             :                                                  const AliMUONAttPainter& att)
     366             : {
     367             :   /// Generate, draw and register a matrix of 10 painters to show all the tracker
     368             :   /// chambers
     369             : 
     370           0 :   AliMUONPainterMatrix* matrix = new AliMUONPainterMatrix("Tracker",5,2);
     371             : 
     372           0 :   for ( Int_t ichamber = 0; ichamber < 10; ++ichamber )
     373             :   {
     374           0 :     AliMUONVPainter* painter = new AliMUONChamberPainter(att,ichamber);
     375             : 
     376           0 :     painter->SetResponder("BUSPATCH");
     377             : 
     378           0 :     painter->SetOutlined("*",kFALSE);
     379             : 
     380           0 :     matrix->Adopt(painter);
     381             :   }
     382             : 
     383           0 :   matrix->SetData("MANU",data,dim);
     384           0 :   matrix->SetDataRange(xmin,xmax);
     385             : 
     386           0 :   AliMUONPainterRegistry::Instance()->Register(matrix);
     387             : 
     388           0 :   return matrix;
     389           0 : }
     390             : 
     391             : //_____________________________________________________________________________
     392             : void
     393             : AliMUONPainterDataSourceFrame::CreateOCDBDataSource()
     394             : {
     395             :   /// Create an OCDB data source (using information from the widgets)
     396             : 
     397           0 :   TString cdbPath = fOCDBPath->GetText();
     398           0 :   Int_t runNumber = fRunSelector->GetIntNumber();
     399           0 :   TGTextLBEntry* t = static_cast<TGTextLBEntry*>(fOCDBTypes->GetSelectedEntry());
     400           0 :   TString type = t->GetText()->GetString();
     401             : 
     402           0 :   CreateOCDBDataSource(cdbPath,runNumber,type,"");
     403           0 : }
     404             : 
     405             : //_____________________________________________________________________________
     406             : void
     407             : AliMUONPainterDataSourceFrame::CreateOCDBDataSource(const TString& dataSourceDescriptor)
     408             : {
     409             :   /// Create an OCDB data source, given it's full descriptor
     410             : 
     411           0 :   TString sid = Env()->Descriptor2ID(dataSourceDescriptor);
     412             : 
     413           0 :   TString ranges = Env()->Descriptor2Ranges(dataSourceDescriptor);
     414             : 
     415           0 :   TString uri = Env()->ID2URI(sid);
     416             : 
     417           0 :   TString cdbPath = Env()->TupleFirst(uri,Env()->SeparatorWithinPart());
     418             : 
     419           0 :   TString type = Env()->ID2Type(sid);
     420             : 
     421           0 :   TString srun = Env()->TupleMiddle(uri,Env()->SeparatorWithinPart());
     422             : 
     423           0 :   CreateOCDBDataSource(cdbPath,atoi(srun.Data()),type,ranges);
     424           0 : }
     425             : 
     426             : //_____________________________________________________________________________
     427             : void
     428             : AliMUONPainterDataSourceFrame::CreateOCDBDataSource(const TString& cdbPath,
     429             :                                                     Int_t runNumber,
     430             :                                                     const TString& type,
     431             :                                                     const TString& ranges)
     432             : {
     433             :   /// Create an OCDB data source for a given (path,runnumber,type) triplet
     434             : 
     435           0 :   AliMUONVTrackerDataMaker* reader = new AliMUONTrackerConditionDataMaker(runNumber,
     436           0 :                                                                           cdbPath.Data(),
     437           0 :                                                                           type.Data());
     438           0 :   if ( reader->Data() )
     439             :   {
     440           0 :     TString sourceID="OCDB";
     441             : 
     442           0 :     sourceID += Env()->SeparatorWithinPart();
     443           0 :     sourceID += cdbPath;
     444           0 :     sourceID += Env()->SeparatorWithinPart();
     445           0 :     sourceID += Form("%d",runNumber);
     446           0 :     sourceID += Env()->SeparatorWithinPart();
     447           0 :     sourceID += type;
     448             : 
     449           0 :     RegisterDataSource(reader,Form("%s%s%s%s%s",sourceID.Data(),
     450           0 :                                    Env()->SeparatorBetweenDescriptorParts(),
     451           0 :                                    reader->Data()->GetName(),
     452           0 :                                    Env()->SeparatorBetweenDescriptorParts(),
     453           0 :                                    ranges.Data()));
     454           0 :   }
     455             :   else
     456             :   {
     457           0 :     AliError(Form("Could not create OCDB data source OCDB %s %d %s",cdbPath.Data(),runNumber,type.Data()));
     458             :   }
     459           0 : }
     460             : 
     461             : //_____________________________________________________________________________
     462             : void
     463             : AliMUONPainterDataSourceFrame::CreatePedestalCanvases(AliMUONVTrackerData* data,
     464             :                                                       Double_t pedMin, Double_t pedMax,
     465             :                                                       Double_t sigmaMin, Double_t sigmaMax)
     466             : {
     467             :   /// Create 4 canvases with the pedestals contained in data
     468             :   /// to show mean and sigma, for bending and non bending, with given limits
     469             : 
     470           0 :   TList matrices;
     471             : 
     472           0 :   AliMUONAttPainter att[2];
     473             : 
     474           0 :   att[0].SetViewPoint(kTRUE,kFALSE);
     475           0 :   att[0].SetCathode(kFALSE,kFALSE);
     476           0 :   att[0].SetPlane(kTRUE,kFALSE);
     477             : 
     478           0 :   att[1].SetViewPoint(kTRUE,kFALSE);
     479           0 :   att[1].SetCathode(kFALSE,kFALSE);
     480           0 :   att[1].SetPlane(kFALSE,kTRUE);
     481             : 
     482           0 :   for ( Int_t iatt = 0; iatt < 2; ++iatt )
     483             :   {
     484           0 :     matrices.Add(CreateFullTracker(data,0,pedMin,pedMax,att[iatt]));
     485           0 :     matrices.Add(CreateFullTracker(data,1,sigmaMin,sigmaMax,att[iatt]));
     486             :   }
     487             : 
     488           0 :   TIter next(&matrices);
     489             :   AliMUONPainterMatrix* matrix;
     490             : 
     491           0 :   Int_t w = TMath::Nint(gClient->GetDisplayWidth()*0.9);
     492           0 :   Int_t h = TMath::Nint(gClient->GetDisplayHeight()*0.9);
     493             : 
     494           0 :   Int_t x[] = { 0, 0, 20 + w/2, 20 + w/2 };
     495           0 :   Int_t y[] = { 0, h/2+30, 0, h/2+30 };
     496             : 
     497             :   Int_t i(0);
     498             : 
     499           0 :   while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next())) )
     500             :   {
     501           0 :     TCanvas* c = matrix->CreateCanvas(x[i],y[i],w/2,h/2);
     502           0 :     c->Draw();
     503           0 :     c->SaveAs(Form("%s.png",c->GetName()));
     504           0 :     ++i;
     505             :   }
     506           0 : }
     507             : 
     508             : //_____________________________________________________________________________
     509             : void
     510             : AliMUONPainterDataSourceFrame::CreateRawDataSource()
     511             : {
     512             :   /// Create a new raw data source (using info from the widgets)
     513             : 
     514           0 :   TString uri(gSystem->ExpandPathName(fFilePath->GetText()));
     515             : 
     516           0 :   TString name("RAW");
     517             :   Bool_t fromMemory(kFALSE);
     518             : 
     519           0 :   if ( uri.Contains(TRegexp("^mem")) )
     520             :   {
     521             :     fromMemory = kTRUE;
     522           0 :   }
     523             :   else
     524             :   {
     525           0 :     if ( gSystem->AccessPathName(uri.Data()) && !uri.BeginsWith("collection://") )
     526             :     {
     527           0 :       AliError(Form("File %s does not exist",uri.Data()));
     528           0 :       fFilePath->SetText("");
     529           0 :       return;
     530             :     }
     531             :   }
     532             : 
     533           0 :   TString calibMode("");
     534             : 
     535           0 :   if ( fCalibrateNoGain->IsOn() )
     536             :   {
     537           0 :     calibMode = "NOGAIN";
     538           0 :     name = "CALZ";
     539             :   }
     540             : 
     541           0 :   uri = Form("%s%s%s;%s;%s;%s;%s;%s;%s;%s",
     542           0 :              ( fHistogramButton->IsOn() ? "H":""),
     543           0 :              ( fromMemory ? "M" : ""),
     544           0 :              name.Data(),uri.Data(),
     545           0 :              ( strlen(fRawOCDBPath->GetText()) > 0 ? fRawOCDBPath->GetText() : " "),
     546           0 :              ( calibMode.Length() > 0 ? calibMode.Data() : " "),
     547           0 :              Form("%e",fHistoMin->GetNumber()),
     548           0 :              Form("%e",fHistoMax->GetNumber()),
     549           0 :              Form("%d",(Int_t)(fEventMin->GetIntNumber())),
     550           0 :              Form("%d",(Int_t)(fEventMax->GetIntNumber())));
     551             : 
     552           0 :   if ( CreateRawDataSource(uri) )
     553             :   {
     554           0 :     fFilePath->SetText("");
     555           0 :     fRawOCDBPath->SetText("");
     556             :   }
     557           0 : }
     558             : 
     559             : //_____________________________________________________________________________
     560             : Bool_t
     561             : AliMUONPainterDataSourceFrame::CreateRawDataSource(const TString& uri)
     562             : {
     563             :   /// Create a new raw data source, given its URI
     564             : 
     565           0 :   TString filename;
     566           0 :   TString ocdbPath;
     567           0 :   TString calibMode;
     568           0 :   TString sxmin("0.0");
     569           0 :   TString sxmax("4096.0");
     570           0 :   TString emin("-1");
     571           0 :   TString emax("-1");
     572             : 
     573           0 :   TObjArray* a = uri.Tokenize(";");
     574             : 
     575           0 :   filename = static_cast<TObjString*>(a->At(1))->String();
     576             : 
     577           0 :   if ( a->GetLast() > 1 )
     578             :   {
     579           0 :     ocdbPath = static_cast<TObjString*>(a->At(2))->String();
     580           0 :     if ( ocdbPath == " " ) ocdbPath = "";
     581             :   }
     582             : 
     583           0 :   if ( a->GetLast() > 2 )
     584             :   {
     585           0 :     calibMode = static_cast<TObjString*>(a->At(3))->String();
     586           0 :     if ( calibMode == " " ) calibMode = "";
     587             :   }
     588             : 
     589           0 :   if ( a->GetLast() > 3 )
     590             :   {
     591           0 :     sxmin = static_cast<TObjString*>(a->At(4))->String();
     592             :   }
     593             : 
     594           0 :   if ( a->GetLast() > 4 )
     595             :   {
     596           0 :     sxmax = static_cast<TObjString*>(a->At(5))->String();
     597             :   }
     598             : 
     599           0 :   if ( a->GetLast() > 5 )
     600             :   {
     601           0 :     emin = static_cast<TObjString*>(a->At(6))->String();
     602             :   }
     603             : 
     604           0 :   if ( a->GetLast() > 6 )
     605             :   {
     606           0 :     emax = static_cast<TObjString*>(a->At(7))->String();
     607             :   }
     608             : 
     609           0 :   delete a;
     610             : 
     611             :   AliRawReader* rawReader = 0x0;
     612             : 
     613           0 :   if ( filename.Contains(TRegexp("^alien")) )
     614             :   {
     615             :     // insure we've initialized the grid...
     616           0 :     if (!gGrid)
     617             :     {
     618           0 :       TGrid::Connect("alien://");
     619             :     }
     620             :   }
     621             : 
     622           0 :   rawReader = AliRawReader::Create(filename.Data());
     623             : 
     624           0 :   if (!rawReader)
     625             :   {
     626           0 :     AliError(Form("Could not open file %s",filename.Data()));
     627           0 :     fFilePath->SetText("");
     628           0 :     return kFALSE;
     629             :   }
     630             : 
     631             :   /// Basic test to see if the file is correct
     632             :   /// and to get run numbre
     633             :   Int_t runNumber(-1);
     634           0 :   Bool_t ok = rawReader->NextEvent();
     635           0 :   if (!ok)
     636             :   {
     637           0 :     AliError(Form("File %s does not seem to be a raw data file",filename.Data()));
     638           0 :     fFilePath->SetText("");
     639           0 :     return kFALSE;
     640             :   }
     641             :   else
     642             :   {
     643           0 :     runNumber = rawReader->GetRunNumber();
     644             :   }
     645             : 
     646           0 :   rawReader->RewindEvents();
     647             : 
     648             :   AliMUONVTrackerDataMaker* reader(0x0);
     649             :   Bool_t histogram(kFALSE);
     650             : 
     651           0 :   if ( uri.Contains(TRegexp("^H")) ) histogram = kTRUE;
     652             : 
     653           0 :   if ( ocdbPath.Length() > 0 )
     654             :   {
     655             : 
     656             :     AliMUONRecoParam* recoParam(0x0);
     657             : 
     658           0 :     AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam",runNumber);
     659           0 :     if (e)
     660             :     {
     661           0 :       TObject* o = e->GetObject();
     662           0 :       if ( o->IsA() == TObjArray::Class() )
     663             :       {
     664           0 :         TIter next(static_cast<TObjArray*>(o));
     665             :         AliMUONRecoParam* p;
     666           0 :         while ( ( p = static_cast<AliMUONRecoParam*>(next()) ))
     667             :         {
     668           0 :           if ( p->IsDefault()) recoParam = p;
     669             :         }
     670           0 :       }
     671             :       else
     672             :       {
     673           0 :         recoParam = static_cast<AliMUONRecoParam*>(o);
     674             :       }
     675           0 :     }
     676             : 
     677           0 :     reader = new AliMUONTrackerDataMaker(recoParam,
     678             :                                          rawReader,
     679           0 :                                          ocdbPath.Data(),
     680           0 :                                          calibMode.Data(),
     681           0 :                                          histogram,
     682           0 :                                          sxmin.Atof(),
     683           0 :                                          sxmax.Atof());
     684           0 :   }
     685             :   else
     686             :   {
     687           0 :     reader = new AliMUONTrackerDataMaker(rawReader,histogram);
     688             :   }
     689             : 
     690           0 :   reader->SetEventRange(emin.Atoi(),emax.Atoi());
     691             : 
     692           0 :   reader->SetSource(filename.Data());
     693             : 
     694           0 :   TString dsName(uri);
     695             : 
     696           0 :   if ( emin.Atoi() <= emax.Atoi() )
     697             :   {
     698             :     // we have an event range
     699           0 :     if ( emin.Atoi() == emax.Atoi())
     700             :     {
     701           0 :       dsName += Form("[%d]",emin.Atoi());
     702             :     }
     703             :     else
     704             :     {
     705           0 :       dsName += Form("[%d,%d]",emin.Atoi(),emax.Atoi());
     706             :     }
     707             :   }
     708             : 
     709           0 :   RegisterDataSource(reader,dsName.Data());
     710             : 
     711             :   return kTRUE;
     712           0 : }
     713             : 
     714             : //_____________________________________________________________________________
     715             : void
     716             : AliMUONPainterDataSourceFrame::DataMakerWasRegistered(AliMUONVTrackerDataMaker* reader)
     717             : {
     718             :   /// Update ourselves as a new data reader was created
     719             : 
     720           0 :   AliMUONPainterDataSourceItem* item = new AliMUONPainterDataSourceItem(fDataReaders,100,20,reader);
     721             : 
     722           0 :   item->Connect("StartRunning()",
     723             :                 "AliMUONPainterDataSourceFrame",
     724           0 :                 this,
     725             :                 "StartRunning()");
     726             : 
     727           0 :   item->Connect("StopRunning()",
     728             :                 "AliMUONPainterDataSourceFrame",
     729             :                 this,
     730             :                 "StopRunning()");
     731             : 
     732           0 :   fDataReaders->AddFrame(item);
     733             : 
     734           0 :   fItems->Add(item);
     735             : 
     736           0 :   fDataReaders->MapSubwindows();
     737           0 :   fDataReaders->Resize();
     738           0 : }
     739             : 
     740             : //_____________________________________________________________________________
     741             : void
     742             : AliMUONPainterDataSourceFrame::DataMakerWasUnregistered(const AliMUONVTrackerDataMaker* maker)
     743             : {
     744             :   /// Update ourselves as a data reader was deleted
     745             : 
     746             :   AliMUONPainterDataSourceItem* theItem(0x0);
     747             : 
     748           0 :   TIter next(fItems);
     749             :   AliMUONPainterDataSourceItem* item;
     750             : 
     751           0 :   while ( ( item = static_cast<AliMUONPainterDataSourceItem*>(next()) ) && !theItem )
     752             :   {
     753           0 :     if ( item->DataMaker() == maker )
     754             :     {
     755             :       theItem = item;
     756           0 :     }
     757             :   }
     758             : 
     759           0 :   if  (!theItem) return;
     760             : 
     761           0 :   fDataReaders->RemoveFrame(theItem);
     762           0 :   fItems->Remove(theItem);
     763           0 :   theItem->DestroyWindow();
     764           0 :   delete theItem;
     765             : 
     766           0 :   fDataReaders->MapSubwindows();
     767           0 :   fDataReaders->Resize();
     768             : 
     769           0 : }
     770             : 
     771             : //_____________________________________________________________________________
     772             : AliMUONPainterEnv*
     773             : AliMUONPainterDataSourceFrame::Env()
     774             : {
     775           0 :   return AliMUONPainterHelper::Instance()->Env();
     776             : }
     777             : 
     778             : //_____________________________________________________________________________
     779             : void
     780             : AliMUONPainterDataSourceFrame::EventRangeButtonClicked()
     781             : {
     782             :   /// EventRange button was clicked.
     783             : 
     784           0 :   if ( fEventRangeButton->IsOn() )
     785             :   {
     786           0 :     fEventMin->SetState(kTRUE);
     787           0 :     fEventMax->SetState(kTRUE);
     788           0 :   }
     789             :   else
     790             :   {
     791           0 :     fEventMin->SetIntNumber(-1);
     792           0 :     fEventMax->SetIntNumber(-1);
     793           0 :     fEventMin->SetState(kFALSE);
     794           0 :     fEventMax->SetState(kFALSE);
     795             :   }
     796           0 : }
     797             : 
     798             : //_____________________________________________________________________________
     799             : void
     800             : AliMUONPainterDataSourceFrame::HistogramButtonClicked()
     801             : {
     802             :   /// Histogram button was clicked.
     803             : 
     804           0 :   if ( fHistogramButton->IsOn() )
     805             :   {
     806           0 :     fHistoMin->SetState(kTRUE);
     807           0 :     fHistoMax->SetState(kTRUE);
     808           0 :   }
     809             :   else
     810             :   {
     811           0 :     fHistoMin->SetState(kFALSE);
     812           0 :     fHistoMax->SetState(kFALSE);
     813             :   }
     814           0 : }
     815             : 
     816             : //_____________________________________________________________________________
     817             : void
     818             : AliMUONPainterDataSourceFrame::OpenFileDialog()
     819             : {
     820             :   /// Open a file dialog to select a file to be read
     821             : 
     822           0 :   TGFileInfo fileInfo;
     823             : 
     824           0 :   const char* fileTypes[] = {
     825             :     "ROOT files","*.root",
     826             :     "DATE files","*.raw",
     827             :     "All files","*",
     828             :     0,0 };
     829             : 
     830           0 :   fileInfo.fFileTypes = fileTypes;
     831           0 :   delete[] fileInfo.fIniDir;
     832             : 
     833           0 :   fileInfo.fIniDir = StrDup(Env()->String("LastOpenDir","."));
     834             : 
     835           0 :   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
     836             :                    kFDOpen,&fileInfo);
     837             : 
     838           0 :   fFilePath->SetText(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
     839             : 
     840           0 :   Env()->Set("LastOpenDir",fileInfo.fIniDir);
     841           0 :   Env()->Save();
     842           0 : }
     843             : 
     844             : 
     845             : //_____________________________________________________________________________
     846             : void
     847             : AliMUONPainterDataSourceFrame::OpenFileDialogACF()
     848             : {
     849             :   /// Open a file dialog to select an ASCII calibration file to be read
     850             : 
     851           0 :   TGFileInfo fileInfo;
     852             : 
     853           0 :   const char* fileTypes[] = {
     854             :     "All files","*",
     855             :     0,0 };
     856             : 
     857           0 :   fileInfo.fFileTypes = fileTypes;
     858           0 :   delete[] fileInfo.fIniDir;
     859             : 
     860           0 :   fileInfo.fIniDir = StrDup(Env()->String("LastOpenDirACF","."));
     861             : 
     862           0 :   new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),
     863             :                    kFDOpen,&fileInfo);
     864             : 
     865           0 :   fACFPath->SetText(gSystem->ExpandPathName(Form("%s",fileInfo.fFilename)));
     866             : 
     867           0 :   Env()->Set("LastOpenDirACF",fileInfo.fIniDir);
     868           0 :   Env()->Save();
     869           0 : }
     870             : 
     871             : 
     872             : //_____________________________________________________________________________
     873             : void
     874             : AliMUONPainterDataSourceFrame::OpenRecentSource()
     875             : {
     876             :   /// Open one source from the recently used ones
     877             : 
     878           0 :   TGTextLBEntry* t = (TGTextLBEntry*)fRecentSources->GetSelectedEntry();
     879             : 
     880           0 :   TString dataSourceDescriptor(t->GetText()->GetString());
     881             : 
     882           0 :   TString name = Env()->Descriptor2Name(dataSourceDescriptor);
     883             : 
     884           0 :   if (AliMUONPainterDataRegistry::Instance()->DataSource(name))
     885             :   {
     886             :     // source already registered.
     887           0 :     return;
     888             :   }
     889             : 
     890           0 :   TString sid = Env()->Descriptor2ID(dataSourceDescriptor);
     891             : 
     892           0 :   TString origin = Env()->ID2Origin(sid);
     893             : 
     894           0 :   if ( origin == "OCDB" )
     895             :   {
     896           0 :     CreateOCDBDataSource(dataSourceDescriptor);
     897             :   }
     898           0 :   else if ( origin == "RAW" )
     899             :   {
     900           0 :     CreateRawDataSource(dataSourceDescriptor);
     901             :   }
     902           0 :   else if ( origin == "ACF" )
     903             :   {
     904           0 :     CreateACFDataSource(dataSourceDescriptor);
     905             :   }
     906             : 
     907           0 :   fRecentSources->Select(-1);
     908           0 : }
     909             : 
     910             : //_____________________________________________________________________________
     911             : void
     912             : AliMUONPainterDataSourceFrame::RegisterDataSource(AliMUONVTrackerDataMaker* reader,
     913             :                                                   const char* dataSourceDescriptor)
     914             : {
     915             :   /// Register a *new* data source
     916             : 
     917           0 :   if ( reader && reader->IsValid() )
     918             :   {
     919           0 :     AliMUONMchViewApplication* app = dynamic_cast<AliMUONMchViewApplication*>(gApplication);
     920           0 :     if (!app)
     921             :     {
     922           0 :       AliError("Could not cast application to the expected type ! CHECK THAT !");
     923           0 :     }
     924             : 
     925           0 :     AliMUONPainterDataRegistry::Instance()->Register(reader);
     926             : 
     927           0 :     TString desc = Env()->AddDataSource(dataSourceDescriptor);
     928             : 
     929           0 :     AddRecentSource(desc.Data());
     930             : 
     931           0 :     if ( app )
     932             :     {
     933           0 :       TString sid = Env()->Descriptor2ID(desc.Data());
     934           0 :       TString type = Env()->ID2Type(sid);
     935             : 
     936           0 :       if ( AliMUONTrackerDataSourceTypes::IsPedestals(type) )
     937             :       {
     938           0 :         if ( Env()->Integer("disableAutoPedCanvas",0)==0)
     939             :         {
     940           0 :           CreatePedestalCanvases(reader->Data());
     941             :         }
     942             :       }
     943           0 :     }
     944           0 :   }
     945           0 : }
     946             : 
     947             : //_____________________________________________________________________________
     948             : void
     949             : AliMUONPainterDataSourceFrame::StartRunning()
     950             : {
     951             :   /// One data source starts running. Disable the Run button of the other ones
     952             : 
     953           0 :   AliMUONPainterDataSourceItem* item = reinterpret_cast<AliMUONPainterDataSourceItem*> (gTQSender);
     954             : 
     955           0 :   AliInfo("");
     956             : 
     957           0 :   TIter next(fItems);
     958             :   AliMUONPainterDataSourceItem* o;
     959           0 :   while ( ( o = static_cast<AliMUONPainterDataSourceItem*>(next()) ) )
     960             :   {
     961           0 :     if ( o != item )
     962             :     {
     963           0 :       o->DisableRun();
     964             :     }
     965             :   }
     966           0 : }
     967             : 
     968             : //_____________________________________________________________________________
     969             : void
     970             : AliMUONPainterDataSourceFrame::StopRunning()
     971             : {
     972             :   /// One data source stops running. Enable the Run button of all items
     973             : 
     974           0 :   TIter next(fItems);
     975             :   AliMUONPainterDataSourceItem* o;
     976           0 :   while ( ( o = static_cast<AliMUONPainterDataSourceItem*>(next()) ) )
     977             :   {
     978           0 :     o->EnableRun();
     979             :   }
     980           0 : }

Generated by: LCOV version 1.11