1 // Author: Mihai Niculesu 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 **************************************************************************/
9 #include "AliOnlineReconstruction.h"
10 #include "AliOnlineReconstructionUtil.h"
11 #include "AliStorageEventManager.h"
13 #include <TSQLServer.h>
14 #include <TSQLResult.h>
16 #include <TTimeStamp.h>
24 void GotSignal(int){gQuit = true;}
26 AliOnlineReconstruction::AliOnlineReconstruction(int run) :
30 fAliReco(new AliReconstruction()),
31 fCDBmanager(AliCDBManager::Instance())
33 // make sure that destructor is called when kill signal comes
35 memset(&sa,0,sizeof(sa));
36 sa.sa_handler = GotSignal;
37 sigfillset(&sa.sa_mask);
38 sigaction(SIGINT,&sa,NULL);
40 printf("CDB Lock is %s\n",AliCDBManager::Instance()->GetLock() ? "ON":"OFF");
42 fSettings.ReadFile(AliOnlineReconstructionUtil::GetPathToServerConf(), kEnvUser);
44 cout<<"after startofrun"<<endl;
47 AliOnlineReconstruction::~AliOnlineReconstruction()
49 cout<<"AliOnlineReconstruction -- destructor called...";
52 // fAliReco->SlaveTerminate();
53 // fAliReco->Terminate();
54 // delete fAliReco;fAliReco=0;
56 if(fCDBmanager){fCDBmanager->Destroy();fCDBmanager=0;}
60 void AliOnlineReconstruction::StartOfRun()
62 if(strcmp("local",fSettings.GetValue("data.source", DEFAULT_DATA_SOURCE))==0)
64 cout<<"Starting Reco for run "<<fRun<<endl;
65 fDataSource = Form("mem://%s/run%d", gSystem->Getenv("ONLINERECO_RAWFILES_DIR"), fRun);
67 else if(strcmp(fSettings.GetValue("data.source", DEFAULT_DATA_SOURCE),"run")==0)
69 cout<<"Starting Reco for GDCs active in current run:"<<fRun<<endl;
70 fDataSource = fSettings.GetValue("data.online.source", DEFAULT_DATA_ONLINE_SOURCE);
72 else{cout<<"\n\nWrong data source. Quitting\n\n"<<endl;}
74 TString recoBaseDir = fSettings.GetValue("server.saveRecoDir",DEFAULT_SERVER_SAVE_RECO_DIR);
75 cout<<"Reco base dir:"<<recoBaseDir<<endl;
77 // Create directories and logfile
78 TString logFile = Form("%s/log/run%d.log",recoBaseDir.Data(),fRun);
79 Info("DoStart","Reconstruction log will be written to %s",logFile.Data());
80 if( gSystem->RedirectOutput(logFile.Data(),"w")!=0)
82 printf(Form("AliRecoServer::StartReconstruction [] Error while trying to redirect output to [%s]. Exiting...", logFile.Data()) );
85 gSystem->cd(recoBaseDir.Data());
87 cout<<"\n\nRetriving GRP\n\n"<<endl;
89 if (RetrieveGRP(gdcs) <= 0 || gdcs.IsNull()){return;}
91 gSystem->Exec(Form("rm -fr run%d;mkdir run%d",fRun,fRun));
92 gSystem->cd(Form("run%d",fRun));
95 cout<<"\n\nStarting reconstruction loop\n\n"<<endl;
99 int AliOnlineReconstruction::RetrieveGRP(TString &gdc)
101 // Retrieve GRP entry for given run from aldaqdb.
102 TString dbHost = fSettings.GetValue("logbook.host", DEFAULT_LOGBOOK_HOST);
103 Int_t dbPort = fSettings.GetValue("logbook.port", DEFAULT_LOGBOOK_PORT);
104 TString dbName = fSettings.GetValue("logbook.db", DEFAULT_LOGBOOK_DB);
105 TString user = fSettings.GetValue("logbook.user", DEFAULT_LOGBOOK_USER);
106 TString password = fSettings.GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS);
107 TString cdbPath = fSettings.GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE);
109 cdbPath = Form("local://%s",gSystem->pwd());
111 gSystem->Exec(Form("rm -fr %s/GRP",cdbPath.Data()));
112 cout<<"CDB path for GRP:"<<cdbPath<<endl;
114 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(fRun, dbHost.Data(),
115 dbPort, dbName.Data(),
116 user.Data(), password.Data(),
117 Form("%s",cdbPath.Data()),
120 if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
121 else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
122 else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);
126 void AliOnlineReconstruction::SetupReco()
128 printf(Form("=========================[local://%s/]===========\n",gSystem->pwd()));
131 cout<<"\n\nSetting CDB manager parameters\n\n"<<endl;
132 //fCDBmanager->SetRun(fRun);
133 cout<<"Set default storage"<<endl;
135 fCDBmanager->SetDefaultStorage(fSettings.GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE));
137 fCDBmanager->Print();
138 cout<<"Set specific storage 1"<<endl;
139 fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath1", DEFAULT_CDB_SPEC_STORAGE_PATH1),
140 fSettings.GetValue( "cdb.specificStorageValue1", DEFAULT_CDB_SPEC_STORAGE_VALUE1));
141 fCDBmanager->Print();
142 cout<<"Set specific storage 2"<<endl;
143 fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2),
144 fSettings.GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2));
145 fCDBmanager->Print();
146 // cout<<"Set specific storage 3"<<endl;
147 // fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3),
148 // fSettings.GetValue( "cdb.specificStorageValue3", DEFAULT_CDB_SPEC_STORAGE_VALUE3));
151 //fCDBmanager->SetSpecificStorage("TPC/Calib//PreprocStatus","local:///local/cdb");
152 //fCDBmanager->SetSpecificStorage("TPC/Calib//HighVoltage","local:///local/cdb");
153 //fCDBmanager->SetSpecificStorage("TPC/Calib//Goofie","local:///local/cdb");
154 //fCDBmanager->SetSpecificStorage("GRP/CTP/LTUConfig","local:///local/cdb");
157 //fCDBmanager->SetSpecificStorage("GRP/CTP/Scalers","local:///local/cdb");
159 fCDBmanager->Print();
161 /* Reconstruction settings */
164 cout<<"\n\nSetting AliReconstruction parameters\n\n"<<endl;
165 fAliReco->SetRunQA(fSettings.GetValue("qa.runDetectors",DEFAULT_QA_RUN));
166 fAliReco->SetRunGlobalQA(fSettings.GetValue("qa.runGlobal",DEFAULT_QA_RUN_GLOBAL));
167 fAliReco->SetQARefDefaultStorage(fSettings.GetValue("qa.defaultStorage",DEFAULT_QAREF_STORAGE)) ;
168 fAliReco->SetRunPlaneEff(fSettings.GetValue("reco.runPlaneEff",DEFAULT_RECO_RUN_PLANE_EFF));
169 fCDBmanager->Print();
170 cout<<"\n\nSetting other reco options"<<endl;
171 // AliReconstruction settings
172 fAliReco->SetWriteESDfriend(fSettings.GetValue( "reco.writeESDfriend",DEFAULT_RECO_WRITE_ESDF));
173 fAliReco->SetWriteAlignmentData(fSettings.GetValue( "reco.writeAlignment",DEFAULT_RECO_WRITE_ALIGN));
174 fAliReco->SetInput(fDataSource.Data()); // reconstruct data from this input
175 fAliReco->SetRunReconstruction(fSettings.GetValue( "reco.detectors", DEFAULT_RECO_DETECTORS));
176 fAliReco->SetUseTrackingErrorsForAlignment("ITS"); //-- !should be set from conf file!
177 fAliReco->SetCleanESD(fSettings.GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD));
178 fCDBmanager->Print();
179 // init reco for given run
180 //fAliReco->SetOption("TPC","useHLTorRAW");
181 fAliReco->InitRun(fDataSource.Data());
184 void AliOnlineReconstruction::ReconstructionLoop()
186 cout<<"\n\nCreating sockets\n\n"<<endl;
187 AliStorageEventManager *eventManager = AliStorageEventManager::GetEventManagerInstance();
188 eventManager->CreateSocket(EVENTS_SERVER_PUB);
189 eventManager->CreateSocket(XML_PUB);
190 eventManager->CreateSocket(ITS_POINTS_PUB);
192 cout<<"\n\nStarting reconstruction\n\n"<<endl;
193 fAliReco->Begin(NULL);
194 if (fAliReco->GetAbort() != TSelector::kContinue) return;
195 fAliReco->SlaveBegin(NULL);
196 if (fAliReco->GetAbort() != TSelector::kContinue) return;
197 cout<<"\n\nStarting loop over events\n\n"<<endl;
199 TString recoBaseDir = fSettings.GetValue("server.saveRecoDir",DEFAULT_SERVER_SAVE_RECO_DIR);
202 //******* The loop over events
205 struct recPointsStruct *files;
206 // while (fAliReco->HasNextEventAfter(iEvent) && !gQuit)
209 if(fAliReco->HasNextEventAfter(iEvent))
211 // remove files for previous event: (needed to send RecPoints:
213 gSystem->cd(recoBaseDir.Data());
214 gSystem->Exec(Form("rm -fr run%d;mkdir run%d",fRun,fRun));
215 gSystem->cd(Form("run%d",fRun));
218 if (!fAliReco->HasEnoughResources(iEvent)) break;
219 cout<<"\n\nProcessing event:"<<iEvent<<endl<<endl;
220 Bool_t status = fAliReco->ProcessEvent(iEvent);
223 event = fAliReco->GetESDEvent();
224 eventManager->Send(event,EVENTS_SERVER_PUB);
225 //eventManager->SendAsXml(event,XML_PUB);
227 // sending RecPoints:
229 cout<<"loading file"<<endl;
230 files->files[0] = TFile::Open("./ITS.RecPoints.root");
231 files->files[1] = TFile::Open("./TOF.RecPoints.root");
232 files->files[2] = TFile::Open("./galice.root");
233 files->files[3] = NULL;
234 files->files[4] = NULL;
235 files->files[5] = NULL;
236 files->files[6] = NULL;
237 files->files[7] = NULL;
238 files->files[8] = NULL;
239 files->files[9] = NULL;
242 cout<<"sending files"<<endl;
243 eventManager->Send(files,ITS_POINTS_PUB);
244 cout<<"files sent"<<endl;
246 for(int i=0;i<10;i++)
250 files->files[i]->Close();
251 delete files->files[i];files->files[i]=0;
252 cout<<"file deleted"<<endl;
257 //Saving ESD to file:
259 TFile *file = new TFile(Form("/local/storedFiles/AliESDs.root_%d",iEvent),"recreate");
260 TTree* tree= new TTree("esdTree", "esdTree");
261 event->WriteToTree(tree);
268 cout<<"Event server -- aborting"<<endl;
269 fAliReco->Abort("ProcessEvent",TSelector::kAbortFile);
272 fAliReco->CleanProcessedEvent();
273 cout<<"iEvent++"<<endl;
278 cout<<"No event after!"<<endl;
281 cout<<"after while"<<endl;
282 // fAliReco->SlaveTerminate();
283 //if (fAliReco->GetAbort() != TSelector::kContinue) return;
284 //fAliReco->Terminate();
285 //if (fAliReco->GetAbort() != TSelector::kContinue) return;