]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MONITOR/AliRecoServer.cxx
Add bkg subtraction (optional); change to LCH11h as default input set
[u/mrichter/AliRoot.git] / MONITOR / AliRecoServer.cxx
CommitLineData
7e0cf530 1// Author: Mihai Niculescu 2013
2
3/**************************************************************************
4 * Copyright(c) 1998-2013, ALICE Experiment at CERN, all rights reserved. *
5 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
6 * full copyright notice. *
7 **************************************************************************/
8
9#include <TEnv.h>
10#include <TSystem.h>
11#include <TThread.h>
12
13#include <AliLog.h>
14#include <AliESDEvent.h>
15#include <AliCDBManager.h>
16#include <AliGRPPreprocessor.h>
17#include <AliReconstruction.h>
18#include <AliTPCRecoParam.h>
19
20#include "AliEventServerUtil.h"
21#include "AliRecoServer.h"
22#include "AliRecoServerThread.h"
23
24ClassImp(AliRecoServer)
25AliRecoServer::AliRecoServer()
26 : TQObject(),
27 fContext(0),
28 fReco(0),
29 fCDBman(0),
30 fCurrentRunId(0),
31 fIsListenning(kFALSE),
32 fSettings(0),
33 fRecoTh(0)
34{
35 fContext = new zmq::context_t(1);
36}
37
38AliRecoServer::~AliRecoServer()
39{
40 Close(); // Full Close Server
41 delete fSettings;
42}
43
44void AliRecoServer::Close()
45{
46 if(fIsListenning){
47 Info("AliRecoServer::Close", "Closing Server");
48
49 StopReconstruction();
50
51 delete fContext; fContext=0;
52 fIsListenning = kFALSE;
53 }
54
55}
56
57const char* AliRecoServer::GetError() const
58{}
59
60Bool_t AliRecoServer::IsListenning() const
61{
62 return fIsListenning;
63}
64
65void AliRecoServer::ThreadFinished(Int_t status)
66{
67 Emit("ThreadFinished(Int_t) ", status);
68}
69
70Bool_t AliRecoServer::StartReconstruction(Int_t run, const char* input)
71{
72 fCurrentRunId = run;
73
74 // stop current reconstruction
75 StopReconstruction();
76
77 // re-read settings
78 if(fSettings) delete fSettings;
79 fSettings = new TEnv(Form("%s/MONITOR/%s", gSystem->Getenv("ALICE_ROOT"), ALIEVENTSERVER_CONF) );
80
81 TString recoBaseDir = fSettings->GetValue("server.saveRecoDir", DEFAULT_SERVER_SAVE_RECO_DIR);
82
83 // Create directories and logfile
84 TString logFile = Form("%s/log/run%d.log",
85 recoBaseDir.Data(),
86 run);
87 Info("DoStart","Reconstruction log will be written to %s",logFile.Data());
88 if( gSystem->RedirectOutput(logFile.Data())!=0){
89 printf(Form("AliRecoServer::StartReconstruction [] Error while trying to redirect output to [%s]. Exiting...", logFile.Data()) );
90 return kFALSE;
91 }
92
93 gSystem->cd(recoBaseDir.Data());
94
95 TString gdcs;
96 if (RetrieveGRP(run,gdcs) <= 0 || gdcs.IsNull())
97 return kFALSE;
98
99 gSystem->mkdir(Form("run%d", run));
100 gSystem->cd(Form("run%d", run));
101
102 // Create Reco and Reco Thread
103 SetupReco(input);
104 fReco->InitRun(input);
105
106 fRecoTh = new AliRecoServerThread(fContext, fReco);
107 fRecoTh->Start( Form("%s:%d", fSettings->GetValue("server.host", DEFAULT_SERVER_HOST), fSettings->GetValue("server.port", DEFAULT_SERVER_PORT)) );
108 fIsListenning = kTRUE;
109}
110
111void AliRecoServer::StopReconstruction()
112{
113 if(!fRecoTh) return;
114
115 fRecoTh->Stop();
116
117 delete fReco; fReco = 0;
118 delete fCDBman; fCDBman = 0;
119
120 // Emit signal
121 ThreadFinished(0);
122}
123
124Int_t AliRecoServer::RetrieveGRP(UInt_t run, TString &gdc)
125{
126 if(!fSettings) return (-1);
127
128 // Retrieve GRP entry for given run from aldaqdb.
129 TString dbHost = fSettings->GetValue("logbook.host", DEFAULT_LOGBOOK_HOST);
130 Int_t dbPort = fSettings->GetValue("logbook.port", DEFAULT_LOGBOOK_PORT);
131 TString dbName = fSettings->GetValue("logbook.db", DEFAULT_LOGBOOK_DB);
132 TString user = fSettings->GetValue("logbook.user", DEFAULT_LOGBOOK_USER);
133 TString password = fSettings->GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS);
134
135 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, dbHost.Data(),
136 dbPort, dbName.Data(),
137 user.Data(), password.Data(),
138 Form("local://%s",gSystem->pwd()),
139 gdc);
140
141 if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
142 else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
143 else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);
144 return(ret);
145}
146
147void AliRecoServer::SetupReco(const char* input)
148{
149 if(!fSettings) return;
150
151 //AliTPCRecoParam::SetUseTimeCalibration(kFALSE); //-- !probably should be set from conf file!
152
153 printf(Form("=========================[local://%s/..]===========\n",gSystem->pwd()));
154
155 /* Settings CDB */
156 fCDBman = AliCDBManager::Instance();
157
158 fCDBman->SetDefaultStorage(fSettings->GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE));
159 fCDBman->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath1", DEFAULT_CDB_SPEC_STORAGE_PATH1),
160 fSettings->GetValue( "cdb.specificStorageValue1", DEFAULT_CDB_SPEC_STORAGE_VALUE1));
161
162 fCDBman->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2),
163 fSettings->GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2));
164
165 fCDBman->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3),
166 fSettings->GetValue( "cdb.specificStorageValue3", DEFAULT_CDB_SPEC_STORAGE_VALUE3));
167
168 /* Reconstruction settings */
169 if(fReco) delete fReco;
170
171 AliReconstruction* rec = new AliReconstruction;
172
173 // QA options
174 rec->SetRunQA(fSettings->GetValue( "qa.runDetectors", DEFAULT_QA_RUN));
175 rec->SetRunGlobalQA(fSettings->GetValue( "qa.runGlobal", DEFAULT_QA_RUN_GLOBAL));
176 rec->SetQARefDefaultStorage(fSettings->GetValue( "qa.defaultStorage",DEFAULT_QAREF_STORAGE)) ;
177 rec->SetRunPlaneEff(fSettings->GetValue( "reco.runPlaneEff", DEFAULT_RECO_RUN_PLANE_EFF));
178
179 // AliReconstruction settings
180 rec->SetWriteESDfriend(fSettings->GetValue( "reco.writeESDfriend", DEFAULT_RECO_WRITE_ESDF));
181 rec->SetWriteAlignmentData(fSettings->GetValue( "reco.writeAlignment",DEFAULT_RECO_WRITE_ALIGN));
182 rec->SetInput(input); // reconstruct data from this input
183 rec->SetRunReconstruction(fSettings->GetValue( "reco.detectors", DEFAULT_RECO_DETECTORS));
184 rec->SetUseTrackingErrorsForAlignment("ITS"); //-- !should be set from conf file!
185
186 // switch off cleanESD
187 rec->SetCleanESD(fSettings->GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD));
188
189 fReco = rec;
190}