STORAGE module added, new macro for Event Display, minor changes in MONITOR
authorjniedzie <jeremi.niedziela@cern.ch>
Wed, 9 Jul 2014 08:25:23 +0000 (10:25 +0200)
committerjniedzie <jeremi.niedziela@cern.ch>
Wed, 9 Jul 2014 09:16:39 +0000 (11:16 +0200)
34 files changed:
CMakeLists.txt
EVE/macros/alieve_online_new.C [new file with mode: 0644]
MONITOR/AliEventServerUtil.h
MONITOR/AliEventServerWindow.cxx
MONITOR/AliRecoServerThread.cxx
MONITOR/alieventserver.rootrc
STORAGE/AliStorageAdministratorPanel.cxx [new file with mode: 0644]
STORAGE/AliStorageAdministratorPanel.h [new file with mode: 0644]
STORAGE/AliStorageAdministratorPanelListEvents.cxx [new file with mode: 0644]
STORAGE/AliStorageAdministratorPanelListEvents.h [new file with mode: 0644]
STORAGE/AliStorageAdministratorPanelMarkEvent.cxx [new file with mode: 0644]
STORAGE/AliStorageAdministratorPanelMarkEvent.h [new file with mode: 0644]
STORAGE/AliStorageAdministratorPanelSetStorageParams.cxx [new file with mode: 0644]
STORAGE/AliStorageAdministratorPanelSetStorageParams.h [new file with mode: 0644]
STORAGE/AliStorageClientThread.cxx [new file with mode: 0644]
STORAGE/AliStorageClientThread.h [new file with mode: 0644]
STORAGE/AliStorageDatabase.cxx [new file with mode: 0644]
STORAGE/AliStorageDatabase.h [new file with mode: 0644]
STORAGE/AliStorageEventManager.cxx [new file with mode: 0644]
STORAGE/AliStorageEventManager.h [new file with mode: 0644]
STORAGE/AliStorageServerThread.cxx [new file with mode: 0644]
STORAGE/AliStorageServerThread.h [new file with mode: 0644]
STORAGE/AliStorageTypes.h [new file with mode: 0644]
STORAGE/CMakeLists.txt [new file with mode: 0755]
STORAGE/CMakebinalifakedisplay.pkg [new file with mode: 0755]
STORAGE/CMakebinalistorage.pkg [new file with mode: 0755]
STORAGE/CMakebinalistorageadmin.pkg [new file with mode: 0755]
STORAGE/CMakelibStorage.pkg [new file with mode: 0755]
STORAGE/StorageLinkDef.h [new file with mode: 0755]
STORAGE/alifakedisplay.cxx [new file with mode: 0644]
STORAGE/alistorage_main/alistorage_main.cxx [new file with mode: 0644]
STORAGE/alistorageadmin_main/alistorageadmin_main.cxx [new file with mode: 0644]
STORAGE/clearAll.sh [new file with mode: 0755]
STORAGE/setupStorageDatabase.sh [new file with mode: 0755]

index e2b1877..ee3f947 100644 (file)
@@ -141,7 +141,7 @@ set(BINLIBDIRS "-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
 
 # Standard Modules
 # ------------------------------
-set(ALIROOTMODULES STEER PHOS TRD TPC ZDC MUON PMD FMD TOF ITS AD ACORDE HMPID T0 BCM STRUCT VZERO THijing THbtp EMCAL THerwig TEPEMGEN FASTSIM TPHIC RAW MONITOR ANALYSIS JETAN HLT STAT TTherminator CORRFW DPMJET TDPMjet STARLIGHT PWGPP PWG PWGCF PWGGA PWGHF PWGDQ PWGJE PWGLF PWGUD TRIGGER PYTHIA8 TAmpt OADB MFT TEvtGen FIT)
+set(ALIROOTMODULES STEER PHOS TRD TPC ZDC MUON PMD FMD TOF ITS AD ACORDE HMPID T0 BCM STRUCT VZERO THijing THbtp EMCAL THerwig TEPEMGEN FASTSIM TPHIC RAW MONITOR STORAGE ANALYSIS JETAN HLT STAT TTherminator CORRFW DPMJET TDPMjet STARLIGHT PWGPP PWG PWGCF PWGGA PWGHF PWGDQ PWGJE PWGLF PWGUD TRIGGER PYTHIA8 TAmpt OADB MFT TEvtGen FIT)
 
 if(THydjet)
   list(APPEND ALIROOTMODULES THydjet)
@@ -332,7 +332,7 @@ set(AEXT a)
 set(LIBPATH ${CMAKE_BINARY_DIR}/lib/tgt_${ALICE_TARGET})
 set(BINPATH ${CMAKE_BINARY_DIR}/bin/tgt_${ALICE_TARGET})
 set(EXPORTDIR ${ALICE_ROOT}/include)
-#set(BINLIBDIRS -L${ALICE_ROOT}/${LIBPATH})
+set(BINLIBDIRS -L${ALICE_ROOT}/${LIBPATH})
 set(RAWDIRO ${CMAKE_BINARY_DIR}/RAW)
 set(ALIMDCSPECFILE ${RAWDIRO}/alimdc.spec)
 set(RAWDatabaseALIB ${LIBPATH}/libRAWDatabase.${AEXT})
diff --git a/EVE/macros/alieve_online_new.C b/EVE/macros/alieve_online_new.C
new file mode 100644 (file)
index 0000000..186e2b9
--- /dev/null
@@ -0,0 +1,237 @@
+/**************************************************************************\r
+ * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *\r
+ * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *\r
+ * full copyright notice.                                                 *\r
+ **************************************************************************/\r
+\r
+#include <../../MONITOR/AliSocket.h>\r
+\r
+class TEveProjectionManager;\r
+class TEveGeoShape;\r
+class TEveUtil;\r
+class AliTriggerAnalysis;\r
+class AliSysInfo;\r
+\r
+TH2D* V0StateHistogram;\r
+\r
+Bool_t gCenterProjectionsAtPrimaryVertex = kFALSE;\r
+\r
+void alieve_online_new()\r
+{\r
+    printf("alieve_online_init() ...\n");\r
+ printf("================================ Correct macro r ...\n");\r
\r
+       if (gSystem->Getenv("ALICE_ROOT") != 0)\r
+  {\r
+    gInterpreter->AddIncludePath(Form("%s/MUON", gSystem->Getenv("ALICE_ROOT")));\r
+    gInterpreter->AddIncludePath(Form("%s/MUON/mapping", gSystem->Getenv("ALICE_ROOT")));\r
+  }\r
+  \r
+   AliEveEventManager::SetCdbUri("local://$ALICE_ROOT/OCDB");\r
+  \r
+  Info("alieve_init", "Adding standard macros.");\r
+  TString  hack = gSystem->pwd(); // Problem with TGFileBrowser cding\r
+  alieve_init_import_macros();\r
+  gSystem->cd(hack);\r
+  \r
+  new AliEveEventManager("online", -1);\r
+  //AliEveEventManager::GetMaster()->AddNewEventCommand("alieve_online_on_new_event()");\r
+  gEve->AddEvent(AliEveEventManager::GetMaster());\r
+  \r
+  \r
+  TEveUtil::AssertMacro("VizDB_scan.C");\r
+  \r
+  gSystem->ProcessEvents();\r
+   \r
+  \r
+  \r
\r
+  \r
+  AliEveMacroExecutor *exec  = AliEveEventManager::GetMaster()->GetExecutor();\r
+  TEveBrowser         *browser = gEve->GetBrowser();\r
+  browser->ShowCloseTab(kFALSE);\r
+  \r
+\r
+  // Gentle-geom loading changes gGeoManager.\r
+  //TEveGeoManagerHolder mgrRestore;\r
+\r
+  AliEveMultiView *multiView = new AliEveMultiView(kTRUE);\r
+\r
+  TEveUtil::LoadMacro("geom_gentle.C");\r
+  multiView->InitGeomGentle(geom_gentle(),\r
+                             geom_gentle_rphi(), \r
+                             geom_gentle_rhoz(),\r
+                             geom_gentle_rhoz());\r
+\r
+  TEveUtil::LoadMacro("geom_gentle_trd.C");\r
+  multiView->InitGeomGentleTrd(geom_gentle_trd());\r
+\r
+  TEveUtil::LoadMacro("geom_gentle_muon.C");\r
+  multiView->InitGeomGentleMuon(geom_gentle_muon(), kFALSE, kFALSE, kTRUE);\r
+\r
+  //============================================================================\r
+  // Standard macros to execute -- not all are enabled by default.\r
+  //============================================================================\r
+\r
+  \r
+   printf("============ Setting macro executor\n");\r
+\r
+  AliEveMacroExecutor *exec = AliEveEventManager::GetMaster()->GetExecutor();\r
+\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex",             "",                kTRUE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse",     "",                kTRUE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box",         "kFALSE, 3, 3, 3", kFALSE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_spd",         "",                kTRUE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_spd", "",                kTRUE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_spd",     "kFALSE, 3, 3, 3", kFALSE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",         "primary_vertex.C", "primary_vertex_tpc",         "",                kFALSE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse", "primary_vertex.C", "primary_vertex_ellipse_tpc", "",                kFALSE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",     "primary_vertex.C", "primary_vertex_box_tpc",     "kFALSE, 3, 3, 3", kFALSE));\r
+\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus ITS",   "its_clusters.C",   "its_clusters"));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TPC",   "tpc_clusters.C",   "tpc_clusters"));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TRD",   "trd_clusters.C",   "trd_clusters"));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus TOF",   "tof_clusters.C",   "tof_clusters"));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus HMPID", "hmpid_clusters.C", "hmpid_clusters"));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clus MUON",  "muon_clusters.C",  "muon_clusters"));\r
+\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "DIG EMCAL",   "emcal_digits.C",   "emcal_digits"));\r
+\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ITS",     "its_raw.C",     "its_raw"));\r
+  //  exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TPC",     "tpc_raw.C",     "tpc_raw"));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TOF",     "tof_raw.C",     "tof_raw"));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW VZERO",   "vzero_raw.C",   "vzero_raw", "", kFALSE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ACORDE",  "acorde_raw.C",  "acorde_raw", "", kFALSE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW MUON",    "muon_raw.C",  "muon_raw"));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW FMD",     "fmd_raw.C",     "fmd_raw"));\r
+\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks",             "", kFALSE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks_MI",          "", kFALSE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track",      "esd_tracks.C",        "esd_tracks_by_category", "", kTRUE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Track MUON", "esd_muon_tracks.C", "esd_muon_tracks",        "kTRUE,kFALSE", kTRUE));\r
+  exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC FMD",        "fmd_esd.C",           "fmd_esd",                "", kTRUE));\r
+\r
+  // ???\r
+  // exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC TRD", "trd_detectors.C", "trd_detectors",         "", kFALSE));\r
+  // trd_tracks disabled due to memory leaks\r
+\r
+  //----------------------------------------------------------------------------\r
+\r
+  slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());\r
+  slot->StartEmbedding();\r
+  AliEveMacroExecutorWindow* exewin = new AliEveMacroExecutorWindow(exec);\r
+  slot->StopEmbedding("DataSelection");\r
+  exewin->PopulateMacros();\r
+\r
+  //============================================================================\r
+  // Final GUI setup\r
+  //============================================================================\r
+\r
+  browser->GetTabRight()->SetTab(1);\r
+\r
+  browser->StartEmbedding(TRootBrowser::kBottom);\r
+  new AliEveEventManagerWindow(AliEveEventManager::GetMaster());\r
+  browser->StopEmbedding("EventCtrl");\r
+\r
+  browser->MoveResize(0, 0, gClient->GetDisplayWidth(),\r
+                     gClient->GetDisplayHeight() - 32);\r
+\r
+  gEve->GetViewers()->SwitchColorSet();\r
+  gEve->FullRedraw3D(kTRUE);\r
+       gSystem->ProcessEvents();\r
+\r
+  TGLViewer *glv1 = multiView->Get3DView()->GetGLViewer();\r
+  TGLViewer *glv2 = multiView->GetRPhiView()->GetGLViewer();\r
+  TGLViewer *glv3 = multiView->GetRhoZView()->GetGLViewer();\r
+\r
+  glv1->CurrentCamera().RotateRad(-0.4, -1.8);\r
+  glv2->CurrentCamera().Dolly(450, kFALSE, kFALSE);\r
+  glv3->CurrentCamera().Dolly(1500, kFALSE, kFALSE);\r
+\r
+  gEve->FullRedraw3D();\r
+  gSystem->ProcessEvents();\r
+  \r
+  // Register command to call on each event.\r
+  // AliEveEventManager::GetMaster()->AddNewEventCommand("alieve_online_on_new_event();");\r
+  //AliEveEventManager::GetMaster()->GotoEvent(-1);\r
\r
+  printf("================================ Connecting to Server ...\n");\r
+   \r
+    //AliEveEventManager::ConnectToServer("tcp://137.138.55.173", 5024);\r
+  if(AliEveEventManager::ConnectToServer("tcp://137.138.93.150", 5024))\r
+  {\r
+         printf("\nconnected\n");\r
+  }    else printf("not connected\n");\r
+    \r
+    AliSocket* subscriber = AliEveEventManager::AssertSubscriber();\r
+  \r
+       if(subscriber ==0) {\r
+               printf("===================== Not connected! ====================\n");\r
+    }\r
+\r
+  \r
+\r
+  gEve->Redraw3D(kTRUE);\r
+    \r
+}\r
+\r
+\r
+Int_t      g_pic_id  = 0;\r
+Int_t      g_pic_max = 100;\r
+TTimeStamp g_pic_prev(0, 0);\r
+\r
+void alieve_online_on_new_event()\r
+{\r
+  AliSysInfo::AddStamp("on_new_event_start");\r
\r
+       AliSysInfo::AddStamp("on_new_event_end");\r
+}\r
+\r
+void alieve_init_import_macros()\r
+{\r
+  // Put macros in the list of browsables, add a macro browser to\r
+  // top-level GUI.\r
+\r
+  TString macdir("$(ALICE_ROOT)/EVE/alice-macros");\r
+  gSystem->ExpandPathName(macdir);\r
+\r
+  TFolder* f = gEve->GetMacroFolder();\r
+  void* dirhandle = gSystem->OpenDirectory(macdir.Data());\r
+  if (dirhandle != 0)\r
+  {\r
+    char* filename;\r
+    TPMERegexp re("\\.C$");\r
+    TObjArray names;\r
+    while ((filename = gSystem->GetDirEntry(dirhandle)) != 0)\r
+    {\r
+      if (re.Match(filename))\r
+       names.AddLast(new TObjString(filename));\r
+    }\r
+    names.Sort();\r
+\r
+    for (Int_t ii=0; ii<names.GetEntries(); ++ii)\r
+    {\r
+      TObjString * si = (TObjString*) names.At(ii);\r
+       f->Add(new TEveMacro(Form("%s/%s", macdir.Data(), (si->GetString()).Data())));\r
+    }\r
+  }\r
+  gSystem->FreeDirectory(dirhandle);\r
+\r
+  gROOT->GetListOfBrowsables()->Add(new TSystemDirectory(macdir.Data(), macdir.Data()));\r
+\r
+  {\r
+    TEveBrowser   *br = gEve->GetBrowser();\r
+    TGFileBrowser *fb = 0;\r
+    fb = br->GetFileBrowser();\r
+    fb->GotoDir(macdir);\r
+    {\r
+      br->StartEmbedding(0);\r
+      fb = br->MakeFileBrowser();\r
+      fb->BrowseObj(f);\r
+      fb->Show();\r
+      br->StopEmbedding();\r
+      br->SetTabTitle("Macros", 0);\r
+      br->SetTab(0, 0);\r
+    }\r
+  }\r
+}\r
index ff303bc..d052b67 100644 (file)
@@ -7,11 +7,11 @@
 //______________DEFAULT SETTINGS________________
 #define DEFAULT_SERVER_HOST "tcp://*"
 #define DEFAULT_SERVER_PORT 5024
-#define DEFAULT_SERVER_SAVE_RECO_DIR "reco"
-#define DEFAULT_CDB_STORAGE "local:///local/cdb"
-#define DEFAULT_CDB_SPEC_STORAGE_PATH1 "GRP/GRP/Data"
+#define DEFAULT_SERVER_SAVE_RECO_DIR "opt/reco"
+#define DEFAULT_CDB_STORAGE "local:///opt/OCDB/2013"
+#define DEFAULT_CDB_SPEC_STORAGE_PATH1 "opt/reco/GRP/GRP/Data"
 #define DEFAULT_CDB_SPEC_STORAGE_VALUE1 ""
-#define DEFAULT_CDB_SPEC_STORAGE_PATH2 "GRP/CTP/Config"
+#define DEFAULT_CDB_SPEC_STORAGE_PATH2 "opt/reco/GRP/CTP/Config"
 #define DEFAULT_CDB_SPEC_STORAGE_VALUE2 ""
 #define DEFAULT_CDB_SPEC_STORAGE_PATH3 ""
 #define DEFAULT_CDB_SPEC_STORAGE_VALUE3 ""
 #define DEFAULT_RECO_WRITE_ESDF 1
 #define DEFAULT_RECO_WRITE_ALIGN 1
 #define DEFAULT_RECO_CLEAN_ESD 0
-#define DEFAULT_RECO_DETECTORS "ALL -PHOS -HLT -EMCAL"
-#define DEFAULT_LOGBOOK_HOST "pcaldbl501"
+#define DEFAULT_RECO_DETECTORS "ALL -PHOS -EMCAL"
+#define DEFAULT_LOGBOOK_HOST "localhost"
 #define DEFAULT_LOGBOOK_PORT 3306
 #define DEFAULT_LOGBOOK_DB "logbook"
 #define DEFAULT_LOGBOOK_USER "dqm"
-#define DEFAULT_LOGBOOK_PASS "nopass"
+#define DEFAULT_LOGBOOK_PASS "dqm123"
 
 namespace AliEventServerUtil
 {
index 2167f07..c519760 100644 (file)
@@ -131,7 +131,7 @@ void AliEventServerWindow::FillRunsFromDatabase()
   }
   TString sqlQuery;
   TTimeStamp ts;
-  sqlQuery.Form("SELECT run FROM logbook WHERE DAQ_time_start > %u AND DAQ_time_end IS NULL AND partition REGEXP 'PHYSICS.*'",
+  sqlQuery.Form("SELECT run FROM logbook WHERE DAQ_time_start > %u AND DAQ_time_end IS NULL AND `partition` REGEXP 'PHYSICS.*'",
     (UInt_t)ts.GetSec()-86400);
   TSQLResult* result = server->Query(sqlQuery);
   if (!result)
index 4dbbe3b..584d960 100644 (file)
@@ -40,6 +40,7 @@ AliRecoServerThread::AliRecoServerThread(zmq::context_t *context, AliReconstruct
 
 AliRecoServerThread::~AliRecoServerThread()
 {
+       Wait();
        Stop();
 }
 
@@ -93,9 +94,10 @@ void AliRecoServerThread::RunThrdWrite()
       }
                
       fReco->CleanProcessedEvent();
+      /*
       if(fCond->TimedWaitRelative(500)==0){
                                break;
-                       }                       
+                               }                       */
       iEvent++;
     }
     fReco->SlaveTerminate();
index 0933595..da80b89 100644 (file)
@@ -1,10 +1,10 @@
 server.host:                             tcp://*
 server.port:                             5024
-server.saveRecoDir:                       /home/user/reco
-cdb.defaultStorage:                      local:///local/cdb
-cdb.specificStoragePath1:                GRP/GRP/Data
+server.saveRecoDir:                      /opt/reco
+cdb.defaultStorage:                      local:///opt/OCDB/2013
+cdb.specificStoragePath1:                local:///opt/reco/GRP/GRP/Data
 cdb.specificStorageValue1:               
-cdb.specificStoragePath2:                GRP/CTP/Config
+cdb.specificStoragePath2:                local:///opt/reco/GRP/CTP/Config
 cdb.specificStorageValue2:               
 cdb.specificStoragePath3:                
 cdb.specificStorageValue3:               
@@ -15,8 +15,8 @@ reco.runPlaneEff:                        1
 reco.writeESDfriend:                     1
 reco.writeAlignment:                     1
 reco.cleanESD:                           0
-reco.detectors:                          ALL  -PHOS -EMCAL -HLT
-logbook.host:                            pcaldbl501
+reco.detectors:                          ALL  -PHOS -EMCAL
+logbook.host:                            localhost
 logbook.port:                            3306
 logbook.db:                              logbook
 logbook.user:                            dqm
diff --git a/STORAGE/AliStorageAdministratorPanel.cxx b/STORAGE/AliStorageAdministratorPanel.cxx
new file mode 100644 (file)
index 0000000..8f45604
--- /dev/null
@@ -0,0 +1,605 @@
+#include "AliStorageAdministratorPanel.h"
+#include "AliStorageAdministratorPanelMarkEvent.h"
+#include "AliStorageAdministratorPanelListEvents.h"
+#include "AliStorageAdministratorPanelSetStorageParams.h"
+#include "AliESDEvent.h"
+
+#include "zmq.hpp"
+#include "zhelpers.hpp"
+#include <fstream>
+
+#include <TGMenu.h>
+
+using namespace std;
+using namespace zmq;
+
+ClassImp(AliStorageAdministratorPanel);
+
+#define WINDOWS_WIDTH 500
+#define WINDOWS_HEIGHT 350
+
+enum TOOLBUTTON{
+       TOOLBUTTON_START=1,
+       TOOLBUTTON_STOP,
+       TOOLBUTTON_PREFERENCES,
+       TOOLBUTTON_EXIT         
+};
+
+enum MENUBAR{
+       MENUBAR_CLIENT_SET_PARAMS=1,
+       MENUBAR_SERVER_LIST_EVENTS,
+       MENUBAR_SERVER_MARK_EVENT,
+       MENUBAR_SERVER_GET_EVENT,
+       MENUBAR_SERVER_GET_NEXT_EVENT,
+       MENUBAR_SERVER_GET_LAST_EVENT
+};
+
+enum FRAME{
+       CLIENT_FRAME=1,
+       SERVER_FRAME
+};
+
+AliStorageAdministratorPanel::AliStorageAdministratorPanel() :
+       TGMainFrame(gClient->GetRoot(), 400, 400),
+       fPanelQuited(false),
+       fConnectionLabel(0),
+       fDataLabel(0),
+       fSavingLabel(0),
+       fCurrentSizeLabel(0),
+       fMaxSizeLabel(0),
+       fMaxOccupationLabel(0),
+       fRemoveEventsLabel(0),
+       fEventsInChunkLabel(0),
+       fMaxStorageSize(0),
+       fMaxOccupation(0),
+       fRemoveEvents(0),
+       fEventsInChunk(0),
+       fCommunicationThread(0),
+       fCommunicationContext(0),
+       fCommunicationSocket(0),
+       fStorageServer(""),
+       fServerContext(0),
+       fServerSocket(0),
+       fEventManager(0)
+{
+       InitWindow();
+
+    //read config file
+    TThread::Lock();
+       ifstream configFile (Form("%s/STORAGE/setupStorageDatabase.sh",
+                              gSystem->Getenv("ALICE_ROOT")));
+    
+       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_SERVER=")==0)
+                       {
+                               fStorageServer=line.substr(from,to-from);
+                       }
+               }
+               if(configFile.eof())
+               {
+                       configFile.clear();
+               }
+               configFile.close();
+       }
+       else
+       {
+               cout<<"ADMIN -- Unable to open config file"<<endl;
+       }
+       TThread::UnLock();
+    
+       //create event manager
+       fEventManager = new AliStorageEventManager();
+       
+       //start communication with server
+       fServerContext = new context_t(1);
+       fServerSocket = new socket_t(*fServerContext,ZMQ_REQ);
+       fServerSocket->connect(Form("tcp://%s:%d",fStorageServer.c_str(),gServerCommunicationPort));
+
+       
+       int linger = 0;
+       fServerSocket->setsockopt (ZMQ_LINGER, &linger, sizeof(linger));
+       
+       if(fServerSocket)
+       {
+               cout<<"\nADMIN -- Connected to server socket"<<endl;
+       }
+       else
+       {
+               cout<<"ADMIN -- ERROR - could not connect to server's socket"<<endl;
+       }
+
+       //start communication with client
+       fCommunicationContext = new context_t(1);
+       fCommunicationSocket = new socket_t(*fCommunicationContext,ZMQ_REQ);
+       fCommunicationSocket->connect(Form("tcp://%s:%d",fStorageServer.c_str(), gClientCommunicationPort));
+       if(fCommunicationSocket)
+       {
+               cout<<"\nADMIN -- Connected to client communication socket:"<<Form("tcp://%s:%d",fStorageServer.c_str(), gClientCommunicationPort)<<endl;
+       }
+       else
+       {
+               cout<<"ADMIN -- ERROR - could not connect to client's communication socket"<<endl;
+       }
+       fCommunicationThread = new TThread("fCommunicationThread",
+                                          AliStorageAdministratorPanel::CheckStateHandler,(void*)this);
+       fCommunicationThread->Run();
+       
+
+}
+
+AliStorageAdministratorPanel::~AliStorageAdministratorPanel()
+{
+       cout<<"ADMIN -- AliStorageAdministratorPanel descructor called";
+       cout<<" --- OK"<<endl;
+}
+
+void* AliStorageAdministratorPanel::CheckStateHandler(void *arg)//ask client about its state
+{
+       AliStorageAdministratorPanel *panelInstance = static_cast<AliStorageAdministratorPanel*>(arg);
+
+
+       while(!(panelInstance->fPanelQuited))
+       {
+               panelInstance->CheckClientState(REQUEST_CONNECTION);
+               sleep(1);
+               panelInstance->CheckClientState(REQUEST_RECEIVING);
+               sleep(1);
+               panelInstance->CheckClientState(REQUEST_SAVING);
+               sleep(1);
+               panelInstance->CheckClientState(REQUEST_CURRENT_SIZE);
+               sleep(1);
+               panelInstance->CheckClientState(REQUEST_GET_PARAMS);
+               sleep(1);
+       }
+       return NULL;
+}
+
+void AliStorageAdministratorPanel::CheckClientState(int option)
+{
+       pollitem_t items[1] =  {{*fCommunicationSocket,0,ZMQ_POLLIN,0}} ;
+
+       struct clientRequestStruct *request = new struct clientRequestStruct;
+       request->messageType = option;
+
+       char *buffer  = (char*)(request);
+       message_t *message = new message_t((void*)buffer,
+                                          sizeof(struct clientRequestStruct),0);
+       fCommunicationSocket->send(*message);
+       if(poll (&items[0], 1, 10000)==0)
+       {
+               SetLabel(fConnectionLabel,STATUS_DOWN);
+               SetLabel(fDataLabel,STATUS_DOWN);
+               SetLabel(fSavingLabel,STATUS_DOWN);
+               cout<<"ADMIN -- CLIENT IS DOWN"<<endl;
+       }
+
+       message_t *responseMessage = new message_t;
+       long response = -1;
+       fCommunicationSocket->recv(responseMessage);    
+       struct clientRequestStruct *responseParams = NULL;
+       if(option == REQUEST_GET_PARAMS)
+       {
+               responseParams = static_cast<struct clientRequestStruct*>(responseMessage->data());
+       }
+       else
+       {
+               response = atoi(static_cast<char*>(responseMessage->data()));
+       }
+       switch(option)
+       {
+       case REQUEST_CONNECTION:
+               SetLabel(fConnectionLabel,response);
+               break;
+       case REQUEST_RECEIVING:
+               SetLabel(fDataLabel,response);
+               break;
+       case REQUEST_SAVING:
+               SetLabel(fSavingLabel,response);
+               break;
+       case REQUEST_CURRENT_SIZE:
+               SetLabelValue(fCurrentSizeLabel,response,1);
+               break;
+       case REQUEST_GET_PARAMS:
+               fMaxStorageSize = responseParams->maxStorageSize;
+               fMaxOccupation = responseParams->maxOccupation;
+               fRemoveEvents = responseParams->removeEvents;
+               fEventsInChunk = responseParams->eventsInChunk;
+               
+               SetLabelValue(fMaxSizeLabel,fMaxStorageSize,1);
+               SetLabelValue(fMaxOccupationLabel,fMaxOccupation,2);
+               SetLabelValue(fRemoveEventsLabel,fRemoveEvents,2);
+               SetLabelValue(fEventsInChunkLabel,fEventsInChunk,3);
+               break;
+       default:break;  
+       }
+}
+
+void AliStorageAdministratorPanel::InitWindow()
+{
+       SetCleanup(kDeepCleanup);
+       // add main manubar on top of the window
+       SetupFixedMenuBar();
+       AddFrame(new TGHorizontal3DLine(this),
+                new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
+       // add toolbar with pictured buttons
+       /*SetupToolbar();
+       AddFrame(new TGHorizontal3DLine(this),
+                new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
+       // add dockable toolbar
+       SetupDockableMenuBar();
+       AddFrame(new TGHorizontal3DLine(this),
+                new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
+       */
+       
+       // add frame with two segments for client and server
+       SetupThreadsFrame();
+       SetWindowName("ALICE Storage Manager");
+       MapSubwindows();
+       Resize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
+       MapWindow();
+}
+
+void AliStorageAdministratorPanel::SetupThreadsFrame()
+{
+       // create frame for both client and server
+       TGHorizontalFrame *threadsFrame = new TGHorizontalFrame(this);
+
+       //create client frame and add components to it
+       TGCompositeFrame *clientThreadFrame = new TGCompositeFrame(threadsFrame,CLIENT_FRAME);
+       fConnectionLabel = new TGLabel(clientThreadFrame,"======Waiting======");
+       fDataLabel = new TGLabel(clientThreadFrame,"======Waiting======");
+       fSavingLabel = new TGLabel(clientThreadFrame,"======Waiting======");
+       fCurrentSizeLabel = new TGLabel(clientThreadFrame,"=========Waiting=========");
+       fMaxSizeLabel = new TGLabel(clientThreadFrame,"==========Waiting=========");
+       fMaxOccupationLabel = new TGLabel(clientThreadFrame,"==========Waiting=========");
+       fRemoveEventsLabel = new TGLabel(clientThreadFrame,"==========Waiting=========");
+       fEventsInChunkLabel = new TGLabel(clientThreadFrame,"==========Waiting=========");
+       
+       clientThreadFrame->AddFrame(new TGLabel(clientThreadFrame,
+                                               "ALICE Storage Client"),
+                                   new TGLayoutHints(kLHintsCenterX));
+
+       //connection label
+       clientThreadFrame->AddFrame(new TGLabel(clientThreadFrame,
+                                               "Connection:"),
+                                   new TGLayoutHints(kLHintsCenterX));
+       clientThreadFrame->AddFrame(fConnectionLabel,
+                                   new TGLayoutHints(kLHintsCenterX));
+
+       //data receiving label
+       clientThreadFrame->AddFrame(new TGLabel(clientThreadFrame,
+                                               "Receiving data:"),
+                                   new TGLayoutHints(kLHintsCenterX));
+       clientThreadFrame->AddFrame(fDataLabel,
+                                   new TGLayoutHints(kLHintsCenterX));
+
+       //saving label
+       clientThreadFrame->AddFrame(new TGLabel(clientThreadFrame,
+                                               "Saving:"),
+                                   new TGLayoutHints(kLHintsCenterX));
+       clientThreadFrame->AddFrame(fSavingLabel,
+                                   new TGLayoutHints(kLHintsCenterX));
+
+       //current size label
+       clientThreadFrame->AddFrame(new TGLabel(clientThreadFrame,
+                                               "Current storage size:"),
+                                   new TGLayoutHints(kLHintsCenterX));
+       clientThreadFrame->AddFrame(fCurrentSizeLabel,
+                                   new TGLayoutHints(kLHintsCenterX));
+
+       //max size label
+       clientThreadFrame->AddFrame(new TGLabel(clientThreadFrame,
+                                               "Max storage size:"),
+                                   new TGLayoutHints(kLHintsCenterX));
+       clientThreadFrame->AddFrame(fMaxSizeLabel,
+                                   new TGLayoutHints(kLHintsCenterX));
+
+       //max occupation label
+       clientThreadFrame->AddFrame(new TGLabel(clientThreadFrame,
+                                               "Max occupation percent:"),
+                                   new TGLayoutHints(kLHintsCenterX));
+       clientThreadFrame->AddFrame(fMaxOccupationLabel,
+                                   new TGLayoutHints(kLHintsCenterX));
+
+       //remove events label
+       clientThreadFrame->AddFrame(new TGLabel(clientThreadFrame,
+                                               "Remove events percentage:"),
+                                   new TGLayoutHints(kLHintsCenterX));
+       clientThreadFrame->AddFrame(fRemoveEventsLabel,
+                                   new TGLayoutHints(kLHintsCenterX));
+
+       //events in chunk label
+       clientThreadFrame->AddFrame(new TGLabel(clientThreadFrame,
+                                               "Number of events in chunk:"),
+                                   new TGLayoutHints(kLHintsCenterX));
+       clientThreadFrame->AddFrame(fEventsInChunkLabel,
+                                   new TGLayoutHints(kLHintsCenterX));
+
+       //create server frame and add components to it
+       TGCompositeFrame *serverThreadFrame = new TGCompositeFrame(threadsFrame,SERVER_FRAME);
+       serverThreadFrame->AddFrame(new TGLabel(serverThreadFrame,
+                                                "ALICE Storage Server"),
+                                    new TGLayoutHints(kLHintsCenterX));
+
+       //add client and server frames to threads frame
+       threadsFrame->AddFrame(clientThreadFrame,
+                               new TGLayoutHints(kLHintsLeft | kLHintsExpandX));
+       threadsFrame->AddFrame(new TGVertical3DLine(threadsFrame),
+                new TGLayoutHints(kLHintsNormal | kLHintsExpandY));
+       threadsFrame->AddFrame(serverThreadFrame,
+                               new TGLayoutHints(kLHintsRight | kLHintsExpandX));
+
+       //add threads frame to main window
+       AddFrame(threadsFrame,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
+}
+
+void AliStorageAdministratorPanel::SetupFixedMenuBar()
+{
+       //create popup menu for client
+       TGPopupMenu *clientPopup = new TGPopupMenu(fClient->GetRoot());
+       clientPopup->AddEntry("&Set storage params",MENUBAR_CLIENT_SET_PARAMS);
+       clientPopup->Associate(this);
+
+       //create popup menu for server
+       TGPopupMenu *serverPopup = new TGPopupMenu(fClient->GetRoot());
+       serverPopup->AddEntry("&Get Events List",MENUBAR_SERVER_LIST_EVENTS);
+       serverPopup->AddEntry("&Mark Event",MENUBAR_SERVER_MARK_EVENT);
+       serverPopup->AddEntry("&Get Event (test)",MENUBAR_SERVER_GET_EVENT);
+       serverPopup->AddEntry("&Get Next Event (test)",MENUBAR_SERVER_GET_NEXT_EVENT);
+       serverPopup->AddEntry("&Get Last Event (test)",MENUBAR_SERVER_GET_LAST_EVENT);
+       serverPopup->Associate(this);
+
+       //create menubar
+       TGMenuBar *menuBar = new TGMenuBar(this,1,1,kHorizontalFrame);
+       menuBar->AddPopup("&Client",clientPopup,
+                         new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
+       menuBar->AddPopup("&Server", serverPopup,
+                         new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
+
+       AddFrame(menuBar,new TGLayoutHints(kLHintsTop | kLHintsExpandX));
+}
+
+//handle GUI actions
+Bool_t AliStorageAdministratorPanel::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
+{
+       switch (GET_MSG(msg))
+       {
+
+       case kC_COMMAND:
+               switch (GET_SUBMSG(msg))
+               {
+               case kCM_BUTTON://when button is pressed
+                       break;
+               case kCM_MENUSELECT://when mouse is over menu entry
+                       break;
+               case kCM_MENU://when menu entry was clicked
+                       switch (parm1)
+                       {
+                       case MENUBAR_CLIENT_SET_PARAMS:onClientSetParams();break;
+                       case MENUBAR_SERVER_LIST_EVENTS:onServerListEvents();break;
+                       case MENUBAR_SERVER_MARK_EVENT:onServerMarkEvent();break;
+                       case MENUBAR_SERVER_GET_EVENT:onServerGetEvent();break;
+                       case MENUBAR_SERVER_GET_NEXT_EVENT:onServerGetNextEvent();break;
+                       case MENUBAR_SERVER_GET_LAST_EVENT:onServerGetLastEvent();break;
+                       default:break;
+                       }
+                       break;
+               default:break;
+               }
+               break;
+       default:break;
+       }
+
+       return false;
+}
+
+void AliStorageAdministratorPanel::onServerListEvents()
+{
+       AliStorageAdministratorPanelListEvents *listEventsWindow =
+               AliStorageAdministratorPanelListEvents::GetInstance();
+
+       listEventsWindow->SetSocket(fServerSocket);
+}
+
+void AliStorageAdministratorPanel::onServerMarkEvent()
+{
+       AliStorageAdministratorPanelMarkEvent *markEventWindow =
+               AliStorageAdministratorPanelMarkEvent::GetInstance();
+
+       markEventWindow->SetSocket(fServerSocket);
+}
+
+void AliStorageAdministratorPanel::onClientSetParams()
+{
+       AliStorageAdministratorPanelSetStorageParams *setParamsWindow =
+               AliStorageAdministratorPanelSetStorageParams::GetInstance();
+
+       setParamsWindow->Setup(fCommunicationSocket,
+                              fMaxStorageSize/1000000,
+                              fMaxOccupation,
+                              fRemoveEvents,
+                              fEventsInChunk);
+}
+
+void AliStorageAdministratorPanel::onServerGetEvent()
+{
+       //this method is just for tests
+       int runNumber=197669;
+       int eventNumber=168;
+       
+       struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
+       struct eventStruct mark;
+       mark.runNumber = runNumber;
+       mark.eventNumber = eventNumber;
+       requestMessage->messageType = REQUEST_GET_EVENT;
+       requestMessage->event = mark;
+
+       fEventManager->Send(requestMessage,fServerSocket);
+       AliESDEvent *resultEvent = fEventManager->GetEvent(fServerSocket);
+       
+       if(resultEvent)
+       {
+               cout<<"ADMIN -- received event. Run no:"<<resultEvent->GetRunNumber()<<"\tEvent no in file:"<<resultEvent->GetEventNumberInFile()<<endl;
+       }
+       else
+       {
+               cout<<"ADMIN -- received no event"<<endl;
+       }
+}
+
+
+void AliStorageAdministratorPanel::onServerGetNextEvent()
+{
+       //this method is just for tests
+       int runNumber=197669;
+       int eventNumber=33;
+       
+       struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
+       struct eventStruct mark;
+       mark.runNumber = runNumber;
+       mark.eventNumber = eventNumber;
+       requestMessage->messageType = REQUEST_GET_NEXT_EVENT;
+       requestMessage->event = mark;
+
+       fEventManager->Send(requestMessage,fServerSocket);
+       AliESDEvent* resultEvent= fEventManager->GetEvent(fServerSocket);       
+       if(resultEvent)
+       {
+               cout<<"ADMIN -- received event. Run no:"<<resultEvent->GetRunNumber()<<"\tEvent no in file:"<<resultEvent->GetEventNumberInFile()<<endl;
+       }
+       else
+       {
+               cout<<"ADMIN -- received no event"<<endl;
+       }
+}
+
+
+void AliStorageAdministratorPanel::onServerGetLastEvent()
+{      
+       struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
+       requestMessage->messageType = REQUEST_GET_LAST_EVENT;
+
+       fEventManager->Send(requestMessage,fServerSocket);
+       AliESDEvent* resultEvent= fEventManager->GetEvent(fServerSocket);
+
+       if(resultEvent)
+       {
+               cout<<"ADMIN -- received event. Run no:"<<resultEvent->GetRunNumber()<<"\tEvent no in file:"<<resultEvent->GetEventNumberInFile()<<endl;
+       }
+       else
+       {
+               cout<<"ADMIN -- received no event"<<endl;
+       }
+}
+
+void AliStorageAdministratorPanel::onExit()
+{
+       cout<<"ADMIN -- Quiting ALICE Storage Admin Panel"<<endl;
+       fPanelQuited=true;
+       gSystem->ExitLoop();
+}
+
+void AliStorageAdministratorPanel::CloseWindow(){onExit();}
+
+
+//methods to change labels:
+void AliStorageAdministratorPanel::SetLabel(TGLabel *label, int option)
+{
+       switch(option)
+       {
+       case STATUS_WAITING:
+               label->SetText("Waiting");
+               label->SetTextColor(kBlack);
+               break;
+       case STATUS_OK:
+               label->SetText("OK");
+               label->SetTextColor(kBlack);
+               break;
+       case STATUS_ERROR:
+               label->SetText("ERROR");
+               label->SetTextColor(kBlack);
+               break;
+       case STATUS_DOWN:
+               label->SetText("CLIENT IS DOWN");
+               label->SetTextColor(kRed);
+               break;
+       default:break;
+       }
+       gClient->HandleInput();
+}
+
+void AliStorageAdministratorPanel::SetLabelValue(TGLabel *label, long value,int option)
+{
+       // options:
+       // 1 - MB
+       // 2 - percentage
+       // 3 - number
+
+       switch(option)
+       {
+       case 1:
+               label->SetText(Form("%lu B (%.2f MB)",value,(float)value/(1000.*1000.)));
+               break;
+       case 2:
+               label->SetText(Form("%d %%",(int)value));
+               break;
+       case 3:
+               label->SetText(Form("%d",(int)value));
+               break;
+       default:break;
+       }
+               label->SetTextColor(kBlack);
+       gClient->HandleInput();
+}
+//other methods that can be useful later
+
+/*
+void AliStorageAdministratorPanel::SetupToolbar()
+{
+       TGToolBar* toolBar = new TGToolBar(this);
+       toolBar->AddButton(this,new TGPictureButton(toolBar,
+                                                    Form("%s/MONITOR/icons/start.png",
+                                                    gSystem->Getenv("ALICE_ROOT")),
+                                                    TOOLBUTTON_START ) );
+       toolBar->AddButton(this, new TGPictureButton(toolBar,
+                                                     Form("%s/MONITOR/icons/stop.png",
+                                                     gSystem->Getenv("ALICE_ROOT")),
+                                                     TOOLBUTTON_STOP) ); 
+       
+       AddFrame(toolBar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
+}
+
+void AliStorageAdministratorPanel::SetupDockableMenuBar()
+{
+       TGDockableFrame *menuDock = new TGDockableFrame(this);
+       AddFrame(menuDock,new TGLayoutHints(kLHintsExpandX,0,0,1,0));
+       menuDock->SetWindowName("ALICE Storage Dockable  MenuBar");
+       menuDock->EnableUndock(kTRUE);
+       menuDock->EnableHide(kTRUE);
+
+       TGPopupMenu *popup1 = new TGPopupMenu(fClient->GetRoot());
+       popup1->AddEntry("&Check client state",MENUBAR_1_OPTION_1);
+       popup1->AddSeparator();
+       popup1->AddEntry("&BBB",MENUBAR_1_OPTION_2);
+       popup1->AddEntry("&CCC",MENUBAR_1_OPTION_3);
+
+       popup1->DisableEntry(MENUBAR_1_OPTION_2);
+       popup1->Associate(this);
+
+       
+       TGMenuBar *menuBar = new TGMenuBar(menuDock,1,1,kHorizontalFrame);
+       menuBar->AddPopup("&File",
+                         popup1,
+                         new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
+
+       menuDock->AddFrame(menuBar,
+                          new TGLayoutHints(kLHintsTop | kLHintsExpandX));
+                          }*/
diff --git a/STORAGE/AliStorageAdministratorPanel.h b/STORAGE/AliStorageAdministratorPanel.h
new file mode 100644 (file)
index 0000000..4bdaf8b
--- /dev/null
@@ -0,0 +1,86 @@
+#ifndef AliStorageAdministratorPanel_H
+#define AliStorageAdministratorPanel_H
+
+#include "AliStorageEventManager.h"
+
+namespace zmq
+{
+       class context_t;
+       class socket_t;
+}
+
+#include <TGFrame.h>
+#include <TGLabel.h>
+#include <TThread.h>
+
+class AliStorageAdministratorPanel : public TGMainFrame
+{
+
+public:
+       AliStorageAdministratorPanel();
+       virtual ~AliStorageAdministratorPanel();
+private:
+       bool fPanelQuited;
+       
+       //gui components and methods
+       TGLabel *fConnectionLabel;
+       TGLabel *fDataLabel;
+       TGLabel *fSavingLabel;
+       TGLabel *fCurrentSizeLabel;
+       TGLabel *fMaxSizeLabel;
+       TGLabel *fMaxOccupationLabel;
+       TGLabel *fRemoveEventsLabel;
+       TGLabel *fEventsInChunkLabel;
+       
+       void InitWindow();
+       void SetupThreadsFrame();
+       void SetupToolbar();
+       void SetupFixedMenuBar();
+       void SetupDockableMenuBar();
+
+       //set labels method
+       void SetLabel(TGLabel *label, int option);
+       void SetLabelValue(TGLabel *label, long value, int option);
+       
+       //handle different actions
+       void onExit();
+       void onOption1();
+       void onOption2();
+       void onOption3();
+
+       void onServerListEvents();
+       void onServerMarkEvent();
+       void onServerGetEvent();
+       void onClientSetParams();
+       void onServerGetNextEvent();
+       void onServerGetLastEvent();
+
+       //client params
+       int fMaxStorageSize;
+       int fMaxOccupation;
+       int fRemoveEvents;
+       int fEventsInChunk;
+       
+       //handle different messages
+       virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t);
+       void CloseWindow();
+        
+       //socket connection
+       TThread *fCommunicationThread;
+       zmq::context_t *fCommunicationContext;
+       zmq::socket_t *fCommunicationSocket;
+       std::string fStorageServer;
+       static void* CheckStateHandler(void *arg);
+       void CheckClientState(int option);
+       
+       zmq::context_t *fServerContext;
+       zmq::socket_t *fServerSocket;//socket for two-way communication with AliStorageServerThread
+       AliStorageEventManager *fEventManager;
+
+       AliStorageAdministratorPanel(const AliStorageAdministratorPanel&);
+       AliStorageAdministratorPanel& operator=(const AliStorageAdministratorPanel&);
+       
+       ClassDef(AliStorageAdministratorPanel,0);
+};
+
+#endif
diff --git a/STORAGE/AliStorageAdministratorPanelListEvents.cxx b/STORAGE/AliStorageAdministratorPanelListEvents.cxx
new file mode 100644 (file)
index 0000000..e0998ec
--- /dev/null
@@ -0,0 +1,369 @@
+#include "AliStorageAdministratorPanelListEvents.h"
+
+#include <iostream>
+#include <sstream>
+#include <vector>
+
+#include <TG3DLine.h>
+#include <TGButton.h>
+#include <TGFrame.h>
+
+#include "zmq.hpp"
+
+using namespace std;
+using namespace zmq;
+
+AliStorageAdministratorPanelListEvents *AliStorageAdministratorPanelListEvents::fInstance=0;
+
+ClassImp(AliStorageAdministratorPanelListEvents);
+
+#define WINDOWS_WIDTH 400
+#define WINDOWS_HEIGHT 500
+
+enum BUTTON{
+       BUTTON_CLOSE=1,
+       BUTTON_GET_LIST,
+       BUTTON_CHECK_PP,
+       BUTTON_CHECK_PBPB,
+       BUTTON_CHECK_TEMP,
+       BUTTON_CHECK_PERM,
+       BUTTON_MARK_EVENT
+};
+
+enum TEXTENTRY{
+       TEXTENTRY_RUN_MIN=1,
+       TEXTENTRY_RUN_MAX,
+       TEXTENTRY_EVENT_MIN,
+       TEXTENTRY_EVENT_MAX,
+       TEXTENTRY_MULTIPLICITY_MIN,
+       TEXTENTRY_MULTIPLICITY_MAX
+};
+
+AliStorageAdministratorPanelListEvents::AliStorageAdministratorPanelListEvents() :
+       TGMainFrame(gClient->GetRoot(),400,400),
+       fStatusLabel(0),
+       fRunNumberMinEntry(0),
+       fRunNumberMaxEntry(0),
+       fEventNumberMinEntry(0),
+       fEventNumberMaxEntry(0),
+       fMultiplicityMinEntry(0),
+       fMultiplicityMaxEntry(0),
+       fProtonProtonCheckButton(0),
+       fLeadLeadCheckButton(0),
+       fTempCheckButton(0),
+       fPermCheckButton(0),
+       fEventsList(0),
+       fEventsListVector(0),
+       fServerSocket(0),
+       fEventManager(0)
+{
+       fEventManager = new AliStorageEventManager();
+       InitWindow();
+}
+
+AliStorageAdministratorPanelListEvents::~AliStorageAdministratorPanelListEvents()
+{
+       cout<<"ADMIN PANEL -- List events descructor called";
+//     DestroyWindow();
+       cout<<" --- OK"<<endl;
+}
+
+AliStorageAdministratorPanelListEvents* AliStorageAdministratorPanelListEvents::GetInstance()
+{
+       if(!fInstance){fInstance = new AliStorageAdministratorPanelListEvents();}
+       return fInstance;
+}
+
+void AliStorageAdministratorPanelListEvents::SetSocket(socket_t *socket)
+{
+       fServerSocket = socket;
+}
+
+void AliStorageAdministratorPanelListEvents::InitWindow()
+{
+       SetCleanup(kDeepCleanup);
+       
+       //min run number
+       AddFrame(new TGLabel(this,"Minimum run number:"),new TGLayoutHints(kLHintsLeft));
+
+       fRunNumberMinEntry = new TGNumberEntry(this,
+                                           0,
+                                           6,
+                                           TEXTENTRY_RUN_MIN,
+                                           TGNumberFormat::kNESInteger,
+                                           TGNumberFormat::kNEAPositive,
+                                           TGNumberFormat::kNELNoLimits);
+       AddFrame(fRunNumberMinEntry,new TGLayoutHints(kLHintsLeft));
+
+       //max run number
+       AddFrame(new TGLabel(this,"Maximum run number:"),new TGLayoutHints(kLHintsLeft));
+
+       fRunNumberMaxEntry = new TGNumberEntry(this,
+                                           999999,
+                                           6,
+                                           TEXTENTRY_RUN_MAX,
+                                           TGNumberFormat::kNESInteger,
+                                           TGNumberFormat::kNEAPositive,
+                                           TGNumberFormat::kNELNoLimits);
+       AddFrame(fRunNumberMaxEntry,new TGLayoutHints(kLHintsLeft));
+
+       //min event number
+       AddFrame(new TGLabel(this,"Minimum event number:"),new TGLayoutHints(kLHintsLeft));
+
+       fEventNumberMinEntry = new TGNumberEntry(this,
+                                             0,
+                                             6,
+                                             TEXTENTRY_EVENT_MIN,
+                                             TGNumberFormat::kNESInteger,
+                                             TGNumberFormat::kNEAPositive,
+                                             TGNumberFormat::kNELNoLimits);
+       AddFrame(fEventNumberMinEntry,new TGLayoutHints(kLHintsLeft));  
+
+       //max event number
+       AddFrame(new TGLabel(this,"Maximum event number:"),new TGLayoutHints(kLHintsLeft));
+
+       fEventNumberMaxEntry = new TGNumberEntry(this,
+                                             99999,
+                                             6,
+                                             TEXTENTRY_EVENT_MAX,
+                                             TGNumberFormat::kNESInteger,
+                                             TGNumberFormat::kNEAPositive,
+                                             TGNumberFormat::kNELNoLimits);
+       AddFrame(fEventNumberMaxEntry,new TGLayoutHints(kLHintsLeft));  
+
+       //min multiplicity
+       AddFrame(new TGLabel(this,"Minimum multiplicity:"),new TGLayoutHints(kLHintsLeft));
+
+       fMultiplicityMinEntry = new TGNumberEntry(this,
+                                             0,
+                                             6,
+                                             TEXTENTRY_MULTIPLICITY_MIN,
+                                             TGNumberFormat::kNESInteger,
+                                             TGNumberFormat::kNEAPositive,
+                                             TGNumberFormat::kNELNoLimits);
+       AddFrame(fMultiplicityMinEntry,new TGLayoutHints(kLHintsLeft)); 
+
+       //max multiplicity
+       AddFrame(new TGLabel(this,"Maximum multiplicity:"),new TGLayoutHints(kLHintsLeft));
+
+       fMultiplicityMaxEntry = new TGNumberEntry(this,
+                                             9999,
+                                             6,
+                                             TEXTENTRY_MULTIPLICITY_MAX,
+                                             TGNumberFormat::kNESInteger,
+                                             TGNumberFormat::kNEAPositive,
+                                             TGNumberFormat::kNELNoLimits);
+       AddFrame(fMultiplicityMaxEntry,new TGLayoutHints(kLHintsLeft)); 
+
+       //p-p check button
+       AddFrame(new TGLabel(this,"System:"),new TGLayoutHints(kLHintsLeft));
+       fProtonProtonCheckButton = new TGCheckButton(this,"p-p",BUTTON_CHECK_PP);
+       fProtonProtonCheckButton->SetOn();
+       AddFrame(fProtonProtonCheckButton,new TGLayoutHints(kLHintsLeft));
+
+       //Pb-Pb check button
+       fLeadLeadCheckButton = new TGCheckButton(this,"Pb-Pb",BUTTON_CHECK_PBPB);
+       fLeadLeadCheckButton->SetOn();
+       AddFrame(fLeadLeadCheckButton,new TGLayoutHints(kLHintsLeft));
+
+       //temp check button
+       AddFrame(new TGLabel(this,"Storage type:"),new TGLayoutHints(kLHintsLeft));
+       fTempCheckButton = new TGCheckButton(this,"Temporary",BUTTON_CHECK_TEMP);
+       fTempCheckButton->SetOn();
+       AddFrame(fTempCheckButton,new TGLayoutHints(kLHintsLeft));
+
+       //perm check button
+       fPermCheckButton = new TGCheckButton(this,"Permanent",BUTTON_CHECK_PERM);
+       fPermCheckButton->SetOn();
+       AddFrame(fPermCheckButton,new TGLayoutHints(kLHintsLeft));
+       
+       // status label
+       fStatusLabel = new TGLabel(this,"");
+       AddFrame(fStatusLabel,new TGLayoutHints(kLHintsExpandX | kLHintsLeft));
+
+       //buttons
+       AddFrame(new TGTextButton(this,"Close",BUTTON_CLOSE),
+                new TGLayoutHints(kLHintsLeft));
+
+       AddFrame(new TGTextButton(this,"Get event's list",BUTTON_GET_LIST),
+                new TGLayoutHints(kLHintsRight));
+
+       AddFrame(new TGTextButton(this,"Mark selected event",BUTTON_MARK_EVENT),
+                new TGLayoutHints(kLHintsRight));
+
+
+       //event's list
+       fEventsList = new TGListBox(this,0);
+       fEventsList->AddEntry(new TGString("Run   Event   System   Mult   Marked"),0);
+       AddFrame(fEventsList,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
+       
+       SetWindowName("List Events");
+       MapSubwindows();
+       Resize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
+       MapWindow();
+}
+
+
+
+
+void AliStorageAdministratorPanelListEvents::onGetListButton()
+{
+//prepare and send request message
+       struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
+       struct listRequestStruct list; 
+
+       //get listing parameters from somwhere
+       list.runNumber[0]=fRunNumberMinEntry->GetIntNumber();
+       list.runNumber[1]=fRunNumberMaxEntry->GetIntNumber();
+       list.eventNumber[0]=fEventNumberMinEntry->GetIntNumber();
+       list.eventNumber[1]=fEventNumberMaxEntry->GetIntNumber();
+       if(fTempCheckButton->GetState()==1)
+       {
+               list.marked[0]=0;
+       }
+       else
+       {
+               list.marked[0]=-1;
+       }
+       if(fPermCheckButton->GetState()==1)
+       {
+               list.marked[1]=1;
+       }
+       else
+       {
+               list.marked[1]=-1;
+       }
+       list.multiplicity[0]=fMultiplicityMinEntry->GetIntNumber();
+       list.multiplicity[1]=fMultiplicityMaxEntry->GetIntNumber();
+       if(fProtonProtonCheckButton->GetState()==1)
+       {
+               strcpy(list.system[0],"p-p");
+       }
+       else
+       {
+               strcpy(list.system[0],"");
+       }
+       if(fLeadLeadCheckButton->GetState()==1)
+       {
+               strcpy(list.system[1],"Pb-Pb");
+       }
+       else
+       {
+               strcpy(list.system[1],"");
+       }
+       
+       requestMessage->messageType = REQUEST_LIST_EVENTS;
+       requestMessage->list = list;
+
+       fEventManager->Send(requestMessage,fServerSocket);
+
+       fEventsList->RemoveAll();
+       fEventsList->AddEntry(new TGString("Run   Event   System   Mult   Marked"),0);
+       
+       vector<serverListStruct> receivedList = fEventManager->GetServerListVector(fServerSocket);
+       
+       cout<<"PANEL:"<<receivedList[0].runNumber<<endl;        
+       cout<<"VECTOR SIZE:"<<receivedList.size()<<endl;
+       
+//do something with list of maching events
+       cout<<"Received list of perm events"<<endl;
+
+       for(unsigned int i=0;i<receivedList.size();i++)
+       {
+               fEventsList->InsertEntry(Form("%d   %d   %s   %d   %d   ",
+                                             receivedList[i].runNumber,
+                                             receivedList[i].eventNumber,
+                                             receivedList[i].system,
+                                             receivedList[i].multiplicity,
+                                             receivedList[i].marked),i+1,i);
+
+               cout<<receivedList[i].runNumber<<receivedList[i].eventNumber<<endl;
+       
+       }
+
+       fEventsListVector = receivedList;
+       
+       gClient->HandleInput();
+       gClient->NeedRedraw(fEventsList, kTRUE);
+       gClient->HandleInput();
+       MapSubwindows();
+       MapWindow();
+       Layout();
+}
+
+
+void AliStorageAdministratorPanelListEvents::onMarkButton()
+{
+       int runNumber;
+       int eventNumber;
+
+       //get run and event number from selected row
+       int selectedEventNumber = fEventsList->GetSelected()-1;
+
+       cout<<"SELECTED:"<<selectedEventNumber<<endl;
+       
+       if(selectedEventNumber<0)return;
+       
+       runNumber=fEventsListVector[selectedEventNumber].runNumber;
+       eventNumber=fEventsListVector[selectedEventNumber].eventNumber;
+       
+       struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
+       struct eventStruct mark;
+       mark.runNumber = runNumber;
+       mark.eventNumber = eventNumber;
+       requestMessage->messageType = REQUEST_MARK_EVENT;
+       requestMessage->event = mark;
+
+       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))
+       {
+               fStatusLabel->SetText("Event marked");
+               cout<<"ADMIN PANEL -- Event marked succesfully"<<endl;
+       }
+       else
+       {
+               fStatusLabel->SetText("Couldn't mark this event");
+               cout<<"ADMIN PANEL -- Could not matk event"<<endl;
+       }
+}
+
+void AliStorageAdministratorPanelListEvents::onCloseButton(){onExit();}
+void AliStorageAdministratorPanelListEvents::CloseWindow(){onExit();}
+
+void AliStorageAdministratorPanelListEvents::onExit()
+{
+       cout<<"Quiting list events";
+       if(fInstance){delete fInstance;fInstance=0;}
+       cout<<" -- OK"<<endl;
+}
+
+Bool_t AliStorageAdministratorPanelListEvents::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
+{
+       switch (GET_MSG(msg))
+       {
+       case kC_COMMAND:
+               switch (GET_SUBMSG(msg))
+               {
+               case kCM_BUTTON:
+                       switch(parm1)
+                       {
+                       case BUTTON_CLOSE:onCloseButton();break;
+                       case BUTTON_GET_LIST:onGetListButton();break;
+                       case BUTTON_MARK_EVENT:onMarkButton();break;
+                       default:break;
+                       }
+                       break;
+               default:break;
+               }
+               break;
+       default:break;
+       }
+
+       return false;
+}
diff --git a/STORAGE/AliStorageAdministratorPanelListEvents.h b/STORAGE/AliStorageAdministratorPanelListEvents.h
new file mode 100644 (file)
index 0000000..11d7fd0
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef AliStorageAdministratorPanelListEvents_H
+#define AliStorageAdministratorPanelListEvents_H
+
+#include "AliStorageTypes.h"
+#include "AliStorageEventManager.h"
+
+#include <TGLabel.h>
+#include <TGNumberEntry.h>
+#include <TGListBox.h>
+
+namespace zmq
+{
+       class socket_t;
+}
+
+class AliStorageAdministratorPanelListEvents : public TGMainFrame
+{
+public:
+       static AliStorageAdministratorPanelListEvents* GetInstance();
+       void SetSocket(zmq::socket_t *socket);
+private:
+       AliStorageAdministratorPanelListEvents();
+       virtual ~AliStorageAdministratorPanelListEvents();
+       
+       static AliStorageAdministratorPanelListEvents *fInstance;
+       
+       //gui components and methods
+       TGLabel *fStatusLabel;
+       TGNumberEntry *fRunNumberMinEntry;
+       TGNumberEntry *fRunNumberMaxEntry;
+       TGNumberEntry *fEventNumberMinEntry;
+       TGNumberEntry *fEventNumberMaxEntry;
+       TGNumberEntry *fMultiplicityMinEntry;
+       TGNumberEntry *fMultiplicityMaxEntry;
+
+       TGCheckButton *fProtonProtonCheckButton;
+       TGCheckButton *fLeadLeadCheckButton;
+       TGCheckButton *fTempCheckButton;
+       TGCheckButton *fPermCheckButton;
+       
+       TGListBox *fEventsList;
+       
+       void InitWindow();
+       void onCloseButton();
+       void onGetListButton();
+       void onMarkButton();
+       void onExit();
+
+       std::vector<serverListStruct> fEventsListVector;
+
+       virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t);
+       void CloseWindow();
+
+       zmq::socket_t *fServerSocket;
+       AliStorageEventManager *fEventManager;
+       
+       AliStorageAdministratorPanelListEvents(const AliStorageAdministratorPanelListEvents&);
+       AliStorageAdministratorPanelListEvents& operator=(const AliStorageAdministratorPanelListEvents&);
+       
+       ClassDef(AliStorageAdministratorPanelListEvents,0);
+};
+
+#endif
diff --git a/STORAGE/AliStorageAdministratorPanelMarkEvent.cxx b/STORAGE/AliStorageAdministratorPanelMarkEvent.cxx
new file mode 100644 (file)
index 0000000..2912055
--- /dev/null
@@ -0,0 +1,175 @@
+#include "AliStorageAdministratorPanelMarkEvent.h"
+#include "AliStorageTypes.h"
+
+#include <iostream>
+#include "zmq.hpp"
+
+#include <TGFrame.h>
+#include <TGButton.h>
+
+using namespace std;
+using namespace zmq;
+
+AliStorageAdministratorPanelMarkEvent *AliStorageAdministratorPanelMarkEvent::fInstance=0;
+
+ClassImp(AliStorageAdministratorPanelMarkEvent);
+
+#define WINDOWS_WIDTH 200
+#define WINDOWS_HEIGHT 200
+
+enum BUTTON{
+       BUTTON_CLOSE=1,
+       BUTTON_MARK     
+};
+
+enum TEXTENTRY{
+       TEXTENTRY_RUN=1,
+       TEXTENTRY_EVENT
+};
+
+AliStorageAdministratorPanelMarkEvent::AliStorageAdministratorPanelMarkEvent() :
+       TGMainFrame(gClient->GetRoot(), 400, 400),
+       fStatusLabel(0),
+       fRunNumberEntry(0),
+       fEventNumberEntry(0),
+       fServerSocket(0),
+       fEventManager(0)
+{
+       fEventManager = new AliStorageEventManager();
+       InitWindow();
+}
+
+AliStorageAdministratorPanelMarkEvent::~AliStorageAdministratorPanelMarkEvent()
+{
+       cout<<"ADMIN PANEL -- Mark Window descructor called";
+//     if(fStatusLabel)delete fStatusLabel;
+//     if(fRunNumberEntry)delete fRunNumberEntry;
+//     if(fEventNumberEntry)delete fEventNumberEntry;
+       //if(fServerSocket)delete fServerSocket;
+//     DestroyWindow();
+       cout<<" --- OK"<<endl;
+}
+
+AliStorageAdministratorPanelMarkEvent* AliStorageAdministratorPanelMarkEvent::GetInstance()
+{
+       if(!fInstance){fInstance = new AliStorageAdministratorPanelMarkEvent();}
+       return fInstance;
+}
+
+void AliStorageAdministratorPanelMarkEvent::SetSocket(socket_t *socket)
+{
+       fServerSocket = socket;
+}
+
+void AliStorageAdministratorPanelMarkEvent::InitWindow()
+{
+       SetCleanup(kDeepCleanup);
+       
+       AddFrame(new TGLabel(this,"Run number:"),new TGLayoutHints(kLHintsLeft));
+
+       fRunNumberEntry = new TGNumberEntry(this,
+                                           0,
+                                           6,
+                                           TEXTENTRY_RUN,
+                                           TGNumberFormat::kNESInteger,
+                                           TGNumberFormat::kNEAPositive,
+                                           TGNumberFormat::kNELNoLimits);
+       AddFrame(fRunNumberEntry,new TGLayoutHints(kLHintsLeft));
+
+       AddFrame(new TGLabel(this,"Event number:"),new TGLayoutHints(kLHintsLeft));
+
+       fEventNumberEntry = new TGNumberEntry(this,
+                                             0,
+                                             6,
+                                             TEXTENTRY_EVENT,
+                                             TGNumberFormat::kNESInteger,
+                                             TGNumberFormat::kNEAPositive,
+                                             TGNumberFormat::kNELNoLimits);
+       AddFrame(fEventNumberEntry,new TGLayoutHints(kLHintsLeft));     
+
+       fStatusLabel = new TGLabel(this,"");
+       AddFrame(fStatusLabel,new TGLayoutHints(kLHintsExpandX | kLHintsLeft));
+
+       AddFrame(new TGTextButton(this,"Close",BUTTON_CLOSE),
+                new TGLayoutHints(kLHintsLeft));
+
+       AddFrame(new TGTextButton(this,"Mark event",BUTTON_MARK),
+                new TGLayoutHints(kLHintsRight));
+
+       
+       SetWindowName("Mark Event");
+       MapSubwindows();
+       Resize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
+       MapWindow();
+}
+
+
+
+
+void AliStorageAdministratorPanelMarkEvent::onMarkButton()
+{
+       int runNumber;
+       int eventNumber;
+
+       //get run and event number from TGNumberEntries
+       runNumber=fRunNumberEntry->GetIntNumber();
+       eventNumber=fEventNumberEntry->GetIntNumber();
+       
+       struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
+       struct eventStruct mark;
+       mark.runNumber = runNumber;
+       mark.eventNumber = eventNumber;
+       requestMessage->messageType = REQUEST_MARK_EVENT;
+       requestMessage->event = mark;
+
+       fEventManager->Send(requestMessage,fServerSocket);
+
+       message_t *response = new message_t();
+       fServerSocket->recv(response);
+       char *result = (char*)response->data();
+       
+       if(!strcmp("true",result))
+       {
+               fStatusLabel->SetText("Event marked");
+               cout<<"ADMIN PANEL -- Event marked succesfully"<<endl;
+       }
+       else
+       {
+               fStatusLabel->SetText("Couldn't mark this event");
+               cout<<"ADMIN PANEL -- Could not matk event"<<endl;
+       }
+}
+
+void AliStorageAdministratorPanelMarkEvent::onCloseButton(){onExit();}
+void AliStorageAdministratorPanelMarkEvent::CloseWindow(){onExit();}
+
+void AliStorageAdministratorPanelMarkEvent::onExit()
+{
+       cout<<"Quiting mark event";
+       if(fInstance){delete fInstance;fInstance=0;}
+       cout<<" -- OK"<<endl;
+}
+
+Bool_t AliStorageAdministratorPanelMarkEvent::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
+{
+       switch (GET_MSG(msg))
+       {
+       case kC_COMMAND:
+               switch (GET_SUBMSG(msg))
+               {
+               case kCM_BUTTON:
+                       switch(parm1)
+                       {
+                       case BUTTON_CLOSE:onCloseButton();break;
+                       case BUTTON_MARK:onMarkButton();break;
+                       default:break;
+                       }
+                       break;
+               default:break;
+               }
+               break;
+       default:break;
+       }
+
+       return false;
+}
diff --git a/STORAGE/AliStorageAdministratorPanelMarkEvent.h b/STORAGE/AliStorageAdministratorPanelMarkEvent.h
new file mode 100644 (file)
index 0000000..f7ca2de
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef AliStorageAdministratorPanelMarkEvent_H
+#define AliStorageAdministratorPanelMarkEvent_H
+
+#include "AliStorageEventManager.h"
+
+#include <TGLabel.h>
+#include <TGNumberEntry.h>
+#include <TG3DLine.h>
+
+namespace zmq
+{
+       class socket_t;
+}
+
+class AliStorageAdministratorPanelMarkEvent : public TGMainFrame
+{
+public:
+       static AliStorageAdministratorPanelMarkEvent* GetInstance();
+       void SetSocket(zmq::socket_t *socket);
+private:
+       AliStorageAdministratorPanelMarkEvent();
+       virtual ~AliStorageAdministratorPanelMarkEvent();
+
+       static AliStorageAdministratorPanelMarkEvent *fInstance;
+       
+       //gui components and methods
+       TGLabel *fStatusLabel;
+       TGNumberEntry *fRunNumberEntry;
+       TGNumberEntry *fEventNumberEntry;
+       
+       void InitWindow();
+       void onCloseButton();
+       void onMarkButton();
+       void onExit();
+
+       virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t);
+       void CloseWindow();
+
+       zmq::socket_t *fServerSocket;
+       AliStorageEventManager *fEventManager;
+       
+       AliStorageAdministratorPanelMarkEvent(const AliStorageAdministratorPanelMarkEvent&);
+       AliStorageAdministratorPanelMarkEvent& operator=(const AliStorageAdministratorPanelMarkEvent&);
+       
+       ClassDef(AliStorageAdministratorPanelMarkEvent,0);
+};
+
+#endif
diff --git a/STORAGE/AliStorageAdministratorPanelSetStorageParams.cxx b/STORAGE/AliStorageAdministratorPanelSetStorageParams.cxx
new file mode 100644 (file)
index 0000000..be03676
--- /dev/null
@@ -0,0 +1,196 @@
+#include "AliStorageAdministratorPanelSetStorageParams.h"
+#include "AliStorageTypes.h"
+
+#include <iostream>
+#include "zmq.hpp"
+
+#include <TGFrame.h>
+#include <TGButton.h>
+
+using namespace std;
+using namespace zmq;
+
+AliStorageAdministratorPanelSetStorageParams *AliStorageAdministratorPanelSetStorageParams::fInstance=0;
+
+ClassImp(AliStorageAdministratorPanelSetStorageParams);
+
+#define WINDOWS_WIDTH 200
+#define WINDOWS_HEIGHT 200
+
+enum BUTTON{
+       BUTTON_CLOSE=1,
+       BUTTON_SET      
+};
+
+enum ENTRY{
+       ENTRY_STORAGE_SIZE=1,
+       ENTRY_OCCUPATION,
+       ENTRY_REMOVE,
+       ENTRY_EVENTS_CHUNK
+};
+
+AliStorageAdministratorPanelSetStorageParams::AliStorageAdministratorPanelSetStorageParams() :
+       TGMainFrame(gClient->GetRoot(), 400, 400),
+       fStatusLabel(0),
+       fMaxStorageSizeEntry(0),
+       fMaxOccupationEntry(0),
+       fRemoveEventsEntry(0),
+       fEventsInChunkEntry(0),
+       fClientSocket(0),
+       fEventManager(0)
+{
+       fEventManager = new AliStorageEventManager();
+       InitWindow();
+}
+
+AliStorageAdministratorPanelSetStorageParams::~AliStorageAdministratorPanelSetStorageParams(){}
+
+AliStorageAdministratorPanelSetStorageParams* AliStorageAdministratorPanelSetStorageParams::GetInstance()
+{
+       if(!fInstance){fInstance = new AliStorageAdministratorPanelSetStorageParams();}
+       return fInstance;
+}
+
+void AliStorageAdministratorPanelSetStorageParams::Setup(socket_t *socket, int maxStorageSize, int maxOccupation, int removeEvents, int eventsInChunk)
+{
+       fClientSocket = socket;
+       fMaxStorageSizeEntry->SetIntNumber(maxStorageSize);
+       fMaxOccupationEntry->SetIntNumber(maxOccupation);
+       fRemoveEventsEntry->SetIntNumber(removeEvents);
+       fEventsInChunkEntry->SetIntNumber(eventsInChunk);
+}
+
+void AliStorageAdministratorPanelSetStorageParams::InitWindow()
+{
+       SetCleanup(kDeepCleanup);
+
+       // max storage size
+       AddFrame(new TGLabel(this,"Max storage size (MB):"),new TGLayoutHints(kLHintsLeft));
+
+       fMaxStorageSizeEntry = new TGNumberEntry(this,
+                                                    0,
+                                                    6,
+                                                    ENTRY_STORAGE_SIZE,
+                                                    TGNumberFormat::kNESInteger,
+                                                    TGNumberFormat::kNEAPositive,
+                                                    TGNumberFormat::kNELNoLimits);
+       AddFrame(fMaxStorageSizeEntry,new TGLayoutHints(kLHintsLeft));
+
+       // max occupation
+       AddFrame(new TGLabel(this,"Max occupation percent (%):"),new TGLayoutHints(kLHintsLeft));
+
+       fMaxOccupationEntry = new TGNumberEntry(this,
+                                               0,
+                                               6,
+                                               ENTRY_OCCUPATION,
+                                               TGNumberFormat::kNESInteger,
+                                               TGNumberFormat::kNEAPositive,
+                                               TGNumberFormat::kNELNoLimits);
+       AddFrame(fMaxOccupationEntry,new TGLayoutHints(kLHintsLeft));   
+
+       // remove events percantage
+       AddFrame(new TGLabel(this,"Remove events percentage (%):"),new TGLayoutHints(kLHintsLeft));
+
+       fRemoveEventsEntry = new TGNumberEntry(this,
+                                               0,
+                                               6,
+                                               ENTRY_OCCUPATION,
+                                               TGNumberFormat::kNESInteger,
+                                               TGNumberFormat::kNEAPositive,
+                                               TGNumberFormat::kNELNoLimits);
+       AddFrame(fRemoveEventsEntry,new TGLayoutHints(kLHintsLeft));
+
+       // events in chunk
+       AddFrame(new TGLabel(this,"Number of events in file:"),new TGLayoutHints(kLHintsLeft));
+
+       fEventsInChunkEntry = new TGNumberEntry(this,
+                                               0,
+                                               6,
+                                               ENTRY_OCCUPATION,
+                                               TGNumberFormat::kNESInteger,
+                                               TGNumberFormat::kNEAPositive,
+                                               TGNumberFormat::kNELNoLimits);
+       AddFrame(fEventsInChunkEntry,new TGLayoutHints(kLHintsLeft));   
+
+       // status label
+       fStatusLabel = new TGLabel(this,"");
+       AddFrame(fStatusLabel,new TGLayoutHints(kLHintsExpandX | kLHintsLeft));
+
+       AddFrame(new TGTextButton(this,"Close",BUTTON_CLOSE),
+                new TGLayoutHints(kLHintsLeft));
+
+       AddFrame(new TGTextButton(this,"Set parameters",BUTTON_SET),
+                new TGLayoutHints(kLHintsRight));
+
+       
+       SetWindowName("Set Storage Parameters");
+       MapSubwindows();
+       Resize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
+       MapWindow();
+}
+
+
+
+
+void AliStorageAdministratorPanelSetStorageParams::onSetParamsButton()
+{
+       
+       struct clientRequestStruct *requestMessage = new struct clientRequestStruct;    
+        //get run and event number from TGNumberEntries
+       requestMessage->messageType = REQUEST_SET_PARAMS;
+       requestMessage->maxStorageSize = fMaxStorageSizeEntry->GetIntNumber()*1000000;
+       requestMessage->maxOccupation = fMaxOccupationEntry->GetIntNumber();
+       requestMessage->removeEvents = fRemoveEventsEntry->GetIntNumber();
+       requestMessage->eventsInChunk = fEventsInChunkEntry->GetIntNumber();
+
+       fEventManager->Send(requestMessage,fClientSocket);
+
+       message_t *response = new message_t();
+       fClientSocket->recv(response);
+       char *result = (char*)response->data();
+       
+       if(!strcmp("true",result))
+       {
+               fStatusLabel->SetText("Params set");
+               cout<<"ADMIN PANEL -- Params set succesfully"<<endl;
+       }
+       else
+       {
+               fStatusLabel->SetText("Couldn't set params");
+               cout<<"ADMIN PANEL -- Couldn't set params"<<endl;
+       }
+}
+
+void AliStorageAdministratorPanelSetStorageParams::onCloseButton(){onExit();}
+void AliStorageAdministratorPanelSetStorageParams::CloseWindow(){onExit();}
+
+void AliStorageAdministratorPanelSetStorageParams::onExit()
+{
+       cout<<"Quiting set storage params";
+       if(fInstance){delete fInstance;fInstance=0;}
+       cout<<" -- OK"<<endl;
+}
+
+Bool_t AliStorageAdministratorPanelSetStorageParams::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
+{
+       switch (GET_MSG(msg))
+       {
+       case kC_COMMAND:
+               switch (GET_SUBMSG(msg))
+               {
+               case kCM_BUTTON:
+                       switch(parm1)
+                       {
+                       case BUTTON_CLOSE:onCloseButton();break;
+                       case BUTTON_SET:onSetParamsButton();break;
+                       default:break;
+                       }
+                       break;
+               default:break;
+               }
+               break;
+       default:break;
+       }
+
+       return false;
+}
diff --git a/STORAGE/AliStorageAdministratorPanelSetStorageParams.h b/STORAGE/AliStorageAdministratorPanelSetStorageParams.h
new file mode 100644 (file)
index 0000000..e895e49
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef AliStorageAdministratorPanelSetStorageParams_H
+#define AliStorageAdministratorPanelSetStorageParams_H
+
+#include "AliStorageEventManager.h"
+
+#include <TGLabel.h>
+#include <TGNumberEntry.h>
+#include <TG3DLine.h>
+
+namespace zmq
+{
+       class socket_t;
+}
+
+class AliStorageAdministratorPanelSetStorageParams : public TGMainFrame
+{
+public:
+       static AliStorageAdministratorPanelSetStorageParams* GetInstance();
+       void Setup(zmq::socket_t *socket,
+                  int maxStorageSize,
+                  int maxOccupation,
+                  int removeEvents,
+                  int eventsInChunk);
+private:
+       AliStorageAdministratorPanelSetStorageParams();
+       virtual ~AliStorageAdministratorPanelSetStorageParams();
+
+       static AliStorageAdministratorPanelSetStorageParams *fInstance;
+       
+       //gui components and methods
+       TGLabel *fStatusLabel;
+       TGNumberEntry *fMaxStorageSizeEntry;
+       TGNumberEntry *fMaxOccupationEntry;
+       TGNumberEntry *fRemoveEventsEntry;
+       TGNumberEntry *fEventsInChunkEntry;
+       
+       void InitWindow();
+       void onCloseButton();
+       void onSetParamsButton();
+       void onExit();
+
+       virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t);
+       void CloseWindow();
+       
+       zmq::socket_t *fClientSocket;
+       AliStorageEventManager *fEventManager;
+
+       AliStorageAdministratorPanelSetStorageParams(const AliStorageAdministratorPanelSetStorageParams&);
+       AliStorageAdministratorPanelSetStorageParams& operator=(const AliStorageAdministratorPanelSetStorageParams&);
+       
+       ClassDef(AliStorageAdministratorPanelSetStorageParams,0);
+};
+
+#endif
diff --git a/STORAGE/AliStorageClientThread.cxx b/STORAGE/AliStorageClientThread.cxx
new file mode 100644 (file)
index 0000000..3be9465
--- /dev/null
@@ -0,0 +1,442 @@
+#include "AliStorageClientThread.h"
+#include "AliMultiplicity.h"
+#include "AliStorageTypes.h"
+#include "AliSocket.h"
+#include "AliStorageEventManager.h"
+
+//#include "zhelpers.hpp"
+#include "zmq.hpp"
+
+#include <sstream>
+#include <signal.h>
+#include <fstream>
+#include <iostream>
+
+#include <TSystemDirectory.h>
+#include <TThread.h>
+#include <TFile.h>
+
+using namespace std;
+using namespace zmq;
+
+bool gClientQuit = false;    // signal flag
+void GotSignalClient(int){gClientQuit = true;}
+
+AliStorageClientThread::AliStorageClientThread() :
+fConnectionStatus(STATUS_WAITING),
+fReceivingStatus(STATUS_WAITING),
+fSavingStatus(STATUS_WAITING),
+fEventServer(""),
+fCommunicationThread(0),
+fCurrentFile(0),
+fDatabase(0),
+fCurrentStorageSize(0),
+fMaximumStorageSize(0),
+fStoragePath(""),
+fNumberOfEventsInFile(0),
+fStorageOccupationLevel(0),
+fRemoveEventsPercentage(0)
+{      
+       // make sure that when program is closed destructor will be called
+       struct sigaction sa;
+       memset(&sa,0,sizeof(sa));
+       sa.sa_handler = GotSignalClient;
+       sigfillset(&sa.sa_mask);
+       sigaction(SIGINT,&sa,NULL);
+       
+       //load storage parameters from file
+       TThread::Lock();
+       ifstream configFile (Form("%s/STORAGE/setupStorageDatabase.sh",
+                                 gSystem->Getenv("ALICE_ROOT")));
+       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);
+                       }
+                       else if(line.find("MAX_SIZE=")==0)
+                       {
+                               fMaximumStorageSize=atoi(line.substr(from,to-from).c_str());
+                       }
+                       else if(line.find("MAX_OCCUPATION=")==0)
+                       {
+                               fStorageOccupationLevel=atoi(line.substr(from,to-from).c_str());
+                       }
+                       else if(line.find("REMOVE_PERCENT=")==0)
+                       {
+                               fRemoveEventsPercentage=atoi(line.substr(from,to-from).c_str());
+                       }
+                       else if(line.find("EVENTS_IN_FILE=")==0)
+                       {
+                               fNumberOfEventsInFile=atoi(line.substr(from,to-from).c_str());
+                       }
+            else if(line.find("EVENT_SERVER=")==0)
+                       {
+                               fEventServer=line.substr(from,to-from);
+                       }
+               }
+               if(configFile.eof())
+               {
+                       configFile.clear();
+               }
+               configFile.close();
+       }
+       else
+       {
+               cout<<"CLIENT -- Unable to open config file"<<endl;
+       }
+       //create directory for storage if it doesn't exist
+       gSystem->Exec(Form("mkdir -p %s",fStoragePath.c_str()));
+
+       //create database class
+       fDatabase = new AliStorageDatabase();
+       TThread::UnLock();
+
+       //check current storage size
+       fCurrentStorageSize = GetSizeOfAllChunks();
+
+       //create two-way commynication thread
+       fCommunicationThread = new TThread("fCommunicationThread",
+                                          AliStorageClientThread::CommunicationHandler,(void*)this);
+       fCommunicationThread->Run();
+}
+
+AliStorageClientThread::~AliStorageClientThread()
+{
+       cout<<"CLIENT -- AliStorageClientThread destructor called";
+       if(fCurrentFile)
+       {
+               fCurrentFile->Close();
+               delete fCurrentFile;
+       }
+       if(fCommunicationThread){delete fCommunicationThread;}
+       cout<<" --- OK"<<endl;
+}
+
+void* AliStorageClientThread::CommunicationHandler(void *arg)
+{
+       AliStorageClientThread *clientInstance = static_cast<AliStorageClientThread*>(arg);
+
+//create socket for two-way communication
+       context_t *context = new context_t();
+        socket_t *socket = new socket_t(*context,ZMQ_REP);
+       socket->bind(Form("tcp://*:%d",gClientCommunicationPort));      
+
+       AliStorageEventManager *eventManager = new AliStorageEventManager();
+       
+       message_t *requestMessage = new message_t();
+       struct clientRequestStruct *request = new struct clientRequestStruct;
+       struct clientRequestStruct *response = new struct clientRequestStruct;
+
+       cout<<"CLIENT -- Communication stated"<<endl;
+       
+       while(!gClientQuit)
+       {
+               socket->recv(requestMessage);
+               request = static_cast<struct clientRequestStruct*>(requestMessage->data());
+               switch(request->messageType)
+               {
+               case REQUEST_CONNECTION:
+                       eventManager->Send((long)clientInstance->fConnectionStatus,socket);
+                       break;
+               case REQUEST_RECEIVING:
+                       eventManager->Send((long)clientInstance->fReceivingStatus,socket);
+                       break;
+               case REQUEST_SAVING:
+                       eventManager->Send((long)clientInstance->fSavingStatus,socket);
+                       break;
+               case REQUEST_CURRENT_SIZE:
+                       eventManager->Send((long)clientInstance->fCurrentStorageSize,socket);
+                       break;
+               case REQUEST_GET_PARAMS:
+                       response->maxStorageSize = clientInstance->fMaximumStorageSize;
+                       response->maxOccupation = clientInstance->fStorageOccupationLevel;
+                       response->removeEvents = clientInstance->fRemoveEventsPercentage;
+                       response->eventsInChunk = clientInstance->fNumberOfEventsInFile;
+
+                       eventManager->Send(response,socket);
+                       break;
+               case REQUEST_SET_PARAMS:
+                       clientInstance->SetStorageParams(request->maxStorageSize,
+                                                        request->maxOccupation,
+                                                        request->removeEvents,
+                                                        request->eventsInChunk);
+
+                       clientInstance->fMaximumStorageSize = request->maxStorageSize;
+                       clientInstance->fStorageOccupationLevel = request->maxOccupation;
+                       clientInstance->fRemoveEventsPercentage = request->removeEvents;
+                       clientInstance->fNumberOfEventsInFile = request->eventsInChunk;
+
+                       eventManager->Send(true,socket);
+                       break;
+               default:break;
+               }
+       }
+       if(context){delete context;}
+       if(socket){delete socket;}
+       if(eventManager){delete eventManager;}
+       return nullptr;
+}
+
+void AliStorageClientThread::SetStorageParams(int maxStorageSize,int maxOccupation,int removeEvents,int eventsInChunk)
+{
+       cout<<maxStorageSize<<endl<<maxOccupation<<endl<<removeEvents<<endl<<eventsInChunk<<endl;
+
+
+       TThread::Lock();
+       ifstream configFile (Form("%s/STORAGE/setupStorageDatabase.sh",
+                                 gSystem->Getenv("ALICE_ROOT")));
+       ofstream tmpFile("tmpFile.bla");
+       
+       if (configFile.is_open())
+       {
+               string line;
+               string tmpLine;
+               int from,to;
+               while(configFile.good())
+               {
+                       getline(configFile,line);
+                       from = line.find("\"")+1;
+                       to = line.find_last_of("\"");
+                       tmpLine = line;
+                       if(line.find("MAX_SIZE=")==0)
+                       {
+                               tmpLine = Form("MAX_SIZE=\"%d\"",maxStorageSize);
+                       }
+                       else if(line.find("MAX_OCCUPATION=")==0)
+                       {
+                               tmpLine = Form("MAX_OCCUPATION=\"%d\"",maxOccupation);
+                       }
+                       else if(line.find("REMOVE_PERCENT=")==0)
+                       {
+                               tmpLine = Form("REMOVE_PERCENT=\"%d\"",removeEvents);
+                       }
+                       else if(line.find("EVENTS_IN_FILE=")==0)
+                       {
+                               tmpLine = Form("EVENTS_IN_FILE=\"%d\"",eventsInChunk);
+                       }
+                       tmpLine += "\n";
+                       tmpFile << tmpLine;
+               }
+               if(configFile.eof())
+               {
+                       configFile.clear();
+               }
+               configFile.close();
+               tmpFile.close();
+               rename("tmpFile.bla",Form("%s/STORAGE/setupStorageDatabase.sh",
+                                         gSystem->Getenv("ALICE_ROOT")));
+       }
+       else
+       {
+               cout<<"CLIENT -- Unable to open config file"<<endl;
+       }
+       TThread::UnLock();
+}
+
+Long64_t AliStorageClientThread::GetSizeOfAllChunks()
+{
+       Long64_t totalStorageSize = 0;
+
+       TSystemDirectory dir(fStoragePath.c_str(),fStoragePath.c_str());
+       TList *listOfDirectories = dir.GetListOfFiles();
+
+       if (!listOfDirectories)
+       {
+               cout<<"CLIENT -- Storage directory is empty"<<endl;
+               return 0;
+       }
+       TIter nextDirectory(listOfDirectories);
+       TSystemFile *runDirectory;
+       string directoryName;
+       
+       while ((runDirectory=(TSystemFile*)nextDirectory()))
+       {
+               directoryName=runDirectory->GetName();
+               if (runDirectory->IsDirectory() && directoryName.find("run")==0)
+               {
+                       TSystemDirectory dirChunks(Form("%s/%s",fStoragePath.c_str(),directoryName.c_str()),Form("%s/%s",fStoragePath.c_str(),directoryName.c_str()));
+                       TList *listOfChunks = dirChunks.GetListOfFiles();
+
+                       if(listOfChunks)
+                       {
+                               TIter nextChunk(listOfChunks);
+                               TSystemFile *chunk;
+                               string chunkFileName;
+
+                               while((chunk=(TSystemFile*)nextChunk()))
+                               {
+                                       chunkFileName = chunk->GetName();
+                                       if(!chunk->IsDirectory() && chunkFileName.find("chunk")==0)
+                                       {
+                                               TFile *tmpFile = new TFile(Form("%s/%s/%s",fStoragePath.c_str(),directoryName.c_str(),chunkFileName.c_str()),"read");
+
+                                               totalStorageSize+=tmpFile->GetSize();
+                                               tmpFile->Close();
+                                               if(tmpFile){delete tmpFile;}
+                                       }
+                               }
+                               if(chunk){delete chunk;}
+                       }
+                       if(listOfChunks){delete listOfChunks;}
+               }
+       }
+
+       //tmpFiles.clear();
+       if(listOfDirectories){delete listOfDirectories;}
+       if(runDirectory){delete runDirectory;}
+       
+       printf("CLIENT -- Total storage size:%lld\t(%.2f MB)\n",totalStorageSize,(float)totalStorageSize/(1000.*1000.));
+
+       return totalStorageSize;
+}
+
+void AliStorageClientThread::CollectData()
+{
+       //connect with events' sockets
+       context_t *context = new context_t(1);
+       socket_t *socket = new socket_t(*context,ZMQ_SUB);
+       socket->setsockopt(ZMQ_SUBSCRIBE,"",0);
+       socket->connect(Form("tcp://%s:%d",fEventServer.c_str(),gEventsSubscriberPort));
+
+       if(socket)
+       {
+               cout<<"CLIENT -- Successfully connected to events' server"<<endl;
+               fConnectionStatus = STATUS_OK;
+       }
+               else
+       {
+               cout<<"CLIENT -- ERROR - could not connect to events' server"<<endl;
+               fConnectionStatus = STATUS_ERROR;
+       }
+
+       AliStorageEventManager *eventManager = new AliStorageEventManager();
+       
+       int chunkNumber=0;
+       int previousChunkNumber=-1;
+       int eventsInChunk=0;
+       int previousRunNumber=-1;
+       AliESDEvent *event = NULL;
+
+       while(!gClientQuit)
+       {               
+               event = eventManager->GetEvent(socket);
+
+               if(event)
+               {
+                       fReceivingStatus=STATUS_OK;
+                       
+                       if(event->GetRunNumber() != previousRunNumber)//when new run starts
+                       {
+                               cout<<"CLIENT -- new run started"<<endl;
+                               previousRunNumber = event->GetRunNumber();
+                               gSystem->Exec(Form("mkdir -p %s/run%d",fStoragePath.c_str(),event->GetRunNumber()));
+                               chunkNumber=0;
+                               eventsInChunk=0;
+                               
+                               TSystemDirectory dir(Form("%s/run%d",fStoragePath.c_str(),event->GetRunNumber()),
+                                                    Form("%s/run%d",fStoragePath.c_str(),event->GetRunNumber()));
+                               TList *files = dir.GetListOfFiles();    
+                               if (files)
+                               {
+                                       TSystemFile *file;
+                                       string fname;
+                                       TIter next(files);
+                                       
+                                       while ((file=(TSystemFile*)next()))
+                                       {
+                                               fname = file->GetName();
+                                       
+                                               if (!file->IsDirectory())
+                                               {
+                                                       int from = fname.find("chunk")+5;
+                                                       int to = fname.find(".root");
+
+                                                       int maxChunkNumber = atoi(fname.substr(from,to-from).c_str());
+
+                                                       if(maxChunkNumber > chunkNumber)
+                                                       {
+                                                               chunkNumber = maxChunkNumber;
+                                                       }
+                                               }
+                                       }
+                                       chunkNumber++;
+                               }
+                       }
+
+                       cout<<"CLIENT -- Received data. Event:"<<event->GetEventNumberInFile()<<"\trun:"<<event->GetRunNumber()<<endl;
+                       
+                       if(chunkNumber != previousChunkNumber)//when new chunk needs to be created
+                       {
+                               if(fCurrentFile)
+                               {
+                                       fCurrentFile->Close();
+                                       delete fCurrentFile;
+                                       fCurrentFile=0;
+                               }
+                               fCurrentStorageSize=GetSizeOfAllChunks();
+                               CheckCurrentStorageSize();
+                               
+                               fCurrentFile = new TFile(Form("%s/run%d/chunk%d.root", fStoragePath.c_str(),event->GetRunNumber(),chunkNumber),"recreate");
+
+                               previousChunkNumber = chunkNumber;
+                       }
+                       
+                       if(0 != fCurrentFile->WriteObject(event,Form("event%d",event->GetEventNumberInFile())))//if event was written to file
+                       {
+                               fDatabase->InsertEvent(event->GetRunNumber(),
+                                             event->GetEventNumberInFile(),
+                                             (char*)event->GetBeamType(),
+                                                      event->GetMultiplicity()->GetNumberOfTracklets(),Form("%s/run%d/chunk%d.root",fStoragePath.c_str(),event->GetRunNumber(),chunkNumber));
+                               
+                               eventsInChunk++;
+                               
+                               if(eventsInChunk == fNumberOfEventsInFile)//if max events number in file was reached
+                               {
+                                       chunkNumber++;
+                                       eventsInChunk=0;
+                               }
+                               
+                               if(fSavingStatus!=STATUS_OK)
+                               {
+                                       fSavingStatus=STATUS_OK;
+                               }
+                       }
+                       else if(fSavingStatus!=STATUS_ERROR)
+                       {
+                               fSavingStatus=STATUS_ERROR;
+                       }
+                       delete event;event=0;
+               }
+               else if(fReceivingStatus!=STATUS_ERROR)
+               {
+                       cout<<"CLIENT -- ERROR -- NO DATA!"<<endl;
+                       fReceivingStatus=STATUS_ERROR;
+               }
+       }
+       if(event){delete event;}
+}
+
+
+void AliStorageClientThread::CheckCurrentStorageSize()
+{
+       if(fCurrentStorageSize >  (float)fStorageOccupationLevel/100. * fMaximumStorageSize)
+       {
+               while(GetSizeOfAllChunks() > (float)fRemoveEventsPercentage/100. * fMaximumStorageSize)
+               {
+                       struct eventStruct oldestEvent = fDatabase->GetOldestEvent();
+                       string oldestEventPath = fDatabase->GetFilePath(oldestEvent);
+                       //remove oldest event
+                       cout<<"CLIENT -- Removing old events:"<<oldestEventPath<<endl;
+                       gSystem->Exec(Form("rm -f %s",oldestEventPath.c_str()));
+                       fDatabase->RemoveEvent(fDatabase->GetOldestEvent());
+               }
+       }
+}
diff --git a/STORAGE/AliStorageClientThread.h b/STORAGE/AliStorageClientThread.h
new file mode 100644 (file)
index 0000000..4c4b70e
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef AliStorageClientThread_H
+#define AliStorageClientThread_H
+
+#include "AliStorageDatabase.h"
+
+#include <string>
+
+#include <TThread.h>
+
+class AliStorageClientThread
+{
+public:
+       AliStorageClientThread();
+        ~AliStorageClientThread();
+       void CollectData();
+
+private:
+       //status flags
+       Int_t fConnectionStatus;
+       Int_t fReceivingStatus;
+       Int_t fSavingStatus;
+       
+       //zmq - receive events
+       std::string fEventServer;
+       
+       //zmq - communication with admin panel
+       static void* CommunicationHandler(void *arg);
+       TThread *fCommunicationThread;
+       
+       //storage file system
+       void CheckCurrentStorageSize();
+       void SetStorageParams(int maxStorageSize,
+                             int maxOccupation,
+                             int removeEvents,
+                             int eventsInChunk);
+       TFile *fCurrentFile;
+
+       AliStorageDatabase *fDatabase;
+       int fCurrentStorageSize;
+       int fMaximumStorageSize;
+       std::string fStoragePath;
+       int fNumberOfEventsInFile;
+       int fStorageOccupationLevel;
+       int fRemoveEventsPercentage;
+
+       Long64_t GetSizeOfAllChunks();
+       
+       AliStorageClientThread(const AliStorageClientThread&);
+       AliStorageClientThread& operator=(const AliStorageClientThread&);
+       
+};
+
+#endif
diff --git a/STORAGE/AliStorageDatabase.cxx b/STORAGE/AliStorageDatabase.cxx
new file mode 100644 (file)
index 0000000..c6a339f
--- /dev/null
@@ -0,0 +1,324 @@
+#include "AliStorageDatabase.h"
+
+#include <iostream>
+#include <fstream>
+
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+#include <TThread.h>
+#include <TSystem.h>
+#include <TFile.h>
+
+using namespace std;
+
+AliStorageDatabase::AliStorageDatabase() :
+       fHost(""),
+       fPort(""),
+       fDatabase(""),
+       fUID(""),
+       fPassword(""),
+       fTable(""),
+       fServer(0),
+       fStoragePath("")
+{
+       TThread::Lock();        
+       ifstream configFile (Form("%s/STORAGE/setupStorageDatabase.sh",
+                                 gSystem->Getenv("ALICE_ROOT")));
+
+       
+       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("HOST=")==0)
+                       {
+                               fHost=line.substr(from,to-from);
+                       }
+                       else if(line.find("PORT=")==0)
+                       {
+                               fPort=line.substr(from,to-from);
+                       }
+                       else if(line.find("DATABASE=")==0)
+                       {
+                               fDatabase=line.substr(from,to-from);
+                       }
+                       else if(line.find("USER=")==0)
+                       {
+                               fUID=line.substr(from,to-from);
+                       }
+                       else if(line.find("PASS=")==0)
+                       {
+                               fPassword=line.substr(from,to-from);
+                       }
+                       else if(line.find("TABLE=")==0)
+                       {
+                               fTable=line.substr(from,to-from);
+                       }
+                       else if(line.find("STORAGE_PATH=")==0)
+                       {
+                               fStoragePath=line.substr(from,to-from);
+                       }
+
+               }
+               if(configFile.eof())
+               {
+                       configFile.clear();
+               }
+               configFile.close();
+       }
+       else
+       {
+               cout << "DATABASE -- Unable to open file" <<endl;
+       }
+       TThread::UnLock();
+
+       
+       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(){}
+
+void AliStorageDatabase::InsertEvent(int runNumber,
+                                    int eventNumber,
+                                    char *system,
+                                    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));
+
+}
+
+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;
+       }
+}
+
+vector<serverListStruct> AliStorageDatabase::GetList(struct listRequestStruct list)
+{
+       TSQLResult *result = fServer->Query(Form("SELECT * FROM %s WHERE run_number >= %d AND run_number <= %d AND event_number >= %d AND event_number <= %d AND multiplicity >= %d AND multiplicity <= %d AND (permanent = %d OR permanent = %d) AND (system = '%s' OR system = '%s') ORDER BY run_number,event_number;",
+                                                fTable.c_str(),
+                                                list.runNumber[0],
+                                                list.runNumber[1],
+                                                list.eventNumber[0],
+                                                list.eventNumber[1],
+                                                list.multiplicity[0],
+                                                list.multiplicity[1],
+                                                list.marked[0],
+                                                list.marked[1],
+                                                list.system[0],
+                                                list.system[1]));
+
+       
+       TSQLRow *row;
+       vector<serverListStruct> eventsVector;
+       
+       while((row = result->Next()))
+       {
+               serverListStruct resultList;
+
+               resultList.runNumber = atoi(row->GetField(0));
+               resultList.eventNumber = atoi(row->GetField(1));
+               strcpy(resultList.system, row->GetField(2));
+               resultList.multiplicity = atoi(row->GetField(3));
+               resultList.marked = atoi(row->GetField(4));
+
+               eventsVector.push_back(resultList);
+               delete row;
+       }
+       
+       return eventsVector;
+}
+
+AliESDEvent* AliStorageDatabase::GetEvent(struct eventStruct event)
+{
+       cout<<"database - get event"<<endl;
+       string pathToFile = GetFilePath(event);
+
+       if(!strcmp(pathToFile.c_str(),""))
+       {
+               cout<<"DATABASE -- no such file in database"<<endl;
+               return NULL;
+       }
+       
+       TFile *tmpFile = new TFile(pathToFile.c_str(),"read");
+       if(!tmpFile)
+       {
+               cout<<"DATABASE -- couldn't open temp file"<<endl;
+               return NULL;
+       }
+       AliESDEvent *data;
+       tmpFile->GetObject(Form("event%d;1",event.eventNumber),data);
+
+       return data;
+       /*
+       //deserialize file??
+       TTree* tree= new TTree("esdTree", "esdTree");
+       data->WriteToTree(tree);
+       tree-> Fill();
+       AliESDEvent* requestedEvent= new AliESDEvent(); 
+       requestedEvent->ReadFromTree(tree);
+       tree->GetEntry(0);
+       delete data;
+       delete tree;
+       
+       
+       if(requestedEvent->GetRunNumber()<0)//if file is not in temp storage, check if it is in perm storage
+       {
+               cout<<"DATABASE -- could not find file in temp storage -- searching in perm"<<endl;
+               TFile *permFile = new TFile(Form("%s/permEvents.root",fStoragePath.c_str()),"update");//open/create perm file
+       
+               if(!permFile)
+               {
+                       cout<<"DATABASE -- Couldn't open perm file"<<endl;
+                       tmpFile->Close();
+                       if(tmpFile){delete tmpFile;}
+                       if(requestedEvent){delete requestedEvent;}
+                       return NULL;
+               }
+               TDirectory *runDirectory = permFile->GetDirectory(Form("run%d",event.runNumber));
+
+               if(!runDirectory)
+               {
+                       cout<<"DATABASE -- Couldn't open run directory"<<endl;
+                       
+                       if(tmpFile)
+                       {
+                               tmpFile->Close();
+                               delete tmpFile;
+                       }
+                       if(permFile)
+                       {
+                               permFile->Close();
+                               delete permFile;
+                       }
+                       if(requestedEvent){delete requestedEvent;}
+                       return NULL;
+               }
+               
+               //if(requestedEvent){delete requestedEvent;}
+               AliESDEvent *requestedEventPerm = (AliESDEvent*)runDirectory->Get(Form("event%d",event.eventNumber));
+
+               if(requestedEventPerm->GetRunNumber()<0)
+               {
+                       cout<<"DATABASE -- could not find event in perm storage"<<endl;
+                       tmpFile->Close();
+                       permFile->Close();
+                       if(tmpFile){delete tmpFile;}
+                       if(permFile){delete permFile;}
+                       return NULL;
+               }
+               else
+               {
+                       return requestedEventPerm;
+               }
+       }
+       else
+       {
+               cout<<"DATABASE -- sending event:"<<requestedEvent->GetRunNumber()<<endl;
+               tmpFile->Close();
+               if(tmpFile){delete tmpFile;}
+               return requestedEvent;
+               }*/
+}
+
+struct eventStruct AliStorageDatabase::GetOldestEvent()
+{
+       struct eventStruct oldestEvent = {0,0};
+
+       TSQLResult *result = fServer->Query(Form("SELECT * FROM %s ORDER BY run_number,event_number;",fTable.c_str()));
+
+       TSQLRow *row;   
+       if((row = result->Next()))
+       {
+               oldestEvent.runNumber = atoi(row->GetField(0));
+               oldestEvent.eventNumber = atoi(row->GetField(1));
+       
+               delete row;
+       }
+       else
+       {
+               cout<<"DATABASE -- NO OLDEST EVENT FOUND. Storage may be corrupted."<<endl;
+       }
+       return oldestEvent;
+}
+
+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));
+}
+
+string AliStorageDatabase::GetFilePath(struct eventStruct event)
+{
+       TSQLResult *result = fServer->Query(Form("SELECT * FROM %s WHERE run_number = %d AND event_number = %d;",fTable.c_str(),event.runNumber,event.eventNumber));
+       TSQLRow *row;
+       row = result->Next();
+       if(row)
+       {
+               string path(row->GetField(5));
+               delete row;
+               return path;
+       }
+       else
+       {
+               return "";
+       }
+}
+
+AliESDEvent* AliStorageDatabase::GetNextEvent(struct eventStruct event)
+{
+       TSQLResult *result = fServer->Query(Form("SELECT * FROM %s ORDER BY run_number,event_number;",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;
+       }
+
+       return NULL;
+}
+
+AliESDEvent* AliStorageDatabase::GetLastEvent()
+{
+       TSQLResult *result = fServer->Query(Form("SELECT * FROM %s ORDER BY run_number,event_number;",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);
+
+}
diff --git a/STORAGE/AliStorageDatabase.h b/STORAGE/AliStorageDatabase.h
new file mode 100644 (file)
index 0000000..9565138
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef AliStorageDatabase_H
+#define AliStorageDatabase_H
+
+#include "AliStorageTypes.h"
+#include "AliESDEvent.h"
+
+#include <string>
+#include <vector>
+
+#include <TSQLServer.h>
+
+class AliStorageDatabase
+{
+public:
+       AliStorageDatabase();
+       ~AliStorageDatabase();
+       
+       void InsertEvent(int runNumber,
+                        int eventNumber,
+                        char *system,
+                        int multiplicity,
+                        char *filePath); //more parameters of the event can be added to this method
+
+       bool MarkEvent(struct eventStruct event);
+       void RemoveEvent(struct eventStruct event);
+       std::string GetFilePath(struct eventStruct event);
+       struct eventStruct GetOldestEvent();
+       std::vector<serverListStruct> GetList(struct listRequestStruct listStruct);
+
+       //not tested:
+       AliESDEvent* GetEvent(struct eventStruct event);
+       AliESDEvent* GetNextEvent(struct eventStruct event);
+       AliESDEvent* GetLastEvent();
+       //
+private:
+       std::string fHost;
+       std::string fPort;
+       std::string fDatabase;
+       std::string fUID;
+       std::string fPassword;
+       std::string fTable;
+
+       TSQLServer *fServer;
+       std::string fStoragePath;
+
+        AliStorageDatabase(const AliStorageDatabase&);
+        AliStorageDatabase& operator=(const AliStorageDatabase&);
+};
+
+#endif
diff --git a/STORAGE/AliStorageEventManager.cxx b/STORAGE/AliStorageEventManager.cxx
new file mode 100644 (file)
index 0000000..26d95bd
--- /dev/null
@@ -0,0 +1,302 @@
+#include "AliStorageEventManager.h"
+#include "AliNetMessage.h"
+
+#include <iostream>
+#include <sstream>
+
+#include <TList.h>
+#include <TStreamerInfo.h>
+
+#include "zmq.hpp"
+
+using namespace zmq;
+using namespace std;
+
+AliStorageEventManager::AliStorageEventManager(){}
+AliStorageEventManager::~AliStorageEventManager(){}
+
+void __freeBuffer (void *data, void *hint)
+{
+    free(data);
+}
+
+void AliStorageEventManager::Send(AliESDEvent *event, socket_t *socket)
+{
+       AliNetMessage tmess(kMESS_OBJECT);
+       tmess.Reset();
+       tmess.WriteObject(event);
+
+       int bufSize = tmess.BufferSize();
+       char* buf = new char[bufSize];
+       memcpy(buf, (char*)tmess.Buffer(), bufSize);
+
+       message_t message(buf, bufSize, __freeBuffer, NULL);
+       //fwrite(mess.Buffer(), sizeof(char), bufSize, stdout);
+       
+       socket->send(message);
+
+       
+       //publisher.Send(tmess);
+                       /*
+       TMessage tmess(kMESS_OBJECT);
+       tmess.Reset();
+       tmess.WriteObject(event);
+       TMessage::EnableSchemaEvolutionForAll(kTRUE);
+       SendStreamerInfos(&tmess, socket);
+       int bufsize = tmess.Length();
+       char* buf = (char*) malloc(bufsize * sizeof(char));
+       memcpy(buf, tmess.Buffer(), bufsize);
+       zmq::message_t message((void*)buf, bufsize, 0, 0);
+       socket->send(message);*/
+}
+
+void AliStorageEventManager::Send(vector<serverListStruct> list, socket_t *socket)
+{
+       //send size of the struct first
+       int numberOfRecords = list.size();
+       message_t message(20);
+       snprintf ((char *)message.data(), 20 ,"%d",numberOfRecords);
+
+       socket->send(message);
+       if(numberOfRecords==0)return;
+       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);
+       socket->send(*reply);
+
+       if(reply){delete reply;}
+}
+
+void AliStorageEventManager::Send(struct serverRequestStruct *request,zmq::socket_t *socket)
+{
+       char *buffer = (char*)(request);
+       message_t *requestMessage = new message_t((void*)buffer,
+                                          sizeof(struct serverRequestStruct)
+                                          +sizeof(struct listRequestStruct)
+                                          +sizeof(struct eventStruct),0);      
+       socket->send(*requestMessage);
+}
+
+void AliStorageEventManager::Send(struct clientRequestStruct *request,zmq::socket_t *socket)
+{
+       char *buffer = (char*)(request);
+       message_t *requestMessage = new message_t((void*)buffer,
+                                          sizeof(struct clientRequestStruct),0);       
+       socket->send(*requestMessage);
+}
+
+void AliStorageEventManager::Send(long message,zmq::socket_t *socket)
+{
+       stringstream streamBuffer;
+       streamBuffer << message;
+       string stringBuffer = streamBuffer.str();
+       char *buffer = (char*)stringBuffer.c_str();
+       message_t *replyMessage = new message_t((void*)buffer,sizeof(long),0);
+       socket->send(*replyMessage);
+       delete replyMessage;
+       streamBuffer.str(string());
+       streamBuffer.clear();
+}
+
+void AliStorageEventManager::Send(bool message,zmq::socket_t *socket)
+{
+       char *buffer;
+       if(message==true)
+       {
+               buffer = (char*)("true");
+       }
+       else
+       {
+               buffer = (char*)("false");
+       }
+       message_t *replyMessage = new message_t((void*)buffer,sizeof(char*),0);
+       socket->send(*replyMessage);
+       delete replyMessage;
+}
+
+vector<serverListStruct> AliStorageEventManager::GetServerListVector(socket_t *socket)
+{
+       //get size of the incomming message
+       message_t sizeMessage;
+       socket->recv(&sizeMessage);
+       int numberOfRecords;
+       istringstream iss(static_cast<char*>(sizeMessage.data()));
+       iss >> numberOfRecords;
+
+       if(numberOfRecords==0){cout<<"MANAGER -- list is empty"<<endl;}
+       
+       socket->send(*(new message_t()));//receive empty message just to keep req-rep order
+       
+//get list of events
+       message_t *response = new message_t(sizeof(serverListStruct)*numberOfRecords);
+       socket->recv(response);
+       
+       vector<serverListStruct> receivedList(static_cast<serverListStruct*>(response->data()), static_cast<serverListStruct*>(response->data()) + numberOfRecords);
+
+       return receivedList;
+}
+
+AliESDEvent* AliStorageEventManager::GetEvent(socket_t *socket)
+{
+       message_t *message = new message_t();
+       
+       socket->recv(message);
+       int bufSize = (int)message->size();
+               
+       char* buf = new char[bufSize];
+       memcpy(buf, (char*)message->data(), bufSize);
+       
+       AliNetMessage *mess = new AliNetMessage(buf, bufSize);
+       
+       /*
+       message_t* message = RecvStreamerInfos(socket);
+       int64_t more;
+       size_t more_size = sizeof more;
+    
+       socket->getsockopt(ZMQ_RCVMORE, &more, &more_size );
+       socket->recv(message);
+       TBufferFile *mess = new TBufferFile(TBuffer::kRead,
+                                           message->size()+sizeof(UInt_t),
+                                           message->data());
+       mess->InitMap();
+       mess->ReadClass();// get first the class stored in message
+       mess->SetBufferOffset(sizeof(UInt_t) + sizeof(kMESS_OBJECT));
+       mess->ResetMap();
+       
+
+       //message_t *mess;
+       //socket->recv(message);
+       */
+       AliESDEvent* data = (AliESDEvent*)(mess->ReadObjectAny(AliESDEvent::Class()));
+       if (data)
+       {
+               TTree* tree= new TTree("esdTree", "esdTree");
+               data->WriteToTree(tree);
+               tree-> Fill();
+               AliESDEvent* event= new AliESDEvent();
+               event->ReadFromTree(tree);
+               tree->GetEntry(0);
+               delete data;
+               delete tree;
+               if(message){delete message;}
+               return event;                   
+       }
+       else
+       {
+               if(message){delete message;}
+               return NULL;
+       }
+}
+
+message_t* AliStorageEventManager::RecvStreamerInfos(socket_t *socket)
+{
+       message_t *message = new message_t;
+       socket->recv(message);
+       TBufferFile *mess = new TBufferFile(TBuffer::kRead,
+                                           message->size()+2*sizeof(UInt_t),
+                                           message->data());
+       if(!mess)
+       {
+               if(message){delete message;}
+               return NULL;
+       }
+       mess->InitMap();
+       mess->ReadClass();     // get first the class stored in message
+       mess->SetBufferOffset(sizeof(UInt_t) + sizeof(TMessage));
+       mess->ResetMap();
+       TList *list = (TList*)mess->ReadObjectAny(TList::Class());
+       if(list==0 || list->IsEmpty())
+       {
+               return message;
+       }
+       if(message){delete message;}
+       TIter next(list);
+       TStreamerInfo *info;
+       TObjLink *lnk = list->FirstLink();
+       // First call BuildCheck for regular class
+       while (lnk)
+       {
+               info = (TStreamerInfo*)lnk->GetObject();
+               TObject *element = info->GetElements()->UncheckedAt(0);
+               Bool_t isstl = element && strcmp("This",element->GetName())==0;
+               if (!isstl)
+               {
+                       info->BuildCheck();
+                       if (gDebug > 0)
+                       {
+                               Info("RecvStreamerInfos",
+                                    "importing TStreamerInfo: %s, version = %d",
+                                    info->GetName(),
+                                    info->GetClassVersion());
+                       }
+               }
+               lnk = lnk->Next();
+       }
+       lnk = list->FirstLink();
+       while (lnk)
+       {
+               info = (TStreamerInfo*)lnk->GetObject();
+               TObject *element = info->GetElements()->UncheckedAt(0);
+               Bool_t isstl = element && strcmp("This",element->GetName())==0;
+               if (isstl)
+               {
+                       info->BuildCheck();
+                       if (gDebug > 0)
+                       {
+                               Info("RecvStreamerInfos",
+                                    "importing TStreamerInfo: %s, version = %d",
+                                    info->GetName(),
+                                    info->GetClassVersion());
+                       }
+               }
+               lnk = lnk->Next();
+       }
+       if(list){delete list;}
+       if(mess){delete mess;}
+       if(lnk){delete lnk;}
+       return message;
+}
+
+void AliStorageEventManager::SendStreamerInfos(TMessage* mess, socket_t *socket)
+{
+       TList* infos = mess->GetStreamerInfos();
+   
+       TIter next(infos);
+       TStreamerInfo *info;
+       TList *minilist = 0;
+       while ((info = (TStreamerInfo*)next()))
+       {
+               //Int_t uid = info->GetNumber();
+               if (!minilist) minilist = new TList();
+         
+               minilist->Add(info);
+       }
+      
+       if (minilist)
+       {
+               TMessage messinfo(kMESS_STREAMERINFO);
+               messinfo.WriteObject(minilist);
+               delete minilist;
+               if (messinfo.GetStreamerInfos())
+                       messinfo.GetStreamerInfos()->Clear();
+          
+               int bufsize = messinfo.Length();
+               char* buf = (char*) malloc(bufsize * sizeof(char));
+               memcpy(buf, messinfo.Buffer(), bufsize);
+
+               // send!
+               zmq::message_t message((void*)buf, bufsize, 0, 0);
+                     
+               if (socket->send(message, ZMQ_SNDMORE))
+               {
+                       Warning("SendStreamerInfos", "problems sending TStreamerInfo's ...");
+               }
+       }
+
+       return;
+}
+
+
diff --git a/STORAGE/AliStorageEventManager.h b/STORAGE/AliStorageEventManager.h
new file mode 100644 (file)
index 0000000..2751f33
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef AliStorageEventManager_H
+#define AliStorageEventManager_H
+
+#include "AliESDEvent.h"
+#include "AliStorageTypes.h"
+
+#include <vector>
+
+#include <TMessage.h>
+
+namespace zmq
+{
+       class socket_t;
+       class message_t;
+}
+
+class AliStorageEventManager
+{
+public:
+       AliStorageEventManager();
+       ~AliStorageEventManager();
+
+       void Send(std::vector<serverListStruct> list,zmq::socket_t *socket);
+       void Send(struct serverRequestStruct *request,zmq::socket_t *socket);
+       void Send(struct clientRequestStruct *request,zmq::socket_t *socket);
+       void Send(AliESDEvent *event, zmq::socket_t *socket);
+       void Send(long message,zmq::socket_t *socket);
+       void Send(bool message,zmq::socket_t *socket);
+       
+       std::vector<serverListStruct> GetServerListVector(zmq::socket_t *socket);
+       AliESDEvent* GetEvent(zmq::socket_t *socket);
+       
+private:
+       void SendStreamerInfos(TMessage *mess, zmq::socket_t *socket);
+       zmq::message_t* RecvStreamerInfos(zmq::socket_t *socket);
+};
+
+#endif
diff --git a/STORAGE/AliStorageServerThread.cxx b/STORAGE/AliStorageServerThread.cxx
new file mode 100644 (file)
index 0000000..180a008
--- /dev/null
@@ -0,0 +1,186 @@
+#include "AliStorageServerThread.h"
+#include "AliStorageTypes.h"
+#include "AliESDEvent.h"
+
+#include "zmq.hpp"
+#include <iostream>
+#include <fstream>
+
+#include <TFile.h>
+#include <TThread.h>
+
+using namespace std;
+using namespace zmq;
+
+AliStorageServerThread::AliStorageServerThread() :
+       fEventManager(0),
+       fDatabase(0),
+       fStoragePath("")
+{
+       TThread::Lock();
+       fDatabase = new AliStorageDatabase();
+       //load parameters from config file
+       ifstream configFile (Form("%s/STORAGE/setupStorageDatabase.sh",
+                                 gSystem->Getenv("ALICE_ROOT")));
+
+       
+       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
+       fEventManager = new AliStorageEventManager();
+       StartCommunication();
+}
+
+AliStorageServerThread::~AliStorageServerThread()
+{
+       cout<<"SERVER -- AliStorageServerThread destructor called";
+       
+       cout<<" --- OK"<<endl;
+}
+
+void AliStorageServerThread::StartCommunication()
+{
+       //create two-way communication socket
+       context_t *context = new context_t(1);
+       socket_t *socket = new socket_t(*context,ZMQ_REP);
+       socket->bind(Form("tcp://*:%d",gServerCommunicationPort));      
+       
+       message_t *request = new message_t;
+       message_t *reply;
+       struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
+       char *buffer;
+       
+       while(1)
+       {
+               socket->recv(request);
+               requestMessage = static_cast<struct serverRequestStruct*>(request->data());
+               
+               switch(requestMessage->messageType)
+               {
+               case REQUEST_LIST_EVENTS:
+               {
+                       vector<serverListStruct> result = fDatabase->GetList(requestMessage->list);
+                       fEventManager->Send(result,socket);
+                       break;
+               }
+               case REQUEST_GET_EVENT:
+               {
+                       AliESDEvent *event = fDatabase->GetEvent(requestMessage->event);
+                       fEventManager->Send(event,socket);
+                       delete event;
+                       break;
+               }
+               case REQUEST_GET_NEXT_EVENT:
+               {
+                       AliESDEvent *event = fDatabase->GetNextEvent(requestMessage->event);
+                       fEventManager->Send(event,socket);
+                       delete event;
+                       break;
+               }
+               case REQUEST_GET_LAST_EVENT:
+               {
+                       AliESDEvent *event = fDatabase->GetLastEvent();
+                       fEventManager->Send(event,socket);
+                       delete event;
+                       break;
+               }
+               case REQUEST_MARK_EVENT:
+               {
+                       struct eventStruct *markData  = &(requestMessage->event);
+                       buffer =(char*)(MarkEvent(*markData) ? "true" : "false");
+                       reply = new message_t((void*)buffer,sizeof(char*),0);
+                       socket->send(*reply);
+                       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;
+               
+       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;
+               if(tmpFile){delete tmpFile;}
+               if(eventToMark){delete eventToMark;}
+               return false;
+       }
+
+       //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();
+       }
+       else
+       {
+               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))
+       {
+               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;
+}
+
diff --git a/STORAGE/AliStorageServerThread.h b/STORAGE/AliStorageServerThread.h
new file mode 100644 (file)
index 0000000..eeff18d
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef AliStorageServerThread_H
+#define AliStorageServerThread_H
+
+#include "AliStorageEventManager.h"
+#include "AliStorageDatabase.h"
+
+class AliStorageServerThread
+{
+public:
+       AliStorageServerThread();
+       ~AliStorageServerThread();
+private:
+       //communication via socket
+       void StartCommunication();
+       AliStorageEventManager *fEventManager;
+       
+       //handling different requests
+       AliESDEvent* GetEvent(struct eventStruct eventStruct);
+       AliESDEvent* GetNextEvent(struct eventStruct eventStruct);
+       AliESDEvent* GetLastEvent();
+       bool MarkEvent(struct eventStruct event);
+
+       //connection to database and storage
+       AliStorageDatabase *fDatabase;
+       std::string fStoragePath;
+
+       AliStorageServerThread(const AliStorageServerThread&);
+       AliStorageServerThread& operator=(const AliStorageServerThread&);
+};
+
+#endif
diff --git a/STORAGE/AliStorageTypes.h b/STORAGE/AliStorageTypes.h
new file mode 100644 (file)
index 0000000..1738a0d
--- /dev/null
@@ -0,0 +1,66 @@
+#ifndef AliStorageTypes_H
+#define AliStorageTypes_H
+
+//sockets
+const int gServerCommunicationPort = 5066;
+const int gEventsSubscriberPort = 5024;
+const int gClientCommunicationPort = 5088;
+const int gClientPublisherPort = 5077;
+
+enum statusType{
+       STATUS_WAITING=1,
+       STATUS_OK,
+       STATUS_ERROR,
+       STATUS_DOWN
+};
+
+enum requestType{
+       REQUEST_CONNECTION=1,
+       REQUEST_RECEIVING,
+       REQUEST_SAVING,
+       REQUEST_CURRENT_SIZE,
+       REQUEST_LIST_EVENTS,
+       REQUEST_GET_EVENT,
+       REQUEST_GET_NEXT_EVENT,
+       REQUEST_GET_LAST_EVENT,
+       REQUEST_MARK_EVENT,
+       REQUEST_SET_PARAMS,
+       REQUEST_GET_PARAMS
+};
+
+struct clientRequestStruct{
+       int messageType;
+       int maxStorageSize;
+       int maxOccupation;
+       int removeEvents;
+       int eventsInChunk;
+};
+
+struct eventStruct{
+       int runNumber;
+       int eventNumber;
+};
+
+struct listRequestStruct{
+       int runNumber[2];
+       int eventNumber[2];
+       int marked[2];
+       int multiplicity[2];
+       char system[2][20];
+};
+
+struct serverRequestStruct{
+       int messageType;
+       struct eventStruct event;
+       struct listRequestStruct list;
+};
+
+typedef struct serverListStruct{
+       int runNumber;
+       int eventNumber;
+       char system[20];
+       int multiplicity;
+       int marked;
+}serverListStruct;
+
+#endif
diff --git a/STORAGE/CMakeLists.txt b/STORAGE/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..b6a97be
--- /dev/null
@@ -0,0 +1,17 @@
+# AliRoot Build System CMakeLists for EVE
+#
+# Author: Johny Jose m(johny.jose@cern.ch)
+#         Port of previous Makefile build to cmake
+
+cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
+
+if(ZEROMQ_FOUND)
+set(PACKAGES "${PACKAGES}"
+    CMakebinalifakedisplay.pkg
+    CMakebinalistorageadmin.pkg
+    CMakebinalistorage.pkg
+    CMakelibStorage.pkg
+)
+ENDIF(ZEROMQ_FOUND)
+
+ALICE_BuildModule()
diff --git a/STORAGE/CMakebinalifakedisplay.pkg b/STORAGE/CMakebinalifakedisplay.pkg
new file mode 100755 (executable)
index 0000000..07e75be
--- /dev/null
@@ -0,0 +1,65 @@
+# -*- mode: CMake -*- 
+#-----------------------------------------------------------------------#
+# Package File for alieve                                                        #
+# Author : Johny Jose (johny.jose@cern.ch)                                       #
+# Variables Defined :                                                            #
+#                                                                                #
+# SRCS - C++ source files                                                        #
+# HDRS - C++ header files                                                        #
+# DHDR - ROOT Dictionary Linkdef header file                                     #
+# CSRCS - C source files                                                         #
+# CHDRS - C header files                                                         #
+# EINCLUDE - Include directories                                                 #
+# EDEFINE - Compiler definitions                                                 #
+# ELIBS - Extra libraries to link                                                #
+# ELIBSDIR - Extra library directories                                           #
+# PACKFFLAGS - Fortran compiler flags for package                                #
+# PACKCXXFLAGS - C++ compiler flags for package                                  #
+# PACKCFLAGS - C compiler flags for package                                      #
+# PACKSOFLAGS - Shared library linking flags                                     #
+# PACKLDFLAGS - Module linker flags                                              #
+# PACKBLIBS - Libraries to link (Executables only)                               #
+# EXPORT - Header files to be exported                                           #
+# CINTHDRS - Dictionary header files                                             #
+# CINTAUTOLINK - Set automatic dictionary generation                             #
+# ARLIBS - Archive Libraries and objects for linking (Executables only)          #
+# SHLIBS - Shared Libraries and objects for linking (Executables only)           #
+#-----------------------------------------------------------------------#
+
+set ( SRCS  alifakedisplay.cxx)
+
+set ( EINCLUDE )
+set ( ELIBSDIR )
+
+set ( ELIBS  EveBase EveDet MUONmapping MUONevaluation MUONsim MUONrec MUONgeometry MUONcalib MUONbase MUONraw MUONtrigger MUONcore TPCsim TPCrec TPCbase TPCutil ITSbase ITSsim ITSrec ITSUpgradeBase ITSUpgradeSim PMDbase PMDsim PMDrec TRDbase TRDsim TRDrec FMDbase FMDsim FMDrec TOFbase TOFrec TOFsim PHOSUtils PHOSbase PHOSsim PHOSrec ACORDEbase ACORDEsim ACORDErec HMPIDbase HMPIDrec HMPIDsim ZDCbase ZDCsim ZDCrec VZERObase VZEROsim VZEROrec EMCALUtils EMCALbase EMCALsim EMCALrec EMCALraw BCM STRUCT T0base T0sim T0rec STEER CDB AOD ESD STEERBase ANALYSISalice ANALYSIS THijing hijing THbtp TEPEMGEN FASTSIM microcern RAWDatasim RAWDatarec RAWDatabase HLTbase XMLParser STAT OADB)
+
+if(PYTHIA6)
+  list (APPEND ELIBS EVGEN)
+endif(PYTHIA6)
+
+set (ARPACKS FMDbase FMDsim FMDrec ACORDEbase ACORDEsim ACORDErec HMPIDbase HMPIDsim HMPIDrec ZDCbase ZDCsim ZDCrec VZERObase VZEROsim VZEROrec MFTbase MFTsim MFTrec EMCALUtils EMCALbase EMCALsim EMCALrec T0base T0sim T0rec TOFbase TOFsim TOFrec TRDbase TRDsim TRDrec PMDbase PMDsim PMDrec MUONmapping MUONmapping MUONgeometry MUONbase MUONsim MUONrec MUONraw PHOSUtils PHOSbase PHOSsim PHOSrec HLTbase ITSbase ITSsim ITSrec STRUCT TPCbase TPCsim TPCrec TPCfast STEER CDB ESD STEERBase RAWDatabase RAWDatasim RAWDatarec MDC TRIGGERbase)
+
+set ( PACKBLIBS  ${ROOTCLIBS} ${ROOTPLIBS} -lTreePlayer -lGeomPainter -lGed -lRGL -lEve -lzmq -lStorage ${SYSLIBS} )
+
+if( ALICE_TARGET STREQUAL "macosx")
+                       
+       set ( ELIBS ${ELIBS} GL)
+       set ( ELIBSDIR ${ELIBSDIR} /usr/X11R6/lib/)
+       
+  set ( ELIBSCPP ${ELIBS})
+       list(REMOVE_ITEM ELIBSCPP microcern lhapdf herwig)
+
+  ALICE_Format(PACKLDFLAGS "-Wl,-u,_G__cpp_setupG__" "" ${LDFLAGS})
+
+       if( MACOSX_MINOR STREQUAL "5")
+                                               
+               set ( PACKLDFLAGS "${PACKLDFLAGS} -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib")
+
+  endif( MACOSX_MINOR STREQUAL "5")
+       
+  set ( ELIBS ${ELIBS} GLU)
+       set ( ELIBSDIR ${ELIBSDIR} ${FINK_ROOT}/lib)
+       
+endif( ALICE_TARGET STREQUAL "macosx")
+
+set ( ELIBS ${ELIBS} Storage )
\ No newline at end of file
diff --git a/STORAGE/CMakebinalistorage.pkg b/STORAGE/CMakebinalistorage.pkg
new file mode 100755 (executable)
index 0000000..e77c7c7
--- /dev/null
@@ -0,0 +1,66 @@
+# -*- mode: CMake -*- 
+#-----------------------------------------------------------------------#
+# Package File for alieve                                                        #
+# Author : Johny Jose (johny.jose@cern.ch)                                       #
+# Variables Defined :                                                            #
+#                                                                                #
+# SRCS - C++ source files                                                        #
+# HDRS - C++ header files                                                        #
+# DHDR - ROOT Dictionary Linkdef header file                                     #
+# CSRCS - C source files                                                         #
+# CHDRS - C header files                                                         #
+# EINCLUDE - Include directories                                                 #
+# EDEFINE - Compiler definitions                                                 #
+# ELIBS - Extra libraries to link                                                #
+# ELIBSDIR - Extra library directories                                           #
+# PACKFFLAGS - Fortran compiler flags for package                                #
+# PACKCXXFLAGS - C++ compiler flags for package                                  #
+# PACKCFLAGS - C compiler flags for package                                      #
+# PACKSOFLAGS - Shared library linking flags                                     #
+# PACKLDFLAGS - Module linker flags                                              #
+# PACKBLIBS - Libraries to link (Executables only)                               #
+# EXPORT - Header files to be exported                                           #
+# CINTHDRS - Dictionary header files                                             #
+# CINTAUTOLINK - Set automatic dictionary generation                             #
+# ARLIBS - Archive Libraries and objects for linking (Executables only)          #
+# SHLIBS - Shared Libraries and objects for linking (Executables only)           #
+#-----------------------------------------------------------------------#
+
+set ( SRCS  alistorage_main/alistorage_main.cxx)
+
+set ( EINCLUDE )
+set ( ELIBSDIR )
+
+set ( ELIBS  EveBase EveDet MUONmapping MUONevaluation MUONsim MUONrec MUONgeometry MUONcalib MUONbase MUONraw MUONtrigger MUONcore TPCsim TPCrec TPCbase TPCutil ITSbase ITSsim ITSrec ITSUpgradeBase ITSUpgradeSim PMDbase PMDsim PMDrec TRDbase TRDsim TRDrec FMDbase FMDsim FMDrec TOFbase TOFrec TOFsim PHOSUtils PHOSbase PHOSsim PHOSrec ACORDEbase ACORDEsim ACORDErec HMPIDbase HMPIDrec HMPIDsim ZDCbase ZDCsim ZDCrec VZERObase VZEROsim VZEROrec EMCALUtils EMCALbase EMCALsim EMCALrec EMCALraw BCM STRUCT T0base T0sim T0rec STEER CDB AOD ESD STEERBase ANALYSISalice ANALYSIS THijing hijing THbtp TEPEMGEN FASTSIM microcern RAWDatasim RAWDatarec RAWDatabase HLTbase XMLParser STAT OADB)
+
+if(PYTHIA6)
+  list (APPEND ELIBS EVGEN)
+endif(PYTHIA6)
+
+set (ARPACKS FMDbase FMDsim FMDrec ACORDEbase ACORDEsim ACORDErec HMPIDbase HMPIDsim HMPIDrec ZDCbase ZDCsim ZDCrec VZERObase VZEROsim VZEROrec MFTbase MFTsim MFTrec EMCALUtils EMCALbase EMCALsim EMCALrec T0base T0sim T0rec TOFbase TOFsim TOFrec TRDbase TRDsim TRDrec PMDbase PMDsim PMDrec MUONmapping MUONmapping MUONgeometry MUONbase MUONsim MUONrec MUONraw PHOSUtils PHOSbase PHOSsim PHOSrec HLTbase ITSbase ITSsim ITSrec STRUCT TPCbase TPCsim TPCrec TPCfast STEER CDB ESD STEERBase RAWDatabase RAWDatasim RAWDatarec MDC TRIGGERbase)
+
+set ( PACKBLIBS  ${ROOTCLIBS} ${ROOTPLIBS} -lTreePlayer -lGeomPainter -lGed -lRGL -lEve -lzmq -lStorage ${SYSLIBS} )
+
+if( ALICE_TARGET STREQUAL "macosx")
+                       
+       set ( ELIBS ${ELIBS} GL)
+       set ( ELIBSDIR ${ELIBSDIR} /usr/X11R6/lib/)
+       
+  set ( ELIBSCPP ${ELIBS})
+       list(REMOVE_ITEM ELIBSCPP microcern lhapdf herwig)
+
+  ALICE_Format(PACKLDFLAGS "-Wl,-u,_G__cpp_setupG__" "" ${LDFLAGS})
+
+       if( MACOSX_MINOR STREQUAL "5")
+                                               
+               set ( PACKLDFLAGS "${PACKLDFLAGS} -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib")
+
+  endif( MACOSX_MINOR STREQUAL "5")
+       
+  set ( ELIBS ${ELIBS} GLU)
+       set ( ELIBSDIR ${ELIBSDIR} ${FINK_ROOT}/lib)
+       
+endif( ALICE_TARGET STREQUAL "macosx")
+
+set ( ELIBS ${ELIBS} Storage )  
+
diff --git a/STORAGE/CMakebinalistorageadmin.pkg b/STORAGE/CMakebinalistorageadmin.pkg
new file mode 100755 (executable)
index 0000000..3ae1109
--- /dev/null
@@ -0,0 +1,65 @@
+# -*- mode: CMake -*- 
+#-----------------------------------------------------------------------#
+# Package File for alieve                                                        #
+# Author : Johny Jose (johny.jose@cern.ch)                                       #
+# Variables Defined :                                                            #
+#                                                                                #
+# SRCS - C++ source files                                                        #
+# HDRS - C++ header files                                                        #
+# DHDR - ROOT Dictionary Linkdef header file                                     #
+# CSRCS - C source files                                                         #
+# CHDRS - C header files                                                         #
+# EINCLUDE - Include directories                                                 #
+# EDEFINE - Compiler definitions                                                 #
+# ELIBS - Extra libraries to link                                                #
+# ELIBSDIR - Extra library directories                                           #
+# PACKFFLAGS - Fortran compiler flags for package                                #
+# PACKCXXFLAGS - C++ compiler flags for package                                  #
+# PACKCFLAGS - C compiler flags for package                                      #
+# PACKSOFLAGS - Shared library linking flags                                     #
+# PACKLDFLAGS - Module linker flags                                              #
+# PACKBLIBS - Libraries to link (Executables only)                               #
+# EXPORT - Header files to be exported                                           #
+# CINTHDRS - Dictionary header files                                             #
+# CINTAUTOLINK - Set automatic dictionary generation                             #
+# ARLIBS - Archive Libraries and objects for linking (Executables only)          #
+# SHLIBS - Shared Libraries and objects for linking (Executables only)           #
+#-----------------------------------------------------------------------#
+
+set ( SRCS  alistorageadmin_main/alistorageadmin_main.cxx)
+
+set ( EINCLUDE )
+set ( ELIBSDIR )
+
+set ( ELIBS  EveBase EveDet MUONmapping MUONevaluation MUONsim MUONrec MUONgeometry MUONcalib MUONbase MUONraw MUONtrigger MUONcore TPCsim TPCrec TPCbase TPCutil ITSbase ITSsim ITSrec ITSUpgradeBase ITSUpgradeSim PMDbase PMDsim PMDrec TRDbase TRDsim TRDrec FMDbase FMDsim FMDrec TOFbase TOFrec TOFsim PHOSUtils PHOSbase PHOSsim PHOSrec ACORDEbase ACORDEsim ACORDErec HMPIDbase HMPIDrec HMPIDsim ZDCbase ZDCsim ZDCrec VZERObase VZEROsim VZEROrec EMCALUtils EMCALbase EMCALsim EMCALrec EMCALraw BCM STRUCT T0base T0sim T0rec STEER CDB AOD ESD STEERBase ANALYSISalice ANALYSIS THijing hijing THbtp TEPEMGEN FASTSIM microcern RAWDatasim RAWDatarec RAWDatabase HLTbase XMLParser STAT OADB)
+
+if(PYTHIA6)
+  list (APPEND ELIBS EVGEN)
+endif(PYTHIA6)
+
+set (ARPACKS FMDbase FMDsim FMDrec ACORDEbase ACORDEsim ACORDErec HMPIDbase HMPIDsim HMPIDrec ZDCbase ZDCsim ZDCrec VZERObase VZEROsim VZEROrec MFTbase MFTsim MFTrec EMCALUtils EMCALbase EMCALsim EMCALrec T0base T0sim T0rec TOFbase TOFsim TOFrec TRDbase TRDsim TRDrec PMDbase PMDsim PMDrec MUONmapping MUONmapping MUONgeometry MUONbase MUONsim MUONrec MUONraw PHOSUtils PHOSbase PHOSsim PHOSrec HLTbase ITSbase ITSsim ITSrec STRUCT TPCbase TPCsim TPCrec TPCfast STEER CDB ESD STEERBase RAWDatabase RAWDatasim RAWDatarec MDC TRIGGERbase)
+
+set ( PACKBLIBS  ${ROOTCLIBS} ${ROOTPLIBS} -lTreePlayer -lGeomPainter -lGed -lRGL -lEve -lzmq -lStorage ${SYSLIBS} )
+
+if( ALICE_TARGET STREQUAL "macosx")
+                       
+       set ( ELIBS ${ELIBS} GL)
+       set ( ELIBSDIR ${ELIBSDIR} /usr/X11R6/lib/)
+       
+  set ( ELIBSCPP ${ELIBS})
+       list(REMOVE_ITEM ELIBSCPP microcern lhapdf herwig)
+
+  ALICE_Format(PACKLDFLAGS "-Wl,-u,_G__cpp_setupG__" "" ${LDFLAGS})
+
+       if( MACOSX_MINOR STREQUAL "5")
+                                               
+               set ( PACKLDFLAGS "${PACKLDFLAGS} -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib")
+
+  endif( MACOSX_MINOR STREQUAL "5")
+       
+  set ( ELIBS ${ELIBS} GLU)
+       set ( ELIBSDIR ${ELIBSDIR} ${FINK_ROOT}/lib)
+       
+endif( ALICE_TARGET STREQUAL "macosx")
+
+set ( ELIBS ${ELIBS} Storage )
\ No newline at end of file
diff --git a/STORAGE/CMakelibStorage.pkg b/STORAGE/CMakelibStorage.pkg
new file mode 100755 (executable)
index 0000000..5b161df
--- /dev/null
@@ -0,0 +1,58 @@
+# -*- mode: CMake -*- 
+#--------------------------------------------------------------------------------#
+# Package File for EveBase                                                       #
+# Author : Johny Jose (johny.jose@cern.ch)                                       #
+# Variables Defined :                                                            #
+#                                                                                #
+# SRCS - C++ source files                                                        #
+# HDRS - C++ header files                                                        #
+# DHDR - ROOT Dictionary Linkdef header file                                     #
+# CSRCS - C source files                                                         #
+# CHDRS - C header files                                                         #
+# EINCLUDE - Include directories                                                 #
+# EDEFINE - Compiler definitions                                                 #
+# ELIBS - Extra libraries to link                                                #
+# ELIBSDIR - Extra library directories                                           #
+# PACKFFLAGS - Fortran compiler flags for package                                #
+# PACKCXXFLAGS - C++ compiler flags for package                                  #
+# PACKCFLAGS - C compiler flags for package                                      #
+# PACKSOFLAGS - Shared library linking flags                                     #
+# PACKLDFLAGS - Module linker flags                                              #
+# PACKBLIBS - Libraries to link (Executables only)                               #
+# EXPORT - Header files to be exported                                           #
+# CINTHDRS - Dictionary header files                                             #
+# CINTAUTOLINK - Set automatic dictionary generation                             #
+# ARLIBS - Archive Libraries and objects for linking (Executables only)          #
+# SHLIBS - Shared Libraries and objects for linking (Executables only)           #
+#--------------------------------------------------------------------------------#
+
+set ( SRCS
+   AliStorageClientThread.cxx
+   AliStorageServerThread.cxx
+   AliStorageAdministratorPanel.cxx
+   AliStorageAdministratorPanelMarkEvent.cxx
+   AliStorageAdministratorPanelListEvents.cxx
+   AliStorageAdministratorPanelSetStorageParams.cxx
+   AliStorageEventManager.cxx
+   AliStorageDatabase.cxx
+)
+
+string ( REPLACE ".cxx" ".h" CINTHDRS "${SRCS}" )
+string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
+
+set ( DHDR  StorageLinkDef.h)
+
+set ( EINCLUDE STORAGE MONITOR MONITORzmq STEER/STEER STEER/AOD STEER/ESD STEER/STEERBase EVE/EveBase )
+
+set ( ELIBS ${ELIBS} ${ZEROMQ_LIBRARIES})
+set ( ELIBSDIR ${ELIBSDIR}  /usr/lib64)
+
+set (EXPORT    
+    AliStorageClientThread.h
+    AliStorageServerThread.h
+    AliStorageAdministratorPanel.h
+    AliStorageAdministratorPanelMarkEvent.h
+    AliStorageAdministratorPanelListEvents.h
+    AliStorageAdministratorPanelSetStorageParams.h
+    AliStorageEventManager.h
+)
diff --git a/STORAGE/StorageLinkDef.h b/STORAGE/StorageLinkDef.h
new file mode 100755 (executable)
index 0000000..5afd7c5
--- /dev/null
@@ -0,0 +1,22 @@
+// $Id$
+// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
+
+/**************************************************************************
+ * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
+ * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
+ * full copyright notice.                                                 *
+ **************************************************************************/
+
+#pragma link off all functions;
+#pragma link off all globals;
+#pragma link off all classes;
+
+#pragma link C++ class AliStorageDatabase+;
+#pragma link C++ class AliStorageClientThread+;
+#pragma link C++ class AliStorageServerThread+;
+#pragma link C++ class AliStorageEventManager+;     
+#pragma link C++ class AliStorageAdministratorPanel+;
+#pragma link C++ class AliStorageAdministratorPanelMarkEvent+;
+#pragma link C++ class AliStorageAdministratorPanelListEvents+;
+#pragma link C++ class AliStorageAdministratorPanelSetStorageParams+;
+
diff --git a/STORAGE/alifakedisplay.cxx b/STORAGE/alifakedisplay.cxx
new file mode 100644 (file)
index 0000000..6580de1
--- /dev/null
@@ -0,0 +1,80 @@
+#include "AliStorageEventManager.h"
+#include "AliStorageTypes.h"
+#include "AliESDEvent.h"
+
+#include "zmq.hpp"
+#include <iostream>
+
+using namespace std;
+using namespace zmq;
+
+/* parameters:
+
+0 - connect directly to reconstruction socket
+1 - connect to Storage Manager and ask for last event
+
+*/
+
+int main(int argc, char **argv)
+{
+       if(argc<2)
+       {
+               cout<<"Usage: alifakedisplay <mode>"<<endl;
+               cout<<"mode:"<<endl;
+               cout<<"0 - connect directly to reconstruction socket"<<endl;
+               cout<<"1 - connect to Storage Manager and ask for last event"<<endl;
+               return 0;
+       }
+       
+       context_t *context = new context_t();
+       socket_t *socket;
+       AliStorageEventManager *manager = new AliStorageEventManager();
+       AliESDEvent *event;
+       
+       if(atoi(argv[1])==0)
+       {
+               socket = new socket_t(*context,ZMQ_SUB);
+               socket->setsockopt(ZMQ_SUBSCRIBE,"",0);
+               socket->connect(Form("tcp://137.138.93.150:%d",gEventsSubscriberPort));
+               while(1)
+               {
+                       event = manager->GetEvent(socket);
+                       if(event)
+                       {
+                               cout<<"Received event. Run:"<<event->GetRunNumber()<<"\t event:"<<event->GetEventNumberInFile()<<endl;
+               
+                               delete event;
+                       }
+                       else
+                       {
+                               cout<<"NO EVENT"<<endl;
+                       }
+               }
+       }
+       else if(atoi(argv[1])==1)
+       {
+               socket = new socket_t(*context,ZMQ_REQ);
+               socket->connect(Form("tcp://137.138.93.150:%d",gServerCommunicationPort));
+               while(1)
+               {
+                       struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
+                       requestMessage->messageType = REQUEST_GET_LAST_EVENT;
+
+                       manager->Send(requestMessage,socket);                   
+                       event = manager->GetEvent(socket);
+                       if(event)
+                       {
+                               cout<<"Last event - Run:"<<event->GetRunNumber()<<"\t event:"<<event->GetEventNumberInFile()<<endl;
+               
+                               delete event;
+                       }
+                       else
+                       {
+                               cout<<"NO EVENT"<<endl;
+                       }
+                       sleep(1);
+               }
+       }
+
+       return 0;
+}
diff --git a/STORAGE/alistorage_main/alistorage_main.cxx b/STORAGE/alistorage_main/alistorage_main.cxx
new file mode 100644 (file)
index 0000000..2b450f8
--- /dev/null
@@ -0,0 +1,50 @@
+#include "AliStorageClientThread.h"
+#include "AliStorageServerThread.h"
+
+#include <iostream>
+
+using namespace std;
+
+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;
+}
+
+void *ServerThreadHandle(void*)
+{
+       cout<<"\nALICE Storage Manager -- Starting server thread"<<endl;
+       AliStorageServerThread *server = new AliStorageServerThread();
+
+       if(!server)
+       {
+               cout<<"ALICE Storage Manager -- ERROR - failed to start server thread!!"<<endl;
+       }
+       if(server){delete server;}
+       return 0;
+}
+
+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    
+       return 0;
+}
diff --git a/STORAGE/alistorageadmin_main/alistorageadmin_main.cxx b/STORAGE/alistorageadmin_main/alistorageadmin_main.cxx
new file mode 100644 (file)
index 0000000..89c177a
--- /dev/null
@@ -0,0 +1,14 @@
+#include "AliStorageAdministratorPanel.h"
+#include <TApplication.h>
+
+
+int main(int argc,char **argv)
+{
+       TApplication app("AliStorageAdmin", &argc, argv);
+       AliStorageAdministratorPanel *mainWindow = new AliStorageAdministratorPanel();
+       app.Run(kTRUE);
+       if(mainWindow){delete mainWindow;}
+
+       
+       return 0;
+}
diff --git a/STORAGE/clearAll.sh b/STORAGE/clearAll.sh
new file mode 100755 (executable)
index 0000000..d53f602
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/bash
+rm -fr /opt/reco/run197669/
+rm -fr /opt/reco/log/run197669.log
+rm -fr ~/storedFiles/
+mysql -u storage -pstorage123 -e "drop database storage"
+$ALICE_ROOT/STORAGE/setupStorageDatabase.sh
diff --git a/STORAGE/setupStorageDatabase.sh b/STORAGE/setupStorageDatabase.sh
new file mode 100755 (executable)
index 0000000..2bbf447
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/bash
+HOST="localhost"   # IP of machine on which mysql database is located
+PORT="5055"
+DATABASE="storage"
+USER="storage"
+PASS="storage123"
+TABLE="events"
+STORAGE_PATH="/local/home/edis/storedFiles"
+MAX_SIZE="5000000"
+MAX_OCCUPATION="80"
+REMOVE_PERCENT="60"
+EVENTS_IN_FILE="7"
+EVENT_SERVER="localhost"   # IP of machine running alieventserver
+STORAGE_SERVER="localhost"      # IP of machine running alistorage
+mysql -u root -pdaq -e "create database if not exists $DATABASE;"
+mysql -u root -pdaq -e "grant ALL PRIVILEGES on $DATABASE.* to '$USER'@'$HOST' identified by '$PASS';"
+mysql -u root -pdaq -e "use $DATABASE;"
+mysql -u root -pdaq -e "CREATE TABLE IF NOT EXISTS $DATABASE.$TABLE(\
+run_number int(6) NOT NULL,\
+event_number int(6) NOT NULL,\
+system text(7) DEFAULT NULL,\
+multiplicity int(5) DEFAULT NULL,\
+permanent tinyint(1) DEFAULT NULL,\
+file_path text(100) DEFAULT NULL,\
+PRIMARY KEY(run_number,event_number));"
+
+echo "-----------------------------"
+echo "Databases successfuly created"
+echo "-----------------------------"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+