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 #if (ZMQ_VERSION_MAJOR>=3)
38 fContext = new zmq::context_t;
40 fContext = new zmq::context_t(1);
41 #endif /* (ZMQ_VERSION_MAJOR>=3) */
44 AliRecoServer::~AliRecoServer()
46 Close(); // Full Close Server
50 void AliRecoServer::Close()
53 Info("AliRecoServer::Close", "Closing Server");
57 delete fContext; fContext=0;
58 fIsListenning = kFALSE;
63 const char* AliRecoServer::GetError() const
66 Bool_t AliRecoServer::IsListenning() const
71 void AliRecoServer::ThreadFinished(Int_t status)
73 Emit("ThreadFinished(Int_t) ", status);
76 Bool_t AliRecoServer::StartReconstruction(Int_t run, const char* input)
80 // stop current reconstruction
84 if(fSettings) delete fSettings;
85 fSettings = new TEnv(Form("%s/MONITOR/%s", gSystem->Getenv("ALICE_ROOT"), ALIEVENTSERVER_CONF) );
87 TString recoBaseDir = fSettings->GetValue("server.saveRecoDir", DEFAULT_SERVER_SAVE_RECO_DIR);
89 // Create directories and logfile
90 TString logFile = Form("%s/log/run%d.log",
93 Info("DoStart","Reconstruction log will be written to %s",logFile.Data());
94 if( gSystem->RedirectOutput(logFile.Data())!=0){
95 printf(Form("AliRecoServer::StartReconstruction [] Error while trying to redirect output to [%s]. Exiting...", logFile.Data()) );
99 gSystem->cd(recoBaseDir.Data());
102 if (RetrieveGRP(run,gdcs) <= 0 || gdcs.IsNull())
105 gSystem->mkdir(Form("run%d", run));
106 gSystem->cd(Form("run%d", run));
108 // Create Reco and Reco Thread
110 fReco->InitRun(input);
112 fRecoTh = new AliRecoServerThread(fContext, fReco);
113 fRecoTh->Start( Form("%s:%d", fSettings->GetValue("server.host", DEFAULT_SERVER_HOST), fSettings->GetValue("server.port", DEFAULT_SERVER_PORT)) );
114 fIsListenning = kTRUE;
117 void AliRecoServer::StopReconstruction()
123 delete fReco; fReco = 0;
124 delete fCDBman; fCDBman = 0;
130 Int_t AliRecoServer::RetrieveGRP(UInt_t run, TString &gdc)
132 if(!fSettings) return (-1);
134 // Retrieve GRP entry for given run from aldaqdb.
135 TString dbHost = fSettings->GetValue("logbook.host", DEFAULT_LOGBOOK_HOST);
136 Int_t dbPort = fSettings->GetValue("logbook.port", DEFAULT_LOGBOOK_PORT);
137 TString dbName = fSettings->GetValue("logbook.db", DEFAULT_LOGBOOK_DB);
138 TString user = fSettings->GetValue("logbook.user", DEFAULT_LOGBOOK_USER);
139 TString password = fSettings->GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS);
141 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, dbHost.Data(),
142 dbPort, dbName.Data(),
143 user.Data(), password.Data(),
144 Form("local://%s",gSystem->pwd()),
147 if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
148 else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
149 else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);
153 void AliRecoServer::SetupReco(const char* input)
155 if(!fSettings) return;
157 //AliTPCRecoParam::SetUseTimeCalibration(kFALSE); //-- !probably should be set from conf file!
159 printf(Form("=========================[local://%s/..]===========\n",gSystem->pwd()));
162 fCDBman = AliCDBManager::Instance();
164 fCDBman->SetDefaultStorage(fSettings->GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE));
165 fCDBman->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath1", DEFAULT_CDB_SPEC_STORAGE_PATH1),
166 fSettings->GetValue( "cdb.specificStorageValue1", DEFAULT_CDB_SPEC_STORAGE_VALUE1));
168 fCDBman->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2),
169 fSettings->GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2));
171 fCDBman->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3),
172 fSettings->GetValue( "cdb.specificStorageValue3", DEFAULT_CDB_SPEC_STORAGE_VALUE3));
174 /* Reconstruction settings */
175 if(fReco) delete fReco;
177 AliReconstruction* rec = new AliReconstruction;
180 rec->SetRunQA(fSettings->GetValue( "qa.runDetectors", DEFAULT_QA_RUN));
181 rec->SetRunGlobalQA(fSettings->GetValue( "qa.runGlobal", DEFAULT_QA_RUN_GLOBAL));
182 rec->SetQARefDefaultStorage(fSettings->GetValue( "qa.defaultStorage",DEFAULT_QAREF_STORAGE)) ;
183 rec->SetRunPlaneEff(fSettings->GetValue( "reco.runPlaneEff", DEFAULT_RECO_RUN_PLANE_EFF));
185 // AliReconstruction settings
186 rec->SetWriteESDfriend(fSettings->GetValue( "reco.writeESDfriend", DEFAULT_RECO_WRITE_ESDF));
187 rec->SetWriteAlignmentData(fSettings->GetValue( "reco.writeAlignment",DEFAULT_RECO_WRITE_ALIGN));
188 rec->SetInput(input); // reconstruct data from this input
189 rec->SetRunReconstruction(fSettings->GetValue( "reco.detectors", DEFAULT_RECO_DETECTORS));
190 rec->SetUseTrackingErrorsForAlignment("ITS"); //-- !should be set from conf file!
192 // switch off cleanESD
193 rec->SetCleanESD(fSettings->GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD));