1 // Author: Mihai Niculescu 2013
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 **************************************************************************/
14 #include <AliESDEvent.h>
15 #include <AliCDBManager.h>
16 #include <AliGRPPreprocessor.h>
17 #include <AliReconstruction.h>
18 #include <AliTPCRecoParam.h>
20 #include "AliEventServerUtil.h"
21 #include "AliRecoServer.h"
22 #include "AliRecoServerThread.h"
24 ClassImp(AliRecoServer)
25 AliRecoServer::AliRecoServer()
31 fIsListenning(kFALSE),
35 fContext = new zmq::context_t(1);
38 AliRecoServer::~AliRecoServer()
40 Close(); // Full Close Server
44 void AliRecoServer::Close()
47 Info("AliRecoServer::Close", "Closing Server");
51 delete fContext; fContext=0;
52 fIsListenning = kFALSE;
57 const char* AliRecoServer::GetError() const
60 Bool_t AliRecoServer::IsListenning() const
65 void AliRecoServer::ThreadFinished(Int_t status)
67 Emit("ThreadFinished(Int_t) ", status);
70 Bool_t AliRecoServer::StartReconstruction(Int_t run, const char* input)
74 // stop current reconstruction
78 if(fSettings) delete fSettings;
79 fSettings = new TEnv(Form("%s/MONITOR/%s", gSystem->Getenv("ALICE_ROOT"), ALIEVENTSERVER_CONF) );
81 TString recoBaseDir = fSettings->GetValue("server.saveRecoDir", DEFAULT_SERVER_SAVE_RECO_DIR);
83 // Create directories and logfile
84 TString logFile = Form("%s/log/run%d.log",
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()) );
93 gSystem->cd(recoBaseDir.Data());
96 if (RetrieveGRP(run,gdcs) <= 0 || gdcs.IsNull())
99 gSystem->mkdir(Form("run%d", run));
100 gSystem->cd(Form("run%d", run));
102 // Create Reco and Reco Thread
104 fReco->InitRun(input);
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;
111 void AliRecoServer::StopReconstruction()
117 delete fReco; fReco = 0;
118 delete fCDBman; fCDBman = 0;
124 Int_t AliRecoServer::RetrieveGRP(UInt_t run, TString &gdc)
126 if(!fSettings) return (-1);
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);
135 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, dbHost.Data(),
136 dbPort, dbName.Data(),
137 user.Data(), password.Data(),
138 Form("local://%s",gSystem->pwd()),
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);
147 void AliRecoServer::SetupReco(const char* input)
149 if(!fSettings) return;
151 //AliTPCRecoParam::SetUseTimeCalibration(kFALSE); //-- !probably should be set from conf file!
153 printf(Form("=========================[local://%s/..]===========\n",gSystem->pwd()));
156 fCDBman = AliCDBManager::Instance();
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));
162 fCDBman->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2),
163 fSettings->GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2));
165 fCDBman->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3),
166 fSettings->GetValue( "cdb.specificStorageValue3", DEFAULT_CDB_SPEC_STORAGE_VALUE3));
168 /* Reconstruction settings */
169 if(fReco) delete fReco;
171 AliReconstruction* rec = new AliReconstruction;
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));
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!
186 // switch off cleanESD
187 rec->SetCleanESD(fSettings->GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD));