2 // Author: Matevz Tadel 2007
4 /**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
10 #include "AliOnlineReco.h"
11 #include "AliChildProcTerminator.h"
12 #include "AliDimIntNotifier.h"
13 #include "AliCDBManager.h"
14 #include "AliGRPPreprocessor.h"
16 #include <TGListBox.h>
22 //______________________________________________________________________________
23 // Full description of AliOnlineReco
26 ClassImp(AliOnlineReco)
28 AliOnlineReco::AliOnlineReco() :
29 TGMainFrame(gClient->GetRoot(), 400, 400),
31 fRunList(0), fStartButt(0), fStopButt(0), fXyzzButt(0),
33 fSOR(new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS")),
34 fEOR(new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS")),
39 fRunList = new TGListBox(this);
40 AddFrame(fRunList, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
42 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 1, 20);
44 fStartButt = new TGTextButton(hf, "Start");
45 hf->AddFrame(fStartButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
46 fStartButt->Connect("Clicked()", "AliOnlineReco", this, "DoStart()");
48 fStopButt = new TGTextButton(hf, "Stop");
49 hf->AddFrame(fStopButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
50 fStopButt->Connect("Clicked()", "AliOnlineReco", this, "DoStop()");
52 fXyzzButt = new TGTextButton(hf, "Exit");
53 hf->AddFrame(fXyzzButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
54 fXyzzButt->Connect("Clicked()", "AliOnlineReco", this, "DoXyzz()");
56 AddFrame(hf, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
60 SetWindowName("Alice Online Reconstruction");
63 fSOR->Connect("DimMessage(Int_t)", "AliOnlineReco", this, "StartOfRun(Int_t)");
64 fEOR->Connect("DimMessage(Int_t)", "AliOnlineReco", this, "EndOfRun(Int_t)");
67 // ROOT's TSignalHAndler works not SIGCHLD ...
68 AliChildProcTerminator::Instance()->Connect("ChildProcTerm(Int_t,Int_t)", "AliOnlineReco", this, "ChildProcTerm(Int_t,Int_t)");
71 AliOnlineReco::mIntInt_i AliOnlineReco::FindMapEntryByPid(Int_t pid)
73 for (mIntInt_i i = fRun2PidMap.begin(); i != fRun2PidMap.end(); ++i)
79 return fRun2PidMap.end();
82 //------------------------------------------------------------------------------
83 // Handlers of DIM signals.
84 //------------------------------------------------------------------------------
86 void AliOnlineReco::StartOfRun(Int_t run)
88 mIntInt_i i = fRun2PidMap.find(run);
89 if (i == fRun2PidMap.end())
92 fRunList->AddEntrySort(TString::Format("%d", run), run);
97 Error("StartOfRun", "Run %d already registered.", run);
101 void AliOnlineReco::EndOfRun(Int_t run)
103 mIntInt_i i = fRun2PidMap.find(run);
104 if (i != fRun2PidMap.end())
106 Int_t pid = i->second;
107 fRunList->RemoveEntry(run);
109 fRun2PidMap.erase(i);
112 // Send terminate signal to process ...
119 // alieve will auto-destruct on SIGUSR1
123 gClient->NeedRedraw(fRunList);
127 Error("EndOfRun", "Run %d not registered.", run);
131 //------------------------------------------------------------------------------
132 // Handlers of OS signals.
133 //------------------------------------------------------------------------------
135 void AliOnlineReco::ChildProcTerm(Int_t pid, Int_t status)
137 printf("child process termination pid=%d, status=%d...\n", pid, status);
139 mIntInt_i i = FindMapEntryByPid(pid);
140 if (i != fRun2PidMap.end())
142 Int_t run = i->first;
143 fRunList->RemoveEntry(run);
146 fRunList->AddEntrySort(TString::Format("%-20d -- FINISHED", run), run);
150 fRunList->AddEntrySort(TString::Format("%-20d -- CRASHED [%d]", run, status), run);
157 Warning("ChildProcTerm", "Process with pid=%d not registered.", pid);
161 //------------------------------------------------------------------------------
162 // Handlers of button signals.
163 //------------------------------------------------------------------------------
165 void AliOnlineReco::DoStart()
167 Int_t run = fRunList->GetSelected();
168 mIntInt_i i = fRun2PidMap.find(run);
170 if (i == fRun2PidMap.end())
172 Error("DoStart", "no selection");
181 perror("DoStart -- Fork failed");
188 fRunList->RemoveEntry(run);
189 fRunList->AddEntrySort(TString::Format("%-20d -- RUNNING", run), run);
197 s = execlp("alitestproc", "alitestproc", TString::Format("%d", run).Data(), (char*) 0);
201 Int_t procPID = gSystem->GetPid();
202 TString logFile = Form("%s/reco/log/run%d_%d.log",
203 gSystem->Getenv("ONLINERECO_BASE_DIR"),
206 Info("DoStart","Reconstruction log will be written to %s",logFile.Data());
207 gSystem->RedirectOutput(logFile.Data());
209 gSystem->cd(Form("%s/reco",gSystem->Getenv("ONLINERECO_BASE_DIR")));
212 if ((RetrieveGRP(run,gdcs) <= 0) ||
216 gSystem->Setenv("DATE_RUN_NUMBER",Form("%d",run));
218 // AliCDBManager * man = AliCDBManager::Instance();
219 // man->SetDefaultStorage("local:///local/cdb");
220 // man->SetSpecificStorage("GRP/GRP/Data",
221 // Form("local://%s",gSystem->pwd()));
222 // man->SetSpecificStorage("GRP/CTP/Config",
223 // Form("local://%s",gSystem->pwd()));
224 // man->SetSpecificStorage("ACORDE/Align/Data",
225 // "local://$ALICE_ROOT/OCDB");
227 gSystem->mkdir(Form("run%d_%d",run,(Int_t)procPID));
228 gSystem->cd(Form("run%d_%d",run,(Int_t)procPID));
230 const char *recMacroPath = "$ALICE_ROOT/test/cosmic/rec.C";
235 Form("%s(\"mem://@*:\")",gSystem->ExpandPathName(recMacroPath)),
241 perror("execlp failed - this will not end well");
248 Error("DoStart", "Process already running.");
252 void AliOnlineReco::DoStop()
254 Int_t run = fRunList->GetSelected();
255 mIntInt_i i = fRun2PidMap.find(run);
257 if (i == fRun2PidMap.end())
259 Error("DoStop", "no selection");
263 Int_t pid = i->second;
272 // alieve will auto-destruct on SIGUSR1
278 Error("DoStop", "Process not running.");
282 void AliOnlineReco::DoXyzz()
287 void AliOnlineReco::CloseWindow()
292 Int_t AliOnlineReco::RetrieveGRP(UInt_t run, TString &gdc) {
294 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, "aldaqdb", 0, "LOGBOOK", "logbook", "alice",
295 Form("local://%s",gSystem->pwd()),
297 if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
298 else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
299 else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);