New class TPCLoader providing (graphical) interface for navigation through the TPC...
authormtadel <mtadel@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 2 Jun 2006 18:15:55 +0000 (18:15 +0000)
committermtadel <mtadel@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 2 Jun 2006 18:15:55 +0000 (18:15 +0000)
EVE/Alieve/LinkDef.h
EVE/Alieve/TPCLoader.cxx [new file with mode: 0644]
EVE/Alieve/TPCLoader.h [new file with mode: 0644]
EVE/Alieve/TPCLoaderEditor.cxx [new file with mode: 0644]
EVE/Alieve/TPCLoaderEditor.h [new file with mode: 0644]

index 901dcdbb56f4b0c44406071dd6297a2809d7d09f..968b8b01262bbaddc8b3f59f16bdb55d6ccc6f8a 100644 (file)
@@ -40,3 +40,7 @@
 #pragma link C++ class Alieve::TPCSector2DGL+;
 #pragma link C++ class Alieve::TPCSector3D+;
 #pragma link C++ class Alieve::TPCSector3DEditor+;
+
+#pragma link C++ class Alieve::TPCLoader+;
+#pragma link C++ class Alieve::TPCLoaderEditor+;
+
diff --git a/EVE/Alieve/TPCLoader.cxx b/EVE/Alieve/TPCLoader.cxx
new file mode 100644 (file)
index 0000000..97feb73
--- /dev/null
@@ -0,0 +1,209 @@
+// $Header$
+
+#include "TPCLoader.h"
+#include "TPCData.h"
+#include <Alieve/TPCSector2D.h>
+#include <Alieve/TPCSector3D.h>
+#include <Reve/RGTopFrame.h>
+
+#include <AliRawReaderRoot.h>
+#include <AliTPCRawStream.h>
+
+#include <TSystem.h>
+
+using namespace Reve;
+using namespace Alieve;
+
+//______________________________________________________________________
+// TPCLoader
+//
+
+ClassImp(TPCLoader)
+
+TPCLoader::TPCLoader(const Text_t* n, const Text_t* t) :
+  RenderElementList(n, t),
+
+  fEvent(-1),
+
+  fReader(0),
+  fData(0),
+
+  fSec2Ds(36),
+  fSec3Ds(36)
+{
+  SetMainColorPtr(0);
+}
+
+TPCLoader::~TPCLoader()
+{
+  delete fReader;
+  delete fData;
+}
+
+/**************************************************************************/
+
+
+void TPCLoader::SetData(TPCData* d)
+{
+  delete fData;
+  fData = d;
+}
+
+/**************************************************************************/
+
+void TPCLoader::OpenFile()
+{
+  static const Exc_t eH("TPCLoader::OpenFile ");
+
+  if(gSystem->AccessPathName(fFile, kReadPermission))
+      throw(eH + "can not read '" + fFile + "'.");
+
+  if(fData == 0)
+    fData = new TPCData;
+
+  delete fReader;
+  fReader =  0;
+  fEvent  = -1;
+
+  fReader = new AliRawReaderRoot(fFile);
+  fReader->LoadEquipmentIdsMap
+    (gSystem->ExpandPathName("$(ALICE_ROOT)/TPC/mapping/EquipmentIdMap.data"));
+
+  NextEvent();
+  LoadEvent();
+  UpdateSectors();
+}
+
+void TPCLoader::LoadEvent()
+{
+  static const Exc_t eH("TPCLoader::LoadEvent ");
+
+  if(fReader == 0)
+    throw(eH + "data file not opened.");
+
+  printf("Now loading event %d\n", fEvent);
+  fReader->Reset();
+  AliTPCRawStream input(fReader);
+  input.SetOldRCUFormat(kTRUE);
+  fReader->Select(0);
+
+  fData->DropAllSectors();
+  fData->LoadRaw(input, kTRUE, kTRUE);  
+}
+
+void TPCLoader::NextEvent(Bool_t rewindOnEnd)
+{
+  static const Exc_t eH("TPCLoader::NextEvent ");
+
+  if(fReader == 0)
+    throw(eH + "data file not opened.");
+
+  if(fReader->NextEvent() == kTRUE) {
+    ++fEvent;
+  } else {
+    if(fEvent == -1)
+      throw(eH + "no events available.");
+    if(rewindOnEnd) {
+      printf("Reached end of stream (event=%d), rewinding to first event.\n", fEvent);
+      fReader->RewindEvents();
+      fReader->NextEvent();
+      fEvent = 0;
+    } else {
+      throw(eH + "last event reached.");
+    }
+  }
+}
+
+void TPCLoader::GotoEvent(Int_t event)
+{
+  static const Exc_t eH("TPCLoader::GotoEvent ");
+
+  if(fReader == 0)
+    throw(eH + "data file not opened.");
+
+  if(event == fEvent)
+    return;
+  Bool_t checkEnd;
+  if(event < fEvent) {
+    fReader->RewindEvents();
+    fEvent = -1;
+    checkEnd = kFALSE;
+  } else {
+    checkEnd = kTRUE;
+  }
+  do {
+    NextEvent();
+  } while(fEvent != event && !(checkEnd == kTRUE && fEvent == 0));
+  LoadEvent();
+  UpdateSectors();
+}
+
+/**************************************************************************/
+
+void TPCLoader::UpdateSectors()
+{
+  gReve->DisableRedraw();
+  for(Int_t i=0; i<=35; ++i) {
+    if(fSec2Ds[i] != 0) {
+      fSec2Ds[i]->IncRTS();
+    } else {
+      TPCSectorData* sd = fData->GetSectorData(i);
+      if(sd != 0) {
+       TPCSector2D* s = new TPCSector2D(Form("Sector2D %d", i));
+       fSec2Ds[i] = s;
+       s->SetSectorID(i);
+       s->SetDataSource(fData);
+       s->SetMinTime(0);
+       s->SetMaxTime(1023);
+
+       s->SetTrans(kTRUE);
+       s->SetFrameColor(36);
+
+       gReve->AddRenderElement(s);
+       gReve->DrawRenderElement(s);
+      }
+    }
+
+    if(fSec3Ds[i] != 0) {
+      fSec3Ds[i]->IncRTS();
+    }
+  }
+  gReve->EnableRedraw();
+}
+
+void TPCLoader::CreateSectors3D()
+{
+  gReve->DisableRedraw();
+  for(Int_t i=0; i<=35; ++i) {
+    TPCSectorData* sd = fData->GetSectorData(i);
+    if(sd != 0 && fSec3Ds[i] == 0) {
+      TPCSector3D* s = new TPCSector3D(Form("Sector3D %d", i));
+      fSec3Ds[i] = s;
+      s->SetSectorID(i);
+      s->SetDataSource(fData);
+      s->SetMinTime(0);
+      s->SetMaxTime(1023);
+
+      s->SetTrans(kTRUE);
+      s->SetFrameColor(36);
+
+      gReve->AddRenderElement(s);
+      gReve->DrawRenderElement(s);
+    }
+  }
+  gReve->EnableRedraw();
+}
+
+void TPCLoader::DeleteSectors3D()
+{
+  gReve->DisableRedraw();
+  for(Int_t i=0; i<=35; ++i) {
+    RenderElement* re = fSec3Ds[i];
+    if(re != 0) {
+      gReve->UndrawRenderElement(re);
+      delete re;
+      fSec3Ds[i] = 0;
+    }
+  }
+  gReve->EnableRedraw();
+}
diff --git a/EVE/Alieve/TPCLoader.h b/EVE/Alieve/TPCLoader.h
new file mode 100644 (file)
index 0000000..9350552
--- /dev/null
@@ -0,0 +1,55 @@
+// $Header$
+
+#ifndef ALIEVE_TPCLoader_H
+#define ALIEVE_TPCLoader_H
+
+#include <Reve/RenderElement.h>
+
+class AliRawReaderRoot;
+
+namespace Alieve {
+
+class TPCData;
+class TPCSector2D;
+class TPCSector3D;
+
+class TPCLoader : public Reve::RenderElementList
+{
+  friend class TPCLoaderEditor;
+
+protected:
+  TString           fFile;
+  Int_t             fEvent;
+
+  AliRawReaderRoot* fReader;
+  TPCData*          fData;
+
+  std::vector<TPCSector2D*> fSec2Ds;
+  std::vector<TPCSector3D*> fSec3Ds;
+
+public:
+  TPCLoader(const Text_t* n="TPCLoader", const Text_t* t=0);
+  virtual ~TPCLoader();
+
+  virtual Bool_t CanEditMainColor() { return kFALSE; }
+
+  void SetFile(const Text_t* f) { fFile = f; }
+
+  TPCData* GetData() const { return fData; }
+  void     SetData(TPCData* d);
+
+  void OpenFile();
+  void LoadEvent();
+  void NextEvent(Bool_t rewindOnEnd=kTRUE);
+  void GotoEvent(Int_t event);
+
+  void UpdateSectors();
+  void CreateSectors3D();
+  void DeleteSectors3D();
+
+  ClassDef(TPCLoader, 1);
+}; // endclass TPCLoader
+
+}
+
+#endif
diff --git a/EVE/Alieve/TPCLoaderEditor.cxx b/EVE/Alieve/TPCLoaderEditor.cxx
new file mode 100644 (file)
index 0000000..07d5ee6
--- /dev/null
@@ -0,0 +1,174 @@
+// $Header$
+
+#include "TPCLoaderEditor.h"
+#include <Alieve/TPCLoader.h>
+#include <Reve/RGTopFrame.h>
+#include <Reve/RGValuators.h>
+
+#include <TSystem.h>
+#include <TVirtualPad.h>
+#include <TColor.h>
+
+#include <TGLabel.h>
+#include <TGButton.h>
+#include <TGTextEntry.h>
+#include <TGNumberEntry.h>
+#include <TGFileDialog.h>
+
+using namespace Reve;
+using namespace Alieve;
+
+//______________________________________________________________________
+// TPCLoaderEditor
+//
+
+ClassImp(TPCLoaderEditor)
+
+TPCLoaderEditor::TPCLoaderEditor(const TGWindow *p, Int_t id, Int_t width, Int_t height,
+                                UInt_t options, Pixel_t back) :
+  TGedFrame(p, id, width, height, options | kVerticalFrame, back)
+{
+  fM = 0;
+  MakeTitle("TPCLoader");
+
+  Int_t labelW = 42;
+  {
+    TGHorizontalFrame* f = new TGHorizontalFrame(this);
+    TGHorizontalFrame* g = new TGHorizontalFrame(f, labelW, 0, kFixedWidth);
+    TGLabel* l = new TGLabel(g, "File: ");
+    g->AddFrame(l, new TGLayoutHints(kLHintsLeft, 0,0,4,0));
+    f->AddFrame(g);
+    fFile = new TGTextEntry(f);
+    fFile->SetWidth(140);
+    f->AddFrame(fFile);
+    fFile->Connect("DoubleClicked()",
+                  "Alieve::TPCLoaderEditor", this, "FileSelect()");
+    fFile->Connect("TextChanged(const char *)",
+                  "Alieve::TPCLoaderEditor", this, "FileChanged()");
+    fOpenFile = new TGTextButton(f, "Open");
+    f->AddFrame(fOpenFile);
+    fOpenFile->Connect("Clicked()",
+                      "Alieve::TPCLoaderEditor", this, "DoOpen()");
+    AddFrame(f);
+  }
+
+  fEvent = new RGValuator(this, "Event:", 110, 0);
+  fEvent->SetShowSlider(kFALSE);
+  fEvent->SetLabelWidth(labelW);
+  fEvent->SetNELength(6);
+  fEvent->Build();
+  fEvent->SetLimits(0, 1000);
+  fEvent->SetToolTip("Current event number");
+  fEvent->Connect("ValueSet(Double_t)",
+                 "Alieve::TPCLoaderEditor", this, "DoEvent()");
+  AddFrame(fEvent);
+
+  fUpdateSectors = new TGTextButton(this, "Update Sectors");
+  AddFrame(fUpdateSectors, new TGLayoutHints(kLHintsExpandX, 8,8,8,0));
+  fUpdateSectors->Connect("Clicked()",
+                    "Alieve::TPCLoaderEditor", this, "DoUpdateSectors()");
+  {
+    TGHorizontalFrame* f = new TGHorizontalFrame(this);
+    fCreateSectors3D = new TGTextButton(f, "Create 3D");
+    f->AddFrame(fCreateSectors3D, new TGLayoutHints(kLHintsExpandX, 0,4,0,0));
+    fCreateSectors3D->Connect("Clicked()",
+                    "Alieve::TPCLoaderEditor", this, "DoCreateSectors3D()");
+    fDeleteSectors3D = new TGTextButton(f, "Delete 3D");
+    f->AddFrame(fDeleteSectors3D, new TGLayoutHints(kLHintsExpandX, 4,0,0,0));
+    fDeleteSectors3D->Connect("Clicked()",
+                    "Alieve::TPCLoaderEditor", this, "DoDeleteSectors3D()");
+    AddFrame(f, new TGLayoutHints(kLHintsExpandX, 8,8,8,0));
+  }
+
+  // Register the editor.
+  TClass *cl = TPCLoader::Class();
+  TGedElement *ge = new TGedElement;
+  ge->fGedFrame = this;
+  ge->fCanvas = 0;
+  cl->GetEditorList()->Add(ge);
+}
+
+TPCLoaderEditor::~TPCLoaderEditor()
+{}
+
+/**************************************************************************/
+
+void TPCLoaderEditor::SetModel(TVirtualPad* pad, TObject* obj, Int_t /*event*/)
+{
+  fModel = 0;
+  fPad   = 0;
+
+  if (!obj || !obj->InheritsFrom(TPCLoader::Class()) || obj->InheritsFrom(TVirtualPad::Class())) {
+    SetActive(kFALSE);
+    return;
+  }
+
+  fModel = obj;
+  fPad   = pad;
+
+  fM = dynamic_cast<TPCLoader*>(fModel);
+
+  fFile->SetText(fM->fFile);
+  fEvent->SetValue(fM->fEvent);
+  fEvent->SetEnabled(fM->fEvent >= 0);
+    
+  SetActive();
+}
+
+/**************************************************************************/
+/**************************************************************************/
+
+namespace {
+const char *tpcfiletypes[] = {
+   "Root files",  "*.root",
+   "All files",   "*.*",
+    0,               0
+};
+}
+
+void TPCLoaderEditor::FileSelect()
+{
+  TGFileInfo fi;
+  fi.fFileTypes = tpcfiletypes;
+  new TGFileDialog(fClient->GetRoot(), gReve, kFDOpen, &fi);
+  if (!fi.fFilename) return;
+  fFile->SetText(gSystem->BaseName(fi.fFilename));
+}
+
+void TPCLoaderEditor::FileChanged()
+{
+  fM->fFile = fFile->GetText();
+}
+
+void TPCLoaderEditor::DoOpen()
+{
+  fM->OpenFile();
+  SetModel(fPad, fModel, 0);
+}
+
+/**************************************************************************/
+
+void TPCLoaderEditor::DoEvent()
+{
+  fM->GotoEvent((Int_t) fEvent->GetValue());
+  SetModel(fPad, fModel, 0);
+}
+
+/**************************************************************************/
+
+void TPCLoaderEditor::DoUpdateSectors()
+{
+  fM->UpdateSectors();
+}
+
+void TPCLoaderEditor::DoCreateSectors3D()
+{
+  fM->CreateSectors3D();
+}
+
+
+void TPCLoaderEditor::DoDeleteSectors3D()
+{
+  fM->DeleteSectors3D();
+}
+
diff --git a/EVE/Alieve/TPCLoaderEditor.h b/EVE/Alieve/TPCLoaderEditor.h
new file mode 100644 (file)
index 0000000..30e5e63
--- /dev/null
@@ -0,0 +1,57 @@
+// $Header$
+
+#ifndef ALIEVE_TPCLoaderEditor_H
+#define ALIEVE_TPCLoaderEditor_H
+
+#include <TGedFrame.h>
+
+class TGTextButton;
+class TGCheckButton;
+class TGNumberEntry;
+class TGColorSelect;
+class TGTextEntry;
+
+namespace Reve {
+class RGValuator;
+}
+
+namespace Alieve {
+
+class TPCLoader;
+
+class TPCLoaderEditor : public TGedFrame
+{
+protected:
+  TPCLoader* fM; // fModel dynamic-casted to TPCLoaderEditor
+
+  TGTextEntry*  fFile;
+  TGTextButton* fOpenFile;
+
+  Reve::RGValuator* fEvent;
+
+  TGTextButton* fUpdateSectors;
+  TGTextButton* fCreateSectors3D;
+  TGTextButton* fDeleteSectors3D;
+
+public:
+  TPCLoaderEditor(const TGWindow* p, Int_t id, Int_t width = 170, Int_t height = 30, UInt_t options = kChildFrame, Pixel_t back = GetDefaultFrameBackground());
+  ~TPCLoaderEditor();
+
+  virtual void SetModel(TVirtualPad* pad, TObject* obj, Int_t event);
+
+  void FileSelect();
+  void FileChanged();
+  void DoOpen();
+
+  void DoEvent();
+
+  void DoUpdateSectors();
+  void DoCreateSectors3D();
+  void DoDeleteSectors3D();
+
+  ClassDef(TPCLoaderEditor, 0); // Editor for TPCLoader
+}; // endclass TPCLoaderEditor
+
+}
+
+#endif