ROOT logo
/**************************************************************************
* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
*                                                                        *
* Author: The ALICE Off-line Project.                                    *
* Contributors are mentioned in the code where appropriate.              *
*                                                                        *
* Permission to use, copy, modify and distribute this software and its   *
* documentation strictly for non-commercial purposes is hereby granted   *
* without fee, provided that the above copyright notice appears in all   *
* copies and that both the copyright notice and this permission notice   *
* appear in the supporting documentation. The authors make no claims     *
* about the suitability of this software for any purpose. It is          *
* provided "as is" without express or implied warranty.                  *
**************************************************************************/

// $Id$

#include "AliMUONPainterRegistry.h"

#include "AliMpManuIterator.h"
#include "AliMUON2DMap.h"
#include "AliMUONCalibParamND.h"
#include "AliMUONPainterMatrix.h"
#include "AliLog.h"
#include <TGMenu.h>
#include <TGWindow.h>
#include <THashList.h>
#include <TObjArray.h>
#include <TString.h>
#include <Riostream.h>

///\class AliMUONPainterRegistry
///
/// Registry for AliMUONVPainter related stuff : painter data sources
/// and painter matrices
///
///\author Laurent Aphecetche, Subatech

using std::cout;
using std::endl;
///\cond CLASSIMP
ClassImp(AliMUONPainterRegistry)
///\endcond

AliMUONPainterRegistry* AliMUONPainterRegistry::fgInstance(0x0);

//_____________________________________________________________________________
AliMUONPainterRegistry::AliMUONPainterRegistry() : TObject(), TQObject(),
fPainterMatrices(new TObjArray),
fHistoryMenu(0x0),
fMenuBar(0x0),
fHistoryCounter(0)
{
  /// ctor
  fPainterMatrices->SetOwner(kTRUE);
}

//_____________________________________________________________________________
AliMUONPainterRegistry::~AliMUONPainterRegistry()
{
  /// dtor
  delete fPainterMatrices;
}

//_____________________________________________________________________________
Int_t 
AliMUONPainterRegistry::FindIndexOf(AliMUONPainterMatrix* group) const
{
  /// Get the index of a given painterMatrix
  return fPainterMatrices->IndexOf(group);
}

//_____________________________________________________________________________
AliMUONPainterMatrix*
AliMUONPainterRegistry::PainterMatrix(const char* name) const
{
  /// Get a painterMatrix by name
  return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->FindObject(name));
}

//_____________________________________________________________________________
void
AliMUONPainterRegistry::HistoryMenuActivated(Int_t i)
{
  /// A painterMatrix was chosen from the history menu
  
  AliDebug(1,Form("i=%d",i));
  
  TGMenuEntry* entry = fHistoryMenu->GetEntry(i);
  
  AliMUONPainterMatrix* group = reinterpret_cast<AliMUONPainterMatrix*>(entry->GetUserData());
  
  PainterMatrixWantToShow(group);
}

//_____________________________________________________________________________
AliMUONPainterRegistry*
AliMUONPainterRegistry::Instance()
{
  /// Get unique instance of this class
  if ( !fgInstance ) fgInstance = new AliMUONPainterRegistry;
  return fgInstance;
}

//_____________________________________________________________________________
AliMUONPainterMatrix* 
AliMUONPainterRegistry::PainterMatrix(Int_t i) const
{
  /// Get one painter matrix
  if ( i >= 0 && i <= fPainterMatrices->GetLast() )
  {
    return static_cast<AliMUONPainterMatrix*>(fPainterMatrices->At(i));
  }
  else
  {
    AliError(Form("Index out of bounds : %d / %d",i,fPainterMatrices->GetLast()+1));
    return 0x0;
  }
}

//_____________________________________________________________________________
void 
AliMUONPainterRegistry::PainterMatrixWantToShow(const AliMUONPainterMatrix* group)
{
  /// A given paintermatrix want to appear on screen
  Long_t param[] = { (Long_t)group };
  
  Emit("PainterMatrixWantToShow(AliMUONPainterMatrix*)",param);  
}

//_____________________________________________________________________________
void
AliMUONPainterRegistry::AddToHistory(AliMUONPainterMatrix* group)
{
  /// Add a matrix to the history
  
  if ( !fHistoryMenu && fMenuBar ) 
  {
    fHistoryMenu =  new TGPopupMenu(gClient->GetRoot());
    TGPopupMenu* before = 0x0; //FIXME: could try to find a place where to put it (e.g. before Help ?)
    
    fMenuBar->AddPopup("&History",fHistoryMenu, new TGLayoutHints(kLHintsNormal),before);
    
    fHistoryMenu->Connect("Activated(Int_t)",
                          "AliMUONPainterRegistry",this,
                          "HistoryMenuActivated(Int_t)");
    
    AliDebug(1,Form("HistoryMenu create at %p",fHistoryMenu));
  }
  
  if ( fHistoryMenu ) 
  {
    TIter next(fHistoryMenu->GetListOfEntries());
    TGMenuEntry* e(0x0);
    
    while ( ( e = static_cast<TGMenuEntry*>(next()) ) )
    {
      if ( e->GetUserData() == group ) 
      {
        fHistoryMenu->DeleteEntry(e);
        break;
      }
    }
    
    e = static_cast<TGMenuEntry*>(fHistoryMenu->GetListOfEntries()->First());
    
    fHistoryMenu->AddEntry(group->GetName(),++fHistoryCounter,(void*)group,0x0,e);
  }
  else
  {
    AliError("fHistoryMenu is null. We probably did not find the relevant menu entry ?");
  }
}

//_____________________________________________________________________________
void 
AliMUONPainterRegistry::PainterMatrixWasRegistered(const AliMUONPainterMatrix* group)
{
  /// A new painter matrix was registered
  Long_t param[] = { (Long_t)group };
  
  Emit("PainterMatrixWasRegistered(AliMUONPainterMatrix*)",param);
}

//_____________________________________________________________________________
void 
AliMUONPainterRegistry::PainterMatrixWasUnregistered(const AliMUONPainterMatrix* group)
{
  /// A painter matrix was unregistered
  Long_t param[] = { (Long_t)group };
  
  Emit("PainterMatrixWasUnregistered(AliMUONPainterMatrix*)",param);
}

//_____________________________________________________________________________
void 
AliMUONPainterRegistry::Print(Option_t* opt) const
{
  /// Printout
  TString sopt(opt);
  sopt.ToUpper();
  
  cout << "Number of painter matrices = " << NumberOfPainterMatrices() << endl;
  
  if ( sopt.Contains("FULL") || sopt.Contains("MATRIX") )
  {
    TIter next(fPainterMatrices);
    AliMUONPainterMatrix* matrix;
    
    while ( ( matrix = static_cast<AliMUONPainterMatrix*>(next()) ) )
    {
      matrix->Print();
    }
  }
  
}

//_____________________________________________________________________________
Int_t
AliMUONPainterRegistry::Register(AliMUONPainterMatrix* group)
{
  /// group is adopted, i.e. the registry becomes the owner of it.
  fPainterMatrices->AddLast(group);
  
  PainterMatrixWasRegistered(group);
  
  return fPainterMatrices->IndexOf(group);
}

//_____________________________________________________________________________
Int_t 
AliMUONPainterRegistry::NumberOfPainterMatrices() const
{
  /// The number of painter matrices we handle
  return fPainterMatrices->GetLast()+1;
}

//_____________________________________________________________________________
Bool_t 
AliMUONPainterRegistry::Unregister(AliMUONPainterMatrix* group)
{
  /// Unregister some matrix
  
  if (!group) return kFALSE;
  
  PainterMatrixWasUnregistered(group);
  
  TObject* o = fPainterMatrices->Remove(group);
  if ( o ) 
  {
    delete o;
  }
  else
  {
    AliError(Form("Could not unregister group named %s",group->GetName()));
  }
  return ( o != 0x0 );
}
 AliMUONPainterRegistry.cxx:1
 AliMUONPainterRegistry.cxx:2
 AliMUONPainterRegistry.cxx:3
 AliMUONPainterRegistry.cxx:4
 AliMUONPainterRegistry.cxx:5
 AliMUONPainterRegistry.cxx:6
 AliMUONPainterRegistry.cxx:7
 AliMUONPainterRegistry.cxx:8
 AliMUONPainterRegistry.cxx:9
 AliMUONPainterRegistry.cxx:10
 AliMUONPainterRegistry.cxx:11
 AliMUONPainterRegistry.cxx:12
 AliMUONPainterRegistry.cxx:13
 AliMUONPainterRegistry.cxx:14
 AliMUONPainterRegistry.cxx:15
 AliMUONPainterRegistry.cxx:16
 AliMUONPainterRegistry.cxx:17
 AliMUONPainterRegistry.cxx:18
 AliMUONPainterRegistry.cxx:19
 AliMUONPainterRegistry.cxx:20
 AliMUONPainterRegistry.cxx:21
 AliMUONPainterRegistry.cxx:22
 AliMUONPainterRegistry.cxx:23
 AliMUONPainterRegistry.cxx:24
 AliMUONPainterRegistry.cxx:25
 AliMUONPainterRegistry.cxx:26
 AliMUONPainterRegistry.cxx:27
 AliMUONPainterRegistry.cxx:28
 AliMUONPainterRegistry.cxx:29
 AliMUONPainterRegistry.cxx:30
 AliMUONPainterRegistry.cxx:31
 AliMUONPainterRegistry.cxx:32
 AliMUONPainterRegistry.cxx:33
 AliMUONPainterRegistry.cxx:34
 AliMUONPainterRegistry.cxx:35
 AliMUONPainterRegistry.cxx:36
 AliMUONPainterRegistry.cxx:37
 AliMUONPainterRegistry.cxx:38
 AliMUONPainterRegistry.cxx:39
 AliMUONPainterRegistry.cxx:40
 AliMUONPainterRegistry.cxx:41
 AliMUONPainterRegistry.cxx:42
 AliMUONPainterRegistry.cxx:43
 AliMUONPainterRegistry.cxx:44
 AliMUONPainterRegistry.cxx:45
 AliMUONPainterRegistry.cxx:46
 AliMUONPainterRegistry.cxx:47
 AliMUONPainterRegistry.cxx:48
 AliMUONPainterRegistry.cxx:49
 AliMUONPainterRegistry.cxx:50
 AliMUONPainterRegistry.cxx:51
 AliMUONPainterRegistry.cxx:52
 AliMUONPainterRegistry.cxx:53
 AliMUONPainterRegistry.cxx:54
 AliMUONPainterRegistry.cxx:55
 AliMUONPainterRegistry.cxx:56
 AliMUONPainterRegistry.cxx:57
 AliMUONPainterRegistry.cxx:58
 AliMUONPainterRegistry.cxx:59
 AliMUONPainterRegistry.cxx:60
 AliMUONPainterRegistry.cxx:61
 AliMUONPainterRegistry.cxx:62
 AliMUONPainterRegistry.cxx:63
 AliMUONPainterRegistry.cxx:64
 AliMUONPainterRegistry.cxx:65
 AliMUONPainterRegistry.cxx:66
 AliMUONPainterRegistry.cxx:67
 AliMUONPainterRegistry.cxx:68
 AliMUONPainterRegistry.cxx:69
 AliMUONPainterRegistry.cxx:70
 AliMUONPainterRegistry.cxx:71
 AliMUONPainterRegistry.cxx:72
 AliMUONPainterRegistry.cxx:73
 AliMUONPainterRegistry.cxx:74
 AliMUONPainterRegistry.cxx:75
 AliMUONPainterRegistry.cxx:76
 AliMUONPainterRegistry.cxx:77
 AliMUONPainterRegistry.cxx:78
 AliMUONPainterRegistry.cxx:79
 AliMUONPainterRegistry.cxx:80
 AliMUONPainterRegistry.cxx:81
 AliMUONPainterRegistry.cxx:82
 AliMUONPainterRegistry.cxx:83
 AliMUONPainterRegistry.cxx:84
 AliMUONPainterRegistry.cxx:85
 AliMUONPainterRegistry.cxx:86
 AliMUONPainterRegistry.cxx:87
 AliMUONPainterRegistry.cxx:88
 AliMUONPainterRegistry.cxx:89
 AliMUONPainterRegistry.cxx:90
 AliMUONPainterRegistry.cxx:91
 AliMUONPainterRegistry.cxx:92
 AliMUONPainterRegistry.cxx:93
 AliMUONPainterRegistry.cxx:94
 AliMUONPainterRegistry.cxx:95
 AliMUONPainterRegistry.cxx:96
 AliMUONPainterRegistry.cxx:97
 AliMUONPainterRegistry.cxx:98
 AliMUONPainterRegistry.cxx:99
 AliMUONPainterRegistry.cxx:100
 AliMUONPainterRegistry.cxx:101
 AliMUONPainterRegistry.cxx:102
 AliMUONPainterRegistry.cxx:103
 AliMUONPainterRegistry.cxx:104
 AliMUONPainterRegistry.cxx:105
 AliMUONPainterRegistry.cxx:106
 AliMUONPainterRegistry.cxx:107
 AliMUONPainterRegistry.cxx:108
 AliMUONPainterRegistry.cxx:109
 AliMUONPainterRegistry.cxx:110
 AliMUONPainterRegistry.cxx:111
 AliMUONPainterRegistry.cxx:112
 AliMUONPainterRegistry.cxx:113
 AliMUONPainterRegistry.cxx:114
 AliMUONPainterRegistry.cxx:115
 AliMUONPainterRegistry.cxx:116
 AliMUONPainterRegistry.cxx:117
 AliMUONPainterRegistry.cxx:118
 AliMUONPainterRegistry.cxx:119
 AliMUONPainterRegistry.cxx:120
 AliMUONPainterRegistry.cxx:121
 AliMUONPainterRegistry.cxx:122
 AliMUONPainterRegistry.cxx:123
 AliMUONPainterRegistry.cxx:124
 AliMUONPainterRegistry.cxx:125
 AliMUONPainterRegistry.cxx:126
 AliMUONPainterRegistry.cxx:127
 AliMUONPainterRegistry.cxx:128
 AliMUONPainterRegistry.cxx:129
 AliMUONPainterRegistry.cxx:130
 AliMUONPainterRegistry.cxx:131
 AliMUONPainterRegistry.cxx:132
 AliMUONPainterRegistry.cxx:133
 AliMUONPainterRegistry.cxx:134
 AliMUONPainterRegistry.cxx:135
 AliMUONPainterRegistry.cxx:136
 AliMUONPainterRegistry.cxx:137
 AliMUONPainterRegistry.cxx:138
 AliMUONPainterRegistry.cxx:139
 AliMUONPainterRegistry.cxx:140
 AliMUONPainterRegistry.cxx:141
 AliMUONPainterRegistry.cxx:142
 AliMUONPainterRegistry.cxx:143
 AliMUONPainterRegistry.cxx:144
 AliMUONPainterRegistry.cxx:145
 AliMUONPainterRegistry.cxx:146
 AliMUONPainterRegistry.cxx:147
 AliMUONPainterRegistry.cxx:148
 AliMUONPainterRegistry.cxx:149
 AliMUONPainterRegistry.cxx:150
 AliMUONPainterRegistry.cxx:151
 AliMUONPainterRegistry.cxx:152
 AliMUONPainterRegistry.cxx:153
 AliMUONPainterRegistry.cxx:154
 AliMUONPainterRegistry.cxx:155
 AliMUONPainterRegistry.cxx:156
 AliMUONPainterRegistry.cxx:157
 AliMUONPainterRegistry.cxx:158
 AliMUONPainterRegistry.cxx:159
 AliMUONPainterRegistry.cxx:160
 AliMUONPainterRegistry.cxx:161
 AliMUONPainterRegistry.cxx:162
 AliMUONPainterRegistry.cxx:163
 AliMUONPainterRegistry.cxx:164
 AliMUONPainterRegistry.cxx:165
 AliMUONPainterRegistry.cxx:166
 AliMUONPainterRegistry.cxx:167
 AliMUONPainterRegistry.cxx:168
 AliMUONPainterRegistry.cxx:169
 AliMUONPainterRegistry.cxx:170
 AliMUONPainterRegistry.cxx:171
 AliMUONPainterRegistry.cxx:172
 AliMUONPainterRegistry.cxx:173
 AliMUONPainterRegistry.cxx:174
 AliMUONPainterRegistry.cxx:175
 AliMUONPainterRegistry.cxx:176
 AliMUONPainterRegistry.cxx:177
 AliMUONPainterRegistry.cxx:178
 AliMUONPainterRegistry.cxx:179
 AliMUONPainterRegistry.cxx:180
 AliMUONPainterRegistry.cxx:181
 AliMUONPainterRegistry.cxx:182
 AliMUONPainterRegistry.cxx:183
 AliMUONPainterRegistry.cxx:184
 AliMUONPainterRegistry.cxx:185
 AliMUONPainterRegistry.cxx:186
 AliMUONPainterRegistry.cxx:187
 AliMUONPainterRegistry.cxx:188
 AliMUONPainterRegistry.cxx:189
 AliMUONPainterRegistry.cxx:190
 AliMUONPainterRegistry.cxx:191
 AliMUONPainterRegistry.cxx:192
 AliMUONPainterRegistry.cxx:193
 AliMUONPainterRegistry.cxx:194
 AliMUONPainterRegistry.cxx:195
 AliMUONPainterRegistry.cxx:196
 AliMUONPainterRegistry.cxx:197
 AliMUONPainterRegistry.cxx:198
 AliMUONPainterRegistry.cxx:199
 AliMUONPainterRegistry.cxx:200
 AliMUONPainterRegistry.cxx:201
 AliMUONPainterRegistry.cxx:202
 AliMUONPainterRegistry.cxx:203
 AliMUONPainterRegistry.cxx:204
 AliMUONPainterRegistry.cxx:205
 AliMUONPainterRegistry.cxx:206
 AliMUONPainterRegistry.cxx:207
 AliMUONPainterRegistry.cxx:208
 AliMUONPainterRegistry.cxx:209
 AliMUONPainterRegistry.cxx:210
 AliMUONPainterRegistry.cxx:211
 AliMUONPainterRegistry.cxx:212
 AliMUONPainterRegistry.cxx:213
 AliMUONPainterRegistry.cxx:214
 AliMUONPainterRegistry.cxx:215
 AliMUONPainterRegistry.cxx:216
 AliMUONPainterRegistry.cxx:217
 AliMUONPainterRegistry.cxx:218
 AliMUONPainterRegistry.cxx:219
 AliMUONPainterRegistry.cxx:220
 AliMUONPainterRegistry.cxx:221
 AliMUONPainterRegistry.cxx:222
 AliMUONPainterRegistry.cxx:223
 AliMUONPainterRegistry.cxx:224
 AliMUONPainterRegistry.cxx:225
 AliMUONPainterRegistry.cxx:226
 AliMUONPainterRegistry.cxx:227
 AliMUONPainterRegistry.cxx:228
 AliMUONPainterRegistry.cxx:229
 AliMUONPainterRegistry.cxx:230
 AliMUONPainterRegistry.cxx:231
 AliMUONPainterRegistry.cxx:232
 AliMUONPainterRegistry.cxx:233
 AliMUONPainterRegistry.cxx:234
 AliMUONPainterRegistry.cxx:235
 AliMUONPainterRegistry.cxx:236
 AliMUONPainterRegistry.cxx:237
 AliMUONPainterRegistry.cxx:238
 AliMUONPainterRegistry.cxx:239
 AliMUONPainterRegistry.cxx:240
 AliMUONPainterRegistry.cxx:241
 AliMUONPainterRegistry.cxx:242
 AliMUONPainterRegistry.cxx:243
 AliMUONPainterRegistry.cxx:244
 AliMUONPainterRegistry.cxx:245
 AliMUONPainterRegistry.cxx:246
 AliMUONPainterRegistry.cxx:247
 AliMUONPainterRegistry.cxx:248
 AliMUONPainterRegistry.cxx:249
 AliMUONPainterRegistry.cxx:250
 AliMUONPainterRegistry.cxx:251
 AliMUONPainterRegistry.cxx:252
 AliMUONPainterRegistry.cxx:253
 AliMUONPainterRegistry.cxx:254
 AliMUONPainterRegistry.cxx:255
 AliMUONPainterRegistry.cxx:256
 AliMUONPainterRegistry.cxx:257
 AliMUONPainterRegistry.cxx:258