00001 #include <cstdlib>
00002 #include <iostream>
00003
00004 #include "MessageService/MsgService.h"
00005 #include "Mad/ScanFrame.h"
00006 #include "Mad/ScanFrameCC.h"
00007 #include "Mad/ScanFrameNC.h"
00008 #include "Mad/ScanFrameTwoTrack.h"
00009
00010 #include <TFile.h>
00011 #include <TGLayout.h>
00012 #include <TG3DLine.h>
00013 #include <TSystem.h>
00014
00015 ClassImp(ScanFrame)
00016
00017 CVSID("$Id: ScanFrame.cxx,v 1.22 2009/10/28 22:32:24 jpaley Exp $");
00018
00019
00020
00021 Bool_t ScanFrame::fgEnableXMLFormat(false);
00022 void ScanFrame::EnableXMLFormat(Bool_t ) {
00023
00024 MSG("Mad",Msg::kError) << "Support for XML is currently disabled as ROOT SegVs when reading the output"
00025 << std::endl;
00026 }
00027
00028
00029
00030 ScanFrame* ScanFrame::CreateScanSheet(const TGWindow *p,
00031 const char* nm) {
00032 std::string name( nm ? nm : "CC");
00033 MSG("Mad",Msg::kInfo) << "Creating a scan sheet named " << name << std::endl;
00034
00035 if ( name == "Base" ) return new ScanFrame(p);
00036 if ( name == "CC" ) return new ScanFrameCC(p);
00037 if ( name == "NC" ) return new ScanFrameNC(p);
00038 if ( name == "TwoTrack" ) return new ScanFrameTwoTrack(p);
00039
00040 MSG("Mad",Msg::kError) << "Cannot create a scan sheet named " << name
00041 << " creating 'Default' instead." << std::endl;
00042 return new ScanFrameCC(p);
00043
00044 }
00045
00046 ScanFrame::ScanFrame(const TGWindow *p ,
00047 Bool_t buildScanFrame ) :
00048 fEnableXMLFormat(fgEnableXMLFormat)
00049 {
00050
00051
00052
00053
00054 if ( ! p ) {
00055 std::cout << "ScanFrame called with TGWindow *p == 0. This is not supported!" << std::endl;
00056 exit(1);
00057 }
00058
00059 this->Init();
00060 if ( buildScanFrame ) this->BuildScanFrame(p);
00061 }
00062
00063 ScanFrame::~ScanFrame() {
00064 }
00065
00066 void ScanFrame::BuildScanFrame(const TGWindow *p) {
00067
00068
00069
00070 fMain = new TGMainFrame(p,600,600);
00071 fSframe = new TGVerticalFrame(fMain,600,600);
00072 fMain->AddFrame(fSframe,new TGLayoutHints(kLHintsCenterX,2,2,2,2));
00073
00074
00075
00076 TGHorizontal3DLine* Line1 = new TGHorizontal3DLine(fSframe,400,2);
00077 fSframe->AddFrame(Line1, new TGLayoutHints(kLHintsExpandX,1,1,1,1));
00078
00079 TGHorizontalFrame * tframe1 = new TGHorizontalFrame(fSframe,400,10);
00080
00081 TGLabel* Label1 = new TGLabel(tframe1," Run: ");
00082 TGLabel* Label2 = new TGLabel(tframe1," Snarl: ");
00083 TGLabel* Label3 = new TGLabel(tframe1," Slice: ");
00084 TGLabel* Label4 = new TGLabel(tframe1," Event: ");
00085
00086 runLabel = new TGLabel(tframe1);
00087 snarlLabel = new TGLabel(tframe1);
00088 eventLabel = new TGLabel(tframe1);
00089 sliceLabel = new TGLabel(tframe1);
00090
00091 runLabel->SetText(fRun);
00092 snarlLabel->SetText(fSnarl);
00093 eventLabel->SetText(fEvent);
00094 sliceLabel->SetText(fSlice);
00095
00096 tframe1->AddFrame(Label1,new TGLayoutHints(kLHintsLeft|kLHintsExpandY,2,2,2,2));
00097 tframe1->AddFrame(runLabel,new TGLayoutHints(kLHintsLeft|kLHintsExpandY,2,2,2,2));
00098 tframe1->AddFrame(Label2,new TGLayoutHints(kLHintsLeft|kLHintsExpandY,2,2,2,2));
00099 tframe1->AddFrame(snarlLabel,new TGLayoutHints(kLHintsLeft|kLHintsExpandY,2,2,2,2));
00100 tframe1->AddFrame(Label3,new TGLayoutHints(kLHintsLeft|kLHintsExpandY,2,2,2,2));
00101 tframe1->AddFrame(sliceLabel,new TGLayoutHints(kLHintsLeft|kLHintsExpandY,2,2,2,2));
00102 tframe1->AddFrame(Label4,new TGLayoutHints(kLHintsLeft|kLHintsExpandY,2,2,2,2));
00103 tframe1->AddFrame(eventLabel,new TGLayoutHints(kLHintsLeft|kLHintsExpandY,2,2,2,2));
00104
00105 fSframe->AddFrame(tframe1,new TGLayoutHints(kLHintsCenterX ,2,2,2,2));
00106
00107 TGHorizontalFrame * tframe2 = new TGHorizontalFrame(fSframe,400,10);
00108
00109 TGLabel* Label5 = new TGLabel(tframe2," Scanner: ");
00110 tframe2->AddFrame(Label5,new TGLayoutHints(kLHintsLeft|kLHintsExpandY,2,2,2,2));
00111 Scanner = new TGTextEntry(tframe2);
00112 Scanner->SetText("Unknown");
00113 tframe2->AddFrame(Scanner,new TGLayoutHints(kLHintsLeft|kLHintsExpandY,2,2,2,2));
00114
00115 fSframe->AddFrame(tframe2,new TGLayoutHints(kLHintsCenterX ,2,2,2,2));
00116
00117 TGHorizontal3DLine* Line3 = new TGHorizontal3DLine(fSframe,400,2);
00118 fSframe->AddFrame(Line3, new TGLayoutHints(kLHintsExpandX,1,1,1,1));
00119
00120
00121
00122 this->BuildScanSheet();
00123
00124
00125
00126 TGHorizontal3DLine* Line5 = new TGHorizontal3DLine(fSframe,400,2);
00127 fSframe->AddFrame(Line5, new TGLayoutHints(kLHintsExpandX,1,1,1,1));
00128
00129 TGHorizontalFrame* tframe = new TGHorizontalFrame(fSframe,400,10);
00130 fSframe->AddFrame(tframe ,new TGLayoutHints(kLHintsLeft|kLHintsExpandX,2,2,2,2));
00131
00132 TGLabel* Label = new TGLabel(tframe,"Comment");
00133 tframe->AddFrame(Label,new TGLayoutHints(kLHintsLeft,2,2,2,2));
00134 Comment = new TGTextEntry(tframe);
00135 Comment->SetText(" ");
00136 tframe->AddFrame(Comment,new TGLayoutHints(kLHintsExpandX,2,2,2,2));
00137
00138 TGHorizontal3DLine* Line6 = new TGHorizontal3DLine(fSframe,400,2);
00139 fSframe->AddFrame(Line6, new TGLayoutHints(kLHintsExpandX,1,1,1,1));
00140
00141
00142
00143 fMain->SetWindowName("Scan Result Entry");
00144 fMain->MapSubwindows();
00145 fMain->Resize(fMain->GetDefaultSize());
00146 fMain->MapWindow();
00147 }
00148
00149 void ScanFrame::EntryProc() {
00150
00151
00152 this->ResyncData();
00153
00154
00155
00156 fComment = Comment->GetText();
00157 fScanner = Scanner->GetText();
00158 char fname[256];
00159 const char* ext = fEnableXMLFormat ? "xml" : "txt";
00160 sprintf(fname,"%s-scan-%s.%s",fScanName.c_str(),Scanner->GetText(),ext);
00161
00162
00163 gSystem->Beep();
00164
00165
00166
00167 if ( fEnableXMLFormat ) {
00168
00169 TDirectory* cwd = gDirectory;
00170 TFile *f = TFile::Open(fname,"update");
00171 this->Write();
00172 delete f;
00173
00174 cwd->cd();
00175 return;
00176 }
00177
00178
00179
00180 ofstream fout(fname,std::ios::app);
00181 fout << fScanFormat << " "
00182 << fScanner << " "
00183 << fSnarl << " "
00184 << fRun << " "
00185 << fSlice << " "
00186 << fEvent << " " ;
00187
00188
00189 this->WriteScanSheet(fout);
00190
00191
00192
00193 fout << "\"" << " " << fComment << " " << "\" " << std::endl;
00194 std::cout << " ENTRY ADDED TO " << fname << std::endl;
00195
00196
00197 Init();
00198 ResetDisplay();
00199
00200 }
00201
00202 void ScanFrame::Init(){
00203
00204 fComment="";
00205 fScanner="";
00206 fScanName="Base";
00207 fScanFormat="Base_v1";
00208 fSnarl=0;
00209 fRun=0;
00210 fSlice=0;
00211 fEvent=0;
00212
00213
00214 this->InitScanSheet();
00215
00216 }
00217
00218 void ScanFrame::ResetDisplay(std::string ) {
00219
00220 runLabel->SetText(fRun);
00221 snarlLabel->SetText(fSnarl);
00222 eventLabel->SetText(fEvent);
00223 sliceLabel->SetText(fSlice);
00224 Comment->SetText(" ");
00225
00226 }