]>
Commit | Line | Data |
---|---|---|
d2416c53 | 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 | ||
9 | #include "AliOnlineReconstruction.h" | |
10 | #include "AliOnlineReconstructionUtil.h" | |
11 | #include "AliStorageEventManager.h" | |
12 | ||
13 | #include <TSQLServer.h> | |
14 | #include <TSQLResult.h> | |
15 | #include <TSQLRow.h> | |
16 | #include <TTimeStamp.h> | |
17 | ||
da6a894f | 18 | #include <signal.h> |
d2416c53 | 19 | #include <iostream> |
20 | ||
21 | using namespace std; | |
22 | ||
da6a894f | 23 | bool gQuit = false; |
24 | void GotSignal(int){gQuit = true;} | |
25 | ||
d2416c53 | 26 | AliOnlineReconstruction::AliOnlineReconstruction(int run) : |
27 | fRun(run), | |
28 | fDataSource(""), | |
29 | fSettings(0), | |
30 | fAliReco(new AliReconstruction()), | |
31 | fCDBmanager(AliCDBManager::Instance()) | |
32 | { | |
da6a894f | 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 | ||
d2416c53 | 42 | fSettings.ReadFile(AliOnlineReconstructionUtil::GetPathToServerConf(), kEnvUser); |
43 | StartOfRun(); | |
da6a894f | 44 | cout<<"after startofrun"<<endl; |
d2416c53 | 45 | } |
46 | ||
47 | AliOnlineReconstruction::~AliOnlineReconstruction() | |
48 | { | |
da6a894f | 49 | cout<<"AliOnlineReconstruction -- destructor called..."; |
50 | if(fAliReco) | |
51 | { | |
52 | // fAliReco->SlaveTerminate(); | |
53 | // fAliReco->Terminate(); | |
54 | // delete fAliReco;fAliReco=0; | |
55 | } | |
d2416c53 | 56 | if(fCDBmanager){fCDBmanager->Destroy();fCDBmanager=0;} |
da6a894f | 57 | cout<<"OK"<<endl; |
d2416c53 | 58 | } |
59 | ||
60 | void AliOnlineReconstruction::StartOfRun() | |
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; | |
89da3878 | 70 | fDataSource = fSettings.GetValue("data.online.source", DEFAULT_DATA_ONLINE_SOURCE); |
d2416c53 | 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()); | |
066a2879 | 80 | if( gSystem->RedirectOutput(logFile.Data(),"w")!=0) |
d2416c53 | 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()); | |
a7f93de6 | 86 | // gSystem->cd("/"); |
066a2879 | 87 | cout<<"\n\nRetriving GRP\n\n"<<endl; |
d2416c53 | 88 | TString gdcs; |
89 | if (RetrieveGRP(gdcs) <= 0 || gdcs.IsNull()){return;} | |
a7f93de6 | 90 | //gSystem->cd(recoBaseDir.Data()); |
066a2879 | 91 | gSystem->Exec(Form("rm -fr run%d;mkdir run%d",fRun,fRun)); |
92 | gSystem->cd(Form("run%d",fRun)); | |
d2416c53 | 93 | |
94 | SetupReco(); | |
066a2879 | 95 | cout<<"\n\nStarting reconstruction loop\n\n"<<endl; |
d2416c53 | 96 | ReconstructionLoop(); |
97 | } | |
98 | ||
99 | int AliOnlineReconstruction::RetrieveGRP(TString &gdc) | |
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); | |
066a2879 | 107 | TString cdbPath = fSettings.GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE); |
d2416c53 | 108 | |
a7f93de6 | 109 | // cdbPath = gSystem->pwd(); |
110 | cout<<"CDB path for GRP:"<<cdbPath<<endl; | |
111 | ||
d2416c53 | 112 | Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(fRun, dbHost.Data(), |
113 | dbPort, dbName.Data(), | |
114 | user.Data(), password.Data(), | |
a7f93de6 | 115 | Form("%s",cdbPath.Data()), |
d2416c53 | 116 | gdc); |
117 | ||
118 | if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret); | |
119 | else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found"); | |
120 | else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret); | |
121 | return(ret); | |
122 | } | |
123 | ||
124 | void AliOnlineReconstruction::SetupReco() | |
125 | { | |
066a2879 | 126 | printf(Form("=========================[local://%s/]===========\n",gSystem->pwd())); |
d2416c53 | 127 | |
128 | /* Settings CDB */ | |
066a2879 | 129 | cout<<"\n\nSetting CDB manager parameters\n\n"<<endl; |
130 | fCDBmanager->SetRun(fRun); | |
d2416c53 | 131 | fCDBmanager->SetDefaultStorage(fSettings.GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE)); |
132 | fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath1", DEFAULT_CDB_SPEC_STORAGE_PATH1), | |
133 | fSettings.GetValue( "cdb.specificStorageValue1", DEFAULT_CDB_SPEC_STORAGE_VALUE1)); | |
134 | fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2), | |
135 | fSettings.GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2)); | |
136 | fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3), | |
137 | fSettings.GetValue( "cdb.specificStorageValue3", DEFAULT_CDB_SPEC_STORAGE_VALUE3)); | |
138 | /* Reconstruction settings */ | |
139 | ||
140 | // QA options | |
066a2879 | 141 | cout<<"\n\nSetting AliReconstruction parameters\n\n"<<endl; |
d2416c53 | 142 | fAliReco->SetRunQA(fSettings.GetValue("qa.runDetectors",DEFAULT_QA_RUN)); |
143 | fAliReco->SetRunGlobalQA(fSettings.GetValue("qa.runGlobal",DEFAULT_QA_RUN_GLOBAL)); | |
144 | fAliReco->SetQARefDefaultStorage(fSettings.GetValue("qa.defaultStorage",DEFAULT_QAREF_STORAGE)) ; | |
145 | fAliReco->SetRunPlaneEff(fSettings.GetValue("reco.runPlaneEff",DEFAULT_RECO_RUN_PLANE_EFF)); | |
146 | ||
147 | // AliReconstruction settings | |
148 | fAliReco->SetWriteESDfriend(fSettings.GetValue( "reco.writeESDfriend",DEFAULT_RECO_WRITE_ESDF)); | |
149 | fAliReco->SetWriteAlignmentData(fSettings.GetValue( "reco.writeAlignment",DEFAULT_RECO_WRITE_ALIGN)); | |
150 | fAliReco->SetInput(fDataSource.Data()); // reconstruct data from this input | |
151 | fAliReco->SetRunReconstruction(fSettings.GetValue( "reco.detectors", DEFAULT_RECO_DETECTORS)); | |
152 | fAliReco->SetUseTrackingErrorsForAlignment("ITS"); //-- !should be set from conf file! | |
153 | fAliReco->SetCleanESD(fSettings.GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD)); | |
154 | ||
155 | // init reco for given run | |
156 | fAliReco->InitRun(fDataSource.Data()); | |
157 | } | |
158 | ||
159 | void AliOnlineReconstruction::ReconstructionLoop() | |
160 | { | |
066a2879 | 161 | cout<<"\n\nCreating sockets\n\n"<<endl; |
d2416c53 | 162 | AliStorageEventManager *eventManager = AliStorageEventManager::GetEventManagerInstance(); |
163 | eventManager->CreateSocket(EVENTS_SERVER_PUB); | |
164 | eventManager->CreateSocket(XML_PUB); | |
a7f93de6 | 165 | eventManager->CreateSocket(ITS_POINTS_PUB); |
d2416c53 | 166 | |
066a2879 | 167 | cout<<"\n\nStarting reconstruction\n\n"<<endl; |
d2416c53 | 168 | fAliReco->Begin(NULL); |
169 | if (fAliReco->GetAbort() != TSelector::kContinue) return; | |
170 | fAliReco->SlaveBegin(NULL); | |
171 | if (fAliReco->GetAbort() != TSelector::kContinue) return; | |
066a2879 | 172 | cout<<"\n\nStarting loop over events\n\n"<<endl; |
173 | ||
a7f93de6 | 174 | TString recoBaseDir = fSettings.GetValue("server.saveRecoDir",DEFAULT_SERVER_SAVE_RECO_DIR); |
175 | ||
176 | ||
d2416c53 | 177 | //******* The loop over events |
178 | Int_t iEvent = 0; | |
179 | AliESDEvent* event; | |
a7f93de6 | 180 | struct recPointsStruct *files; |
066a2879 | 181 | // while (fAliReco->HasNextEventAfter(iEvent) && !gQuit) |
182 | while (!gQuit) | |
d2416c53 | 183 | { |
066a2879 | 184 | if(fAliReco->HasNextEventAfter(iEvent)) |
185 | { | |
a7f93de6 | 186 | // remove files for previous event: (needed to send RecPoints: |
187 | /* | |
188 | gSystem->cd(recoBaseDir.Data()); | |
189 | gSystem->Exec(Form("rm -fr run%d;mkdir run%d",fRun,fRun)); | |
190 | gSystem->cd(Form("run%d",fRun)); | |
191 | */ | |
192 | ||
193 | if (!fAliReco->HasEnoughResources(iEvent)) break; | |
194 | cout<<"\n\nProcessing event:"<<iEvent<<endl<<endl; | |
195 | Bool_t status = fAliReco->ProcessEvent(iEvent); | |
d2416c53 | 196 | |
a7f93de6 | 197 | if (status){ |
198 | event = fAliReco->GetESDEvent(); | |
199 | eventManager->Send(event,EVENTS_SERVER_PUB); | |
200 | eventManager->SendAsXml(event,XML_PUB); | |
201 | ||
202 | // sending RecPoints: | |
203 | /* | |
204 | cout<<"loading file"<<endl; | |
205 | files->files[0] = TFile::Open("./ITS.RecPoints.root"); | |
206 | files->files[1] = TFile::Open("./TOF.RecPoints.root"); | |
207 | files->files[2] = TFile::Open("./galice.root"); | |
208 | files->files[3] = NULL; | |
209 | files->files[4] = NULL; | |
210 | files->files[5] = NULL; | |
211 | files->files[6] = NULL; | |
212 | files->files[7] = NULL; | |
213 | files->files[8] = NULL; | |
214 | files->files[9] = NULL; | |
215 | ||
216 | ||
217 | cout<<"sending files"<<endl; | |
218 | eventManager->Send(files,ITS_POINTS_PUB); | |
219 | cout<<"files sent"<<endl; | |
220 | ||
221 | for(int i=0;i<10;i++) | |
222 | { | |
223 | if(files->files[i]) | |
224 | { | |
225 | files->files[i]->Close(); | |
226 | delete files->files[i];files->files[i]=0; | |
227 | cout<<"file deleted"<<endl; | |
228 | } | |
229 | } | |
230 | */ | |
231 | ||
232 | //Saving ESD to file: | |
233 | /* | |
234 | TFile *file = new TFile(Form("/local/storedFiles/AliESDs.root_%d",iEvent),"recreate"); | |
235 | TTree* tree= new TTree("esdTree", "esdTree"); | |
236 | event->WriteToTree(tree); | |
237 | tree-> Fill(); | |
238 | tree->Write(); | |
239 | file->Close(); | |
240 | */ | |
241 | } | |
242 | else{ | |
243 | cout<<"Event server -- aborting"<<endl; | |
244 | fAliReco->Abort("ProcessEvent",TSelector::kAbortFile); | |
245 | } | |
246 | cout<<"clean"<<endl; | |
247 | fAliReco->CleanProcessedEvent(); | |
248 | cout<<"iEvent++"<<endl; | |
249 | iEvent++; | |
066a2879 | 250 | } |
251 | else | |
252 | { | |
253 | cout<<"No event after!"<<endl; | |
254 | } | |
d2416c53 | 255 | } |
da6a894f | 256 | cout<<"after while"<<endl; |
257 | // fAliReco->SlaveTerminate(); | |
258 | //if (fAliReco->GetAbort() != TSelector::kContinue) return; | |
259 | //fAliReco->Terminate(); | |
260 | //if (fAliReco->GetAbort() != TSelector::kContinue) return; | |
d2416c53 | 261 | } |