]>
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 | ||
18 | #include <iostream> | |
19 | ||
20 | using namespace std; | |
21 | ||
22 | AliOnlineReconstruction::AliOnlineReconstruction(int run) : | |
23 | fRun(run), | |
24 | fDataSource(""), | |
25 | fSettings(0), | |
26 | fAliReco(new AliReconstruction()), | |
27 | fCDBmanager(AliCDBManager::Instance()) | |
28 | { | |
29 | fSettings.ReadFile(AliOnlineReconstructionUtil::GetPathToServerConf(), kEnvUser); | |
30 | StartOfRun(); | |
31 | } | |
32 | ||
33 | AliOnlineReconstruction::~AliOnlineReconstruction() | |
34 | { | |
35 | if(fAliReco){delete fAliReco;fAliReco=0;} | |
36 | if(fCDBmanager){fCDBmanager->Destroy();fCDBmanager=0;} | |
37 | } | |
38 | ||
39 | void AliOnlineReconstruction::StartOfRun() | |
40 | { | |
41 | if(strcmp("local",fSettings.GetValue("data.source", DEFAULT_DATA_SOURCE))==0) | |
42 | { | |
43 | cout<<"Starting Reco for run "<<fRun<<endl; | |
44 | fDataSource = Form("mem://%s/run%d", gSystem->Getenv("ONLINERECO_RAWFILES_DIR"), fRun); | |
45 | } | |
46 | else if(strcmp(fSettings.GetValue("data.source", DEFAULT_DATA_SOURCE),"run")==0) | |
47 | { | |
48 | cout<<"Starting Reco for GDCs active in current run:"<<fRun<<endl; | |
49 | fDataSource = "mem://@*:"; | |
50 | } | |
51 | else{cout<<"\n\nWrong data source. Quitting\n\n"<<endl;} | |
52 | ||
53 | TString recoBaseDir = fSettings.GetValue("server.saveRecoDir",DEFAULT_SERVER_SAVE_RECO_DIR); | |
54 | cout<<"Reco base dir:"<<recoBaseDir<<endl; | |
55 | ||
56 | // Create directories and logfile | |
57 | TString logFile = Form("%s/log/run%d.log",recoBaseDir.Data(),fRun); | |
58 | Info("DoStart","Reconstruction log will be written to %s",logFile.Data()); | |
59 | if( gSystem->RedirectOutput(logFile.Data())!=0) | |
60 | { | |
61 | printf(Form("AliRecoServer::StartReconstruction [] Error while trying to redirect output to [%s]. Exiting...", logFile.Data()) ); | |
62 | return; | |
63 | } | |
64 | gSystem->cd(recoBaseDir.Data()); | |
65 | ||
66 | TString gdcs; | |
67 | if (RetrieveGRP(gdcs) <= 0 || gdcs.IsNull()){return;} | |
68 | ||
69 | gSystem->Exec(Form("rm -fr run%d;mkdir run%d;cd run%d",fRun,fRun,fRun)); | |
70 | ||
71 | SetupReco(); | |
72 | ReconstructionLoop(); | |
73 | } | |
74 | ||
75 | int AliOnlineReconstruction::RetrieveGRP(TString &gdc) | |
76 | { | |
77 | // Retrieve GRP entry for given run from aldaqdb. | |
78 | TString dbHost = fSettings.GetValue("logbook.host", DEFAULT_LOGBOOK_HOST); | |
79 | Int_t dbPort = fSettings.GetValue("logbook.port", DEFAULT_LOGBOOK_PORT); | |
80 | TString dbName = fSettings.GetValue("logbook.db", DEFAULT_LOGBOOK_DB); | |
81 | TString user = fSettings.GetValue("logbook.user", DEFAULT_LOGBOOK_USER); | |
82 | TString password = fSettings.GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS); | |
83 | ||
84 | Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(fRun, dbHost.Data(), | |
85 | dbPort, dbName.Data(), | |
86 | user.Data(), password.Data(), | |
87 | Form("local://%s",gSystem->pwd()), | |
88 | gdc); | |
89 | ||
90 | if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret); | |
91 | else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found"); | |
92 | else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret); | |
93 | return(ret); | |
94 | } | |
95 | ||
96 | void AliOnlineReconstruction::SetupReco() | |
97 | { | |
98 | printf(Form("=========================[local://%s/..]===========\n",gSystem->pwd())); | |
99 | ||
100 | /* Settings CDB */ | |
101 | fCDBmanager->SetDefaultStorage(fSettings.GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE)); | |
102 | fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath1", DEFAULT_CDB_SPEC_STORAGE_PATH1), | |
103 | fSettings.GetValue( "cdb.specificStorageValue1", DEFAULT_CDB_SPEC_STORAGE_VALUE1)); | |
104 | fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2), | |
105 | fSettings.GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2)); | |
106 | fCDBmanager->SetSpecificStorage(fSettings.GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3), | |
107 | fSettings.GetValue( "cdb.specificStorageValue3", DEFAULT_CDB_SPEC_STORAGE_VALUE3)); | |
108 | /* Reconstruction settings */ | |
109 | ||
110 | // QA options | |
111 | fAliReco->SetRunQA(fSettings.GetValue("qa.runDetectors",DEFAULT_QA_RUN)); | |
112 | fAliReco->SetRunGlobalQA(fSettings.GetValue("qa.runGlobal",DEFAULT_QA_RUN_GLOBAL)); | |
113 | fAliReco->SetQARefDefaultStorage(fSettings.GetValue("qa.defaultStorage",DEFAULT_QAREF_STORAGE)) ; | |
114 | fAliReco->SetRunPlaneEff(fSettings.GetValue("reco.runPlaneEff",DEFAULT_RECO_RUN_PLANE_EFF)); | |
115 | ||
116 | // AliReconstruction settings | |
117 | fAliReco->SetWriteESDfriend(fSettings.GetValue( "reco.writeESDfriend",DEFAULT_RECO_WRITE_ESDF)); | |
118 | fAliReco->SetWriteAlignmentData(fSettings.GetValue( "reco.writeAlignment",DEFAULT_RECO_WRITE_ALIGN)); | |
119 | fAliReco->SetInput(fDataSource.Data()); // reconstruct data from this input | |
120 | fAliReco->SetRunReconstruction(fSettings.GetValue( "reco.detectors", DEFAULT_RECO_DETECTORS)); | |
121 | fAliReco->SetUseTrackingErrorsForAlignment("ITS"); //-- !should be set from conf file! | |
122 | fAliReco->SetCleanESD(fSettings.GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD)); | |
123 | ||
124 | // init reco for given run | |
125 | fAliReco->InitRun(fDataSource.Data()); | |
126 | } | |
127 | ||
128 | void AliOnlineReconstruction::ReconstructionLoop() | |
129 | { | |
130 | AliStorageEventManager *eventManager = AliStorageEventManager::GetEventManagerInstance(); | |
131 | eventManager->CreateSocket(EVENTS_SERVER_PUB); | |
132 | eventManager->CreateSocket(XML_PUB); | |
133 | ||
134 | fAliReco->Begin(NULL); | |
135 | if (fAliReco->GetAbort() != TSelector::kContinue) return; | |
136 | fAliReco->SlaveBegin(NULL); | |
137 | if (fAliReco->GetAbort() != TSelector::kContinue) return; | |
138 | ||
139 | //******* The loop over events | |
140 | Int_t iEvent = 0; | |
141 | AliESDEvent* event; | |
142 | while (fAliReco->HasNextEventAfter(iEvent)) | |
143 | { | |
144 | if (!fAliReco->HasEnoughResources(iEvent)) break; | |
145 | Bool_t status = fAliReco->ProcessEvent(iEvent); | |
146 | ||
147 | if (status){ | |
148 | event = fAliReco->GetESDEvent(); | |
149 | eventManager->Send(event,EVENTS_SERVER_PUB); | |
150 | eventManager->SendAsXml(event,XML_PUB); | |
151 | } | |
152 | else{ | |
153 | cout<<"Event server -- aborting"<<endl; | |
154 | fAliReco->Abort("ProcessEvent",TSelector::kAbortFile); | |
155 | } | |
156 | fAliReco->CleanProcessedEvent(); | |
157 | iEvent++; | |
158 | } | |
159 | fAliReco->SlaveTerminate(); | |
160 | if (fAliReco->GetAbort() != TSelector::kContinue) return; | |
161 | fAliReco->Terminate(); | |
162 | if (fAliReco->GetAbort() != TSelector::kContinue) return; | |
163 | } |