7d4577cbab497ad75350e8354ecba34ef206d05a
[u/mrichter/AliRoot.git] / MONITOR / alieventserver / AliEventServerPreferencesWindow.cxx
1 // Author: Mihai Niculescu 2013
2
3 /**************************************************************************
4  * Copyright(c) 1998-2013, ALICE Experiment at CERN, all rights reserved. *
5  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
6  * full copyright notice.                                                 *
7  **************************************************************************/
8  
9 #include <TEnv.h>
10 #include <TObjString.h>
11 #include <TString.h>
12 #include <TSystem.h>
13
14 #include <TGButton.h>
15 #include <TGLabel.h>
16 #include <TGMsgBox.h>
17 #include <TGTab.h>
18 #include <TGTextEntry.h>
19
20 #include <AliReconstruction.h>
21
22 #include "AliEventServerUtil.h"
23 #include "AliEventServerPreferencesWindow.h"
24
25 //_________________________________________________________
26 ClassImp(AliEventServerPreferencesWindow)
27 AliEventServerPreferencesWindow::AliEventServerPreferencesWindow(const TGWindow* p, const char* window_title)
28         : TGTransientFrame(gClient->GetRoot(), p),
29         fTab(0),
30         fEntryServerHost(0),
31         fEntryServerPort(0),
32         fEntryCDBDefaultStorage(0),
33         fEntryCDBSpecStoragePath1(0),
34         fEntryCDBSpecStorageValue1(0),
35         fEntryCDBSpecStoragePath2(0),
36         fEntryCDBSpecStorageValue2(0),
37         fEntryCDBSpecStoragePath3(0),
38         fEntryCDBSpecStorageValue3(0),
39         fEntryRecoRunQA(0),
40         fEntryRecoQARefDefStorage(0),
41         fChkRecoRunGlobalQA(0),
42         fChkRecoRunPlaneEff(0),
43         fChkRecoWriteESDf(0),
44         fChkRecoWriteAlignment(0),
45         fChkRecoCleanESD(0),
46         fDetectors(0),
47         fEntryLogbookHost(0),
48         fEntryLogbookPort(0),
49         fEntryLogbookDB(0),
50         fEntryLogbookUser(0),
51         fEntryLogbookPass(0)
52 {
53         SetCleanup(kDeepCleanup);
54         SetWindowName(window_title);
55         
56          // Tab Preferences
57         fTab = new TGTab(this);
58   TGCompositeFrame* tab1 = fTab->AddTab("Server");
59   TGCompositeFrame* tab2 = fTab->AddTab("Reconstruction");
60   TGCompositeFrame* tab3 = fTab->AddTab("Logbook");
61         
62         SetupServerTab(tab1);
63         SetupRecoTab(tab2);
64         SetupLogbookTab(tab3);
65         
66         // dialog buttons
67         TGHorizontalFrame* hf = new TGHorizontalFrame(this);
68         TGTextButton* btDefaults = new TGTextButton(hf, "Restore Defaults");
69         TGTextButton* btCancel = new TGTextButton(hf, "Cancel");
70         TGTextButton* btApply = new TGTextButton(hf, "Apply");
71         
72         btDefaults->Connect("Clicked()", "AliEventServerPreferencesWindow", this, "onRestoreDefaults()");
73         btCancel->Connect("Clicked()", "AliEventServerPreferencesWindow", this, "onCancel()");
74         btApply->Connect("Clicked()", "AliEventServerPreferencesWindow", this, "onApply()");
75         
76         hf->AddFrame(btDefaults, new  TGLayoutHints(kLHintsNormal) );
77         hf->AddFrame(btApply, new  TGLayoutHints(kLHintsRight) );
78         hf->AddFrame(btCancel, new  TGLayoutHints(kLHintsRight) );
79         
80         
81         // Add Tab Widget and Dialog buttons to Main Window
82         AddFrame(fTab, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
83         AddFrame(hf,  new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
84         
85         if(ReadSettings()!=0) Info("AliEventServerPreferencesWindow::AliEventServerPreferencesWindow", "Problems while reading settings from file!\n");
86         
87         SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
88                               kMWMDecorMinimize | kMWMDecorMenu,
89                kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize |
90                               kMWMFuncMinimize,
91                kMWMInputModeless);
92                
93         MapSubwindows();
94   Resize();
95   MapWindow();
96   
97   gClient->WaitFor(this);
98 }
99
100 AliEventServerPreferencesWindow::~AliEventServerPreferencesWindow()
101 {
102         delete fDetectors; 
103         fDetectors=0;
104 }
105
106 /*********************/
107 /* Server Settings Tab  */
108 /*********************/
109 void AliEventServerPreferencesWindow::SetupServerTab(TGCompositeFrame* tab)
110 {
111         TGHorizontalFrame *t2hf = new TGHorizontalFrame(tab, 1, 20);
112         TGLabel* lbServerHost = new TGLabel(t2hf, "Host:");
113         t2hf->AddFrame(lbServerHost, new TGLayoutHints(kLHintsCenterY));
114         
115         fEntryServerHost = new TGTextEntry(t2hf, "tcp://*");
116         t2hf->AddFrame(fEntryServerHost, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
117         
118         TGLabel* lbServerPort = new TGLabel(t2hf, "Port:");
119         t2hf->AddFrame(lbServerPort, new TGLayoutHints(kLHintsCenterY));
120         
121         fEntryServerPort = new TGTextEntry(t2hf, "5024");
122         fEntryServerPort->SetMaxLength(5);
123         t2hf->AddFrame(fEntryServerPort, new TGLayoutHints(kLHintsNormal));
124         
125         tab->AddFrame(t2hf, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
126 }
127         
128   /*******************/
129         /* Reco Settings Tab */
130         /*******************/
131 void AliEventServerPreferencesWindow::SetupRecoTab(TGCompositeFrame* tab)
132 {
133         /* CDB Manager Group Frame */
134         TGGroupFrame* grCDBMan = new TGGroupFrame(tab, "CDB Manager");
135         // Default Storage Frame
136         TGHorizontalFrame *hfCDBDefaultStorage = new TGHorizontalFrame(grCDBMan, 1, 20);
137         TGLabel* lbCDBDefaultStorage = new TGLabel(hfCDBDefaultStorage, "Default Storage:");
138         fEntryCDBDefaultStorage = new TGTextEntry(hfCDBDefaultStorage, "local:///local/cdb");
139         
140         hfCDBDefaultStorage->AddFrame(lbCDBDefaultStorage, new TGLayoutHints(kLHintsCenterY));
141         hfCDBDefaultStorage->AddFrame(fEntryCDBDefaultStorage, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
142         
143         // Specific Storage 1 Frame
144         TGHorizontalFrame *hfCDBSpecStorage1 = new TGHorizontalFrame(grCDBMan, 1, 20);
145         TGLabel* lbCDBSpecStorage1 = new TGLabel(hfCDBSpecStorage1, "Specific Storage:");
146         fEntryCDBSpecStoragePath1 = new TGTextEntry(hfCDBSpecStorage1, "GRP/GRP/Data");
147         fEntryCDBSpecStorageValue1 = new TGTextEntry(hfCDBSpecStorage1, "");
148         
149         hfCDBSpecStorage1->AddFrame(lbCDBSpecStorage1, new TGLayoutHints(kLHintsCenterY));
150         hfCDBSpecStorage1->AddFrame(fEntryCDBSpecStoragePath1, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
151         hfCDBSpecStorage1->AddFrame(fEntryCDBSpecStorageValue1, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
152         
153         // Specific Storage 2 Frame
154         TGHorizontalFrame *hfCDBSpecStorage2 = new TGHorizontalFrame(grCDBMan, 1, 20);
155         TGLabel* lbCDBSpecStorage2 = new TGLabel(hfCDBSpecStorage2, "Specific Storage:");
156         fEntryCDBSpecStoragePath2 = new TGTextEntry(hfCDBSpecStorage2, "GRP/CTP/Config");
157   fEntryCDBSpecStorageValue2 = new TGTextEntry(hfCDBSpecStorage2, "");
158         
159         hfCDBSpecStorage2->AddFrame(lbCDBSpecStorage2, new TGLayoutHints(kLHintsCenterY));
160         hfCDBSpecStorage2->AddFrame(fEntryCDBSpecStoragePath2, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
161         hfCDBSpecStorage2->AddFrame(fEntryCDBSpecStorageValue2, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
162         
163         // Specific Storage 3 Frame
164         TGHorizontalFrame *hfCDBSpecStorage3 = new TGHorizontalFrame(grCDBMan, 1, 20);
165         TGLabel* lbCDBSpecStorage3 = new TGLabel(hfCDBSpecStorage3, "Specific Storage:");
166         fEntryCDBSpecStoragePath3 = new TGTextEntry(hfCDBSpecStorage3, "");
167         fEntryCDBSpecStorageValue3 = new TGTextEntry(hfCDBSpecStorage3, "");
168         
169         hfCDBSpecStorage3->AddFrame(lbCDBSpecStorage3, new TGLayoutHints(kLHintsCenterY));
170         hfCDBSpecStorage3->AddFrame(fEntryCDBSpecStoragePath3, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
171         hfCDBSpecStorage3->AddFrame(fEntryCDBSpecStorageValue3, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
172         
173         grCDBMan->AddFrame(hfCDBDefaultStorage, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
174         grCDBMan->AddFrame(hfCDBSpecStorage1, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
175         grCDBMan->AddFrame(hfCDBSpecStorage2, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
176         grCDBMan->AddFrame(hfCDBSpecStorage3, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
177         
178         tab->AddFrame(grCDBMan, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
179         grCDBMan->Resize();
180         
181         /* Reconstruction Settings Group Frame */
182         TGGroupFrame* grRecoFrame = new TGGroupFrame(tab, "Reconstruction");
183         // SetRunQA
184         TGHorizontalFrame *hfRecoRunQA = new TGHorizontalFrame(grRecoFrame, 1, 20);
185         TGLabel* lbRecoRunQA = new TGLabel(hfRecoRunQA, "Run QA:");
186         fEntryRecoRunQA = new TGTextEntry(hfRecoRunQA, ":");
187         
188         hfRecoRunQA->AddFrame( lbRecoRunQA, new TGLayoutHints(kLHintsCenterY));
189         hfRecoRunQA->AddFrame( fEntryRecoRunQA, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
190         
191         // QARef Default Storage
192         TGHorizontalFrame *hfRecoQARefDefStorage = new TGHorizontalFrame(grRecoFrame, 1, 20);
193         TGLabel* lbRecoQARefDefStorage= new TGLabel(hfRecoQARefDefStorage, "QARef Default Storage:");
194         fEntryRecoQARefDefStorage = new TGTextEntry(hfRecoQARefDefStorage, "local://$ALICE_ROOT/QAref");
195         
196         hfRecoQARefDefStorage->AddFrame( lbRecoQARefDefStorage, new TGLayoutHints(kLHintsCenterY));
197         hfRecoQARefDefStorage->AddFrame( fEntryRecoQARefDefStorage, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
198         
199         // RunGlobalQA
200         fChkRecoRunGlobalQA = new TGCheckButton(grRecoFrame, "Run Global QA");
201         
202         // Plane Efficiency Evalution
203         fChkRecoRunPlaneEff= new TGCheckButton(grRecoFrame, "Plane Efficiency Evaluation");
204         
205         // Write ESD Friend
206         fChkRecoWriteESDf= new TGCheckButton(grRecoFrame, "Write ESD friend");
207         
208         // Write Alignement Data
209         fChkRecoWriteAlignment= new TGCheckButton(grRecoFrame, "Write Alignment Data");
210         
211         // Clean ESD
212         fChkRecoCleanESD= new TGCheckButton(grRecoFrame, "Clean ESD");
213         
214         // Participating Detectors
215         TGGroupFrame* grRecoDetFrame = new TGGroupFrame(grRecoFrame, "Participating Detectors");
216         TGHorizontalFrame *hfRecoDets = new TGHorizontalFrame(grRecoDetFrame, 1, 20);
217         TGTextButton* btRecoCheckAll = new TGTextButton(hfRecoDets, "Check All");
218         TGTextButton* btRecoUnCheckAll = new TGTextButton(hfRecoDets, "Uncheck All");
219         
220         btRecoCheckAll->Connect("Clicked()", "AliEventServerPreferencesWindow", this, "onCheckAllDetectors()");
221         btRecoUnCheckAll->Connect("Clicked()", "AliEventServerPreferencesWindow", this, "onUnCheckAllDetectors()");
222         
223         hfRecoDets->AddFrame( btRecoCheckAll, new TGLayoutHints(kLHintsNormal));
224         hfRecoDets->AddFrame( btRecoUnCheckAll, new TGLayoutHints(kLHintsNormal));
225         
226         grRecoDetFrame->AddFrame(hfRecoDets, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
227         
228         // get detectors names from AliReconstruction
229         const char** detnames= AliReconstruction::GetDetectorNames();
230         TGCompositeFrame* cfDetectors = new TGCompositeFrame(grRecoDetFrame);
231         cfDetectors->SetLayoutManager(new TGMatrixLayout(cfDetectors, 0, 4, 10));
232         
233         fDetectors = new TObjArray;
234         for(int i=0;  i< AliReconstruction::kNDetectors; i++){
235                 TGCheckButton* chkRecoDet = new TGCheckButton(cfDetectors, detnames[i]);
236                 cfDetectors->AddFrame(chkRecoDet, new TGLayoutHints(kLHintsNormal));
237                 fDetectors->Add(chkRecoDet);
238         }
239         
240         grRecoDetFrame->AddFrame(cfDetectors,  new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
241         grRecoDetFrame->Resize();
242         
243         grRecoFrame->AddFrame(hfRecoRunQA, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
244         grRecoFrame->AddFrame(hfRecoQARefDefStorage, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
245         grRecoFrame->AddFrame(fChkRecoRunGlobalQA, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
246         grRecoFrame->AddFrame(fChkRecoRunPlaneEff, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
247         grRecoFrame->AddFrame(fChkRecoWriteESDf, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
248         grRecoFrame->AddFrame(fChkRecoWriteAlignment, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
249         grRecoFrame->AddFrame(fChkRecoCleanESD, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
250         grRecoFrame->AddFrame(grRecoDetFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
251         
252         tab->AddFrame(grRecoFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
253         grRecoFrame->Resize();
254 }
255
256         
257 /***********************/
258 /* Logbook Settings Tab  */
259 /***********************/
260 void AliEventServerPreferencesWindow::SetupLogbookTab(TGCompositeFrame* tab)
261 {
262         // host and port
263         TGCompositeFrame* cfLogbook = new TGCompositeFrame(tab);
264         cfLogbook->SetLayoutManager(new TGMatrixLayout(cfLogbook, 0, 2));
265         
266         TGLabel* lbLogbookHost = new TGLabel(cfLogbook, "Host:");
267         fEntryLogbookHost = new TGTextEntry(cfLogbook, "pcaldbl501");
268         fEntryLogbookHost->Resize(150,0);
269         TGLabel* lbLogbookPort = new TGLabel(cfLogbook, "Port:");
270         fEntryLogbookPort = new TGTextEntry(cfLogbook, "3306");
271         fEntryLogbookPort->SetMaxLength(5);
272         
273         // database name
274         TGLabel* lbLogbookDB = new TGLabel(cfLogbook, "Database:");
275         fEntryLogbookDB = new TGTextEntry(cfLogbook, "logbook");
276         fEntryLogbookDB->Resize(150,0);
277         
278   // username
279         TGLabel* lbLogbookUser = new TGLabel(cfLogbook, "User:");
280         fEntryLogbookUser = new TGTextEntry(cfLogbook, "dqm");
281         fEntryLogbookUser->Resize(150,0);
282                         
283         // password
284         TGLabel* lbLogbookPass = new TGLabel(cfLogbook, "Password:");
285         fEntryLogbookPass = new TGTextEntry(cfLogbook, "dqm123");
286         fEntryLogbookPass->SetEchoMode(TGTextEntry::kPassword);
287         fEntryLogbookPass->Resize(150,0);
288     
289     // data source
290     TGLabel* lbDataSource = new TGLabel(cfLogbook, "Data source:");
291     fEntryDataSource = new TGTextEntry(cfLogbook, "local");
292     fEntryDataSource->Resize(150,0);
293         
294         cfLogbook->AddFrame(lbLogbookHost, new TGLayoutHints(kLHintsCenterY));
295         cfLogbook->AddFrame(fEntryLogbookHost, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
296         cfLogbook->AddFrame(lbLogbookPort, new TGLayoutHints(kLHintsCenterY));
297         cfLogbook->AddFrame(fEntryLogbookPort, new TGLayoutHints(kLHintsNormal));
298         cfLogbook->AddFrame(lbLogbookDB, new TGLayoutHints(kLHintsCenterY));
299         cfLogbook->AddFrame(fEntryLogbookDB, new TGLayoutHints(kLHintsNormal));
300         cfLogbook->AddFrame(lbLogbookUser, new TGLayoutHints(kLHintsCenterY));
301         cfLogbook->AddFrame(fEntryLogbookUser, new TGLayoutHints(kLHintsNormal));
302         cfLogbook->AddFrame(lbLogbookPass, new TGLayoutHints(kLHintsCenterY));
303         cfLogbook->AddFrame(fEntryLogbookPass, new TGLayoutHints(kLHintsNormal));
304     cfLogbook->AddFrame(lbDataSource, new TGLayoutHints(kLHintsCenterY));
305     cfLogbook->AddFrame(fEntryDataSource, new TGLayoutHints(kLHintsNormal));
306         
307         tab->AddFrame(cfLogbook, new TGLayoutHints(kLHintsNormal));
308 }
309
310 void AliEventServerPreferencesWindow::onRestoreDefaults()
311 {
312         int retCode;
313         const char* messageInfo = "Are you sure you want to restore the default settings?\n";
314  
315         new TGMsgBox(gClient->GetRoot(), this, "Restore Default Settings?", messageInfo, kMBIconQuestion, kMBNo|kMBYes, &retCode);
316   
317   if(retCode==kMBNo) return;
318         RestoreDefaults();
319 }
320
321 void AliEventServerPreferencesWindow::onCancel()
322 {
323         SendCloseMessage();
324 }
325
326 void AliEventServerPreferencesWindow::onApply()
327 {
328         if(WriteSettings()==0){// success!
329         const char* messageInfo = "The changes were saved.\n"
330         "Notice: They will take effect when a new run starts or\n"
331         "after the reconstruction is restarted (if it is already running)";
332          
333         new TGMsgBox(gClient->GetRoot(), this, "New Settings Notice", messageInfo, kMBIconExclamation, kMBOk);
334         
335         SendCloseMessage();
336         }
337         else{
338                 const char* messageInfo = "The changes could not be saved!\n"
339         "Check if you have permissions to write to that location.";
340          
341         new TGMsgBox(gClient->GetRoot(), this, "New Settings Notice", messageInfo, kMBIconExclamation, kMBOk);
342         }
343                 
344 }
345
346 void AliEventServerPreferencesWindow::onCheckAllDetectors()
347 {
348         for(int i=0; i<fDetectors->GetEntries(); ++i){
349                 TGCheckButton* bt = (TGCheckButton*)fDetectors->At(i);
350                 bt->SetOn(kTRUE);
351         }
352 }
353
354 void AliEventServerPreferencesWindow::onUnCheckAllDetectors()
355 {
356         for(int i=0; i<fDetectors->GetEntries(); ++i){
357                 TGCheckButton* bt = (TGCheckButton*)fDetectors->At(i);
358                 bt->SetOn(kFALSE);
359         }
360 }
361
362 Int_t AliEventServerPreferencesWindow::ReadSettings()
363 {
364         TEnv settings;
365         int readStatus = settings.ReadFile(AliEventServerUtil::GetPathToServerConf(), kEnvUser);
366         //check if there was an error reading the file
367         if(readStatus!=0) return readStatus;
368         
369         // server settings
370         fEntryServerHost->SetText( settings.GetValue("server.host", DEFAULT_SERVER_HOST), kFALSE);
371         fEntryServerPort->SetText(  Form("%d", settings.GetValue("server.port", DEFAULT_SERVER_PORT)), kFALSE);
372         
373         // reco settings
374         fEntryCDBDefaultStorage->SetText( settings.GetValue( "cdb.defaultStorage", DEFAULT_CDB_STORAGE), kFALSE);
375         fEntryCDBSpecStoragePath1->SetText( settings.GetValue( "cdb.specificStoragePath1", DEFAULT_CDB_SPEC_STORAGE_PATH1), kFALSE);
376         fEntryCDBSpecStorageValue1->SetText( settings.GetValue( "cdb.specificStorageValue1", DEFAULT_CDB_SPEC_STORAGE_VALUE1), kFALSE);
377         fEntryCDBSpecStoragePath2->SetText( settings.GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2), kFALSE);
378         fEntryCDBSpecStorageValue2->SetText(settings.GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2), kFALSE);
379         fEntryCDBSpecStoragePath3->SetText( settings.GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3), kFALSE);
380         fEntryCDBSpecStorageValue3->SetText(settings.GetValue( "cdb.specificStorageValue3",  DEFAULT_CDB_SPEC_STORAGE_VALUE3), kFALSE);
381         fEntryRecoRunQA->SetText( settings.GetValue( "qa.runDetectors", DEFAULT_QA_RUN), kFALSE );
382         fEntryRecoQARefDefStorage->SetText(settings.GetValue( "qa.defaultStorage",DEFAULT_QAREF_STORAGE), kFALSE);
383         fChkRecoRunGlobalQA->SetOn(settings.GetValue( "qa.runGlobal", DEFAULT_QA_RUN_GLOBAL), kFALSE);
384         fChkRecoRunPlaneEff->SetOn(settings.GetValue( "reco.runPlaneEff", DEFAULT_RECO_RUN_PLANE_EFF), kFALSE);
385         fChkRecoWriteESDf->SetOn(settings.GetValue( "reco.writeESDfriend", DEFAULT_RECO_WRITE_ESDF), kFALSE);
386         fChkRecoWriteAlignment->SetOn(settings.GetValue( "reco.writeAlignment",DEFAULT_RECO_WRITE_ALIGN), kFALSE);
387         fChkRecoCleanESD->SetOn(settings.GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD), kFALSE);
388         
389         // parse reco run detectors from string
390         TString strRunDetectors(settings.GetValue( "reco.detectors", DEFAULT_RECO_DETECTORS) );
391         TObjArray* arrRecoDets = strRunDetectors.Tokenize(" ");
392         
393         for(int i=0; i<arrRecoDets->GetEntries(); ++i){
394                 TObjString* objStr = (TObjString*)arrRecoDets->At(i);
395                 if(objStr->GetString().BeginsWith("-")){ // detector is disabled
396                         for(int j=0; j<fDetectors->GetEntries();++j){
397                                 TGCheckButton* bt = (TGCheckButton*)fDetectors->At(j);
398                                 TString btTitle(Form("-%s",bt->GetTitle()));
399                                 if(btTitle.CompareTo(objStr->GetString())==0) {// match
400                                         bt->SetOn(kFALSE); // uncheck detector button
401                                         break;
402                                 }
403                         }
404                 }
405                 else if(objStr->GetString().CompareTo("ALL")==0){
406                         onCheckAllDetectors();
407                 }
408                 else{ // detector is enabled
409                         for(int j=0; j<fDetectors->GetEntries();++j){
410                                 TGCheckButton* bt = (TGCheckButton*)fDetectors->At(j);
411                                 TString btTitle(bt->GetTitle());
412                                 if(btTitle.CompareTo(objStr->GetString())==0) {// match
413                                         bt->SetOn(kTRUE); // check detector
414                                         break;
415                                 }
416                         }
417                 }
418         }
419         
420         // logbook settings
421         fEntryLogbookHost->SetText( settings.GetValue("logbook.host", DEFAULT_LOGBOOK_HOST), kFALSE);
422         fEntryLogbookPort->SetText( Form("%d", settings.GetValue("logbook.port", DEFAULT_LOGBOOK_PORT)), kFALSE);
423         fEntryLogbookDB->SetText( settings.GetValue("logbook.db", DEFAULT_LOGBOOK_DB), kFALSE);
424         fEntryLogbookUser->SetText( settings.GetValue("logbook.user", DEFAULT_LOGBOOK_USER), kFALSE);
425         fEntryLogbookPass->SetText( settings.GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS), kFALSE);
426     fEntryDataSource->SetText( settings.GetValue("data.source", DEFAULT_LOGBOOK_PASS), kFALSE);
427
428         return readStatus;
429 }
430
431 // write settings to a rootrc file
432 // returns 0 in case of success, -1 in case of error
433 Int_t AliEventServerPreferencesWindow::WriteSettings()
434 {
435         TEnv settings;
436         // server settings
437         settings.SetValue("server.host", fEntryServerHost->GetText());
438         settings.SetValue("server.port", TString(fEntryServerPort->GetText()).Atoi());
439         
440         // reco settings
441         settings.SetValue( "cdb.defaultStorage", fEntryCDBDefaultStorage->GetText());
442         settings.SetValue( "cdb.specificStoragePath1", fEntryCDBSpecStoragePath1->GetText());
443         settings.SetValue( "cdb.specificStorageValue1", fEntryCDBSpecStorageValue1->GetText());
444         settings.SetValue( "cdb.specificStoragePath2", fEntryCDBSpecStoragePath2->GetText());
445         settings.SetValue( "cdb.specificStorageValue2", fEntryCDBSpecStorageValue2->GetText());
446         settings.SetValue( "cdb.specificStoragePath3", fEntryCDBSpecStoragePath3->GetText());
447         settings.SetValue( "cdb.specificStorageValue3", fEntryCDBSpecStorageValue3->GetText());
448         settings.SetValue( "qa.runDetectors", fEntryRecoRunQA->GetText());
449         settings.SetValue( "qa.defaultStorage", fEntryRecoQARefDefStorage->GetText());
450         settings.SetValue( "qa.runGlobal", fChkRecoRunGlobalQA->IsOn());
451         settings.SetValue( "reco.runPlaneEff", fChkRecoRunPlaneEff->IsOn());
452         settings.SetValue( "reco.writeESDfriend", fChkRecoWriteESDf->IsOn());
453         settings.SetValue( "reco.writeAlignment", fChkRecoWriteAlignment->IsOn());
454         settings.SetValue( "reco.cleanESD", fChkRecoCleanESD->IsOn());
455         
456         // will write reco run detectors as a single string
457         TObjArray checkedDetectors;
458         TObjArray uncheckedDetectors;
459         TString strRunDetectors;
460         
461         for(int i=0; i<fDetectors->GetEntries(); ++i){
462                 TGCheckButton* bt = (TGCheckButton*)fDetectors->At(i);
463                 if(bt->IsOn()){
464                         checkedDetectors.Add(bt);
465                 }
466                 else{
467                         uncheckedDetectors.Add(bt);
468                 }
469         }
470         
471         int nChkDets = checkedDetectors.GetEntries();
472         int nUnChkDets = uncheckedDetectors.GetEntries();
473         if(nChkDets>=nUnChkDets){
474                 strRunDetectors="ALL ";
475                 for(int i=0; i<nUnChkDets; ++i ){
476                         strRunDetectors.Append( Form(" -%s",uncheckedDetectors.At(i)->GetTitle()) );
477                 }
478         }
479         else {
480                 for(int i=0; i<nChkDets; ++i ){
481                         strRunDetectors.Append( Form(" %s",checkedDetectors.At(i)->GetTitle()) );
482                 }
483         }
484         
485         settings.SetValue( "reco.detectors", strRunDetectors.Data());
486         
487         // logbook settings
488         settings.SetValue("logbook.host", fEntryLogbookHost->GetText());
489         settings.SetValue("logbook.port", TString(fEntryLogbookPort->GetText()).Atoi());
490         settings.SetValue("logbook.db", fEntryLogbookDB->GetText());
491         settings.SetValue("logbook.user", fEntryLogbookUser->GetText());
492         settings.SetValue("logbook.pass", fEntryLogbookPass->GetText());
493     settings.SetValue("data.source", fEntryDataSource->GetText());
494         
495         printf("Writting settings to file: %s\n", Form("%s/MONITOR/%s", gSystem->Getenv("ALICE_ROOT"), ALIEVENTSERVER_CONF) );
496         
497         return settings.WriteFile(AliEventServerUtil::GetPathToServerConf());
498 }
499
500 void AliEventServerPreferencesWindow::RestoreDefaults()
501 {
502         // server settings
503         fEntryServerHost->SetText( DEFAULT_SERVER_HOST, kFALSE);
504         fEntryServerPort->SetText(  Form("%d", DEFAULT_SERVER_PORT), kFALSE);
505         
506         // reco settings
507         fEntryCDBDefaultStorage->SetText( DEFAULT_CDB_STORAGE, kFALSE);
508         fEntryCDBSpecStoragePath1->SetText( DEFAULT_CDB_SPEC_STORAGE_PATH1, kFALSE);
509         fEntryCDBSpecStorageValue1->SetText( DEFAULT_CDB_SPEC_STORAGE_VALUE1, kFALSE);
510         fEntryCDBSpecStoragePath2->SetText( DEFAULT_CDB_SPEC_STORAGE_PATH2, kFALSE);
511         fEntryCDBSpecStorageValue2->SetText(DEFAULT_CDB_SPEC_STORAGE_VALUE2, kFALSE);
512         fEntryCDBSpecStoragePath3->SetText( DEFAULT_CDB_SPEC_STORAGE_PATH3, kFALSE);
513         fEntryCDBSpecStorageValue3->SetText( DEFAULT_CDB_SPEC_STORAGE_VALUE3, kFALSE);
514         fEntryRecoRunQA->SetText( DEFAULT_QA_RUN, kFALSE );
515         fEntryRecoQARefDefStorage->SetText(DEFAULT_QAREF_STORAGE, kFALSE);
516         fChkRecoRunGlobalQA->SetOn(DEFAULT_QA_RUN_GLOBAL, kFALSE);
517         fChkRecoRunPlaneEff->SetOn(DEFAULT_RECO_RUN_PLANE_EFF, kFALSE);
518         fChkRecoWriteESDf->SetOn(DEFAULT_RECO_WRITE_ESDF, kFALSE);
519         fChkRecoWriteAlignment->SetOn(DEFAULT_RECO_WRITE_ALIGN, kFALSE);
520         fChkRecoCleanESD->SetOn(DEFAULT_RECO_CLEAN_ESD, kFALSE);
521         
522         // parse reco run detectors from string
523         TString strRunDetectors( DEFAULT_RECO_DETECTORS );
524         TObjArray* arrRecoDets = strRunDetectors.Tokenize(" ");
525         
526         for(int i=0; i<arrRecoDets->GetEntries(); ++i){
527                 TObjString* objStr = (TObjString*)arrRecoDets->At(i);
528                 if(objStr->GetString().BeginsWith("-")){ // detector is disabled
529                         for(int j=0; j<fDetectors->GetEntries();++j){
530                                 TGCheckButton* bt = (TGCheckButton*)fDetectors->At(j);
531                                 TString btTitle(Form("-%s",bt->GetTitle()));
532                                 if(btTitle.CompareTo(objStr->GetString())==0) {// match
533                                         bt->SetOn(kFALSE); // uncheck detector button
534                                         break;
535                                 }
536                         }
537                 }
538                 else if(objStr->GetString().CompareTo("ALL")==0){
539                         onCheckAllDetectors();
540                 }
541                 else{ // detector is enabled
542                         for(int j=0; j<fDetectors->GetEntries();++j){
543                                 TGCheckButton* bt = (TGCheckButton*)fDetectors->At(j);
544                                 TString btTitle(bt->GetTitle());
545                                 if(btTitle.CompareTo(objStr->GetString())==0) {// match
546                                         bt->SetOn(kTRUE); // check detector
547                                         break;
548                                 }
549                         }
550                 }
551         }
552         
553         // logbook settings
554         fEntryLogbookHost->SetText( DEFAULT_LOGBOOK_HOST, kFALSE);
555         fEntryLogbookPort->SetText( Form("%d", DEFAULT_LOGBOOK_PORT), kFALSE);
556         fEntryLogbookDB->SetText( DEFAULT_LOGBOOK_DB, kFALSE);
557         fEntryLogbookUser->SetText( DEFAULT_LOGBOOK_USER, kFALSE);
558         fEntryLogbookPass->SetText( DEFAULT_LOGBOOK_PASS, kFALSE);
559     fEntryDataSource->SetText( DEFAULT_DATA_SOURCE, kFALSE);
560 }