Fixing file after rebasing master
[u/mrichter/AliRoot.git] / MONITOR / alistoragemanager / AliStorageAdministratorPanelMarkEvent.cxx
1 #include "AliStorageAdministratorPanelMarkEvent.h"
2 #include "AliStorageTypes.h"
3
4 #include <iostream>
5
6 #include <TGFrame.h>
7 #include <TGButton.h>
8
9 using namespace std;
10
11 AliStorageAdministratorPanelMarkEvent *AliStorageAdministratorPanelMarkEvent::fInstance=0;
12
13 ClassImp(AliStorageAdministratorPanelMarkEvent);
14
15 #define WINDOWS_WIDTH 200
16 #define WINDOWS_HEIGHT 200
17
18 enum BUTTON{
19         BUTTON_CLOSE=1,
20         BUTTON_MARK     
21 };
22
23 enum TEXTENTRY{
24         TEXTENTRY_RUN=1,
25         TEXTENTRY_EVENT
26 };
27
28 AliStorageAdministratorPanelMarkEvent::AliStorageAdministratorPanelMarkEvent() :
29         TGMainFrame(gClient->GetRoot(), 400, 400),
30         fStatusLabel(0),
31         fRunNumberEntry(0),
32         fEventNumberEntry(0),
33         fServerSocket(SERVER_COMMUNICATION_REQ),
34         fEventManager(0)
35 {
36         fEventManager = AliStorageEventManager::GetEventManagerInstance();
37         fEventManager->CreateSocket(fServerSocket);
38         InitWindow();
39 }
40
41 AliStorageAdministratorPanelMarkEvent::~AliStorageAdministratorPanelMarkEvent()
42 {
43         cout<<"ADMIN PANEL -- Mark Window descructor called";
44         cout<<" --- OK"<<endl;
45 }
46
47 AliStorageAdministratorPanelMarkEvent* AliStorageAdministratorPanelMarkEvent::GetInstance()
48 {
49         if(!fInstance){fInstance = new AliStorageAdministratorPanelMarkEvent();}
50         return fInstance;
51 }
52
53 void AliStorageAdministratorPanelMarkEvent::InitWindow()
54 {
55         SetCleanup(kDeepCleanup);
56         
57         AddFrame(new TGLabel(this,"Run number:"),new TGLayoutHints(kLHintsLeft));
58
59         fRunNumberEntry = new TGNumberEntry(this,
60                                             0,
61                                             6,
62                                             TEXTENTRY_RUN,
63                                             TGNumberFormat::kNESInteger,
64                                             TGNumberFormat::kNEAPositive,
65                                             TGNumberFormat::kNELNoLimits);
66         AddFrame(fRunNumberEntry,new TGLayoutHints(kLHintsLeft));
67
68         AddFrame(new TGLabel(this,"Event number:"),new TGLayoutHints(kLHintsLeft));
69
70         fEventNumberEntry = new TGNumberEntry(this,
71                                               0,
72                                               6,
73                                               TEXTENTRY_EVENT,
74                                               TGNumberFormat::kNESInteger,
75                                               TGNumberFormat::kNEAPositive,
76                                               TGNumberFormat::kNELNoLimits);
77         AddFrame(fEventNumberEntry,new TGLayoutHints(kLHintsLeft));     
78
79         fStatusLabel = new TGLabel(this,"");
80         AddFrame(fStatusLabel,new TGLayoutHints(kLHintsExpandX | kLHintsLeft));
81
82         AddFrame(new TGTextButton(this,"Close",BUTTON_CLOSE),
83                  new TGLayoutHints(kLHintsLeft));
84
85         AddFrame(new TGTextButton(this,"Mark event",BUTTON_MARK),
86                  new TGLayoutHints(kLHintsRight));
87
88         
89         SetWindowName("Mark Event");
90         MapSubwindows();
91         Resize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
92         MapWindow();
93 }
94
95
96
97
98 void AliStorageAdministratorPanelMarkEvent::onMarkButton()
99 {
100         int runNumber;
101         int eventNumber;
102
103         //get run and event number from TGNumberEntries
104         runNumber=fRunNumberEntry->GetIntNumber();
105         eventNumber=fEventNumberEntry->GetIntNumber();
106         
107         struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
108         struct eventStruct mark;
109         mark.runNumber = runNumber;
110         mark.eventNumber = eventNumber;
111         requestMessage->messageType = REQUEST_MARK_EVENT;
112         requestMessage->event = mark;
113
114         fEventManager->Send(requestMessage,fServerSocket);
115         bool response = fEventManager->GetBool(fServerSocket);
116         
117         if(response)
118         {
119                 fStatusLabel->SetText("Event marked");
120                 cout<<"ADMIN PANEL -- Event marked succesfully"<<endl;
121         }
122         else
123         {
124                 fStatusLabel->SetText("Couldn't mark this event");
125                 cout<<"ADMIN PANEL -- Could not matk event"<<endl;
126         }
127 }
128
129 void AliStorageAdministratorPanelMarkEvent::onCloseButton(){onExit();}
130 void AliStorageAdministratorPanelMarkEvent::CloseWindow(){onExit();}
131
132 void AliStorageAdministratorPanelMarkEvent::onExit()
133 {
134         cout<<"Quiting mark event";
135         if(fInstance){delete fInstance;fInstance=0;}
136         cout<<" -- OK"<<endl;
137 }
138
139 Bool_t AliStorageAdministratorPanelMarkEvent::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
140 {
141         switch (GET_MSG(msg))
142         {
143         case kC_COMMAND:
144                 switch (GET_SUBMSG(msg))
145                 {
146                 case kCM_BUTTON:
147                         switch(parm1)
148                         {
149                         case BUTTON_CLOSE:onCloseButton();break;
150                         case BUTTON_MARK:onMarkButton();break;
151                         default:break;
152                         }
153                         break;
154                 default:break;
155                 }
156                 break;
157         default:break;
158         }
159
160         return false;
161 }