From 9a11b2ee7701a952752a928412a35f23d6276cb9 Mon Sep 17 00:00:00 2001 From: abercuci Date: Mon, 2 Nov 2009 08:58:23 +0000 Subject: [PATCH] add "friendiness" to macro creation wizzard (Ben & Alex) --- EVE/EveDet/AliEveTRDTrackList.cxx | 22 +++++--- EVE/EveDet/AliEveTRDTrackList.h | 2 +- EVE/EveDet/AliEveTRDTrackListEditor.cxx | 71 ++++++++++++++++++++----- EVE/EveDet/AliEveTRDTrackListEditor.h | 9 ++-- 4 files changed, 78 insertions(+), 26 deletions(-) diff --git a/EVE/EveDet/AliEveTRDTrackList.cxx b/EVE/EveDet/AliEveTRDTrackList.cxx index f627d287f54..f61594db92b 100644 --- a/EVE/EveDet/AliEveTRDTrackList.cxx +++ b/EVE/EveDet/AliEveTRDTrackList.cxx @@ -1,7 +1,7 @@ // Author: Benjamin Hess 25/09/2008 /************************************************************************* - * Copyright (C) 2008, Alexandru Bercuci, Benjamin Hess. * + * Copyright (C) 2008-2009, Alexandru Bercuci, Benjamin Hess. * * All rights reserved. * *************************************************************************/ @@ -337,17 +337,17 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL TMacroData* macro = 0; - TString* procCmds = 0; + Char_t** procCmds = 0; AliEveTRDTrackListMacroType* mProcType = 0; if (procIterator->GetEntries() > 0) { - procCmds = new TString[procIterator->GetEntries()]; + procCmds = new Char_t*[procIterator->GetEntries()]; mProcType = new AliEveTRDTrackListMacroType[procIterator->GetEntries()]; } - TString* selCmds = 0; + Char_t** selCmds = 0; AliEveTRDTrackListMacroType* mSelType = 0; if (selIterator->GetEntries() > 0) { - selCmds = new TString[selIterator->GetEntries()]; + selCmds = new Char_t*[selIterator->GetEntries()]; mSelType = new AliEveTRDTrackListMacroType[selIterator->GetEntries()]; } @@ -362,6 +362,9 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL // Collect the commands for each process macro and add them to "data-from-list" for (Int_t i = 0; i < procIterator->GetEntries(); i++){ + procCmds[i] = new Char_t[(fkMaxMacroPathNameLength + fkMaxApplyCommandLength)]; + memset(procCmds[i], '\0', sizeof(Char_t) * (fkMaxMacroNameLength + fkMaxApplyCommandLength)); + macro = (TMacroData*)fMacroList->GetValue(procIterator->At(i)->GetTitle()); if (!macro){ @@ -381,14 +384,14 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL mProcType[i] = macroType; numHistoMacros++; // Create the command - procCmds[i] = macro->GetCmd(); + sprintf(procCmds[i], macro->GetCmd()); // Add to "data-from-list" -> Mark as a histo macro with the substring "(histo macro)" fDataFromMacroList->Add(new TObjString(Form("%s (histo macro)", macro->GetName()))); } else if (macroType == kSingleTrackAnalyse || macroType == kCorrelTrackAnalyse) { mProcType[i] = macroType; // Create the command - procCmds[i] = macro->GetCmd(); + sprintf(procCmds[i], macro->GetCmd()); // Add to "data-from-list" fDataFromMacroList->Add(new TObjString(macro->GetName())); @@ -402,6 +405,9 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL // Collect the commands for each selection macro and add them to "data-from-list" for (Int_t i = 0; i < selIterator->GetEntries(); i++){ + selCmds[i] = new Char_t[(fkMaxMacroPathNameLength + fkMaxApplyCommandLength)]; + memset(selCmds[i], '\0', sizeof(Char_t) * (fkMaxMacroNameLength + fkMaxApplyCommandLength)); + macro = (TMacroData*)fMacroList->GetValue(selIterator->At(i)->GetTitle()); if (!macro){ @@ -428,7 +434,7 @@ Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TL mSelType[i] = macroType; // Create the command - selCmds[i] = macro->GetCmd(); + sprintf(selCmds[i], macro->GetCmd()); } else { Error("Apply process macros", Form("Macro list corrupted: Macro \"%s/%s.C\" is not registered as a selection macro!", diff --git a/EVE/EveDet/AliEveTRDTrackList.h b/EVE/EveDet/AliEveTRDTrackList.h index 09d543790dc..6a5abcb5106 100644 --- a/EVE/EveDet/AliEveTRDTrackList.h +++ b/EVE/EveDet/AliEveTRDTrackList.h @@ -1,7 +1,7 @@ // Author: Benjamin Hess 25/09/2008 /************************************************************************* - * Copyright (C) 2008, Alexandru Bercuci, Benjamin Hess. * + * Copyright (C) 2008-2009, Alexandru Bercuci, Benjamin Hess. * * All rights reserved. * *************************************************************************/ diff --git a/EVE/EveDet/AliEveTRDTrackListEditor.cxx b/EVE/EveDet/AliEveTRDTrackListEditor.cxx index dd29e1fb4d7..88199a7c1ea 100644 --- a/EVE/EveDet/AliEveTRDTrackListEditor.cxx +++ b/EVE/EveDet/AliEveTRDTrackListEditor.cxx @@ -1,7 +1,7 @@ -// Author: Benjamin Hess 25/09/2008 +// Author: Benjamin Hess 30/10/2009 /************************************************************************* - * Copyright (C) 2008, Alexandru Bercuci, Benjamin Hess. * + * Copyright (C) 2008-2009, Alexandru Bercuci, Benjamin Hess. * * All rights reserved. * *************************************************************************/ @@ -1108,6 +1108,8 @@ AliEveTRDMacroWizzard::AliEveTRDMacroWizzard(const TGWindow* p) ,fText(0x0) ,fCombo(0x0) ,fTextEdit(0x0) + ,fbCreate(0x0) + ,fbCancel(0x0) { const Int_t width = 300; @@ -1157,6 +1159,15 @@ AliEveTRDMacroWizzard::AliEveTRDMacroWizzard(const TGWindow* p) fCombo->Resize(width, fText->GetDefaultHeight()); fFrameType->AddFrame(fCombo, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2)); + // horizontal frame + TGHorizontalFrame *fFrameAction = new TGHorizontalFrame(this,10,10,kHorizontalFrame); + fbCancel = new TGTextButton(fFrameAction, "Cancel"); + fbCancel->SetToolTipText("Exit macro creation wizzard"); + fFrameAction->AddFrame(fbCancel, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2)); + fbCreate = new TGTextButton(fFrameAction, "Done"); + fbCreate->SetToolTipText("Use settings to create the macro"); + fFrameAction->AddFrame(fbCreate, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2)); + // horizontal frame TGHorizontalFrame *fFrameText = new TGHorizontalFrame(this,10,10,kHorizontalFrame); @@ -1170,6 +1181,7 @@ AliEveTRDMacroWizzard::AliEveTRDMacroWizzard(const TGWindow* p) AddFrame(fFrameName, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2)); AddFrame(fFrameComment, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2)); AddFrame(fFrameType, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2)); + AddFrame(fFrameAction, new TGLayoutHints(kLHintsRight | kLHintsTop | kLHintsExpandX,2,2,2,2)); TGHorizontal3DLine *fLine = new TGHorizontal3DLine(this, 281, 2); AddFrame(fLine, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2)); @@ -1186,7 +1198,12 @@ AliEveTRDMacroWizzard::AliEveTRDMacroWizzard(const TGWindow* p) MapWindow(); // Do the linking - fCombo->Connect("Selected(Int_t)", "AliEveTRDMacroWizzard", this, "Create(Int_t)"); + //fCombo->Connect("Selected(Int_t)", "AliEveTRDMacroWizzard", this, "Create(Int_t)"); + fbCreate->Connect("Clicked()", "AliEveTRDMacroWizzard", this, "HandleCreate()"); + fbCancel->Connect("Clicked()", "AliEveTRDMacroWizzard", this, "CloseWindow()"); + + // Standard choice + fCombo->Select(1, kFALSE); } const Char_t *fIncludes = @@ -1202,39 +1219,43 @@ const Char_t *fIncludes = const Char_t *fMacroTemplate[7] = { "" ," if (!track) return kFALSE;\n" -" return kFALSE;\n" ," n = 0;\n" -" r=0x0;\n" +" r = 0x0;\n" " if (!track) return;\n" ," if (!track) return 0x0;\n" -" TH1* h = 0x0;\n" +" TH1* h = 0x0;\n\n" +"// Set bins, xmin and xmax here\n" +" Int_t n = 1;\n" +" Double_t xmin = 0;\n" +" Double_t xmax = 100;\n\n" " if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n" " h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n" " h->GetXaxis()->SetTitle("");\n" " h->GetYaxis()->SetTitle("");\n" " } else h->Reset();\n" -" return h;\n" ," if (!track) return kFALSE;\n" " if (!track2) return kFALSE;\n" -" return kFALSE;\n" ," n = 0;\n" -" r=0x0;\n" +" r = 0x0;\n" " if (!track) return;\n" " if (!track2) return;\n" ," if (!track) return 0x0;\n" " if (!track2) return 0x0;\n" -" TH1* h = 0x0;\n" +" TH1* h = 0x0;\n\n" +"// Set bins, xmin and xmax here\n" +" Int_t n = 1;\n" +" Double_t xmin = 0;\n" +" Double_t xmax = 100;\n\n" " if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n" " h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n" " h->GetXaxis()->SetTitle("");\n" " h->GetYaxis()->SetTitle("");\n" " } else h->Reset();\n" -" return h;\n" }; //______________________________________________________ void AliEveTRDMacroWizzard::Create(Int_t typ) @@ -1242,14 +1263,28 @@ void AliEveTRDMacroWizzard::Create(Int_t typ) const Char_t *name = fText->GetText(); if(strcmp(name,"")==0){ AliInfo("Please specify a name for your macro."); - fCombo->Select(-1); + new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", + "Please specify a name for your macro.", kMBIconExclamation, kMBOk); + //fCombo->Select(-1); + return; + } + + // Note: gSystem->AccessPathName(...) returns kTRUE, if the access FAILED! + if(!gSystem->AccessPathName(Form("./%s.C", name))){ + // If there is already a file with this name -> Error + AliInfo(Form("A macro \"%s.C\" already exists in the current directory!\nPlease choose another name!", name)); + new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", + Form("A macro \"%s.C\" already exists in the current directory!\nPlease choose another name!", name), kMBIconExclamation, kMBOk); + //fCombo->Select(-1); return; } FILE* fp = 0x0; if(!(fp = fopen(Form("%s.C", name), "wt"))){ AliInfo("Couldn't create macro file."); - fCombo->Select(-1); + new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", + "Couldn't create macro file.", kMBIconExclamation, kMBOk); + //fCombo->Select(-1); return; } @@ -1280,9 +1315,11 @@ void AliEveTRDMacroWizzard::Create(Int_t typ) break; default: AliInfo(Form("Unknown typ[%d]", typ)); + new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", + Form("Unknown typ[%d]", typ), kMBIconExclamation, kMBOk); fclose(fp); gSystem->Exec(Form("rm -f %s.C", name)); - fCombo->Select(-1); + //fCombo->Select(-1); return; } @@ -1300,3 +1337,9 @@ void AliEveTRDMacroWizzard::Create(Char_t *name) { Emit("Create(Char_t*)", Form("%s.C", name)); } + +//______________________________________________________ +void AliEveTRDMacroWizzard::HandleCreate() +{ + Create(fCombo->GetSelected()); +} diff --git a/EVE/EveDet/AliEveTRDTrackListEditor.h b/EVE/EveDet/AliEveTRDTrackListEditor.h index c24e0069300..37aa86c33a8 100644 --- a/EVE/EveDet/AliEveTRDTrackListEditor.h +++ b/EVE/EveDet/AliEveTRDTrackListEditor.h @@ -1,7 +1,7 @@ -// Author: Benjamin Hess 25/09/2008 +// Author: Benjamin Hess 30/10/2009 /************************************************************************* - * Copyright (C) 2008, Alexandru Bercuci, Benjamin Hess. * + * Copyright (C) 2008-2009, Alexandru Bercuci, Benjamin Hess. * * All rights reserved. * *************************************************************************/ @@ -158,6 +158,7 @@ public: AliEveTRDMacroWizzard(const TGWindow* p = 0); void Create(Int_t typ); //*SIGNAL* void Create(Char_t *pname); //*SIGNAL* + void HandleCreate(); private: AliEveTRDMacroWizzard(const AliEveTRDMacroWizzard&); @@ -166,8 +167,10 @@ private: TGTextEntry *fText; TGComboBox *fCombo; TGTextEdit *fTextEdit; + TGTextButton *fbCreate; // "Done" button + TGTextButton *fbCancel; // "Cancel" button - ClassDef(AliEveTRDMacroWizzard, 0); // Helper class to create macro templates + ClassDef(AliEveTRDMacroWizzard, 0); // Helper class to create macro templates }; #endif -- 2.39.3