Minor changes.
authorjniedzie <jeremi.niedziela@cern.ch>
Wed, 19 Nov 2014 11:06:23 +0000 (12:06 +0100)
committerjniedzie <jeremi.niedziela@cern.ch>
Wed, 19 Nov 2014 11:12:06 +0000 (12:12 +0100)
MONITOR/alistoragemanager/AliStorageClientThread.cxx
MONITOR/alistoragemanager/AliStorageDatabase.cxx
MONITOR/alistoragemanager/AliStorageServerThread.cxx
MONITOR/alistoragemanager/alistorage.cxx

index 4bc3f7d..25ff3f8 100644 (file)
@@ -1,6 +1,5 @@
 #include "AliStorageClientThread.h"
 
-//#include <sstream>
 #include <signal.h>
 #include <fstream>
 #include <iostream>
@@ -30,7 +29,7 @@ fRemoveEventsPercentage(0)
     sa.sa_handler = GotSignalClient;
     sigfillset(&sa.sa_mask);
     sigaction(SIGINT,&sa,NULL);
-    
+   
     ifstream configFile (GetConfigFilePath());
     if (configFile.is_open())
     {
index df94223..e101e5d 100644 (file)
@@ -21,10 +21,8 @@ AliStorageDatabase::AliStorageDatabase() :
        fServer(0),
        fStoragePath("")
 {
-       TThread::Lock();        
+    TThread::Lock();
        ifstream configFile (GetConfigFilePath());
-
-       
        if (configFile.is_open())
        {
                string line;
@@ -34,50 +32,38 @@ AliStorageDatabase::AliStorageDatabase() :
                        getline(configFile,line);
                        from = line.find("\"")+1;
                        to = line.find_last_of("\"");
-                       if(line.find("HOST=")==0)
-                       {
+                       if(line.find("HOST=")==0){
                                fHost=line.substr(from,to-from);
                        }
-                       else if(line.find("PORT=")==0)
-                       {
+                       else if(line.find("PORT=")==0){
                                fPort=line.substr(from,to-from);
                        }
-                       else if(line.find("DATABASE=")==0)
-                       {
+                       else if(line.find("DATABASE=")==0){
                                fDatabase=line.substr(from,to-from);
                        }
-                       else if(line.find("USER=")==0)
-                       {
+                       else if(line.find("USER=")==0){
                                fUID=line.substr(from,to-from);
                        }
-                       else if(line.find("PASS=")==0)
-                       {
+                       else if(line.find("PASS=")==0){
                                fPassword=line.substr(from,to-from);
                        }
-                       else if(line.find("TABLE=")==0)
-                       {
+                       else if(line.find("TABLE=")==0){
                                fTable=line.substr(from,to-from);
                        }
-                       else if(line.find("STORAGE_PATH=")==0)
-                       {
+                       else if(line.find("STORAGE_PATH=")==0){
                                fStoragePath=line.substr(from,to-from);
                        }
 
                }
-               if(configFile.eof())
-               {
-                       configFile.clear();
-               }
+               if(configFile.eof()){configFile.clear();}
                configFile.close();
        }
-       else
-       {
-               cout << "DATABASE -- Unable to open file" <<endl;
-       }
+       else{cout << "DATABASE -- Unable to open file" <<endl;}
        TThread::UnLock();
 
-       
+    cout<<"DATABASE -- connecting to server:"<<Form("mysql://%s:%s/%s",fHost.c_str(),fPort.c_str(),fDatabase.c_str())<<fUID.c_str()<<fPassword.c_str()<<endl;
        fServer = TSQLServer::Connect(Form("mysql://%s:%s/%s",fHost.c_str(),fPort.c_str(),fDatabase.c_str()),fUID.c_str(),fPassword.c_str());
+    cout<<"Connected"<<endl;
 }
 
 AliStorageDatabase::~AliStorageDatabase(){
index 368a94a..a01ffb0 100644 (file)
 using namespace std;
 
 AliStorageServerThread::AliStorageServerThread() :
-       fDatabase(0),
-       fStoragePath("")
+fDatabase(0),
+fStoragePath("")
 {
-       TThread::Lock();
-       fDatabase = new AliStorageDatabase();
-       //load parameters from config file
-       ifstream configFile (GetConfigFilePath());
-
-       
-       if (configFile.is_open())
-       {
-               string line;
-               int from,to;
-               while(configFile.good())
-               {
-                       getline(configFile,line);
-                       from = line.find("\"")+1;
-                       to = line.find_last_of("\"");
-                       if(line.find("STORAGE_PATH=")==0)
-                       {
-                               fStoragePath=line.substr(from,to-from);
-                       }
-               }
-               if(configFile.eof())
-               {
-                       configFile.clear();
-               }
-               configFile.close();
-       }
-       else
-       {
-               cout<<"SERVER -- Unable to open config file"<<endl;
-       }
-       TThread::UnLock();
-
-       //start communication on socket
-       StartCommunication();
+    fDatabase = new AliStorageDatabase();
+    
+    TThread::Lock();
+    //load parameters from config file
+    ifstream configFile (GetConfigFilePath());
+    if (configFile.is_open())
+    {
+        string line;
+        int from,to;
+        while(configFile.good())
+        {
+            getline(configFile,line);
+            from = line.find("\"")+1;
+            to = line.find_last_of("\"");
+            if(line.find("STORAGE_PATH=")==0){
+                fStoragePath=line.substr(from,to-from);
+            }
+        }
+        if(configFile.eof()){configFile.clear();}
+        configFile.close();
+    }
+    else{cout<<"SERVER -- Unable to open config file"<<endl;}
+    TThread::UnLock();
+    
+    //start communication on socket
+    cout<<"Starting server's communication"<<endl;
+    StartCommunication();
 }
 
 AliStorageServerThread::~AliStorageServerThread()
 {
-       cout<<"SERVER -- AliStorageServerThread destructor called";     
-       if (fDatabase) {delete fDatabase;}
-       cout<<" --- OK"<<endl;
+    cout<<"SERVER -- AliStorageServerThread destructor called";
+    if (fDatabase) {delete fDatabase;}
+    cout<<" --- OK"<<endl;
 }
 
 void AliStorageServerThread::StartCommunication()
 {
-       AliStorageEventManager *eventManager = AliStorageEventManager::GetEventManagerInstance();
-       storageSockets socket = SERVER_COMMUNICATION_REP;
-       eventManager->CreateSocket(socket);
-
-       struct serverRequestStruct *request;
-       
-       while(1)
-       {
+    AliStorageEventManager *eventManager = AliStorageEventManager::GetEventManagerInstance();
+    storageSockets socket = SERVER_COMMUNICATION_REP;
+    eventManager->CreateSocket(socket);
+    
+    struct serverRequestStruct *request;
+    
+    while(1)
+    {
         cout<<"Server waiting for requests"<<endl;
-               request = eventManager->GetServerStruct(socket);
+        request = eventManager->GetServerStruct(socket);
         cout<<"Server received request"<<endl;
-               switch(request->messageType)
-                 {
-                 case REQUEST_LIST_EVENTS:
-                   {
+        switch(request->messageType)
+        {
+            case REQUEST_LIST_EVENTS:
+            {
                 cout<<"SERVER -- received request for list of events"<<endl;
-                     vector<serverListStruct> result = fDatabase->GetList(request->list);
+                vector<serverListStruct> result = fDatabase->GetList(request->list);
                 cout<<"SERVER -- got list from database"<<endl;
-                     eventManager->Send(result,socket);
+                eventManager->Send(result,socket);
                 cout<<"SERVER -- list was sent"<<endl;
-                     break;
-                   }
-                 case REQUEST_GET_EVENT:
-                   {
-                     AliESDEvent *event = fDatabase->GetEvent(request->event);
-                     eventManager->Send(event,socket);
-                     delete event;
-                     break;
-                   }
-                 case REQUEST_GET_NEXT_EVENT:
-                   {
+                break;
+            }
+            case REQUEST_GET_EVENT:
+            {
+                TThread::Lock();
+                AliESDEvent *event = fDatabase->GetEvent(request->event);
+                TThread::UnLock();
+                eventManager->Send(event,socket);
+                delete event;
+                break;
+            }
+            case REQUEST_GET_NEXT_EVENT:
+            {
                 cout<<"NEXT EVENT request received"<<endl;
-                     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:
-                  sleep(1);
-                  break;
-                 }
-
-       }
+                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:
+                sleep(1);
+                break;
+        }
+        
+    }
 }
 
 bool AliStorageServerThread::MarkEvent(struct eventStruct event)
 {
-  string pathToFile = fDatabase->GetFilePath(event);
-  TFile *tmpFile = new TFile(pathToFile.c_str(),"read");
-  if(!tmpFile)
+    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;
+        cout<<"SERVER -- couldn't open temp file"<<endl;
+        return false;
     }
-
-  tmpFile->cd(Form("run%d",event.runNumber));
-
-  AliESDEvent *eventToMark = (AliESDEvent*)gDirectory->Get(Form("event%d",event.eventNumber));
-  if(!eventToMark)
+    
+    tmpFile->cd(Form("run%d",event.runNumber));
+    
+    AliESDEvent *eventToMark = (AliESDEvent*)gDirectory->Get(Form("event%d",event.eventNumber));
+    if(!eventToMark)
     {
-      cout<<"SERVER -- couldn't find such event"<<endl;
+        cout<<"SERVER -- couldn't find such event"<<endl;
         if(tmpFile){tmpFile->Close();delete tmpFile;}
-      return false;
+        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
-       
-  if(!permFile)
+    cout<<"SERVER -- Marking event:"<<eventToMark->GetEventNumberInFile()<<endl;
+    
+    TFile *permFile = new TFile(Form("%s/permEvents.root",fStoragePath.c_str()),"update");//open/create perm file
+    
+    if(!permFile)
     {
-      cout<<"SERVER -- Couldn't open perm file"<<endl;
+        cout<<"SERVER -- Couldn't open perm file"<<endl;
         if(tmpFile){tmpFile->Close();delete tmpFile;}
-      if(eventToMark){delete eventToMark;}
-      return false;
+        if(eventToMark){delete eventToMark;}
+        return false;
     }
-
-  //create new directory for this run
-  TDirectory *currentRun;
-  if((currentRun = permFile->mkdir(Form("run%d",event.runNumber))))
+    
+    //create new directory for this run
+    TDirectory *currentRun;
+    if((currentRun = permFile->mkdir(Form("run%d",event.runNumber))))
     {
-      cout<<"SERVER -- creating new directory for this run"<<endl;
-      currentRun->cd();
+        cout<<"SERVER -- creating new directory for this run"<<endl;
+        currentRun->cd();
     }
-  else
+    else
     {
-      cout<<"SERVER -- opening existing directory for this run"<<endl;
-      permFile->cd(Form("run%d",event.runNumber));
+        cout<<"SERVER -- opening existing directory for this run"<<endl;
+        permFile->cd(Form("run%d",event.runNumber));
     }
-
-  //try to add record to the database
-  if(!fDatabase->MarkEvent(event))
+    
+    //try to add record to the database
+    if(!fDatabase->MarkEvent(event))
     {
-      cout<<"SERVER -- could not mark event in the database"<<endl;
-      if(tmpFile){delete tmpFile;}
-      if(eventToMark){delete eventToMark;}
-      if(permFile){delete permFile;}
-      return false;
+        cout<<"SERVER -- could not mark event in the database"<<endl;
+        if(tmpFile){delete tmpFile;}
+        if(eventToMark){delete eventToMark;}
+        if(permFile){delete permFile;}
+        return false;
     }
-
-  eventToMark->Write(Form("event%d",event.eventNumber));
-  permFile->Close();
-  tmpFile->Close();
-
-  if(tmpFile){delete tmpFile;}
-  if(eventToMark){delete eventToMark;}
-  if(permFile){delete permFile;}
-  //   if(currentRun)delete currentRun;//this line crashes if there is no permanent file yet
-  return true;
+    
+    eventToMark->Write(Form("event%d",event.eventNumber));
+    permFile->Close();
+    tmpFile->Close();
+    
+    if(tmpFile){delete tmpFile;}
+    if(eventToMark){delete eventToMark;}
+    if(permFile){delete permFile;}
+    // if(currentRun)delete currentRun;//this line crashes if there is no permanent file yet
+    return true;
 }
 
index 572eaee..01e29b1 100644 (file)
@@ -1,6 +1,7 @@
 #include "AliStorageClientThread.h"
 #include "AliStorageServerThread.h"
 
+#include <TThread.h>
 #include <iostream>
 
 using namespace std;
@@ -9,16 +10,6 @@ void *ClientThreadHandle(void*)
 {
        cout<<"ALICE Storage Manager -- Starting client thread"<<endl;
        AliStorageClientThread *client = new AliStorageClientThread();
-
-       if(client)
-       {
-//             client->CollectData();
-       }
-       else
-       {
-               cout<<"ALICE Storage Manager -- ERROR - failed to start client thread!!"<<endl;
-       }
-       
        if(client){delete client;}
        return 0;
 }
@@ -26,19 +17,7 @@ void *ClientThreadHandle(void*)
 void *ServerThreadHandle(void*)
 {
        cout<<"\nALICE Storage Manager -- Starting server thread"<<endl;
-
-#ifdef ZMQ
-       cout<<"ZMQ found"<<endl;
-#else
-       cout<<"no ZMQ found"<<endl;
-#endif
-       
        AliStorageServerThread *server = new AliStorageServerThread();
-
-       if(!server)
-       {
-               cout<<"ALICE Storage Manager -- ERROR - failed to start server thread!!"<<endl;
-       }
        if(server){delete server;}
        return 0;
 }
@@ -46,12 +25,12 @@ void *ServerThreadHandle(void*)
 int main()
 {
        TThread *clientThread = new TThread("clientThread", ClientThreadHandle,NULL);
-       
        TThread *serverThread = new TThread("serverThread", ServerThreadHandle,NULL);
+    
        clientThread->Run();
        serverThread->Run();
        
        clientThread->Join();
-       serverThread->Kill();//if client thread if finished, server thread is killed    
+       serverThread->Kill();//if client thread if finished, server thread is killed
        return 0;
 }