AliRoot Core  v5-06-30 (35d6c57)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliOnlineReconstruction.cxx
Go to the documentation of this file.
1 // Author: Mihai Niculesu 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 
10 #include "AliOnlineReconstructionUtil.h"
11 #include "AliZMQManager.h"
12 
13 #include <TSQLServer.h>
14 #include <TSQLResult.h>
15 #include <TSQLRow.h>
16 #include <TTimeStamp.h>
17 
18 #include <signal.h>
19 #include <iostream>
20 
21 using namespace std;
22 
23 bool gQuit = false;
24 void GotSignal(int){gQuit = true;}
25 
27  fRun(run),
28  fDataSource(""),
29  fSettings(0),
30  fAliReco(new AliReconstruction()),
31  fCDBmanager(AliCDBManager::Instance())
32 {
33  // make sure that destructor is called when kill signal comes
34  struct sigaction sa;
35  memset(&sa,0,sizeof(sa));
36  sa.sa_handler = GotSignal;
37  sigfillset(&sa.sa_mask);
38  sigaction(SIGINT,&sa,NULL);
39 
40  printf("CDB Lock is %s\n",AliCDBManager::Instance()->GetLock() ? "ON":"OFF");
41 
42  fSettings.ReadFile(AliOnlineReconstructionUtil::GetPathToServerConf(), kEnvUser);
43  StartOfRun();
44  cout<<"after startofrun"<<endl;
45 }
46 
48 {
49  cout<<"AliOnlineReconstruction -- destructor called...";
50  if(fAliReco)
51  {
52  // fAliReco->SlaveTerminate();
53  // fAliReco->Terminate();
54  // delete fAliReco;fAliReco=0;
55  }
56  if(fCDBmanager){fCDBmanager->Destroy();fCDBmanager=0;}
57  cout<<"OK"<<endl;
58 }
59 
61 {
62  if(strcmp("local",fSettings.GetValue("data.source", DEFAULT_DATA_SOURCE))==0)
63  {
64  cout<<"Starting Reco for run "<<fRun<<endl;
65  fDataSource = Form("mem://%s/run%d", gSystem->Getenv("ONLINERECO_RAWFILES_DIR"), fRun);
66  }
67  else if(strcmp(fSettings.GetValue("data.source", DEFAULT_DATA_SOURCE),"run")==0)
68  {
69  cout<<"Starting Reco for GDCs active in current run:"<<fRun<<endl;
70  fDataSource = fSettings.GetValue("data.online.source", DEFAULT_DATA_ONLINE_SOURCE);
71  }
72  else{cout<<"\n\nWrong data source. Quitting\n\n"<<endl;}
73 
74  TString recoBaseDir = fSettings.GetValue("server.saveRecoDir",DEFAULT_SERVER_SAVE_RECO_DIR);
75  cout<<"Reco base dir:"<<recoBaseDir<<endl;
76 
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)
81  {
82  printf(Form("AliRecoServer::StartReconstruction [] Error while trying to redirect output to [%s]. Exiting...", logFile.Data()) );
83  return;
84  }
85  gSystem->cd(recoBaseDir.Data());
86 
87  cout<<"\n\nRetriving GRP\n\n"<<endl;
88  TString gdcs;
89  if (RetrieveGRP(gdcs) <= 0 || gdcs.IsNull()){return;}
90 
91  gSystem->Exec(Form("rm -fr run%d;mkdir run%d",fRun,fRun));
92  gSystem->cd(Form("run%d",fRun));
93 
94  SetupReco();
95  cout<<"\n\nStarting reconstruction loop\n\n"<<endl;
97 }
98 
100 {
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);
108 
109  cdbPath = Form("local://%s",gSystem->pwd());
110  gSystem->Exec(Form("rm -fr %s/GRP",cdbPath.Data()));
111  cout<<"CDB path for GRP:"<<cdbPath<<endl;
112 
113  Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(fRun, dbHost.Data(),
114  dbPort, dbName.Data(),
115  user.Data(), password.Data(),
116  Form("%s",cdbPath.Data()),
117  gdc);
118 
119  if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
120  else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
121  else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);
122  return(ret);
123 }
124 
126 {
127  printf(Form("=========================[local://%s/]===========\n",gSystem->pwd()));
128 
129  /* Settings CDB */
130  cout<<"\n\nSetting CDB manager parameters\n\n"<<endl;
131  //fCDBmanager->SetRun(fRun);
132  cout<<"Set default storage"<<endl;
133 
134  fCDBmanager->SetDefaultStorage(fSettings.GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE));
135 
136  fCDBmanager->Print();
137  cout<<"Set specific storage 1"<<endl;
138  fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath1", DEFAULT_CDB_SPEC_STORAGE_PATH1),
139  fSettings.GetValue( "cdb.specificStorageValue1", DEFAULT_CDB_SPEC_STORAGE_VALUE1));
140  fCDBmanager->Print();
141 cout<<"Set specific storage 2"<<endl;
142  fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2),
143  fSettings.GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2));
144  fCDBmanager->Print();
145  cout<<"Set specific storage 3"<<endl;
146  fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3),
147  fSettings.GetValue( "cdb.specificStorageValue3", DEFAULT_CDB_SPEC_STORAGE_VALUE3));
148 
149 
150  //fCDBmanager->SetSpecificStorage("TPC/Calib//PreprocStatus","local:///local/cdb");
151  //fCDBmanager->SetSpecificStorage("TPC/Calib//HighVoltage","local:///local/cdb");
152  //fCDBmanager->SetSpecificStorage("TPC/Calib//Goofie","local:///local/cdb");
153  //fCDBmanager->SetSpecificStorage("GRP/CTP/LTUConfig","local:///local/cdb");
154 
155 
156  //fCDBmanager->SetSpecificStorage("GRP/CTP/Scalers","local:///local/cdb");
157 
158  fCDBmanager->Print();
159 
160  /* Reconstruction settings */
161 
162  // QA options
163  cout<<"\n\nSetting AliReconstruction parameters\n\n"<<endl;
164  fAliReco->SetRunQA(fSettings.GetValue("qa.runDetectors",DEFAULT_QA_RUN));
165  fAliReco->SetRunGlobalQA(fSettings.GetValue("qa.runGlobal",DEFAULT_QA_RUN_GLOBAL));
166  fAliReco->SetQARefDefaultStorage(fSettings.GetValue("qa.defaultStorage",DEFAULT_QAREF_STORAGE)) ;
167  fAliReco->SetRunPlaneEff(fSettings.GetValue("reco.runPlaneEff",DEFAULT_RECO_RUN_PLANE_EFF));
168  fCDBmanager->Print();
169  cout<<"\n\nSetting other reco options"<<endl;
170  // AliReconstruction settings
171  fAliReco->SetWriteESDfriend(fSettings.GetValue( "reco.writeESDfriend",DEFAULT_RECO_WRITE_ESDF));
172  fAliReco->SetWriteAlignmentData(fSettings.GetValue( "reco.writeAlignment",DEFAULT_RECO_WRITE_ALIGN));
173  fAliReco->SetInput(fDataSource.Data()); // reconstruct data from this input
174  fAliReco->SetRunReconstruction(fSettings.GetValue( "reco.detectors", DEFAULT_RECO_DETECTORS));
175  fAliReco->SetUseTrackingErrorsForAlignment("ITS"); //-- !should be set from conf file!
176  fAliReco->SetCleanESD(fSettings.GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD));
177  fCDBmanager->Print();
178  // init reco for given run
179  //fAliReco->SetOption("TPC","useHLTorRAW");
180  fAliReco->InitRun(fDataSource.Data());
181 }
182 
184 {
185  cout<<"\n\nCreating sockets\n\n"<<endl;
186  AliZMQManager *eventManager = AliZMQManager::GetInstance();
187  eventManager->CreateSocket(EVENTS_SERVER_PUB);
188 
189  cout<<"\n\nStarting reconstruction\n\n"<<endl;
190  fAliReco->Begin(NULL);
191  if (fAliReco->GetAbort() != TSelector::kContinue) return;
192  fAliReco->SlaveBegin(NULL);
193  if (fAliReco->GetAbort() != TSelector::kContinue) return;
194  cout<<"\n\nStarting loop over events\n\n"<<endl;
195 
196  TString recoBaseDir = fSettings.GetValue("server.saveRecoDir",DEFAULT_SERVER_SAVE_RECO_DIR);
197 
198 
199  //******* The loop over events
200  Int_t iEvent = 0;
201  AliESDEvent* event;
202  struct recPointsStruct *files;
203  // while (fAliReco->HasNextEventAfter(iEvent) && !gQuit)
204  while (!gQuit)
205  {
206  if(fAliReco->HasNextEventAfter(iEvent))
207  {
208  // remove files for previous event: (needed to send RecPoints:
209  /*
210  gSystem->cd(recoBaseDir.Data());
211  gSystem->Exec(Form("rm -fr run%d;mkdir run%d",fRun,fRun));
212  gSystem->cd(Form("run%d",fRun));
213  */
214 
215  if (!fAliReco->HasEnoughResources(iEvent)) break;
216  cout<<"\n\nProcessing event:"<<iEvent<<endl<<endl;
217  Bool_t status = fAliReco->ProcessEvent(iEvent);
218 
219  if (status){
220  event = fAliReco->GetESDEvent();
221  eventManager->Send(event,EVENTS_SERVER_PUB);
222  //eventManager->SendAsXml(event,XML_PUB);
223 
224  // sending RecPoints:
225  /*
226  cout<<"loading file"<<endl;
227  files->files[0] = TFile::Open("./ITS.RecPoints.root");
228  files->files[1] = TFile::Open("./TOF.RecPoints.root");
229  files->files[2] = TFile::Open("./galice.root");
230  files->files[3] = NULL;
231  files->files[4] = NULL;
232  files->files[5] = NULL;
233  files->files[6] = NULL;
234  files->files[7] = NULL;
235  files->files[8] = NULL;
236  files->files[9] = NULL;
237 
238 
239  cout<<"sending files"<<endl;
240  eventManager->Send(files,ITS_POINTS_PUB);
241  cout<<"files sent"<<endl;
242 
243  for(int i=0;i<10;i++)
244  {
245  if(files->files[i])
246  {
247  files->files[i]->Close();
248  delete files->files[i];files->files[i]=0;
249  cout<<"file deleted"<<endl;
250  }
251  }
252  */
253 
254  //Saving ESD to file:
255  /*
256  TFile *file = new TFile(Form("/local/storedFiles/AliESDs.root_%d",iEvent),"recreate");
257  TTree* tree= new TTree("esdTree", "esdTree");
258  event->WriteToTree(tree);
259  tree-> Fill();
260  tree->Write();
261  file->Close();
262  */
263  }
264  else{
265  cout<<"Event server -- aborting"<<endl;
266  fAliReco->Abort("ProcessEvent",TSelector::kAbortFile);
267  }
268  cout<<"clean"<<endl;
269  fAliReco->CleanProcessedEvent();
270  /* if(event)
271  {
272  delete event;
273  event=0;
274  }*/
275  cout<<"iEvent++"<<endl;
276  iEvent++;
277  }
278  else
279  {
280  cout<<"No event after!"<<endl;
281  gQuit=true;
282  }
283  }
284  cout<<"after while"<<endl;
285  // fAliReco->SlaveTerminate();
286  //if (fAliReco->GetAbort() != TSelector::kContinue) return;
287  //fAliReco->Terminate();
288  //if (fAliReco->GetAbort() != TSelector::kContinue) return;
289 }
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
static AliZMQManager * GetInstance()
void GotSignal(int)
ZMQ communication manager.
Definition: AliZMQManager.h:57
void CreateSocket(storageSockets socket)
bool Send(std::vector< serverListStruct > list, storageSockets socket)