e8034e449c004c192b95101009005e269c31c6ff
[u/mrichter/AliRoot.git] / MONITOR / alistoragemanager / AliStorageAdministratorPanelListEvents.cxx
1 #include "AliStorageAdministratorPanelListEvents.h"
2
3 #include <iostream>
4 #include <sstream>
5 #include <vector>
6
7 #include <TG3DLine.h>
8 #include <TGButton.h>
9 #include <TGFrame.h>
10
11 using namespace std;
12
13 AliStorageAdministratorPanelListEvents *AliStorageAdministratorPanelListEvents::fInstance=0;
14
15 ClassImp(AliStorageAdministratorPanelListEvents);
16
17 #define WINDOWS_WIDTH 400
18 #define WINDOWS_HEIGHT 500
19
20 enum BUTTON{
21         BUTTON_CLOSE=1,
22         BUTTON_GET_LIST,
23         BUTTON_CHECK_PP,
24         BUTTON_CHECK_PBPB,
25         BUTTON_CHECK_TEMP,
26         BUTTON_CHECK_PERM,
27         BUTTON_MARK_EVENT,
28     BUTTON_LOAD_EVENT
29 };
30
31 enum TEXTENTRY{
32         TEXTENTRY_RUN_MIN=1,
33         TEXTENTRY_RUN_MAX,
34         TEXTENTRY_EVENT_MIN,
35         TEXTENTRY_EVENT_MAX,
36         TEXTENTRY_MULTIPLICITY_MIN,
37         TEXTENTRY_MULTIPLICITY_MAX
38 };
39
40 AliStorageAdministratorPanelListEvents::AliStorageAdministratorPanelListEvents() :
41         TGMainFrame(gClient->GetRoot(),400,400),
42         fStatusLabel(0),
43         fRunNumberMinEntry(0),
44         fRunNumberMaxEntry(0),
45         fEventNumberMinEntry(0),
46         fEventNumberMaxEntry(0),
47         fMultiplicityMinEntry(0),
48         fMultiplicityMaxEntry(0),
49         fProtonProtonCheckButton(0),
50         fLeadLeadCheckButton(0),
51         fTempCheckButton(0),
52         fPermCheckButton(0),
53         fEventsList(0),
54         fEventsListVector(0),
55         fServerSocket(SERVER_COMMUNICATION_REQ),
56         fEventManager(0)
57 {
58         fEventManager = AliStorageEventManager::GetEventManagerInstance();
59         fEventManager->CreateSocket(fServerSocket);
60         InitWindow();
61 }
62
63 AliStorageAdministratorPanelListEvents::~AliStorageAdministratorPanelListEvents()
64 {
65         cout<<"ADMIN PANEL -- List events descructor called";
66         cout<<" --- OK"<<endl;
67 }
68
69 AliStorageAdministratorPanelListEvents* AliStorageAdministratorPanelListEvents::GetInstance()
70 {
71         if(!fInstance){fInstance = new AliStorageAdministratorPanelListEvents();}
72         return fInstance;
73 }
74
75
76 void AliStorageAdministratorPanelListEvents::SelectedEvent()
77 {
78     Emit("SelectedEvent()");
79 }
80
81 void AliStorageAdministratorPanelListEvents::InitWindow()
82 {
83         SetCleanup(kDeepCleanup);
84         
85         //min run number
86         AddFrame(new TGLabel(this,"Minimum run number:"),new TGLayoutHints(kLHintsLeft));
87
88         fRunNumberMinEntry = new TGNumberEntry(this,
89                                             0,
90                                             6,
91                                             TEXTENTRY_RUN_MIN,
92                                             TGNumberFormat::kNESInteger,
93                                             TGNumberFormat::kNEAPositive,
94                                             TGNumberFormat::kNELNoLimits);
95         AddFrame(fRunNumberMinEntry,new TGLayoutHints(kLHintsLeft));
96
97         //max run number
98         AddFrame(new TGLabel(this,"Maximum run number:"),new TGLayoutHints(kLHintsLeft));
99
100         fRunNumberMaxEntry = new TGNumberEntry(this,
101                                             999999,
102                                             6,
103                                             TEXTENTRY_RUN_MAX,
104                                             TGNumberFormat::kNESInteger,
105                                             TGNumberFormat::kNEAPositive,
106                                             TGNumberFormat::kNELNoLimits);
107         AddFrame(fRunNumberMaxEntry,new TGLayoutHints(kLHintsLeft));
108
109         //min event number
110         AddFrame(new TGLabel(this,"Minimum event number:"),new TGLayoutHints(kLHintsLeft));
111
112         fEventNumberMinEntry = new TGNumberEntry(this,
113                                               0,
114                                               6,
115                                               TEXTENTRY_EVENT_MIN,
116                                               TGNumberFormat::kNESInteger,
117                                               TGNumberFormat::kNEAPositive,
118                                               TGNumberFormat::kNELNoLimits);
119         AddFrame(fEventNumberMinEntry,new TGLayoutHints(kLHintsLeft));  
120
121         //max event number
122         AddFrame(new TGLabel(this,"Maximum event number:"),new TGLayoutHints(kLHintsLeft));
123
124         fEventNumberMaxEntry = new TGNumberEntry(this,
125                                               99999,
126                                               6,
127                                               TEXTENTRY_EVENT_MAX,
128                                               TGNumberFormat::kNESInteger,
129                                               TGNumberFormat::kNEAPositive,
130                                               TGNumberFormat::kNELNoLimits);
131         AddFrame(fEventNumberMaxEntry,new TGLayoutHints(kLHintsLeft));  
132
133         //min multiplicity
134         AddFrame(new TGLabel(this,"Minimum multiplicity:"),new TGLayoutHints(kLHintsLeft));
135
136         fMultiplicityMinEntry = new TGNumberEntry(this,
137                                               0,
138                                               6,
139                                               TEXTENTRY_MULTIPLICITY_MIN,
140                                               TGNumberFormat::kNESInteger,
141                                               TGNumberFormat::kNEAPositive,
142                                               TGNumberFormat::kNELNoLimits);
143         AddFrame(fMultiplicityMinEntry,new TGLayoutHints(kLHintsLeft)); 
144
145         //max multiplicity
146         AddFrame(new TGLabel(this,"Maximum multiplicity:"),new TGLayoutHints(kLHintsLeft));
147
148         fMultiplicityMaxEntry = new TGNumberEntry(this,
149                                               9999,
150                                               6,
151                                               TEXTENTRY_MULTIPLICITY_MAX,
152                                               TGNumberFormat::kNESInteger,
153                                               TGNumberFormat::kNEAPositive,
154                                               TGNumberFormat::kNELNoLimits);
155         AddFrame(fMultiplicityMaxEntry,new TGLayoutHints(kLHintsLeft)); 
156
157         //p-p check button
158         AddFrame(new TGLabel(this,"System:"),new TGLayoutHints(kLHintsLeft));
159         fProtonProtonCheckButton = new TGCheckButton(this,"p-p",BUTTON_CHECK_PP);
160         fProtonProtonCheckButton->SetOn();
161         AddFrame(fProtonProtonCheckButton,new TGLayoutHints(kLHintsLeft));
162
163         //Pb-Pb check button
164         fLeadLeadCheckButton = new TGCheckButton(this,"Pb-Pb",BUTTON_CHECK_PBPB);
165         fLeadLeadCheckButton->SetOn();
166         AddFrame(fLeadLeadCheckButton,new TGLayoutHints(kLHintsLeft));
167
168         //temp check button
169         AddFrame(new TGLabel(this,"Storage type:"),new TGLayoutHints(kLHintsLeft));
170         fTempCheckButton = new TGCheckButton(this,"Temporary",BUTTON_CHECK_TEMP);
171         fTempCheckButton->SetOn();
172         AddFrame(fTempCheckButton,new TGLayoutHints(kLHintsLeft));
173
174         //perm check button
175         fPermCheckButton = new TGCheckButton(this,"Permanent",BUTTON_CHECK_PERM);
176         fPermCheckButton->SetOn();
177         AddFrame(fPermCheckButton,new TGLayoutHints(kLHintsLeft));
178         
179         // status label
180         fStatusLabel = new TGLabel(this,"");
181         AddFrame(fStatusLabel,new TGLayoutHints(kLHintsExpandX | kLHintsLeft));
182
183         //buttons
184         AddFrame(new TGTextButton(this,"Close",BUTTON_CLOSE),
185                  new TGLayoutHints(kLHintsLeft));
186
187         AddFrame(new TGTextButton(this,"Get event's list",BUTTON_GET_LIST),
188                  new TGLayoutHints(kLHintsRight));
189
190         AddFrame(new TGTextButton(this,"Mark selected event",BUTTON_MARK_EVENT),
191                  new TGLayoutHints(kLHintsRight));
192
193     AddFrame(new TGTextButton(this,"Load event",BUTTON_LOAD_EVENT),
194              new TGLayoutHints(kLHintsRight));
195     
196
197         //event's list
198         fEventsList = new TGListBox(this,0);
199         fEventsList->AddEntry(new TGString("Run   Event   System   Mult   Marked"),0);
200         AddFrame(fEventsList,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
201         
202         SetWindowName("List Events");
203         MapSubwindows();
204         Resize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
205         MapWindow();
206 }
207
208
209
210
211 void AliStorageAdministratorPanelListEvents::onGetListButton()
212 {
213 //prepare and send request message
214         struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
215         struct listRequestStruct list; 
216
217         //get listing parameters from somwhere
218         list.runNumber[0]=fRunNumberMinEntry->GetIntNumber();
219         list.runNumber[1]=fRunNumberMaxEntry->GetIntNumber();
220         list.eventNumber[0]=fEventNumberMinEntry->GetIntNumber();
221         list.eventNumber[1]=fEventNumberMaxEntry->GetIntNumber();
222         if(fTempCheckButton->GetState()==1)
223         {
224                 list.marked[0]=0;
225         }
226         else
227         {
228                 list.marked[0]=-1;
229         }
230         if(fPermCheckButton->GetState()==1)
231         {
232                 list.marked[1]=1;
233         }
234         else
235         {
236                 list.marked[1]=-1;
237         }
238         list.multiplicity[0]=fMultiplicityMinEntry->GetIntNumber();
239         list.multiplicity[1]=fMultiplicityMaxEntry->GetIntNumber();
240         if(fProtonProtonCheckButton->GetState()==1)
241         {
242                 strcpy(list.system[0],"p-p");
243         }
244         else
245         {
246                 strcpy(list.system[0],"");
247         }
248         if(fLeadLeadCheckButton->GetState()==1)
249         {
250                 strcpy(list.system[1],"Pb-Pb");
251         }
252         else
253         {
254                 strcpy(list.system[1],"");
255         }
256         
257         requestMessage->messageType = REQUEST_LIST_EVENTS;
258         requestMessage->list = list;
259
260         fEventManager->Send(requestMessage,fServerSocket);
261
262         fEventsList->RemoveAll();
263         fEventsList->AddEntry(new TGString("Run   Event   System   Mult   Marked"),0);
264         
265         vector<serverListStruct> receivedList = fEventManager->GetServerListVector(fServerSocket);
266         
267         cout<<"PANEL:"<<receivedList[0].runNumber<<endl;        
268         cout<<"VECTOR SIZE:"<<receivedList.size()<<endl;
269         
270 //do something with list of maching events
271         cout<<"Received list of perm events"<<endl;
272
273         for(unsigned int i=0;i<receivedList.size();i++)
274         {
275                 fEventsList->InsertEntry(Form("%d   %d   %s   %d   %d   ",
276                                               receivedList[i].runNumber,
277                                               receivedList[i].eventNumber,
278                                               receivedList[i].system,
279                                               receivedList[i].multiplicity,
280                                               receivedList[i].marked),i+1,i);
281
282                 cout<<receivedList[i].runNumber<<receivedList[i].eventNumber<<endl;
283         
284         }
285
286         fEventsListVector = receivedList;
287         
288         gClient->HandleInput();
289         gClient->NeedRedraw(fEventsList, kTRUE);
290         gClient->HandleInput();
291         MapSubwindows();
292         MapWindow();
293         Layout();
294         delete requestMessage;
295 }
296
297
298 void AliStorageAdministratorPanelListEvents::onMarkButton()
299 {
300         int runNumber;
301         int eventNumber;
302
303         //get run and event number from selected row
304         int selectedEventNumber = fEventsList->GetSelected()-1;
305
306         cout<<"SELECTED:"<<selectedEventNumber<<endl;
307         
308         if(selectedEventNumber<0)return;
309         
310         runNumber=fEventsListVector[selectedEventNumber].runNumber;
311         eventNumber=fEventsListVector[selectedEventNumber].eventNumber;
312         
313         struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
314         struct eventStruct mark;
315         mark.runNumber = runNumber;
316         mark.eventNumber = eventNumber;
317         requestMessage->messageType = REQUEST_MARK_EVENT;
318         requestMessage->event = mark;
319
320         fEventManager->Send(requestMessage,fServerSocket);
321
322         bool response = fEventManager->GetBool(fServerSocket);
323                 
324         if(response)
325         {
326                 fStatusLabel->SetText("Event marked");
327                 cout<<"ADMIN PANEL -- Event marked succesfully"<<endl;
328         }
329         else
330         {
331                 fStatusLabel->SetText("Couldn't mark this event");
332                 cout<<"ADMIN PANEL -- Could not matk event"<<endl;
333         }
334 }
335
336 void AliStorageAdministratorPanelListEvents::onLoadButton()
337 {
338     int selectedEventNumber = fEventsList->GetSelected()-1;
339     int runNumber=fEventsListVector[selectedEventNumber].runNumber;
340     int eventNumber=fEventsListVector[selectedEventNumber].eventNumber;
341     
342     
343     struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
344     struct eventStruct eventToLoad;
345     eventToLoad.runNumber = runNumber;
346     eventToLoad.eventNumber = eventNumber;
347     requestMessage->messageType = REQUEST_GET_EVENT;
348     requestMessage->event = eventToLoad;
349     
350     fEventManager->Send(requestMessage,fServerSocket);
351     AliESDEvent *resultEvent = fEventManager->GetEvent(fServerSocket);
352     
353     if(resultEvent)
354     {
355         cout<<"ADMIN -- received event"<<endl;
356         fCurrentEvent = resultEvent;
357     }
358     else
359     {
360         cout<<"ADMIN -- received no event"<<endl;
361     }
362
363     SelectedEvent();
364 }
365
366 void AliStorageAdministratorPanelListEvents::onCloseButton(){onExit();}
367 void AliStorageAdministratorPanelListEvents::CloseWindow(){onExit();}
368
369 void AliStorageAdministratorPanelListEvents::onExit()
370 {
371         cout<<"Quiting list events";
372         if(fInstance){delete fInstance;fInstance=0;}
373         cout<<" -- OK"<<endl;
374 }
375
376 Bool_t AliStorageAdministratorPanelListEvents::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
377 {
378         switch (GET_MSG(msg))
379         {
380         case kC_COMMAND:
381                 switch (GET_SUBMSG(msg))
382                 {
383                 case kCM_BUTTON:
384                         switch(parm1)
385                         {
386                         case BUTTON_CLOSE:onCloseButton();break;
387                         case BUTTON_GET_LIST:onGetListButton();break;
388                         case BUTTON_MARK_EVENT:onMarkButton();break;
389             case BUTTON_LOAD_EVENT:onLoadButton();break;
390                         default:break;
391                         }
392                         break;
393                 default:break;
394                 }
395                 break;
396         default:break;
397         }
398
399         return false;
400 }