]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/alistoragemanager/AliDIMListenerThread.cxx
Fixing file after rebasing master
[u/mrichter/AliRoot.git] / MONITOR / alistoragemanager / AliDIMListenerThread.cxx
1 #include "AliDIMListenerThread.h"
2 #include "AliStorageTypes.h"
3
4 #include <iostream>
5 #include <sstream>
6 #include <fstream>
7
8 using namespace std;
9
10 AliDIMListenerThread::AliDIMListenerThread() : 
11   fDimSORListener(0),
12   fDimEORListener(0),
13   fOnlineReconstructionHostname(""),
14   fOnlineReconstructionUsername("")
15 {    
16     ifstream configFile (GetConfigFilePath());
17     
18     if (configFile.is_open())
19     {
20         string line;
21         int from,to;
22         while(configFile.good())
23         {
24             getline(configFile,line);
25             from = line.find("\"")+1;
26             to = line.find_last_of("\"");
27             if(line.find("EVENT_SERVER=")==0){fOnlineReconstructionHostname=line.substr(from,to-from);}
28             else if(line.find("EVENT_SERVER_USER=")==0){fOnlineReconstructionUsername=line.substr(from,to-from);}
29         }
30         if(configFile.eof()){configFile.clear();}
31         configFile.close();
32     }
33     else{cout<<"AliDIMListenerThread -- Unable to open config file"<<endl;}
34
35     InitDIMListeners();
36
37 #ifdef ALI_DATE
38     // check if there is a run in partition PHYSICS_1
39     DimCurrentInfo SORrunNumber("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS_1",-1);
40     DimCurrentInfo EORrunNumber("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS_1",-1);
41
42     if(SORrunNumber.getData() && EORrunNumber.getData())
43     {
44         cout<<"DIM Listener -- current SOR signal:"<<SORrunNumber.getInt()<<endl;
45         cout<<"DIM Listener -- current EOR signal:"<<EORrunNumber.getInt()<<endl;
46         
47         if(SORrunNumber.getInt() != EORrunNumber.getInt()){StartOfRun(SORrunNumber.getInt());}
48     }
49     else{cout<<"AliDIMListenerThread -- no data received from dim server"<<endl;}
50 #endif
51 }
52
53 AliDIMListenerThread::~AliDIMListenerThread()
54 {
55   cout<<"AliDIMListenerThread -- destructor called...";
56   if(fDimSORListener){delete fDimSORListener;fDimSORListener = 0;}
57   if(fDimEORListener){delete fDimEORListener;fDimEORListener = 0;}
58
59   // kill all running reconstructions (to be changed later)
60     gSystem->Exec(Form("ssh -n -f %s@%s \"killall alionlinereco\"",fOnlineReconstructionUsername.c_str(),fOnlineReconstructionHostname.c_str()));
61
62   /*
63     for (int i = 0; i < 5; ++i){
64         if(fDimSORListener[i]) delete fDimSORListener[i];
65         if(fDimEORListener[i]) delete fDimEORListener[i];
66         
67         fDimSORListener[i] = 0;
68         fDimEORListener[i] = 0;
69         }*/
70   cout<<"OK"<<endl;
71 }
72
73 void AliDIMListenerThread::InitDIMListeners()
74 {
75
76 #ifdef ALI_DATE
77   /*
78   for (int i = 0; i < 5; ++i)
79   {
80   
81   if (i == 0)
82         {
83             fDimSORListener[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS");
84             fDimEORListener[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS");
85         }
86         else
87         {
88             fDimSORListener[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS_%d", i));
89             fDimEORListener[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS_%d", i));
90         }
91         fDimSORListener[i]->Connect("DimMessage(int)", "AliDIMListenerThread", this, "StartOfRun(int)");
92         fDimEORListener[i]->Connect("DimMessage(int)", "AliDIMListenerThread", this, "EndOfRun(int)");
93 }
94   */
95   fDimSORListener = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS_1");
96   fDimEORListener = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS_1");
97   fDimSORListener->Connect("DimMessage(int)", "AliDIMListenerThread", this, "StartOfRun(int)");
98   fDimEORListener->Connect("DimMessage(int)", "AliDIMListenerThread", this, "EndOfRun(int)");
99 #endif
100 }
101
102 void AliDIMListenerThread::StartOfRun(int run)
103 {
104     cout<<"AliDIMListenerThread -- SOR signal received for run:"<<run<<endl;
105    
106     // Kill reconstruction and start new one
107     gSystem->Exec(Form("ssh -n -f %s@%s \". ~/EventServerTesting/setEnv.sh;killall alionlinereco;alionlinereco %d\"",fOnlineReconstructionUsername.c_str(),fOnlineReconstructionHostname.c_str(),run));
108 }
109
110 void AliDIMListenerThread::EndOfRun(int run)
111 {
112     cout<<"AliDIMListenerThread -- EOR signal received for run:"<<run<<endl;
113
114     // kill all running reconstructions (to be changed later)
115     gSystem->Exec(Form("ssh -n -f %s@%s \"killall alionlinereco\"",fOnlineReconstructionUsername.c_str(),fOnlineReconstructionHostname.c_str()));
116 }