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>
22 #include "AliEventServerUtil.h"
23 #include "AliRecoServer.h"
24 #include "AliRecoServerThread.h"
26 ClassImp(AliRecoServer)
27 AliRecoServer::AliRecoServer()
33 fIsListenning(kFALSE),
37 fContext = new zmq::context_t;
40 AliRecoServer::~AliRecoServer()
42 Close(); // Full Close Server
46 void AliRecoServer::Close()
49 Info("AliRecoServer::Close", "Closing Server");
53 delete fContext; fContext=0;
54 fIsListenning = kFALSE;
59 const char* AliRecoServer::GetError() const
62 Bool_t AliRecoServer::IsListenning() const
67 void AliRecoServer::ThreadFinished(Int_t status)
69 Emit("ThreadFinished(Int_t) ", status);
72 Bool_t AliRecoServer::StartReconstruction(Int_t run, const char* input)
76 // stop current reconstruction
80 if(fSettings) delete fSettings;
81 fSettings = new TEnv(Form("%s/MONITOR/%s", gSystem->Getenv("ALICE_ROOT"), ALIEVENTSERVER_CONF) );
83 TString recoBaseDir = fSettings->GetValue("server.saveRecoDir", DEFAULT_SERVER_SAVE_RECO_DIR);
85 // Create directories and logfile
86 TString logFile = Form("%s/log/run%d.log",
89 Info("DoStart","Reconstruction log will be written to %s",logFile.Data());
90 if( gSystem->RedirectOutput(logFile.Data())!=0){
91 printf(Form("AliRecoServer::StartReconstruction [] Error while trying to redirect output to [%s]. Exiting...", logFile.Data()) );
95 gSystem->cd(recoBaseDir.Data());
98 if (RetrieveGRP(run,gdcs) <= 0 || gdcs.IsNull())
101 gSystem->mkdir(Form("run%d", run));
102 gSystem->cd(Form("run%d", run));
104 // Create Reco and Reco Thread
106 fReco->InitRun(input);
108 fRecoTh = new AliRecoServerThread(fContext, fReco);
109 fRecoTh->Start( Form("%s:%d", fSettings->GetValue("server.host", DEFAULT_SERVER_HOST), fSettings->GetValue("server.port", DEFAULT_SERVER_PORT)) );
110 fIsListenning = kTRUE;
113 void AliRecoServer::StopReconstruction()
119 delete fReco; fReco = 0;
120 delete fCDBman; fCDBman = 0;
126 Int_t AliRecoServer::RetrieveGRP(UInt_t run, TString &gdc)
128 if(!fSettings) return (-1);
130 // Retrieve GRP entry for given run from aldaqdb.
131 TString dbHost = fSettings->GetValue("logbook.host", DEFAULT_LOGBOOK_HOST);
132 Int_t dbPort = fSettings->GetValue("logbook.port", DEFAULT_LOGBOOK_PORT);
133 TString dbName = fSettings->GetValue("logbook.db", DEFAULT_LOGBOOK_DB);
134 TString user = fSettings->GetValue("logbook.user", DEFAULT_LOGBOOK_USER);
135 TString password = fSettings->GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS);
137 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, dbHost.Data(),
138 dbPort, dbName.Data(),
139 user.Data(), password.Data(),
140 Form("local://%s",gSystem->pwd()),
143 if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
144 else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
145 else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);
149 void AliRecoServer::SetupReco(const char* input)
151 if(!fSettings) return;
153 //AliTPCRecoParam::SetUseTimeCalibration(kFALSE); //-- !probably should be set from conf file!
155 printf(Form("=========================[local://%s/..]===========\n",gSystem->pwd()));
158 fCDBman = AliCDBManager::Instance();
160 fCDBman->SetDefaultStorage(fSettings->GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE));
161 fCDBman->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath1", DEFAULT_CDB_SPEC_STORAGE_PATH1),
162 fSettings->GetValue( "cdb.specificStorageValue1", DEFAULT_CDB_SPEC_STORAGE_VALUE1));
164 fCDBman->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2),
165 fSettings->GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2));
167 fCDBman->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3),
168 fSettings->GetValue( "cdb.specificStorageValue3", DEFAULT_CDB_SPEC_STORAGE_VALUE3));
170 /* Reconstruction settings */
171 if(fReco) delete fReco;
173 AliReconstruction* rec = new AliReconstruction;
176 rec->SetRunQA(fSettings->GetValue( "qa.runDetectors", DEFAULT_QA_RUN));
177 rec->SetRunGlobalQA(fSettings->GetValue( "qa.runGlobal", DEFAULT_QA_RUN_GLOBAL));
178 rec->SetQARefDefaultStorage(fSettings->GetValue( "qa.defaultStorage",DEFAULT_QAREF_STORAGE)) ;
179 rec->SetRunPlaneEff(fSettings->GetValue( "reco.runPlaneEff", DEFAULT_RECO_RUN_PLANE_EFF));
181 // AliReconstruction settings
182 rec->SetWriteESDfriend(fSettings->GetValue( "reco.writeESDfriend", DEFAULT_RECO_WRITE_ESDF));
183 rec->SetWriteAlignmentData(fSettings->GetValue( "reco.writeAlignment",DEFAULT_RECO_WRITE_ALIGN));
184 rec->SetInput(input); // reconstruct data from this input
185 rec->SetRunReconstruction(fSettings->GetValue( "reco.detectors", DEFAULT_RECO_DETECTORS));
186 rec->SetUseTrackingErrorsForAlignment("ITS"); //-- !should be set from conf file!
188 // switch off cleanESD
189 rec->SetCleanESD(fSettings->GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD));