Merging STORAGE-dev to master
[u/mrichter/AliRoot.git] / MONITOR / alistoragemanager / AliStorageAdministratorPanelListEvents.cxx
@@ -8,10 +8,7 @@
 #include <TGButton.h>
 #include <TGFrame.h>
 
-#include "zmq.hpp"
-
 using namespace std;
-using namespace zmq;
 
 AliStorageAdministratorPanelListEvents *AliStorageAdministratorPanelListEvents::fInstance=0;
 
@@ -27,7 +24,8 @@ enum BUTTON{
        BUTTON_CHECK_PBPB,
        BUTTON_CHECK_TEMP,
        BUTTON_CHECK_PERM,
-       BUTTON_MARK_EVENT
+       BUTTON_MARK_EVENT,
+    BUTTON_LOAD_EVENT
 };
 
 enum TEXTENTRY{
@@ -54,17 +52,17 @@ AliStorageAdministratorPanelListEvents::AliStorageAdministratorPanelListEvents()
        fPermCheckButton(0),
        fEventsList(0),
        fEventsListVector(0),
-       fServerSocket(0),
+       fServerSocket(SERVER_COMMUNICATION_REQ),
        fEventManager(0)
 {
-       fEventManager = new AliStorageEventManager();
+       fEventManager = AliStorageEventManager::GetEventManagerInstance();
+       fEventManager->CreateSocket(fServerSocket);
        InitWindow();
 }
 
 AliStorageAdministratorPanelListEvents::~AliStorageAdministratorPanelListEvents()
 {
        cout<<"ADMIN PANEL -- List events descructor called";
-//     DestroyWindow();
        cout<<" --- OK"<<endl;
 }
 
@@ -74,9 +72,10 @@ AliStorageAdministratorPanelListEvents* AliStorageAdministratorPanelListEvents::
        return fInstance;
 }
 
-void AliStorageAdministratorPanelListEvents::SetSocket(socket_t *socket)
+
+void AliStorageAdministratorPanelListEvents::SelectedEvent()
 {
-       fServerSocket = socket;
+    Emit("SelectedEvent()");
 }
 
 void AliStorageAdministratorPanelListEvents::InitWindow()
@@ -191,6 +190,9 @@ void AliStorageAdministratorPanelListEvents::InitWindow()
        AddFrame(new TGTextButton(this,"Mark selected event",BUTTON_MARK_EVENT),
                 new TGLayoutHints(kLHintsRight));
 
+    AddFrame(new TGTextButton(this,"Load event",BUTTON_LOAD_EVENT),
+             new TGLayoutHints(kLHintsRight));
+    
 
        //event's list
        fEventsList = new TGListBox(this,0);
@@ -316,12 +318,9 @@ void AliStorageAdministratorPanelListEvents::onMarkButton()
 
        fEventManager->Send(requestMessage,fServerSocket);
 
-       message_t *response = new message_t();
-       fServerSocket->recv(response);
-       char *result = (char*)response->data();
-       //if(response)delete response;
-       
-       if(!strcmp("true",result))
+       bool response = fEventManager->GetBool(fServerSocket);
+               
+       if(response)
        {
                fStatusLabel->SetText("Event marked");
                cout<<"ADMIN PANEL -- Event marked succesfully"<<endl;
@@ -333,6 +332,36 @@ void AliStorageAdministratorPanelListEvents::onMarkButton()
        }
 }
 
+void AliStorageAdministratorPanelListEvents::onLoadButton()
+{
+    int selectedEventNumber = fEventsList->GetSelected()-1;
+    int runNumber=fEventsListVector[selectedEventNumber].runNumber;
+    int eventNumber=fEventsListVector[selectedEventNumber].eventNumber;
+    
+    
+    struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
+    struct eventStruct eventToLoad;
+    eventToLoad.runNumber = runNumber;
+    eventToLoad.eventNumber = eventNumber;
+    requestMessage->messageType = REQUEST_GET_EVENT;
+    requestMessage->event = eventToLoad;
+    
+    fEventManager->Send(requestMessage,fServerSocket);
+    AliESDEvent *resultEvent = fEventManager->GetEvent(fServerSocket);
+    
+    if(resultEvent)
+    {
+        cout<<"ADMIN -- received event"<<endl;
+        fCurrentEvent = resultEvent;
+    }
+    else
+    {
+        cout<<"ADMIN -- received no event"<<endl;
+    }
+
+    SelectedEvent();
+}
+
 void AliStorageAdministratorPanelListEvents::onCloseButton(){onExit();}
 void AliStorageAdministratorPanelListEvents::CloseWindow(){onExit();}
 
@@ -356,6 +385,7 @@ Bool_t AliStorageAdministratorPanelListEvents::ProcessMessage(Long_t msg, Long_t
                        case BUTTON_CLOSE:onCloseButton();break;
                        case BUTTON_GET_LIST:onGetListButton();break;
                        case BUTTON_MARK_EVENT:onMarkButton();break;
+            case BUTTON_LOAD_EVENT:onLoadButton();break;
                        default:break;
                        }
                        break;