1. Fixing memory leaks in alistorage
authormaszyman <maszyman@cern.ch>
Wed, 10 Sep 2014 15:55:01 +0000 (17:55 +0200)
committerjniedzie <jeremi.niedziela@cern.ch>
Mon, 15 Sep 2014 06:19:41 +0000 (08:19 +0200)
    2. Implementing GUI in ED (prev,next,first,last buttons)
    3. Fixing the first element of the events list

EVE/EveBase/AliEveEventManager.cxx
EVE/EveBase/AliEveEventManagerEditor.cxx
MONITOR/alistoragemanager/AliStorageAdministratorPanel.cxx
MONITOR/alistoragemanager/AliStorageAdministratorPanelListEvents.cxx
MONITOR/alistoragemanager/AliStorageClientThread.cxx
MONITOR/alistoragemanager/AliStorageDatabase.cxx
MONITOR/alistoragemanager/AliStorageDatabase.h
MONITOR/alistoragemanager/AliStorageEventManager.cxx
MONITOR/alistoragemanager/AliStorageServerThread.cxx
MONITOR/alistoragemanager/AliStorageTypes.h

index 3e7eae1..18e3104 100644 (file)
@@ -848,7 +848,61 @@ void AliEveEventManager::GotoEvent(Int_t event)
     }
     if (fExternalCtrl)
     {
-        throw (kEH + "Event-loop is under external control.");
+        // throw (kEH + "Event-loop is under external control.");
+
+#ifdef ZMQ
+
+      if (fESD) {
+       int runNumber=fESD->GetRunNumber();
+       int eventNumber=fESD->GetEventNumberInFile();
+       struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
+       struct eventStruct eventToLoad;
+       eventToLoad.runNumber = runNumber;
+       // // careful! check if exists!
+       eventToLoad.eventNumber = eventNumber;
+
+       if (event == -1) {
+         requestMessage->messageType = REQUEST_GET_LAST_EVENT;
+       } 
+       else  if (event == 0) {
+         requestMessage->messageType = REQUEST_GET_FIRST_EVENT;
+       } 
+       else  if (event == 1) {
+         requestMessage->messageType = REQUEST_GET_PREV_EVENT;
+       } 
+       else  if (event == 2) {
+         requestMessage->messageType = REQUEST_GET_NEXT_EVENT;
+       } 
+
+       requestMessage->event = eventToLoad;
+
+       AliStorageEventManager *eventManager =
+         AliStorageEventManager::GetEventManagerInstance();
+       AliESDEvent *resultEvent = NULL;
+      
+       eventManager->CreateSocket(SERVER_COMMUNICATION_REQ);
+       fMutex.Lock();
+       eventManager->Send(requestMessage,SERVER_COMMUNICATION_REQ);
+       resultEvent = eventManager->GetEvent(SERVER_COMMUNICATION_REQ);
+
+       if(resultEvent)
+         {
+           cout<<"Event Manager -- first/last or prev/next event loaded "<<resultEvent->GetRunNumber() <<endl;
+           DestroyElements();
+           InitOCDB(resultEvent->GetRunNumber());
+           SetEvent(0,0,resultEvent,0);
+           fMutex.UnLock();
+
+         }
+       else{cout<<"No first/last event is avaliable."<<endl;}
+      }
+      else {
+
+      }
+
+
+#endif 
+
     }
     else if (!fIsOpen)
     {
index 36c752a..0f8dc2c 100644 (file)
@@ -214,14 +214,18 @@ void AliEveEventManagerWindow::DoFirstEvent()
 void AliEveEventManagerWindow::DoPrevEvent()
 {
   // Load previous event
-  fM->PrevEvent();
+  // fM->PrevEvent();
+  fM->GotoEvent(1);
+
 }
 
 //______________________________________________________________________________
 void AliEveEventManagerWindow::DoNextEvent()
 {
   // Load next event
-  fM->NextEvent();
+  // fM->NextEvent();
+  fM->GotoEvent(2);
+
 }
 
 //______________________________________________________________________________
@@ -290,9 +294,12 @@ void AliEveEventManagerWindow::Update()
   Bool_t extCtrl  = fM->IsUnderExternalControl();
   Bool_t evNavOn  = !autoLoad && !extCtrl;
 
-  fFirstEvent->SetEnabled(evNavOn);
-  fPrevEvent ->SetEnabled(evNavOn);
-  fLastEvent ->SetEnabled(evNavOn);
+  // fFirstEvent->SetEnabled(evNavOn);
+  // fPrevEvent ->SetEnabled(evNavOn);
+  // fLastEvent ->SetEnabled(evNavOn);
+  fFirstEvent->SetEnabled(!autoLoad);
+  fPrevEvent ->SetEnabled(!autoLoad);
+  fLastEvent ->SetEnabled(!autoLoad);
   fNextEvent ->SetEnabled(!autoLoad);
   fRefresh   ->SetEnabled(evNavOn);
 
index 9926324..39b3617 100644 (file)
@@ -144,6 +144,7 @@ void AliStorageAdministratorPanel::CheckClientState(int option)
                break;
        default:break;  
        }
+       if(request){delete request;}
 }
 
 void AliStorageAdministratorPanel::InitWindow()
index adedaa1..e8034e4 100644 (file)
@@ -291,6 +291,7 @@ void AliStorageAdministratorPanelListEvents::onGetListButton()
        MapSubwindows();
        MapWindow();
        Layout();
+       delete requestMessage;
 }
 
 
index 76d2efb..8cb7841 100644 (file)
@@ -106,6 +106,7 @@ AliStorageClientThread::~AliStorageClientThread()
                delete fCurrentFile;
        }
        if(fCommunicationThread){delete fCommunicationThread;}
+       if(fDatabase){delete fDatabase;}
        cout<<" --- OK"<<endl;
 }
 
index 5f75106..58df700 100644 (file)
@@ -80,7 +80,9 @@ AliStorageDatabase::AliStorageDatabase() :
        fServer = TSQLServer::Connect(Form("mysql://%s:%s/%s",fHost.c_str(),fPort.c_str(),fDatabase.c_str()),fUID.c_str(),fPassword.c_str());
 }
 
-AliStorageDatabase::~AliStorageDatabase(){}
+AliStorageDatabase::~AliStorageDatabase(){
+  if (fServer) {delete fServer;}
+}
 
 void AliStorageDatabase::InsertEvent(int runNumber,
                                     int eventNumber,
@@ -88,20 +90,24 @@ void AliStorageDatabase::InsertEvent(int runNumber,
                                     int multiplicity,
                                     char *filePath)
 {
-       fServer->Query(Form("replace into %s (run_number,event_number,system,multiplicity,permanent,file_path) values (%d,%d,'%s',%d,0,'%s');",fTable.c_str(),runNumber,eventNumber,system,multiplicity,filePath));
+  TSQLResult* res;
+  res = fServer->Query(Form("replace into %s (run_number,event_number,system,multiplicity,permanent,file_path) values (%d,%d,'%s',%d,0,'%s');",fTable.c_str(),runNumber,eventNumber,system,multiplicity,filePath));
+  delete res;
 
 }
 
 bool AliStorageDatabase::MarkEvent(struct eventStruct event)
-{
-       if(fServer->Query(Form("UPDATE %s SET permanent = 1 WHERE run_number = %d AND event_number = %d;",fTable.c_str(),event.runNumber,event.eventNumber)))
-       {
-               return 1;
-       }
-       else
-       {
-               return 0;
-       }
+{  
+  TSQLResult* res;
+  res = fServer->Query(Form("UPDATE %s SET permanent = 1 WHERE run_number = %d AND event_number = %d;",fTable.c_str(),event.runNumber,event.eventNumber));
+  if(res) {
+    delete res;
+    return 1;
+  }
+  else {
+    delete res;
+    return 0;
+  }
 }
 
 vector<serverListStruct> AliStorageDatabase::GetList(struct listRequestStruct list)
@@ -136,7 +142,7 @@ vector<serverListStruct> AliStorageDatabase::GetList(struct listRequestStruct li
                eventsVector.push_back(resultList);
                delete row;
        }
-       
+       delete result;
        return eventsVector;
 }
 
@@ -186,7 +192,10 @@ struct eventStruct AliStorageDatabase::GetOldestEvent()
 
 void AliStorageDatabase::RemoveEvent(struct eventStruct event)
 {
-       fServer->Query(Form("DELETE FROM %s WHERE run_number = %d AND event_number = %d",fTable.c_str(),event.runNumber,event.eventNumber));
+  TSQLResult* res;
+  res = fServer->Query(Form("DELETE FROM %s WHERE run_number = %d AND event_number = %d",fTable.c_str(),event.runNumber,event.eventNumber));
+  delete res;
+
 }
 
 string AliStorageDatabase::GetFilePath(struct eventStruct event)
@@ -235,6 +244,36 @@ AliESDEvent* AliStorageDatabase::GetNextEvent(struct eventStruct event)
        return NULL;
 }
 
+AliESDEvent* AliStorageDatabase::GetPrevEvent(struct eventStruct event)
+{
+       TSQLResult *result = fServer->Query(Form("SELECT * FROM %s ORDER BY run_number,event_number DESC;",fTable.c_str()));
+
+       TSQLRow *row;
+       bool isCurrentEvent=false;
+       struct eventStruct nextEvent;
+       
+       while((row = result->Next()))
+       {
+               if(isCurrentEvent)
+               {
+                       nextEvent.runNumber = atoi(row->GetField(0));
+                       nextEvent.eventNumber = atoi(row->GetField(1));
+                       return GetEvent(nextEvent);
+               }
+
+               //if current event found
+               if(atoi(row->GetField(0))==event.runNumber && atoi(row->GetField(1))==event.eventNumber)
+               {
+                       isCurrentEvent=true;
+               }
+               
+               delete row;
+       }
+       delete result;
+       return NULL;
+}
+
+
 AliESDEvent* AliStorageDatabase::GetLastEvent()
 {
        TSQLResult *result = fServer->Query(Form("SELECT * FROM %s ORDER BY run_number,event_number;",fTable.c_str()));
@@ -252,3 +291,21 @@ AliESDEvent* AliStorageDatabase::GetLastEvent()
        return GetEvent(lastEvent);
 
 }
+
+AliESDEvent* AliStorageDatabase::GetFirstEvent()
+{
+       TSQLResult *result = fServer->Query(Form("SELECT * FROM %s ORDER BY run_number,event_number DESC;",fTable.c_str()));
+
+       TSQLRow *row;
+       struct eventStruct lastEvent = {0,0};
+
+       while((row = result->Next()))
+       {
+               lastEvent.runNumber = atoi(row->GetField(0));
+               lastEvent.eventNumber = atoi(row->GetField(1));
+               delete row;
+       }
+       cout<<"Last event is:"<<lastEvent.eventNumber<<endl;
+       return GetEvent(lastEvent);
+
+}
index 65e9094..8e8f828 100644 (file)
@@ -30,6 +30,8 @@ public:
        AliESDEvent* GetEvent(struct eventStruct event);
        AliESDEvent* GetNextEvent(struct eventStruct event);
        AliESDEvent* GetLastEvent();
+       AliESDEvent* GetPrevEvent(struct eventStruct event);
+       AliESDEvent* GetFirstEvent();
 private:
        std::string fHost;
        std::string fPort;
index 4b8e3d9..d55260a 100644 (file)
@@ -230,13 +230,18 @@ void AliStorageEventManager::Send(vector<serverListStruct> list,storageSockets s
        if(numberOfRecords==0)return;
        fSockets[socket]->recv((new message_t));//empty message just to keep req-rep order
 
-       //prepare message with event's list
-       char *buffer = reinterpret_cast<char*> (&list[0]);
-       message_t *reply = new message_t((void*)buffer,
-                             sizeof(serverListStruct)*numberOfRecords,0);
-       fSockets[socket]->send(*reply);
+       // //prepare message with event's list
+       // char *buffer = reinterpret_cast<char*> (&list[0]);
+       // message_t *reply = new message_t((void*)buffer,
+       //                    sizeof(serverListStruct)*numberOfRecords,0);
+       // fSockets[socket]->send(*reply);
+       // if(reply){delete reply;}
+
+       zmq::message_t reply(sizeof(serverListStruct)*numberOfRecords);
+       memcpy(reply.data(), reinterpret_cast<const char*> (&list[0]), sizeof(serverListStruct)*numberOfRecords);
+
+       fSockets[socket]->send(reply);
 
-       if(reply){delete reply;}
 }
 
 void AliStorageEventManager::Send(struct serverRequestStruct *request,storageSockets socket)
@@ -269,6 +274,7 @@ bool AliStorageEventManager::Send(struct clientRequestStruct *request,storageSoc
                if(fSockets[socket]){delete fSockets[socket];fSockets[socket]=0;}
 
                CreateSocket(socket);
+               delete requestMessage;
                return 0;
                
        }       
@@ -276,10 +282,11 @@ bool AliStorageEventManager::Send(struct clientRequestStruct *request,storageSoc
        {
                if(poll (&items[0], 1, timeout)==0)
                {
+                 delete requestMessage;
                        return 0;
                }
        }
-
+       delete requestMessage;          
        return 1;
 }
 
@@ -392,6 +399,7 @@ vector<serverListStruct> AliStorageEventManager::GetServerListVector(storageSock
        
        vector<serverListStruct> receivedList(static_cast<serverListStruct*>(response->data()), static_cast<serverListStruct*>(response->data()) + numberOfRecords);
 
+       if (response) {delete response;}
        return receivedList;
 }
 
index bd8fd3d..af9de8c 100644 (file)
@@ -53,6 +53,7 @@ AliStorageServerThread::AliStorageServerThread() :
 AliStorageServerThread::~AliStorageServerThread()
 {
        cout<<"SERVER -- AliStorageServerThread destructor called";     
+       if (fDatabase) {delete fDatabase;}
        cout<<" --- OK"<<endl;
 }
 
@@ -69,62 +70,77 @@ void AliStorageServerThread::StartCommunication()
                request = eventManager->GetServerStruct(socket);
                
                switch(request->messageType)
-               {
-               case REQUEST_LIST_EVENTS:
-               {
-                       vector<serverListStruct> result = fDatabase->GetList(request->list);
-                       eventManager->Send(result,socket);
-                       break;
-               }
-               case REQUEST_GET_EVENT:
-               {
-                       AliESDEvent *event = fDatabase->GetEvent(request->event);
-                       eventManager->Send(event,socket);
-                       delete event;
-                       break;
-               }
-               case REQUEST_GET_NEXT_EVENT:
-               {
-                       AliESDEvent *event = fDatabase->GetNextEvent(request->event);
-                       eventManager->Send(event,socket);
-                       delete event;
-                       break;
-               }
-               case REQUEST_GET_LAST_EVENT:
-               {
-                       AliESDEvent *event = fDatabase->GetLastEvent();
-                       eventManager->Send(event,socket);
-                       delete event;
-                       break;
-               }
-               case REQUEST_MARK_EVENT:
-               {
-                       struct eventStruct *markData  = &(request->event);
-                       eventManager->Send(MarkEvent(*markData),socket);
-                       break;
-               }
-               default:break;
-               }
+                 {
+                 case REQUEST_LIST_EVENTS:
+                   {
+                     vector<serverListStruct> result = fDatabase->GetList(request->list);
+                     eventManager->Send(result,socket);
+                     break;
+                   }
+                 case REQUEST_GET_EVENT:
+                   {
+                     AliESDEvent *event = fDatabase->GetEvent(request->event);
+                     eventManager->Send(event,socket);
+                     delete event;
+                     break;
+                   }
+                 case REQUEST_GET_NEXT_EVENT:
+                   {
+                     AliESDEvent *event = fDatabase->GetNextEvent(request->event);
+                     eventManager->Send(event,socket);
+                     delete event;
+                     break;
+                   }
+                 case REQUEST_GET_PREV_EVENT:
+                   {
+                     AliESDEvent *event = fDatabase->GetPrevEvent(request->event);
+                     eventManager->Send(event,socket);
+                     delete event;
+                     break;
+                   }
+                 case REQUEST_GET_LAST_EVENT:
+                   {
+                     AliESDEvent *event = fDatabase->GetLastEvent();
+                     eventManager->Send(event,socket);
+                     delete event;
+                     break;
+                   }
+                 case REQUEST_GET_FIRST_EVENT:
+                   {
+                     AliESDEvent *event = fDatabase->GetFirstEvent();
+                     eventManager->Send(event,socket);
+                     delete event;
+                     break;
+                   }
+                 case REQUEST_MARK_EVENT:
+                   {
+                     struct eventStruct *markData  = &(request->event);
+                     eventManager->Send(MarkEvent(*markData),socket);
+                     break;
+                   }
+                 default:break;
+                 }
+
        }
 }
 
 bool AliStorageServerThread::MarkEvent(struct eventStruct event)
 {
-       string pathToFile = fDatabase->GetFilePath(event);
-       TFile *tmpFile = new TFile(pathToFile.c_str(),"read");
-       if(!tmpFile)
-       {
-               cout<<"SERVER -- couldn't open temp file"<<endl;
-               return false;
-       }
-       AliESDEvent *eventToMark = (AliESDEvent*)tmpFile->Get(Form("event%d",event.eventNumber));
-       if(!eventToMark)
-       {
-               cout<<"SERVER -- couldn't find such event"<<endl;
-               if(tmpFile){delete tmpFile;}
-               return false;
-       }
-       cout<<"SERVER -- Marking event:"<<eventToMark->GetEventNumberInFile()<<endl;
+  string pathToFile = fDatabase->GetFilePath(event);
+  TFile *tmpFile = new TFile(pathToFile.c_str(),"read");
+  if(!tmpFile)
+    {
+      cout<<"SERVER -- couldn't open temp file"<<endl;
+      return false;
+    }
+  AliESDEvent *eventToMark = (AliESDEvent*)tmpFile->Get(Form("event%d",event.eventNumber));
+  if(!eventToMark)
+    {
+      cout<<"SERVER -- couldn't find such event"<<endl;
+      if(tmpFile){delete tmpFile;}
+      return false;
+    }
+  cout<<"SERVER -- Marking event:"<<eventToMark->GetEventNumberInFile()<<endl;
                
        TFile *permFile = new TFile(Form("%s/permEvents.root",fStoragePath.c_str()),"update");//open/create perm file
        
index b4cc90a..4247094 100644 (file)
@@ -35,7 +35,9 @@ enum requestType{
        REQUEST_LIST_EVENTS,
        REQUEST_GET_EVENT,
        REQUEST_GET_NEXT_EVENT,
+       REQUEST_GET_PREV_EVENT,
        REQUEST_GET_LAST_EVENT,
+       REQUEST_GET_FIRST_EVENT,
        REQUEST_MARK_EVENT,
        REQUEST_SET_PARAMS,
        REQUEST_GET_PARAMS