]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliReconstruction.cxx
Fix for Savannah bug 63624 (M.Masera)
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
CommitLineData
596a855f 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
fc07289e 3 * *
596a855f 4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// class for running the reconstruction //
21// //
22// Clusters and tracks are created for all detectors and all events by //
23// typing: //
24// //
25// AliReconstruction rec; //
26// rec.Run(); //
27// //
28// The Run method returns kTRUE in case of successful execution. //
c71de921 29// //
30// If the input to the reconstruction are not simulated digits but raw data, //
31// this can be specified by an argument of the Run method or by the method //
32// //
33// rec.SetInput("..."); //
34// //
35// The input formats and the corresponding argument are: //
36// - DDL raw data files: directory name, ends with "/" //
37// - raw data root file: root file name, extension ".root" //
38// - raw data DATE file: DATE file name, any other non-empty string //
39// - MC root files : empty string, default //
40// //
b26c3770 41// By default all events are reconstructed. The reconstruction can be //
42// limited to a range of events by giving the index of the first and the //
43// last event as an argument to the Run method or by calling //
44// //
45// rec.SetEventRange(..., ...); //
46// //
47// The index -1 (default) can be used for the last event to indicate no //
48// upper limit of the event range. //
49// //
973388c2 50// In case of raw-data reconstruction the user can modify the default //
51// number of events per digits/clusters/tracks file. In case the option //
52// is not used the number is set 1. In case the user provides 0, than //
53// the number of events is equal to the number of events inside the //
54// raw-data file (i.e. one digits/clusters/tracks file): //
55// //
56// rec.SetNumberOfEventsPerFile(...); //
57// //
58// //
596a855f 59// The name of the galice file can be changed from the default //
e583c30d 60// "galice.root" by passing it as argument to the AliReconstruction //
61// constructor or by //
596a855f 62// //
63// rec.SetGAliceFile("..."); //
64// //
59697224 65// The local reconstruction can be switched on or off for individual //
66// detectors by //
596a855f 67// //
59697224 68// rec.SetRunLocalReconstruction("..."); //
596a855f 69// //
70// The argument is a (case sensitive) string with the names of the //
71// detectors separated by a space. The special string "ALL" selects all //
72// available detectors. This is the default. //
73// //
c71de921 74// The reconstruction of the primary vertex position can be switched off by //
75// //
76// rec.SetRunVertexFinder(kFALSE); //
77// //
b8cd5251 78// The tracking and the creation of ESD tracks can be switched on for //
79// selected detectors by //
596a855f 80// //
b8cd5251 81// rec.SetRunTracking("..."); //
596a855f 82// //
c84a5e9e 83// Uniform/nonuniform field tracking switches (default: uniform field) //
84// //
1d99986f 85// rec.SetUniformFieldTracking(); ( rec.SetUniformFieldTracking(kFALSE); ) //
c84a5e9e 86// //
596a855f 87// The filling of additional ESD information can be steered by //
88// //
89// rec.SetFillESD("..."); //
90// //
b8cd5251 91// Again, for both methods the string specifies the list of detectors. //
92// The default is "ALL". //
93// //
94// The call of the shortcut method //
95// //
96// rec.SetRunReconstruction("..."); //
97// //
98// is equivalent to calling SetRunLocalReconstruction, SetRunTracking and //
99// SetFillESD with the same detector selecting string as argument. //
596a855f 100// //
c71de921 101// The reconstruction requires digits or raw data as input. For the creation //
102// of digits and raw data have a look at the class AliSimulation. //
596a855f 103// //
cd0b062e 104// The input data of a detector can be replaced by the corresponding HLT //
105// data by calling (usual detector string) //
106// SetUseHLTData("..."); //
107// //
24f7a148 108// //
596a855f 109///////////////////////////////////////////////////////////////////////////////
110
f7a1cc68 111#include <TArrayD.h>
024a7e64 112#include <TArrayF.h>
f7a1cc68 113#include <TArrayS.h>
114#include <TChain.h>
024a7e64 115#include <TFile.h>
f7a1cc68 116#include <TGeoGlobalMagField.h>
3103d196 117#include <TGeoManager.h>
f7a1cc68 118#include <TList.h>
2bdb9d38 119#include <TLorentzVector.h>
325aa76f 120#include <TMap.h>
f7a1cc68 121#include <TObjArray.h>
122#include <TPRegexp.h>
123#include <TParameter.h>
124#include <TPluginManager.h>
4b71572b 125#include <TProof.h>
db4aeca1 126#include <TProofOutputFile.h>
f7a1cc68 127#include <TROOT.h>
128#include <TSystem.h>
77ba28ba 129#include <THashTable.h>
6c6f2624 130#include <TGrid.h>
131#include <TMessage.h>
596a855f 132
f7a1cc68 133#include "AliAlignObj.h"
134#include "AliCDBEntry.h"
135#include "AliCDBManager.h"
136#include "AliCDBStorage.h"
137#include "AliCTPRawStream.h"
138#include "AliCascadeVertexer.h"
139#include "AliCentralTrigger.h"
87932dab 140#include "AliCodeTimer.h"
f7a1cc68 141#include "AliDAQ.h"
142#include "AliDetectorRecoParam.h"
143#include "AliESDCaloCells.h"
144#include "AliESDCaloCluster.h"
af885e0f 145#include "AliESDEvent.h"
faffd83e 146#include "AliESDMuonTrack.h"
f7a1cc68 147#include "AliESDPmdTrack.h"
148#include "AliESDTagCreator.h"
2257f27e 149#include "AliESDVertex.h"
faffd83e 150#include "AliESDcascade.h"
f7a1cc68 151#include "AliESDfriend.h"
faffd83e 152#include "AliESDkink.h"
596a855f 153#include "AliESDpid.h"
ff8bb5ae 154#include "AliESDtrack.h"
f7a1cc68 155#include "AliESDtrack.h"
156#include "AliEventInfo.h"
157#include "AliGRPObject.h"
158#include "AliGRPRecoParam.h"
159#include "AliGenEventHeader.h"
25be1e5c 160#include "AliGeomManager.h"
aa3c69a9 161#include "AliGlobalQADataMaker.h"
f7a1cc68 162#include "AliHeader.h"
163#include "AliLog.h"
164#include "AliMagF.h"
165#include "AliMultiplicity.h"
166#include "AliPID.h"
167#include "AliPlaneEff.h"
4e25ac79 168#include "AliQAv1.h"
f7a1cc68 169#include "AliQADataMakerRec.h"
b03591ab 170#include "AliQAManager.h"
33314186 171#include "AliRawVEvent.h"
f7a1cc68 172#include "AliRawEventHeaderBase.h"
cd0b062e 173#include "AliRawHLTManager.h"
f7a1cc68 174#include "AliRawReaderDate.h"
175#include "AliRawReaderFile.h"
176#include "AliRawReaderRoot.h"
177#include "AliReconstruction.h"
178#include "AliReconstructor.h"
179#include "AliRun.h"
7e88424f 180#include "AliRunInfo.h"
f7a1cc68 181#include "AliRunLoader.h"
182#include "AliSysInfo.h" // memory snapshots
183#include "AliTrackPointArray.h"
184#include "AliTracker.h"
185#include "AliTriggerClass.h"
186#include "AliTriggerCluster.h"
a6dd87ad 187#include "AliTriggerIR.h"
f7a1cc68 188#include "AliTriggerConfiguration.h"
189#include "AliV0vertexer.h"
190#include "AliVertexer.h"
191#include "AliVertexerTracks.h"
52dd4a8c 192#include "AliTriggerRunScalers.h"
193#include "AliCTPTimeParams.h"
8b12d288 194#include "AliESDHLTDecision.h"
6ef9caeb 195#include "AliTriggerInput.h"
596a855f 196ClassImp(AliReconstruction)
197
c757bafd 198//_____________________________________________________________________________
ac4a7581 199const char* AliReconstruction::fgkDetectorName[AliReconstruction::kNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
c757bafd 200
596a855f 201//_____________________________________________________________________________
4b71572b 202AliReconstruction::AliReconstruction(const char* gAliceFilename) :
203 TSelector(),
2257f27e 204 fRunVertexFinder(kTRUE),
a84e2607 205 fRunVertexFinderTracks(kTRUE),
1f46a9ae 206 fRunHLTTracking(kFALSE),
e66fbafb 207 fRunMuonTracking(kFALSE),
d1683eef 208 fRunV0Finder(kTRUE),
209 fRunCascadeFinder(kTRUE),
c8025cc8 210 fStopOnError(kTRUE),
1d99986f 211 fWriteAlignmentData(kFALSE),
212 fWriteESDfriend(kFALSE),
b647652d 213 fFillTriggerESD(kTRUE),
1d99986f 214
7f68891d 215 fCleanESD(kTRUE),
a023d8d8 216 fV0DCAmax(3.),
217 fV0CsPmin(0.),
7f68891d 218 fDmax(50.),
219 fZmax(50.),
220
1d99986f 221 fRunLocalReconstruction("ALL"),
b8cd5251 222 fRunTracking("ALL"),
e583c30d 223 fFillESD("ALL"),
7d566c20 224 fLoadCDB(""),
48ce48d1 225 fUseTrackingErrorsForAlignment(""),
e583c30d 226 fGAliceFileName(gAliceFilename),
4b71572b 227 fRawInput(""),
975320a0 228 fESDOutput(""),
81d57268 229 fProofOutputFileName(""),
230 fProofOutputLocation(""),
231 fProofOutputDataset(kFALSE),
232 fProofOutputArchive(""),
35042093 233 fEquipIdMap(""),
b26c3770 234 fFirstEvent(0),
235 fLastEvent(-1),
9d705769 236 fNumberOfEventsPerFile((UInt_t)-1),
b8cd5251 237 fOptions(),
6bae477a 238 fLoadAlignFromCDB(kTRUE),
239 fLoadAlignData("ALL"),
cd0b062e 240 fUseHLTData(),
7e88424f 241 fRunInfo(NULL),
242 fEventInfo(),
522fdd91 243 fRunScalers(NULL),
52dd4a8c 244 fCTPTimeParams(NULL),
e583c30d 245
246 fRunLoader(NULL),
b649205a 247 fRawReader(NULL),
cd0b062e 248 fParentRawReader(NULL),
b8cd5251 249
7e88424f 250 fRecoParam(),
251
58e8dc31 252 fSPDTrackleter(NULL),
253
f2a195c1 254 fDiamondProfileSPD(NULL),
9178838a 255 fDiamondProfile(NULL),
43c9dae1 256 fDiamondProfileTPC(NULL),
77ba28ba 257 fListOfCosmicTriggers(NULL),
f2a195c1 258
6b6e4472 259 fGRPData(NULL),
444753c6 260
6bae477a 261 fAlignObjArray(NULL),
795e4a22 262 fCDBUri(),
f1c1204d 263 fQARefUri(),
759c1df1 264 fSpecCDBUri(),
795e4a22 265 fInitCDBCalled(kFALSE),
266 fSetRunNumberFromDataCalled(kFALSE),
ce43afbe 267 fQADetectors("ALL"),
268 fQATasks("ALL"),
7e963665 269 fRunQA(kTRUE),
6b150027 270 fRunGlobalQA(kTRUE),
e4a998ed 271 fSameQACycle(kFALSE),
f1c1204d 272 fInitQACalled(kFALSE),
75373542 273 fWriteQAExpertData(kTRUE),
21a3aa09 274 fRunPlaneEff(kFALSE),
275
276 fesd(NULL),
277 fhltesd(NULL),
278 fesdf(NULL),
279 ffile(NULL),
280 ftree(NULL),
281 fhlttree(NULL),
21a3aa09 282 ftVertexer(NULL),
14dd053c 283 fIsNewRunLoader(kFALSE),
4b71572b 284 fRunAliEVE(kFALSE),
285 fChain(NULL)
596a855f 286{
287// create reconstruction object with default parameters
002c9d1b 288 gGeoManager = NULL;
b8cd5251 289
ac4a7581 290 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 291 fReconstructor[iDet] = NULL;
292 fLoader[iDet] = NULL;
293 fTracker[iDet] = NULL;
294 }
4e25ac79 295 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
252f8aa8 296 fQACycles[iDet] = 999999 ;
297 fQAWriteExpert[iDet] = kFALSE ;
298 }
299
e47c4c2e 300 AliPID pid;
596a855f 301}
302
303//_____________________________________________________________________________
304AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
4b71572b 305 TSelector(),
2257f27e 306 fRunVertexFinder(rec.fRunVertexFinder),
a84e2607 307 fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
1f46a9ae 308 fRunHLTTracking(rec.fRunHLTTracking),
e66fbafb 309 fRunMuonTracking(rec.fRunMuonTracking),
d1683eef 310 fRunV0Finder(rec.fRunV0Finder),
311 fRunCascadeFinder(rec.fRunCascadeFinder),
1d99986f 312 fStopOnError(rec.fStopOnError),
313 fWriteAlignmentData(rec.fWriteAlignmentData),
314 fWriteESDfriend(rec.fWriteESDfriend),
b647652d 315 fFillTriggerESD(rec.fFillTriggerESD),
1d99986f 316
7f68891d 317 fCleanESD(rec.fCleanESD),
a023d8d8 318 fV0DCAmax(rec.fV0DCAmax),
5e5c1aa9 319 fV0CsPmin(rec.fV0CsPmin),
7f68891d 320 fDmax(rec.fDmax),
321 fZmax(rec.fZmax),
322
1d99986f 323 fRunLocalReconstruction(rec.fRunLocalReconstruction),
e583c30d 324 fRunTracking(rec.fRunTracking),
325 fFillESD(rec.fFillESD),
7d566c20 326 fLoadCDB(rec.fLoadCDB),
48ce48d1 327 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
e583c30d 328 fGAliceFileName(rec.fGAliceFileName),
4b71572b 329 fRawInput(rec.fRawInput),
975320a0 330 fESDOutput(rec.fESDOutput),
81d57268 331 fProofOutputFileName(rec.fProofOutputFileName),
332 fProofOutputLocation(rec.fProofOutputLocation),
333 fProofOutputDataset(rec.fProofOutputDataset),
334 fProofOutputArchive(rec.fProofOutputArchive),
35042093 335 fEquipIdMap(rec.fEquipIdMap),
b26c3770 336 fFirstEvent(rec.fFirstEvent),
337 fLastEvent(rec.fLastEvent),
973388c2 338 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
b8cd5251 339 fOptions(),
6bae477a 340 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
341 fLoadAlignData(rec.fLoadAlignData),
2972d4eb 342 fUseHLTData(rec.fUseHLTData),
7e88424f 343 fRunInfo(NULL),
344 fEventInfo(),
522fdd91 345 fRunScalers(NULL),
52dd4a8c 346 fCTPTimeParams(NULL),
e583c30d 347
348 fRunLoader(NULL),
b649205a 349 fRawReader(NULL),
2972d4eb 350 fParentRawReader(NULL),
b8cd5251 351
4b71572b 352 fRecoParam(rec.fRecoParam),
7e88424f 353
58e8dc31 354 fSPDTrackleter(NULL),
355
f2a195c1 356 fDiamondProfileSPD(rec.fDiamondProfileSPD),
4b71572b 357 fDiamondProfile(rec.fDiamondProfile),
358 fDiamondProfileTPC(rec.fDiamondProfileTPC),
77ba28ba 359 fListOfCosmicTriggers(NULL),
f2a195c1 360
6b6e4472 361 fGRPData(NULL),
444753c6 362
6bae477a 363 fAlignObjArray(rec.fAlignObjArray),
ec92bee0 364 fCDBUri(rec.fCDBUri),
f1c1204d 365 fQARefUri(rec.fQARefUri),
7e963665 366 fSpecCDBUri(),
795e4a22 367 fInitCDBCalled(rec.fInitCDBCalled),
368 fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
ce43afbe 369 fQADetectors(rec.fQADetectors),
370 fQATasks(rec.fQATasks),
aa3c69a9 371 fRunQA(rec.fRunQA),
372 fRunGlobalQA(rec.fRunGlobalQA),
e4a998ed 373 fSameQACycle(rec.fSameQACycle),
f1c1204d 374 fInitQACalled(rec.fInitQACalled),
75373542 375 fWriteQAExpertData(rec.fWriteQAExpertData),
21a3aa09 376 fRunPlaneEff(rec.fRunPlaneEff),
377
378 fesd(NULL),
379 fhltesd(NULL),
380 fesdf(NULL),
381 ffile(NULL),
382 ftree(NULL),
383 fhlttree(NULL),
21a3aa09 384 ftVertexer(NULL),
14dd053c 385 fIsNewRunLoader(rec.fIsNewRunLoader),
4b71572b 386 fRunAliEVE(kFALSE),
387 fChain(NULL)
596a855f 388{
389// copy constructor
390
ec92bee0 391 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
efd2085e 392 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
393 }
ac4a7581 394 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 395 fReconstructor[iDet] = NULL;
396 fLoader[iDet] = NULL;
397 fTracker[iDet] = NULL;
b1af1125 398 }
399
4e25ac79 400 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
b1af1125 401 fQACycles[iDet] = rec.fQACycles[iDet];
252f8aa8 402 fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ;
403 }
b1af1125 404
ec92bee0 405 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
406 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
407 }
596a855f 408}
409
410//_____________________________________________________________________________
411AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
412{
413// assignment operator
4b71572b 414// Used in PROOF mode
415// Be very careful while modifing it!
416// Simple rules to follow:
417// for persistent data members - use their assignment operators
418// for non-persistent ones - do nothing or take the default values from constructor
419// TSelector members should not be touched
420 if(&rec == this) return *this;
421
4b71572b 422 fRunVertexFinder = rec.fRunVertexFinder;
423 fRunVertexFinderTracks = rec.fRunVertexFinderTracks;
424 fRunHLTTracking = rec.fRunHLTTracking;
425 fRunMuonTracking = rec.fRunMuonTracking;
426 fRunV0Finder = rec.fRunV0Finder;
427 fRunCascadeFinder = rec.fRunCascadeFinder;
428 fStopOnError = rec.fStopOnError;
429 fWriteAlignmentData = rec.fWriteAlignmentData;
430 fWriteESDfriend = rec.fWriteESDfriend;
431 fFillTriggerESD = rec.fFillTriggerESD;
432
433 fCleanESD = rec.fCleanESD;
434 fV0DCAmax = rec.fV0DCAmax;
435 fV0CsPmin = rec.fV0CsPmin;
436 fDmax = rec.fDmax;
437 fZmax = rec.fZmax;
438
439 fRunLocalReconstruction = rec.fRunLocalReconstruction;
440 fRunTracking = rec.fRunTracking;
441 fFillESD = rec.fFillESD;
7d566c20 442 fLoadCDB = rec.fLoadCDB;
4b71572b 443 fUseTrackingErrorsForAlignment = rec.fUseTrackingErrorsForAlignment;
444 fGAliceFileName = rec.fGAliceFileName;
445 fRawInput = rec.fRawInput;
975320a0 446 fESDOutput = rec.fESDOutput;
81d57268 447 fProofOutputFileName = rec.fProofOutputFileName;
448 fProofOutputLocation = rec.fProofOutputLocation;
449 fProofOutputDataset = rec.fProofOutputDataset;
450 fProofOutputArchive = rec.fProofOutputArchive;
4b71572b 451 fEquipIdMap = rec.fEquipIdMap;
452 fFirstEvent = rec.fFirstEvent;
453 fLastEvent = rec.fLastEvent;
454 fNumberOfEventsPerFile = rec.fNumberOfEventsPerFile;
455
456 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
457 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
458 }
459
460 fLoadAlignFromCDB = rec.fLoadAlignFromCDB;
461 fLoadAlignData = rec.fLoadAlignData;
4b71572b 462 fUseHLTData = rec.fUseHLTData;
463
464 delete fRunInfo; fRunInfo = NULL;
465 if (rec.fRunInfo) fRunInfo = new AliRunInfo(*rec.fRunInfo);
466
467 fEventInfo = rec.fEventInfo;
468
522fdd91 469 delete fRunScalers; fRunScalers = NULL;
470 if (rec.fRunScalers) fRunScalers = new AliTriggerRunScalers(*rec.fRunScalers);
471
52dd4a8c 472 delete fCTPTimeParams; fCTPTimeParams = NULL;
473 if (rec.fCTPTimeParams) fCTPTimeParams = new AliCTPTimeParams(*rec.fCTPTimeParams);
474
4b71572b 475 fRunLoader = NULL;
476 fRawReader = NULL;
477 fParentRawReader = NULL;
478
479 fRecoParam = rec.fRecoParam;
480
ac4a7581 481 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
4b71572b 482 delete fReconstructor[iDet]; fReconstructor[iDet] = NULL;
483 delete fLoader[iDet]; fLoader[iDet] = NULL;
484 delete fTracker[iDet]; fTracker[iDet] = NULL;
4b71572b 485 }
b1af1125 486
4e25ac79 487 for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
b1af1125 488 fQACycles[iDet] = rec.fQACycles[iDet];
252f8aa8 489 fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ;
490 }
58e8dc31 491
492 delete fSPDTrackleter; fSPDTrackleter = NULL;
252f8aa8 493
f2a195c1 494 delete fDiamondProfileSPD; fDiamondProfileSPD = NULL;
495 if (rec.fDiamondProfileSPD) fDiamondProfileSPD = new AliESDVertex(*rec.fDiamondProfileSPD);
4b71572b 496 delete fDiamondProfile; fDiamondProfile = NULL;
497 if (rec.fDiamondProfile) fDiamondProfile = new AliESDVertex(*rec.fDiamondProfile);
498 delete fDiamondProfileTPC; fDiamondProfileTPC = NULL;
499 if (rec.fDiamondProfileTPC) fDiamondProfileTPC = new AliESDVertex(*rec.fDiamondProfileTPC);
4b71572b 500
77ba28ba 501 delete fListOfCosmicTriggers; fListOfCosmicTriggers = NULL;
502 if (rec.fListOfCosmicTriggers) fListOfCosmicTriggers = (THashTable*)((rec.fListOfCosmicTriggers)->Clone());
503
4b71572b 504 delete fGRPData; fGRPData = NULL;
44e45fac 505 // if (rec.fGRPData) fGRPData = (TMap*)((rec.fGRPData)->Clone());
506 if (rec.fGRPData) fGRPData = (AliGRPObject*)((rec.fGRPData)->Clone());
4b71572b 507
508 delete fAlignObjArray; fAlignObjArray = NULL;
509
510 fCDBUri = "";
f1c1204d 511 fQARefUri = rec.fQARefUri;
4b71572b 512 fSpecCDBUri.Delete();
513 fInitCDBCalled = rec.fInitCDBCalled;
514 fSetRunNumberFromDataCalled = rec.fSetRunNumberFromDataCalled;
515 fQADetectors = rec.fQADetectors;
4b71572b 516 fQATasks = rec.fQATasks;
517 fRunQA = rec.fRunQA;
518 fRunGlobalQA = rec.fRunGlobalQA;
4b71572b 519 fSameQACycle = rec.fSameQACycle;
f1c1204d 520 fInitQACalled = rec.fInitQACalled;
75373542 521 fWriteQAExpertData = rec.fWriteQAExpertData;
4b71572b 522 fRunPlaneEff = rec.fRunPlaneEff;
523
524 fesd = NULL;
525 fhltesd = NULL;
526 fesdf = NULL;
527 ffile = NULL;
528 ftree = NULL;
529 fhlttree = NULL;
530 ftVertexer = NULL;
531 fIsNewRunLoader = rec.fIsNewRunLoader;
532 fRunAliEVE = kFALSE;
533 fChain = NULL;
596a855f 534
596a855f 535 return *this;
536}
537
538//_____________________________________________________________________________
539AliReconstruction::~AliReconstruction()
540{
541// clean up
542
e583c30d 543 CleanUp();
77ba28ba 544 if (fListOfCosmicTriggers) {
545 fListOfCosmicTriggers->Delete();
546 delete fListOfCosmicTriggers;
547 }
4f3c479a 548 delete fGRPData;
522fdd91 549 delete fRunScalers;
52dd4a8c 550 delete fCTPTimeParams;
efd2085e 551 fOptions.Delete();
4b71572b 552 if (fAlignObjArray) {
553 fAlignObjArray->Delete();
554 delete fAlignObjArray;
555 }
ec92bee0 556 fSpecCDBUri.Delete();
e6d66370 557
87932dab 558 AliCodeTimer::Instance()->Print();
596a855f 559}
560
f1c1204d 561//_____________________________________________________________________________
562void AliReconstruction::InitQA()
563{
564 //Initialize the QA and start of cycle
52dd4a8c 565 AliCodeTimerAuto("",0);
f1c1204d 566
567 if (fInitQACalled) return;
568 fInitQACalled = kTRUE;
569
634696f5 570 AliQAManager * qam = AliQAManager::QAManager(AliQAv1::kRECMODE) ;
75373542 571 if (fWriteQAExpertData)
eca4fa66 572 qam->SetWriteExpert() ;
75373542 573
eca4fa66 574 if (qam->IsDefaultStorageSet()) {
f1c1204d 575 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
576 AliWarning("Default QA reference storage has been already set !");
577 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fQARefUri.Data()));
578 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
eca4fa66 579 fQARefUri = qam->GetDefaultStorage()->GetURI();
f1c1204d 580 } else {
581 if (fQARefUri.Length() > 0) {
582 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
583 AliDebug(2, Form("Default QA reference storage is set to: %s", fQARefUri.Data()));
584 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
585 } else {
586 fQARefUri="local://$ALICE_ROOT/QAref";
587 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
588 AliWarning("Default QA refeference storage not yet set !!!!");
589 AliWarning(Form("Setting it now to: %s", fQARefUri.Data()));
590 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
591
592 }
eca4fa66 593 qam->SetDefaultStorage(fQARefUri);
f1c1204d 594 }
595
596 if (fRunQA) {
eca4fa66 597 qam->SetActiveDetectors(fQADetectors) ;
4e25ac79 598 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++) {
eca4fa66 599 qam->SetCycleLength(AliQAv1::DETECTORINDEX_t(det), fQACycles[det]) ;
600 qam->SetWriteExpert(AliQAv1::DETECTORINDEX_t(det)) ;
f1c1204d 601 }
514cb8c7 602 if (!fRawReader && !fInput && IsInTasks(AliQAv1::kRAWS))
4e25ac79 603 fQATasks.ReplaceAll(Form("%d",AliQAv1::kRAWS), "") ;
eca4fa66 604 qam->SetTasks(fQATasks) ;
605 qam->InitQADataMaker(AliCDBManager::Instance()->GetRun()) ;
f1c1204d 606 }
607 if (fRunGlobalQA) {
608 Bool_t sameCycle = kFALSE ;
eca4fa66 609 AliQADataMaker *qadm = qam->GetQADataMaker(AliQAv1::kGLOBAL);
f1c1204d 610 AliInfo(Form("Initializing the global QA data maker"));
514cb8c7 611 if (IsInTasks(AliQAv1::kRECPOINTS)) {
4e25ac79 612 qadm->StartOfCycle(AliQAv1::kRECPOINTS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
613 TObjArray **arr=qadm->Init(AliQAv1::kRECPOINTS);
f1c1204d 614 AliTracker::SetResidualsArray(arr);
615 sameCycle = kTRUE ;
616 }
514cb8c7 617 if (IsInTasks(AliQAv1::kESDS)) {
4e25ac79 618 qadm->StartOfCycle(AliQAv1::kESDS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
619 qadm->Init(AliQAv1::kESDS);
f1c1204d 620 }
f1c1204d 621 }
fc07289e 622 AliSysInfo::AddStamp("InitQA") ;
f1c1204d 623}
624
fc07289e 625//_____________________________________________________________________________
87da0921 626void AliReconstruction::MergeQA(const char *fileName)
fc07289e 627{
628 //Initialize the QA and start of cycle
52dd4a8c 629 AliCodeTimerAuto("",0) ;
eca4fa66 630 AliQAManager::QAManager()->Merge(AliCDBManager::Instance()->GetRun(),fileName) ;
fc07289e 631 AliSysInfo::AddStamp("MergeQA") ;
632}
633
024cf675 634//_____________________________________________________________________________
795e4a22 635void AliReconstruction::InitCDB()
024cf675 636{
637// activate a default CDB storage
638// First check if we have any CDB storage set, because it is used
639// to retrieve the calibration and alignment constants
52dd4a8c 640 AliCodeTimerAuto("",0);
024cf675 641
795e4a22 642 if (fInitCDBCalled) return;
643 fInitCDBCalled = kTRUE;
644
024cf675 645 AliCDBManager* man = AliCDBManager::Instance();
ec92bee0 646 if (man->IsDefaultStorageSet())
024cf675 647 {
648 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
ec92bee0 649 AliWarning("Default CDB storage has been already set !");
650 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
024cf675 651 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 652 fCDBUri = man->GetDefaultStorage()->GetURI();
ec92bee0 653 }
654 else {
795e4a22 655 if (fCDBUri.Length() > 0)
656 {
657 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
658 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
659 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
52dd4a8c 660 man->SetDefaultStorage(fCDBUri);
661 }
662 else if (!man->GetRaw()){
663 fCDBUri="local://$ALICE_ROOT/OCDB";
795e4a22 664 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
665 AliWarning("Default CDB storage not yet set !!!!");
666 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
667 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
52dd4a8c 668 man->SetDefaultStorage(fCDBUri);
669 }
670 else {
671 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
672 AliWarning("Default storage will be set after setting the Run Number!!!");
673 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 674 }
ec92bee0 675 }
676
677 // Now activate the detector specific CDB storage locations
c3a7b59a 678 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
679 TObject* obj = fSpecCDBUri[i];
680 if (!obj) continue;
b8ec52f6 681 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
682 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
683 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
c3a7b59a 684 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
ec92bee0 685 }
002c9d1b 686 AliSysInfo::AddStamp("InitCDB");
024cf675 687}
688
689//_____________________________________________________________________________
690void AliReconstruction::SetDefaultStorage(const char* uri) {
ec92bee0 691// Store the desired default CDB storage location
692// Activate it later within the Run() method
024cf675 693
ec92bee0 694 fCDBUri = uri;
024cf675 695
696}
697
f1c1204d 698//_____________________________________________________________________________
699void AliReconstruction::SetQARefDefaultStorage(const char* uri) {
700 // Store the desired default CDB storage location
701 // Activate it later within the Run() method
702
703 fQARefUri = uri;
4e25ac79 704 AliQAv1::SetQARefStorage(fQARefUri.Data()) ;
f1c1204d 705
706}
00aa02d5 707//_____________________________________________________________________________
c3a7b59a 708void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
ec92bee0 709// Store a detector-specific CDB storage location
710// Activate it later within the Run() method
024cf675 711
c3a7b59a 712 AliCDBPath aPath(calibType);
713 if(!aPath.IsValid()){
714 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
ac4a7581 715 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
c3a7b59a 716 if(!strcmp(calibType, fgkDetectorName[iDet])) {
717 aPath.SetPath(Form("%s/*", calibType));
718 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
719 break;
720 }
721 }
722 if(!aPath.IsValid()){
723 AliError(Form("Not a valid path or detector: %s", calibType));
724 return;
725 }
726 }
727
53dd3c3d 728// // check that calibType refers to a "valid" detector name
729// Bool_t isDetector = kFALSE;
ac4a7581 730// for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
53dd3c3d 731// TString detName = fgkDetectorName[iDet];
732// if(aPath.GetLevel0() == detName) {
733// isDetector = kTRUE;
734// break;
735// }
736// }
737//
738// if(!isDetector) {
739// AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
740// return;
741// }
c3a7b59a 742
743 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
ec92bee0 744 if (obj) fSpecCDBUri.Remove(obj);
c3a7b59a 745 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
024cf675 746
747}
748
6bae477a 749//_____________________________________________________________________________
795e4a22 750Bool_t AliReconstruction::SetRunNumberFromData()
6bae477a 751{
752 // The method is called in Run() in order
753 // to set a correct run number.
754 // In case of raw data reconstruction the
755 // run number is taken from the raw data header
756
795e4a22 757 if (fSetRunNumberFromDataCalled) return kTRUE;
758 fSetRunNumberFromDataCalled = kTRUE;
759
760 AliCDBManager* man = AliCDBManager::Instance();
4b71572b 761
762 if(fRawReader) {
763 if(fRawReader->NextEvent()) {
764 if(man->GetRun() > 0) {
21a3aa09 765 AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
4b71572b 766 }
767 man->SetRun(fRawReader->GetRunNumber());
768 fRawReader->RewindEvents();
769 }
770 else {
771 if(man->GetRun() > 0) {
772 AliWarning("No raw-data events are found ! Using settings in AliCDBManager !");
773 }
774 else {
775 AliWarning("Neither raw events nor settings in AliCDBManager are found !");
776 return kFALSE;
777 }
778 }
779 }
780 else {
781 AliRunLoader *rl = AliRunLoader::Open(fGAliceFileName.Data());
782 if (!rl) {
783 AliError(Form("No run loader found in file %s", fGAliceFileName.Data()));
6bae477a 784 return kFALSE;
785 }
ec92bee0 786 else {
4b71572b 787 rl->LoadHeader();
788 // read run number from gAlice
789 if(rl->GetHeader()) {
790 man->SetRun(rl->GetHeader()->GetRun());
791 rl->UnloadHeader();
792 delete rl;
ec92bee0 793 }
794 else {
4b71572b 795 AliError("Neither run-loader header nor RawReader objects are found !");
796 delete rl;
ec92bee0 797 return kFALSE;
798 }
4b71572b 799 }
6bae477a 800 }
795e4a22 801
802 man->Print();
803
6bae477a 804 return kTRUE;
805}
806
795e4a22 807//_____________________________________________________________________________
808void AliReconstruction::SetCDBLock() {
809 // Set CDB lock: from now on it is forbidden to reset the run number
810 // or the default storage or to activate any further storage!
811
812 AliCDBManager::Instance()->SetLock(1);
813}
814
6bae477a 815//_____________________________________________________________________________
816Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
817{
818 // Read the alignment objects from CDB.
819 // Each detector is supposed to have the
820 // alignment objects in DET/Align/Data CDB path.
821 // All the detector objects are then collected,
822 // sorted by geometry level (starting from ALIC) and
823 // then applied to the TGeo geometry.
824 // Finally an overlaps check is performed.
825
826 // Load alignment data from CDB and fill fAlignObjArray
827 if(fLoadAlignFromCDB){
6bae477a 828
25be1e5c 829 TString detStr = detectors;
830 TString loadAlObjsListOfDets = "";
831
ac4a7581 832 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
8cb26cdf 833 if(!IsSelected(fgkDetectorName[iDet], detStr)) continue;
f12d42ce 834 if(!strcmp(fgkDetectorName[iDet],"HLT")) continue;
4fbb8e9d 835
836 if(AliGeomManager::GetNalignable(fgkDetectorName[iDet]) != 0)
8cb26cdf 837 {
838 loadAlObjsListOfDets += fgkDetectorName[iDet];
839 loadAlObjsListOfDets += " ";
840 }
25be1e5c 841 } // end loop over detectors
4fbb8e9d 842
843 if(AliGeomManager::GetNalignable("GRP") != 0)
8cb26cdf 844 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
98e303d9 845 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
e30a9b4d 846 AliCDBManager::Instance()->UnloadFromCache("*/Align/*");
25be1e5c 847 }else{
848 // Check if the array with alignment objects was
849 // provided by the user. If yes, apply the objects
850 // to the present TGeo geometry
851 if (fAlignObjArray) {
852 if (gGeoManager && gGeoManager->IsClosed()) {
98e303d9 853 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
25be1e5c 854 AliError("The misalignment of one or more volumes failed!"
855 "Compare the list of simulated detectors and the list of detector alignment data!");
856 return kFALSE;
857 }
858 }
859 else {
860 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
6bae477a 861 return kFALSE;
862 }
863 }
6bae477a 864 }
25be1e5c 865
4b71572b 866 if (fAlignObjArray) {
867 fAlignObjArray->Delete();
868 delete fAlignObjArray; fAlignObjArray=NULL;
869 }
a03b0371 870
6bae477a 871 return kTRUE;
872}
596a855f 873
874//_____________________________________________________________________________
875void AliReconstruction::SetGAliceFile(const char* fileName)
876{
877// set the name of the galice file
878
879 fGAliceFileName = fileName;
880}
881
21a3aa09 882//_____________________________________________________________________________
b58710ef 883void AliReconstruction::SetInput(const char* input)
21a3aa09 884{
b58710ef 885 // In case the input string starts with 'mem://', we run in an online mode
886 // and AliRawReaderDateOnline object is created. In all other cases a raw-data
887 // file is assumed. One can give as an input:
888 // mem://: - events taken from DAQ monitoring libs online
889 // or
890 // mem://<filename> - emulation of the above mode (via DATE monitoring libs)
4b71572b 891 if (input) fRawInput = input;
21a3aa09 892}
893
975320a0 894//_____________________________________________________________________________
895void AliReconstruction::SetOutput(const char* output)
896{
897 // Set the output ESD filename
898 // 'output' is a normalt ROOT url
899 // The method is used in case of raw-data reco with PROOF
81d57268 900 if (output) fESDOutput = output;
975320a0 901}
902
efd2085e 903//_____________________________________________________________________________
904void AliReconstruction::SetOption(const char* detector, const char* option)
905{
906// set options for the reconstruction of a detector
907
908 TObject* obj = fOptions.FindObject(detector);
909 if (obj) fOptions.Remove(obj);
910 fOptions.Add(new TNamed(detector, option));
911}
912
7e88424f 913//_____________________________________________________________________________
914void AliReconstruction::SetRecoParam(const char* detector, AliDetectorRecoParam *par)
915{
916 // Set custom reconstruction parameters for a given detector
917 // Single set of parameters for all the events
a00021a7 918
919 // First check if the reco-params are global
920 if(!strcmp(detector, "GRP")) {
921 par->SetAsDefault();
ac4a7581 922 fRecoParam.AddDetRecoParam(kNDetectors,par);
a00021a7 923 return;
924 }
925
ac4a7581 926 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
7e88424f 927 if(!strcmp(detector, fgkDetectorName[iDet])) {
928 par->SetAsDefault();
929 fRecoParam.AddDetRecoParam(iDet,par);
930 break;
931 }
932 }
933
934}
935
61807e09 936//_____________________________________________________________________________
61807e09 937Bool_t AliReconstruction::InitGRP() {
938 //------------------------------------
939 // Initialization of the GRP entry
940 //------------------------------------
941 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
942
4b71572b 943 if (entry) {
44e45fac 944
945 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
946
947 if (m) {
948 AliInfo("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject");
949 m->Print();
950 fGRPData = new AliGRPObject();
951 fGRPData->ReadValuesFromMap(m);
952 }
953
954 else {
955 AliInfo("Found an AliGRPObject in GRP/GRP/Data, reading it");
956 fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
957 entry->SetOwner(0);
958 }
959
f168abba 960 // FIX ME: The unloading of GRP entry is temporarily disabled
961 // because ZDC and VZERO are using it in order to initialize
962 // their reconstructor objects. In the future one has to think
963 // of propagating AliRunInfo to the reconstructors.
964 // AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
4b71572b 965 }
61807e09 966
967 if (!fGRPData) {
968 AliError("No GRP entry found in OCDB!");
969 return kFALSE;
970 }
971
44e45fac 972 TString lhcState = fGRPData->GetLHCState();
973 if (lhcState==AliGRPObject::GetInvalidString()) {
7e88424f 974 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
44e45fac 975 lhcState = "UNKNOWN";
7e88424f 976 }
977
44e45fac 978 TString beamType = fGRPData->GetBeamType();
979 if (beamType==AliGRPObject::GetInvalidString()) {
7e88424f 980 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
44e45fac 981 beamType = "UNKNOWN";
7e88424f 982 }
983
44e45fac 984 Float_t beamEnergy = fGRPData->GetBeamEnergy();
985 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
7e88424f 986 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
44e45fac 987 beamEnergy = 0;
7e88424f 988 }
989
44e45fac 990 TString runType = fGRPData->GetRunType();
991 if (runType==AliGRPObject::GetInvalidString()) {
7e88424f 992 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
44e45fac 993 runType = "UNKNOWN";
7e88424f 994 }
995
44e45fac 996 Int_t activeDetectors = fGRPData->GetDetectorMask();
a5dede5c 997 if (activeDetectors==AliGRPObject::GetInvalidUInt()) {
7e88424f 998 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
44e45fac 999 activeDetectors = 1074790399;
7e88424f 1000 }
1001
44e45fac 1002 fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
44e45fac 1003 fRunInfo->Dump();
1004
7e88424f 1005
1006 // Process the list of active detectors
44e45fac 1007 if (activeDetectors) {
1008 UInt_t detMask = activeDetectors;
7a317bef 1009 fRunLocalReconstruction = MatchDetectorList(fRunLocalReconstruction,detMask);
1010 fRunTracking = MatchDetectorList(fRunTracking,detMask);
1011 fFillESD = MatchDetectorList(fFillESD,detMask);
1012 fQADetectors = MatchDetectorList(fQADetectors,detMask);
7d566c20 1013 fLoadCDB.Form("%s %s %s %s",
1014 fRunLocalReconstruction.Data(),
1015 fRunTracking.Data(),
1016 fFillESD.Data(),
1017 fQADetectors.Data());
7d566c20 1018 fLoadCDB = MatchDetectorList(fLoadCDB,detMask);
d0f84c42 1019 if (!((detMask >> AliDAQ::DetectorID("ITSSPD")) & 0x1) &&
1020 !((detMask >> AliDAQ::DetectorID("ITSSDD")) & 0x1) &&
1021 !((detMask >> AliDAQ::DetectorID("ITSSSD")) & 0x1) ) {
91e2f025 1022 // switch off the vertexer
d0f84c42 1023 AliInfo("SPD,SDD,SSD is not in the list of active detectors. Vertexer switched off.");
91e2f025 1024 fRunVertexFinder = kFALSE;
1025 }
304d7f0b 1026 if (!((detMask >> AliDAQ::DetectorID("TRG")) & 0x1)) {
1027 // switch off the reading of CTP raw-data payload
1028 if (fFillTriggerESD) {
1029 AliInfo("CTP is not in the list of active detectors. CTP data reading switched off.");
1030 fFillTriggerESD = kFALSE;
1031 }
1032 }
7e88424f 1033 }
1034
1035 AliInfo("===================================================================================");
1036 AliInfo(Form("Running local reconstruction for detectors: %s",fRunLocalReconstruction.Data()));
1037 AliInfo(Form("Running tracking for detectors: %s",fRunTracking.Data()));
1038 AliInfo(Form("Filling ESD for detectors: %s",fFillESD.Data()));
ca13fb87 1039 AliInfo(Form("Quality assurance is active for detectors: %s",fQADetectors.Data()));
7d566c20 1040 AliInfo(Form("CDB and reconstruction parameters are loaded for detectors: %s",fLoadCDB.Data()));
7e88424f 1041 AliInfo("===================================================================================");
61807e09 1042
1043 //*** Dealing with the magnetic field map
5a004fb4 1044 if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
1045 if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
1046 AliInfo("ExpertMode!!! GRP information will be ignored !");
1047 AliInfo("ExpertMode!!! Running with the externally locked B field !");
1048 }
1049 else {
1050 AliInfo("Destroying existing B field instance!");
1051 delete TGeoGlobalMagField::Instance();
1052 }
1053 }
1054 if ( !TGeoGlobalMagField::Instance()->IsLocked() ) {
61807e09 1055 // Construct the field map out of the information retrieved from GRP.
856024f0 1056 Bool_t ok = kTRUE;
61807e09 1057 // L3
44e45fac 1058 Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
1059 if (l3Current == AliGRPObject::GetInvalidFloat()) {
1060 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
1061 ok = kFALSE;
1062 }
f7a1cc68 1063
44e45fac 1064 Char_t l3Polarity = fGRPData->GetL3Polarity();
1065 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
1066 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
1067 ok = kFALSE;
1068 }
1069
1070 // Dipole
1071 Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
1072 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
1073 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
1074 ok = kFALSE;
1075 }
1076
1077 Char_t diPolarity = fGRPData->GetDipolePolarity();
1078 if (diPolarity == AliGRPObject::GetInvalidChar()) {
1079 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
1080 ok = kFALSE;
1081 }
1082
99c7d495 1083 // read special bits for the polarity convention and map type
1084 Int_t polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
1085 Bool_t uniformB = fGRPData->IsUniformBMap();
61807e09 1086
856024f0 1087 if (ok) {
33fe5eb1 1088 AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1),
1089 TMath::Abs(diCurrent) * (diPolarity ? -1:1),
1090 polConvention,uniformB,beamEnergy, beamType.Data());
1091 if (fld) {
1092 TGeoGlobalMagField::Instance()->SetField( fld );
1093 TGeoGlobalMagField::Instance()->Lock();
1094 AliInfo("Running with the B field constructed out of GRP !");
1095 }
1096 else AliFatal("Failed to create a B field map !");
856024f0 1097 }
f7a1cc68 1098 else AliFatal("B field is neither set nor constructed from GRP ! Exitig...");
61807e09 1099 }
f7a1cc68 1100
f2a195c1 1101 //*** Get the diamond profiles from OCDB
1102 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexSPD");
1103 if (entry) {
1104 fDiamondProfileSPD = dynamic_cast<AliESDVertex*> (entry->GetObject());
1105 } else {
1106 AliError("No SPD diamond profile found in OCDB!");
1107 }
1108
61807e09 1109 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertex");
1110 if (entry) {
f2a195c1 1111 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
61807e09 1112 } else {
1113 AliError("No diamond profile found in OCDB!");
1114 }
1115
1116 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexTPC");
1117 if (entry) {
f2a195c1 1118 fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
61807e09 1119 } else {
f2a195c1 1120 AliError("No TPC diamond profile found in OCDB!");
61807e09 1121 }
1122
77ba28ba 1123 entry = AliCDBManager::Instance()->Get("GRP/Calib/CosmicTriggers");
1124 if (entry) {
1125 fListOfCosmicTriggers = dynamic_cast<THashTable*>(entry->GetObject());
1126 entry->SetOwner(0);
1127 AliCDBManager::Instance()->UnloadFromCache("GRP/Calib/CosmicTriggers");
1128 }
1129
1130 if (!fListOfCosmicTriggers) {
1131 AliWarning("Can not get list of cosmic triggers from OCDB! Cosmic event specie will be effectively disabled!");
1132 }
1133
61807e09 1134 return kTRUE;
1135}
1136
4b71572b 1137//_____________________________________________________________________________
1138Bool_t AliReconstruction::LoadCDB()
1139{
52dd4a8c 1140 AliCodeTimerAuto("",0);
4b71572b 1141
1142 AliCDBManager::Instance()->Get("GRP/CTP/Config");
1143
7d566c20 1144 TString detStr = fLoadCDB;
ac4a7581 1145 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
4b71572b 1146 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1147 AliCDBManager::Instance()->GetAll(Form("%s/Calib/*",fgkDetectorName[iDet]));
1148 }
e122592f 1149
1150 // Temporary fix - one has to define the correct policy in order
1151 // to load the trigger OCDB entries only for the detectors that
1152 // in the trigger or that are needed in order to put correct
1153 // information in ESD
1154 AliCDBManager::Instance()->GetAll("TRIGGER/*/*");
1155
4b71572b 1156 return kTRUE;
1157}
522fdd91 1158//_____________________________________________________________________________
1159Bool_t AliReconstruction::LoadTriggerScalersCDB()
1160{
52dd4a8c 1161 AliCodeTimerAuto("",0);
522fdd91 1162
1163 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/Scalers");
4b71572b 1164
522fdd91 1165 if (entry) {
1166
1167 AliInfo("Found an AliTriggerRunScalers in GRP/CTP/Scalers, reading it");
1168 fRunScalers = dynamic_cast<AliTriggerRunScalers*> (entry->GetObject());
1169 entry->SetOwner(0);
82ebedd6 1170 if (fRunScalers->CorrectScalersOverflow() == 0) AliInfo("32bit Trigger counters corrected for overflow");
1171
522fdd91 1172 }
1173 return kTRUE;
1174}
596a855f 1175//_____________________________________________________________________________
52dd4a8c 1176Bool_t AliReconstruction::LoadCTPTimeParamsCDB()
1177{
1178 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
1179
1180 if (entry) {
1181
1182 AliInfo("Found an AliCTPTimeParams in GRP/CTP/CTPtiming, reading it");
1183 fCTPTimeParams = dynamic_cast<AliCTPTimeParams*> (entry->GetObject());
1184 entry->SetOwner(0);
1185 return kTRUE;
1186 }
1187
1188 return kFALSE;
1189}
1190//_____________________________________________________________________________
21a3aa09 1191Bool_t AliReconstruction::Run(const char* input)
596a855f 1192{
21a3aa09 1193 // Run Run Run
52dd4a8c 1194 AliCodeTimerAuto("",0);
596a855f 1195
4b71572b 1196 InitRun(input);
1197 if (GetAbort() != TSelector::kContinue) return kFALSE;
1198
1199 TChain *chain = NULL;
1200 if (fRawReader && (chain = fRawReader->GetChain())) {
2a284cef 1201 Long64_t nEntries = (fLastEvent < 0) ? (TChain::kBigNumber) : (fLastEvent - fFirstEvent + 1);
4b71572b 1202 // Proof mode
1203 if (gProof) {
52dd4a8c 1204 // Temporary fix for long raw-data runs (until socket timeout handling in PROOF is revised)
1205 gProof->Exec("gEnv->SetValue(\"Proof.SocketActivityTimeout\",-1)", kTRUE);
6c6f2624 1206
1207 if (gGrid)
1208 gProof->Exec("TGrid::Connect(\"alien://\")",kTRUE);
1209
1210 TMessage::EnableSchemaEvolutionForAll(kTRUE);
1211 gProof->Exec("TMessage::EnableSchemaEvolutionForAll(kTRUE)",kTRUE);
1212
4b71572b 1213 gProof->AddInput(this);
81d57268 1214
1215 if (!ParseOutput()) return kFALSE;
1216
975320a0 1217 gProof->SetParameter("PROOF_MaxSlavesPerNode", 9999);
4b71572b 1218 chain->SetProof();
2a284cef 1219 chain->Process("AliReconstruction","",nEntries,fFirstEvent);
4b71572b 1220 }
1221 else {
2a284cef 1222 chain->Process(this,"",nEntries,fFirstEvent);
4b71572b 1223 }
1224 }
1225 else {
1226 Begin(NULL);
1227 if (GetAbort() != TSelector::kContinue) return kFALSE;
1228 SlaveBegin(NULL);
1229 if (GetAbort() != TSelector::kContinue) return kFALSE;
1230 //******* The loop over events
44e45fac 1231 AliInfo("Starting looping over events");
4b71572b 1232 Int_t iEvent = 0;
1233 while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
1234 (fRawReader && fRawReader->NextEvent())) {
1235 if (!ProcessEvent(iEvent)) {
930e6e3e 1236 Abort("ProcessEvent",TSelector::kAbortFile);
1237 return kFALSE;
4b71572b 1238 }
1239 iEvent++;
1240 }
1241 SlaveTerminate();
1242 if (GetAbort() != TSelector::kContinue) return kFALSE;
1243 Terminate();
1244 if (GetAbort() != TSelector::kContinue) return kFALSE;
21a3aa09 1245 }
21a3aa09 1246
1247 return kTRUE;
1248}
1249
1250//_____________________________________________________________________________
4b71572b 1251void AliReconstruction::InitRawReader(const char* input)
21a3aa09 1252{
52dd4a8c 1253 AliCodeTimerAuto("",0);
21a3aa09 1254
4b71572b 1255 // Init raw-reader and
21a3aa09 1256 // set the input in case of raw data
4b71572b 1257 if (input) fRawInput = input;
1258 fRawReader = AliRawReader::Create(fRawInput.Data());
c35f192e 1259 if (!fRawReader) {
1260 if (fRawInput.IsNull()) {
1261 AliInfo("Reconstruction will run over digits");
1262 }
1263 else {
1264 AliFatal("Can not create raw-data reader ! Exiting...");
1265 }
1266 }
e0027792 1267
35042093 1268 if (!fEquipIdMap.IsNull() && fRawReader)
1269 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
1270
cd0b062e 1271 if (!fUseHLTData.IsNull()) {
1272 // create the RawReaderHLT which performs redirection of HLT input data for
1273 // the specified detectors
1274 AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
1275 if (pRawReader) {
1276 fParentRawReader=fRawReader;
1277 fRawReader=pRawReader;
1278 } else {
1279 AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
1280 }
1281 }
4b71572b 1282 AliSysInfo::AddStamp("CreateRawReader");
1283}
cd0b062e 1284
4b71572b 1285//_____________________________________________________________________________
1286void AliReconstruction::InitRun(const char* input)
1287{
1288 // Initialization of raw-reader,
1289 // run number, CDB etc.
52dd4a8c 1290 AliCodeTimerAuto("",0);
4b71572b 1291 AliSysInfo::AddStamp("Start");
1292
002c9d1b 1293 // Initialize raw-reader if any
4b71572b 1294 InitRawReader(input);
596a855f 1295
ec92bee0 1296 // Initialize the CDB storage
795e4a22 1297 InitCDB();
ec92bee0 1298
6bae477a 1299 // Set run number in CDBManager (if it is not already set by the user)
4b71572b 1300 if (!SetRunNumberFromData()) {
1301 Abort("SetRunNumberFromData", TSelector::kAbortProcess);
1302 return;
1303 }
002c9d1b 1304
795e4a22 1305 // Set CDB lock: from now on it is forbidden to reset the run number
1306 // or the default storage or to activate any further storage!
1307 SetCDBLock();
1308
002c9d1b 1309}
1310
1311//_____________________________________________________________________________
1312void AliReconstruction::Begin(TTree *)
1313{
1314 // Initialize AlReconstruction before
1315 // going into the event loop
1316 // Should follow the TSelector convention
1317 // i.e. initialize only the object on the client side
52dd4a8c 1318 AliCodeTimerAuto("",0);
db4aeca1 1319
b4fef0d2 1320 AliReconstruction *reco = NULL;
002c9d1b 1321 if (fInput) {
8fb1f1dc 1322 if ((reco = (AliReconstruction*)fInput->FindObject("AliReconstruction"))) {
002c9d1b 1323 *this = *reco;
002c9d1b 1324 }
1325 AliSysInfo::AddStamp("ReadInputInBegin");
1326 }
1327
6bae477a 1328 // Import ideal TGeo geometry and apply misalignment
1329 if (!gGeoManager) {
1330 TString geom(gSystem->DirName(fGAliceFileName));
1331 geom += "/geometry.root";
98e303d9 1332 AliGeomManager::LoadGeometry(geom.Data());
4b71572b 1333 if (!gGeoManager) {
1334 Abort("LoadGeometry", TSelector::kAbortProcess);
1335 return;
1336 }
281270d3 1337 AliSysInfo::AddStamp("LoadGeom");
ff5970a3 1338 TString detsToCheck=fRunLocalReconstruction;
4b71572b 1339 if(!AliGeomManager::CheckSymNamesLUT(detsToCheck.Data())) {
1340 Abort("CheckSymNamesLUT", TSelector::kAbortProcess);
1341 return;
1342 }
281270d3 1343 AliSysInfo::AddStamp("CheckGeom");
6bae477a 1344 }
8e245d15 1345
4b71572b 1346 if (!MisalignGeometry(fLoadAlignData)) {
1347 Abort("MisalignGeometry", TSelector::kAbortProcess);
1348 return;
1349 }
1350 AliCDBManager::Instance()->UnloadFromCache("GRP/Geometry/Data");
281270d3 1351 AliSysInfo::AddStamp("MisalignGeom");
6bae477a 1352
8cb26cdf 1353 if (!InitGRP()) {
1354 Abort("InitGRP", TSelector::kAbortProcess);
1355 return;
1356 }
1357 AliSysInfo::AddStamp("InitGRP");
1358
4b71572b 1359 if (!LoadCDB()) {
1360 Abort("LoadCDB", TSelector::kAbortProcess);
1361 return;
1362 }
1363 AliSysInfo::AddStamp("LoadCDB");
325aa76f 1364
a6dd87ad 1365 if (!LoadTriggerScalersCDB()) {
1366 Abort("LoadTriggerScalersCDB", TSelector::kAbortProcess);
1367 return;
1368 }
1369 AliSysInfo::AddStamp("LoadTriggerScalersCDB");
1370
52dd4a8c 1371 if (!LoadCTPTimeParamsCDB()) {
1372 Abort("LoadCTPTimeParamsCDB", TSelector::kAbortProcess);
1373 return;
1374 }
1375 AliSysInfo::AddStamp("LoadCTPTimeParamsCDB");
a6dd87ad 1376
7e88424f 1377 // Read the reconstruction parameters from OCDB
1378 if (!InitRecoParams()) {
002c9d1b 1379 AliWarning("Not all detectors have correct RecoParam objects initialized");
4b71572b 1380 }
1381 AliSysInfo::AddStamp("InitRecoParams");
1382
fd2b273c 1383 if (fInput && gProof) {
b4fef0d2 1384 if (reco) *reco = *this;
fd2b273c 1385
45a6dee6 1386 gGeoManager->SetName("Geometry");
fd2b273c 1387 gProof->AddInputData(gGeoManager,kTRUE);
002c9d1b 1388 gGeoManager = NULL;
fd2b273c 1389 gProof->AddInputData(const_cast<TMap*>(AliCDBManager::Instance()->GetEntryCache()),kTRUE);
002c9d1b 1390 fInput->Add(new TParameter<Int_t>("RunNumber",AliCDBManager::Instance()->GetRun()));
f7a1cc68 1391 AliMagF *magFieldMap = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
ead7b391 1392 magFieldMap->SetName("MagneticFieldMap");
fd2b273c 1393 gProof->AddInputData(magFieldMap,kTRUE);
002c9d1b 1394 }
4b71572b 1395
1396}
1397
1398//_____________________________________________________________________________
1399void AliReconstruction::SlaveBegin(TTree*)
1400{
1401 // Initialization related to run-loader,
1402 // vertexer, trackers, recontructors
1403 // In proof mode it is executed on the slave
52dd4a8c 1404 AliCodeTimerAuto("",0);
4b71572b 1405
db4aeca1 1406 TProofOutputFile *outProofFile = NULL;
81d57268 1407 if (fInput) {
1408 if (AliDebugLevel() > 0) fInput->Print();
ef5e52f6 1409 if (AliDebugLevel() > 10) fInput->Dump();
db4aeca1 1410 if (AliReconstruction *reco = (AliReconstruction*)fInput->FindObject("AliReconstruction")) {
1411 *this = *reco;
1412 }
4b71572b 1413 if (TGeoManager *tgeo = (TGeoManager*)fInput->FindObject("Geometry")) {
1414 gGeoManager = tgeo;
1415 AliGeomManager::SetGeometry(tgeo);
7e88424f 1416 }
281270d3 1417 if (TMap *entryCache = (TMap*)fInput->FindObject("CDBEntryCache")) {
1418 Int_t runNumber = -1;
1419 if (TProof::GetParameter(fInput,"RunNumber",runNumber) == 0) {
1420 AliCDBManager *man = AliCDBManager::Instance(entryCache,runNumber);
1421 man->SetCacheFlag(kTRUE);
1422 man->SetLock(kTRUE);
1423 man->Print();
1424 }
4b71572b 1425 }
ead7b391 1426 if (AliMagF *map = (AliMagF*)fInput->FindObject("MagneticFieldMap")) {
ef5e52f6 1427 AliMagF *newMap = new AliMagF(*map);
1428 if (!newMap->LoadParameterization()) {
1429 Abort("AliMagF::LoadParameterization", TSelector::kAbortProcess);
1430 return;
1431 }
1432 TGeoGlobalMagField::Instance()->SetField(newMap);
1433 TGeoGlobalMagField::Instance()->Lock();
4b71572b 1434 }
81d57268 1435 if (TNamed *outputFileName = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE"))
1436 fProofOutputFileName = outputFileName->GetTitle();
1437 if (TNamed *outputLocation = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE_LOCATION"))
1438 fProofOutputLocation = outputLocation->GetTitle();
1439 if (fInput->FindObject("PROOF_OUTPUTFILE_DATASET"))
1440 fProofOutputDataset = kTRUE;
1441 if (TNamed *archiveList = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE_ARCHIVE"))
1442 fProofOutputArchive = archiveList->GetTitle();
1443 if (!fProofOutputFileName.IsNull() &&
1444 !fProofOutputLocation.IsNull() &&
1445 fProofOutputArchive.IsNull()) {
1446 if (!fProofOutputDataset) {
1447 outProofFile = new TProofOutputFile(fProofOutputFileName.Data(),"M");
1448 outProofFile->SetOutputFileName(Form("%s%s",fProofOutputLocation.Data(),fProofOutputFileName.Data()));
1449 }
1450 else {
1451 outProofFile = new TProofOutputFile(fProofOutputFileName.Data(),"DROV",fProofOutputLocation.Data());
1452 }
1453 if (AliDebugLevel() > 0) outProofFile->Dump();
db4aeca1 1454 fOutput->Add(outProofFile);
4b71572b 1455 }
002c9d1b 1456 AliSysInfo::AddStamp("ReadInputInSlaveBegin");
7e88424f 1457 }
325aa76f 1458
4b71572b 1459 // get the run loader
1460 if (!InitRunLoader()) {
1461 Abort("InitRunLoader", TSelector::kAbortProcess);
1462 return;
1463 }
1464 AliSysInfo::AddStamp("LoadLoader");
1465
325aa76f 1466 ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
2257f27e 1467
f08fc9f5 1468 // get trackers
b8cd5251 1469 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
4b71572b 1470 Abort("CreateTrackers", TSelector::kAbortProcess);
1471 return;
1472 }
1473 AliSysInfo::AddStamp("CreateTrackers");
24f7a148 1474
36711aa4 1475 // create the ESD output file and tree
db4aeca1 1476 if (!outProofFile) {
1477 ffile = TFile::Open("AliESDs.root", "RECREATE");
1478 ffile->SetCompressionLevel(2);
1479 if (!ffile->IsOpen()) {
1480 Abort("OpenESDFile", TSelector::kAbortProcess);
1481 return;
1482 }
1483 }
1484 else {
81d57268 1485 AliInfo(Form("Opening output PROOF file: %s/%s",
1486 outProofFile->GetDir(), outProofFile->GetFileName()));
db4aeca1 1487 if (!(ffile = outProofFile->OpenFile("RECREATE"))) {
1488 Abort(Form("Problems opening output PROOF file: %s/%s",
1489 outProofFile->GetDir(), outProofFile->GetFileName()),
1490 TSelector::kAbortProcess);
1491 return;
1492 }
596a855f 1493 }
46698ae4 1494
21a3aa09 1495 ftree = new TTree("esdTree", "Tree with ESD objects");
1496 fesd = new AliESDEvent();
1497 fesd->CreateStdContent();
8b12d288 1498 // add a so far non-std object to the ESD, this will
1499 // become part of the std content
1500 fesd->AddObject(new AliESDHLTDecision);
1501
32ba9c61 1502 fesd->WriteToTree(ftree);
1d99986f 1503 if (fWriteESDfriend) {
32ba9c61 1504 // careful:
1505 // Since we add the branch manually we must
1506 // book and add it after WriteToTree
1507 // otherwise it is created twice,
1508 // once via writetotree and once here.
1509 // The case for AliESDfriend is now
1510 // caught also in AlIESDEvent::WriteToTree but
1511 // be careful when changing the name (AliESDfriend is not
1512 // a TNamed so we had to hardwire it)
21a3aa09 1513 fesdf = new AliESDfriend();
1514 TBranch *br=ftree->Branch("ESDfriend.","AliESDfriend", &fesdf);
46698ae4 1515 br->SetFile("AliESDfriends.root");
21a3aa09 1516 fesd->AddObject(fesdf);
1d99986f 1517 }
f9604a22 1518 ftree->GetUserInfo()->Add(fesd);
1519
1520 fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
1521 fhltesd = new AliESDEvent();
1522 fhltesd->CreateStdContent();
7491aea6 1523 // read the ESD template from CDB
1524 // HLT is allowed to put non-std content to its ESD, the non-std
1525 // objects need to be created before invocation of WriteToTree in
1526 // order to create all branches. Initialization is done from an
1527 // ESD layout template in CDB
1528 AliCDBManager* man = AliCDBManager::Instance();
1529 AliCDBPath hltESDConfigPath("HLT/ConfigHLT/esdLayout");
1530 AliCDBEntry* hltESDConfig=NULL;
1531 if (man->GetId(hltESDConfigPath)!=NULL &&
1532 (hltESDConfig=man->Get(hltESDConfigPath))!=NULL) {
1533 AliESDEvent* pESDLayout=dynamic_cast<AliESDEvent*>(hltESDConfig->GetObject());
1534 if (pESDLayout) {
1535 // init all internal variables from the list of objects
1536 pESDLayout->GetStdContent();
1537
1538 // copy content and create non-std objects
1539 *fhltesd=*pESDLayout;
1540 fhltesd->Reset();
1541 } else {
1542 AliError(Form("error setting hltEsd layout from %s: invalid object type",
1543 hltESDConfigPath.GetPath().Data()));
1544 }
1545 }
1546
f9604a22 1547 fhltesd->WriteToTree(fhlttree);
1548 fhlttree->GetUserInfo()->Add(fhltesd);
5728d3d5 1549
ac4a7581 1550 ProcInfo_t procInfo;
1551 gSystem->GetProcInfo(&procInfo);
1552 AliInfo(Form("Current memory usage %d %d", procInfo.fMemResident, procInfo.fMemVirtual));
8661738e 1553
325aa76f 1554 //QA
930e6e3e 1555 //Initialize the QA and start of cycle
f1c1204d 1556 if (fRunQA || fRunGlobalQA)
1557 InitQA() ;
aa3c69a9 1558
7167ae53 1559 //Initialize the Plane Efficiency framework
1560 if (fRunPlaneEff && !InitPlaneEff()) {
4b71572b 1561 Abort("InitPlaneEff", TSelector::kAbortProcess);
1562 return;
7167ae53 1563 }
aa3c69a9 1564
14dd053c 1565 if (strcmp(gProgName,"alieve") == 0)
1566 fRunAliEVE = InitAliEVE();
1567
4b71572b 1568 return;
21a3aa09 1569}
1570
1571//_____________________________________________________________________________
4b71572b 1572Bool_t AliReconstruction::Process(Long64_t entry)
1573{
1574 // run the reconstruction over a single entry
1575 // from the chain with raw data
52dd4a8c 1576 AliCodeTimerAuto("",0);
4b71572b 1577
1578 TTree *currTree = fChain->GetTree();
33314186 1579 AliRawVEvent *event = NULL;
4b71572b 1580 currTree->SetBranchAddress("rawevent",&event);
1581 currTree->GetEntry(entry);
1582 fRawReader = new AliRawReaderRoot(event);
1583 fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());
1584 delete fRawReader;
1585 fRawReader = NULL;
1586 delete event;
1587
1588 return fStatus;
1589}
1590
1591//_____________________________________________________________________________
1592void AliReconstruction::Init(TTree *tree)
1593{
1594 if (tree == 0) {
1595 AliError("The input tree is not found!");
1596 return;
1597 }
1598 fChain = tree;
1599}
1600
1601//_____________________________________________________________________________
1602Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
21a3aa09 1603{
1604 // run the reconstruction over a single event
1605 // The event loop is steered in Run method
1606
10d100d4 1607
470f88b0 1608 static Long_t oldMres=0;
1609 static Long_t oldMvir=0;
1610 static Float_t oldCPU=0;
1611
52dd4a8c 1612 AliCodeTimerAuto("",0);
21a3aa09 1613
10d100d4 1614 AliESDpid PID;
1615
21a3aa09 1616 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
1617 fRunLoader->SetEventNumber(iEvent);
1618 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1619 iEvent, iEvent);
21a3aa09 1620 fRunLoader->TreeE()->Fill();
4b71572b 1621 if (fRawReader && fRawReader->UseAutoSaveESD())
1622 fRunLoader->TreeE()->AutoSave("SaveSelf");
21a3aa09 1623 }
1624
1625 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
21a3aa09 1626 return kTRUE;
1627 }
1628
aa3c69a9 1629
16447f18 1630 fRunLoader->GetEvent(iEvent);
1631
7e88424f 1632 // Fill Event-info object
1633 GetEventInfo();
77ba28ba 1634 fRecoParam.SetEventSpecie(fRunInfo,fEventInfo,fListOfCosmicTriggers);
470f88b0 1635 AliInfo(Form("================================= Processing event %d of type %-10s ==================================", iEvent,fRecoParam.PrintEventSpecie()));
7e88424f 1636
a00021a7 1637 // Set the reco-params
1638 {
1639 TString detStr = fLoadCDB;
ac4a7581 1640 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
a00021a7 1641 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1642 AliReconstructor *reconstructor = GetReconstructor(iDet);
1643 if (reconstructor && fRecoParam.GetDetRecoParamArray(iDet)) {
57acd2d2 1644 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
1645 reconstructor->SetRecoParam(par);
10d100d4 1646 reconstructor->GetPidSettings(&PID);
1647 reconstructor->SetEventInfo(&fEventInfo);
57acd2d2 1648 if (fRunQA) {
eca4fa66 1649 AliQAManager::QAManager()->SetRecoParam(iDet, par) ;
619aafe6 1650 if (par) AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(par->GetEventSpecie())) ;
57acd2d2 1651 }
a00021a7 1652 }
1653 }
9dad1020 1654 if (fRunQA) {
1655 const AliDetectorRecoParam *grppar = fRecoParam.GetDetRecoParam(kNDetectors);
1656 AliQAManager::QAManager()->SetRecoParam(AliQAv1::kGLOBAL, grppar) ;
1657 AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(grppar->GetEventSpecie())) ;
1658 }
a00021a7 1659 }
1660
ca13fb87 1661 // QA on single raw
514cb8c7 1662 if (fRunQA && IsInTasks(AliQAv1::kRAWS)) {
eca4fa66 1663 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
1664 AliQAManager::QAManager()->RunOneEvent(fRawReader) ;
57acd2d2 1665 }
d506c543 1666 // local single event reconstruction
b26c3770 1667 if (!fRunLocalReconstruction.IsNull()) {
d506c543 1668 TString detectors=fRunLocalReconstruction;
a441bf51 1669 // run HLT event reconstruction first
d506c543 1670 // ;-( IsSelected changes the string
1671 if (IsSelected("HLT", detectors) &&
1672 !RunLocalEventReconstruction("HLT")) {
4b71572b 1673 if (fStopOnError) {CleanUp(); return kFALSE;}
a441bf51 1674 }
1675 detectors=fRunLocalReconstruction;
1676 detectors.ReplaceAll("HLT", "");
1677 if (!RunLocalEventReconstruction(detectors)) {
13effe3f 1678 if (fStopOnError) {
1679 CleanUp();
1680 return kFALSE;
1681 }
b26c3770 1682 }
1683 }
1684
6b3a883f 1685
1686 // fill Event header information from the RawEventHeader
1687 if (fRawReader){FillRawEventHeaderESD(fesd);}
1688 if (fRawReader){FillRawEventHeaderESD(fhltesd);}
1689
21a3aa09 1690 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1691 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1692 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
1693 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
fd2e2210 1694
1695 fesd->SetEventSpecie(fRecoParam.GetEventSpecie());
1696 fhltesd->SetEventSpecie(fRecoParam.GetEventSpecie());
46698ae4 1697
d6ee376f 1698 // Set magnetic field from the tracker
21a3aa09 1699 fesd->SetMagneticField(AliTracker::GetBz());
1700 fhltesd->SetMagneticField(AliTracker::GetBz());
33fe5eb1 1701 //
c587bcde 1702 ((AliESDRun*)fesd->GetESDRun())->SetBeamEnergyIsSqrtSHalfGeV();
1703 ((AliESDRun*)fhltesd->GetESDRun())->SetBeamEnergyIsSqrtSHalfGeV();
1704 //
33fe5eb1 1705 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
1706 if (fld) { // set info needed for field initialization
1707 fesd->SetCurrentL3(fld->GetCurrentSol());
1708 fesd->SetCurrentDip(fld->GetCurrentDip());
1709 fesd->SetBeamEnergy(fld->GetBeamEnergy());
1710 fesd->SetBeamType(fld->GetBeamTypeText());
1711 fesd->SetUniformBMap(fld->IsUniform());
1712 fesd->SetBInfoStored();
1713 //
1714 fhltesd->SetCurrentL3(fld->GetCurrentSol());
1715 fhltesd->SetCurrentDip(fld->GetCurrentDip());
1716 fhltesd->SetBeamEnergy(fld->GetBeamEnergy());
1717 fhltesd->SetBeamType(fld->GetBeamTypeText());
1718 fhltesd->SetUniformBMap(fld->IsUniform());
1719 fhltesd->SetBInfoStored();
1720 }
1721 //
71f6cda4 1722 // Set most probable pt, for B=0 tracking
9257a1bd 1723 // Get the global reco-params. They are atposition 16 inside the array of detectors in fRecoParam
ac4a7581 1724 const AliGRPRecoParam *grpRecoParam = dynamic_cast<const AliGRPRecoParam*>(fRecoParam.GetDetRecoParam(kNDetectors));
71f6cda4 1725 if (grpRecoParam) AliExternalTrackParam::SetMostProbablePt(grpRecoParam->GetMostProbablePt());
46698ae4 1726
2e3550da 1727 // Fill raw-data error log into the ESD
21a3aa09 1728 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
2e3550da 1729
2257f27e 1730 // vertex finder
1731 if (fRunVertexFinder) {
4b71572b 1732 if (!RunVertexFinder(fesd)) {
1733 if (fStopOnError) {CleanUp(); return kFALSE;}
2257f27e 1734 }
1735 }
1736
58e8dc31 1737 // For Plane Efficiency: run the SPD trackleter
1738 if (fRunPlaneEff && fSPDTrackleter) {
1739 if (!RunSPDTrackleting(fesd)) {
1740 if (fStopOnError) {CleanUp(); return kFALSE;}
1741 }
1742 }
1743
e66fbafb 1744 // Muon tracking
b8cd5251 1745 if (!fRunTracking.IsNull()) {
e66fbafb 1746 if (fRunMuonTracking) {
21a3aa09 1747 if (!RunMuonTracking(fesd)) {
4b71572b 1748 if (fStopOnError) {CleanUp(); return kFALSE;}
24f7a148 1749 }
596a855f 1750 }
1751 }
1752
e66fbafb 1753 // barrel tracking
1754 if (!fRunTracking.IsNull()) {
10d100d4 1755 if (!RunTracking(fesd,PID)) {
4b71572b 1756 if (fStopOnError) {CleanUp(); return kFALSE;}
e66fbafb 1757 }
1758 }
21c573b7 1759
596a855f 1760 // fill ESD
1761 if (!fFillESD.IsNull()) {
d506c543 1762 TString detectors=fFillESD;
f6806ad3 1763 // run HLT first and on hltesd
d506c543 1764 // ;-( IsSelected changes the string
1765 if (IsSelected("HLT", detectors) &&
1766 !FillESD(fhltesd, "HLT")) {
4b71572b 1767 if (fStopOnError) {CleanUp(); return kFALSE;}
f6806ad3 1768 }
1769 detectors=fFillESD;
d5105682 1770 // Temporary fix to avoid problems with HLT that overwrites the offline ESDs
1771 if (detectors.Contains("ALL")) {
1772 detectors="";
ac4a7581 1773 for (Int_t idet=0; idet<kNDetectors; ++idet){
d5105682 1774 detectors += fgkDetectorName[idet];
1775 detectors += " ";
1776 }
1777 }
f6806ad3 1778 detectors.ReplaceAll("HLT", "");
1779 if (!FillESD(fesd, detectors)) {
4b71572b 1780 if (fStopOnError) {CleanUp(); return kFALSE;}
596a855f 1781 }
1782 }
6b3a883f 1783
596a855f 1784 // combined PID
10d100d4 1785 PID.MakePID(fesd);
596a855f 1786
b647652d 1787 if (fFillTriggerESD) {
4b71572b 1788 if (!FillTriggerESD(fesd)) {
1789 if (fStopOnError) {CleanUp(); return kFALSE;}
b647652d 1790 }
1791 }
f7812afc 1792 // Always fill scalers
1793 if (!FillTriggerScalers(fesd)) {
1794 if (fStopOnError) {CleanUp(); return kFALSE;}
1795 }
1796
b647652d 1797
21a3aa09 1798 ffile->cd();
a6ee503a 1799
3c3709c4 1800 //
67be5c77 1801 // Propagate track to the beam pipe (if not already done by ITS)
3c3709c4 1802 //
21a3aa09 1803 const Int_t ntracks = fesd->GetNumberOfTracks();
3c3709c4 1804 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1805
1806 TObjArray trkArray;
1807 UShort_t *selectedIdx=new UShort_t[ntracks];
1808
1809 for (Int_t itrack=0; itrack<ntracks; itrack++){
98a50ff3 1810 const Double_t kMaxStep = 1; //max step over the material
3c3709c4 1811 Bool_t ok;
1812
21a3aa09 1813 AliESDtrack *track = fesd->GetTrack(itrack);
3c3709c4 1814 if (!track) continue;
1815
1816 AliExternalTrackParam *tpcTrack =
1817 (AliExternalTrackParam *)track->GetTPCInnerParam();
bcabd6af 1818 ok = kFALSE;
1819 if (tpcTrack)
1820 ok = AliTracker::
52dd4a8c 1821 PropagateTrackToBxByBz(tpcTrack,kRadius,track->GetMass(),kMaxStep,kFALSE);
43c9dae1 1822
3c3709c4 1823 if (ok) {
1824 Int_t n=trkArray.GetEntriesFast();
1825 selectedIdx[n]=track->GetID();
1826 trkArray.AddLast(tpcTrack);
1827 }
1828
3d65e645 1829 //Tracks refitted by ITS should already be at the SPD vertex
1830 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1831
1832 AliTracker::
52dd4a8c 1833 PropagateTrackToBxByBz(track,kRadius,track->GetMass(),kMaxStep,kFALSE);
1834 Double_t x[3]; track->GetXYZ(x);
1835 Double_t b[3]; AliTracker::GetBxByBz(x,b);
1836 track->RelateToVertexBxByBz(fesd->GetPrimaryVertexSPD(), b, kVeryBig);
3c3709c4 1837
3c3709c4 1838 }
1839
1840 //
1841 // Improve the reconstructed primary vertex position using the tracks
1842 //
59224b2b 1843 Bool_t runVertexFinderTracks = fRunVertexFinderTracks;
1844 if(fesd->GetPrimaryVertexSPD()) {
1845 TString vtitle = fesd->GetPrimaryVertexSPD()->GetTitle();
1846 if(vtitle.Contains("cosmics")) {
1847 runVertexFinderTracks=kFALSE;
1848 }
c060d7fe 1849 }
a00021a7 1850
1851 if (runVertexFinderTracks) {
3c3709c4 1852 // TPC + ITS primary vertex
f09c879d 1853 ftVertexer->SetITSMode();
f2a195c1 1854 ftVertexer->SetConstraintOff();
a00021a7 1855 // get cuts for vertexer from AliGRPRecoParam
1856 if (grpRecoParam) {
1857 Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
1858 Double_t *cutsVertexer = new Double_t[nCutsVertexer];
1859 grpRecoParam->GetVertexerTracksCutsITS(cutsVertexer);
1860 ftVertexer->SetCuts(cutsVertexer);
1861 delete [] cutsVertexer; cutsVertexer = NULL;
f2a195c1 1862 if(fDiamondProfile && grpRecoParam->GetVertexerTracksConstraintITS())
1863 ftVertexer->SetVtxStart(fDiamondProfile);
43c9dae1 1864 }
21a3aa09 1865 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
3c3709c4 1866 if (pvtx) {
1867 if (pvtx->GetStatus()) {
c264b61b 1868 fesd->SetPrimaryVertexTracks(pvtx);
3c3709c4 1869 for (Int_t i=0; i<ntracks; i++) {
21a3aa09 1870 AliESDtrack *t = fesd->GetTrack(i);
52dd4a8c 1871 Double_t x[3]; t->GetXYZ(x);
1872 Double_t b[3]; AliTracker::GetBxByBz(x,b);
1873 t->RelateToVertexBxByBz(pvtx, b, kVeryBig);
3c3709c4 1874 }
1875 }
9bcaa1d7 1876 delete pvtx; pvtx=NULL;
3c3709c4 1877 }
1878
1879 // TPC-only primary vertex
f09c879d 1880 ftVertexer->SetTPCMode();
f2a195c1 1881 ftVertexer->SetConstraintOff();
a00021a7 1882 // get cuts for vertexer from AliGRPRecoParam
1883 if (grpRecoParam) {
1884 Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
1885 Double_t *cutsVertexer = new Double_t[nCutsVertexer];
1886 grpRecoParam->GetVertexerTracksCutsTPC(cutsVertexer);
1887 ftVertexer->SetCuts(cutsVertexer);
1888 delete [] cutsVertexer; cutsVertexer = NULL;
f2a195c1 1889 if(fDiamondProfileTPC && grpRecoParam->GetVertexerTracksConstraintTPC())
1890 ftVertexer->SetVtxStart(fDiamondProfileTPC);
43c9dae1 1891 }
21a3aa09 1892 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
3c3709c4 1893 if (pvtx) {
1894 if (pvtx->GetStatus()) {
21a3aa09 1895 fesd->SetPrimaryVertexTPC(pvtx);
3d65e645 1896 for (Int_t i=0; i<ntracks; i++) {
1897 AliESDtrack *t = fesd->GetTrack(i);
52dd4a8c 1898 Double_t x[3]; t->GetXYZ(x);
1899 Double_t b[3]; AliTracker::GetBxByBz(x,b);
1900 t->RelateToVertexTPCBxByBz(pvtx, b, kVeryBig);
3c3709c4 1901 }
1902 }
9bcaa1d7 1903 delete pvtx; pvtx=NULL;
3c3709c4 1904 }
1905
1906 }
1907 delete[] selectedIdx;
1908
21a3aa09 1909 if(fDiamondProfile) fesd->SetDiamond(fDiamondProfile);
17c86e90 1910
c5e3e5d1 1911
d1683eef 1912 if (fRunV0Finder) {
1913 // V0 finding
1914 AliV0vertexer vtxer;
21a3aa09 1915 vtxer.Tracks2V0vertices(fesd);
5e4ff34d 1916
d1683eef 1917 if (fRunCascadeFinder) {
1918 // Cascade finding
1919 AliCascadeVertexer cvtxer;
21a3aa09 1920 cvtxer.V0sTracks2CascadeVertices(fesd);
d1683eef 1921 }
5e4ff34d 1922 }
1923
596a855f 1924 // write ESD
21a3aa09 1925 if (fCleanESD) CleanESD(fesd);
854c6476 1926
514cb8c7 1927 if (fRunQA && IsInTasks(AliQAv1::kESDS)) {
eca4fa66 1928 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
aeb8fc30 1929 AliQAManager::QAManager()->RunOneEvent(fesd, fhltesd) ;
57acd2d2 1930 }
bea94759 1931 if (fRunGlobalQA) {
eca4fa66 1932 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
57acd2d2 1933 qadm->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
514cb8c7 1934 if (qadm && IsInTasks(AliQAv1::kESDS))
4e25ac79 1935 qadm->Exec(AliQAv1::kESDS, fesd);
b03591ab 1936 }
854c6476 1937
8b12d288 1938 // copy HLT decision from HLTesd to esd
1939 // the most relevant information is stored in a reduced container in the esd,
1940 // while the full information can be found in the HLTesd
1941 TObject* pHLTSrc=fhltesd->FindListObject(AliESDHLTDecision::Name());
1942 TObject* pHLTTgt=fesd->FindListObject(AliESDHLTDecision::Name());
1943 if (pHLTSrc && pHLTTgt) {
1944 pHLTSrc->Copy(*pHLTTgt);
1945 }
1946
1d99986f 1947 if (fWriteESDfriend) {
b090e6a3 1948 // fesdf->~AliESDfriend();
1949 // new (fesdf) AliESDfriend(); // Reset...
21a3aa09 1950 fesd->GetESDfriend(fesdf);
1d99986f 1951 }
21a3aa09 1952 ftree->Fill();
500d54ab 1953
2d91a353 1954 // Auto-save the ESD tree in case of prompt reco @P2
be103ac8 1955 if (fRawReader && fRawReader->UseAutoSaveESD()) {
2d91a353 1956 ftree->AutoSave("SaveSelf");
be103ac8 1957 TFile *friendfile = (TFile *)(gROOT->GetListOfFiles()->FindObject("AliESDfriends.root"));
1958 if (friendfile) friendfile->Save();
1959 }
2d91a353 1960
500d54ab 1961 // write HLT ESD
21a3aa09 1962 fhlttree->Fill();
1d99986f 1963
14dd053c 1964 // call AliEVE
1965 if (fRunAliEVE) RunAliEVE();
1966
21a3aa09 1967 fesd->Reset();
1968 fhltesd->Reset();
5728d3d5 1969 if (fWriteESDfriend) {
21a3aa09 1970 fesdf->~AliESDfriend();
1971 new (fesdf) AliESDfriend(); // Reset...
5728d3d5 1972 }
a5fa6165 1973
ac4a7581 1974 ProcInfo_t procInfo;
1975 gSystem->GetProcInfo(&procInfo);
470f88b0 1976 AliInfo(Form("========================= End Event %d: memory res %d(%3d) vir %d(%3d) CPU %5.2f =====================",
1977 iEvent, procInfo.fMemResident/1024, (procInfo.fMemResident-oldMres)/1024,
1978 procInfo.fMemVirtual/1024,(procInfo.fMemVirtual-oldMvir)/1024,procInfo.fCpuUser+procInfo.fCpuSys-oldCPU));
1979 oldMres=procInfo.fMemResident;
1980 oldMvir=procInfo.fMemVirtual;
1981 oldCPU=procInfo.fCpuUser+procInfo.fCpuSys;
a5fa6165 1982
ca13fb87 1983 fEventInfo.Reset();
ac4a7581 1984 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
42ec5d3d 1985 if (fReconstructor[iDet]) {
a00021a7 1986 fReconstructor[iDet]->SetRecoParam(NULL);
42ec5d3d 1987 fReconstructor[iDet]->SetEventInfo(NULL);
1988 }
1f26f3e7 1989 if (fTracker[iDet]) fTracker[iDet]->SetEventInfo(NULL);
ca13fb87 1990 }
1991
53c8f690 1992 if (fRunQA || fRunGlobalQA)
eca4fa66 1993 AliQAManager::QAManager()->Increment() ;
53c8f690 1994
ca13fb87 1995 return kTRUE;
21a3aa09 1996}
1997
21a3aa09 1998//_____________________________________________________________________________
4b71572b 1999void AliReconstruction::SlaveTerminate()
21a3aa09 2000{
4b71572b 2001 // Finalize the run on the slave side
21a3aa09 2002 // Called after the exit
2003 // from the event loop
52dd4a8c 2004 AliCodeTimerAuto("",0);
21a3aa09 2005
2006 if (fIsNewRunLoader) { // galice.root didn't exist
2007 fRunLoader->WriteHeader("OVERWRITE");
2008 fRunLoader->CdGAFile();
2009 fRunLoader->Write(0, TObject::kOverwrite);
2010 }
2011
f747912b 2012 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
2013 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
2014
2015 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
2016 cdbMapCopy->SetOwner(1);
2017 cdbMapCopy->SetName("cdbMap");
2018 TIter iter(cdbMap->GetTable());
2019
2020 TPair* pair = 0;
2021 while((pair = dynamic_cast<TPair*> (iter.Next()))){
2022 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
2023 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
2024 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
2025 }
2026
2027 TList *cdbListCopy = new TList();
2028 cdbListCopy->SetOwner(1);
2029 cdbListCopy->SetName("cdbList");
2030
2031 TIter iter2(cdbList);
2032
b940cb9b 2033 AliCDBId* id=0;
e84c88f5 2034 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
a4970db9 2035 cdbListCopy->Add(new TObjString(id->ToString().Data()));
f747912b 2036 }
2037
21a3aa09 2038 ftree->GetUserInfo()->Add(cdbMapCopy);
2039 ftree->GetUserInfo()->Add(cdbListCopy);
abe0c04e 2040
46698ae4 2041
21a3aa09 2042 ffile->cd();
aa3c69a9 2043
a9c0e6db 2044 if (fWriteESDfriend)
21a3aa09 2045 ftree->SetBranchStatus("ESDfriend*",0);
562dd0b4 2046 // we want to have only one tree version number
21a3aa09 2047 ftree->Write(ftree->GetName(),TObject::kOverwrite);
63314086 2048 fhlttree->Write(fhlttree->GetName(),TObject::kOverwrite);
f3a97c86 2049
a7a1e1c7 2050// Finish with Plane Efficiency evaluation: before of CleanUp !!!
2051 if (fRunPlaneEff && !FinishPlaneEff()) {
2052 AliWarning("Finish PlaneEff evaluation failed");
2053 }
2054
930e6e3e 2055 // End of cycle for the in-loop
87da0921 2056
2057 if (fRunQA || fRunGlobalQA) {
5cbed243 2058 AliQAManager::QAManager()->EndOfCycle() ;
81d57268 2059 if (fInput &&
2060 !fProofOutputLocation.IsNull() &&
2061 fProofOutputArchive.IsNull() &&
2062 !fProofOutputDataset) {
2063 TString qaOutputFile(Form("%sMerged.%s.Data.root",
2064 fProofOutputLocation.Data(),
2065 AliQAv1::GetQADataFileName()));
2066 TProofOutputFile *qaProofFile = new TProofOutputFile(Form("Merged.%s.Data.root",
2067 AliQAv1::GetQADataFileName()));
2068 qaProofFile->SetOutputFileName(qaOutputFile.Data());
2069 if (AliDebugLevel() > 0) qaProofFile->Dump();
2070 fOutput->Add(qaProofFile);
2071 MergeQA(qaProofFile->GetFileName());
87da0921 2072 }
2073 else {
2074 MergeQA();
2075 }
2076 }
2077
4b71572b 2078 gROOT->cd();
2079 CleanUp();
81d57268 2080
2081 if (fInput) {
2082 if (!fProofOutputFileName.IsNull() &&
2083 !fProofOutputLocation.IsNull() &&
2084 fProofOutputDataset &&
2085 !fProofOutputArchive.IsNull()) {
2086 TProofOutputFile *zipProofFile = new TProofOutputFile(fProofOutputFileName.Data(),
2087 "DROV",
2088 fProofOutputLocation.Data());
2089 if (AliDebugLevel() > 0) zipProofFile->Dump();
2090 fOutput->Add(zipProofFile);
2091 TString fileList(fProofOutputArchive.Data());
2092 fileList.ReplaceAll(","," ");
38c18bf1 2093 TString command;
2094#if ROOT_SVN_REVISION >= 30174
2095 command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(kTRUE),zipProofFile->GetFileName(),fileList.Data());
2096#else
2097 command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(),zipProofFile->GetFileName(),fileList.Data());
2098#endif
2099 AliInfo(Form("Executing: %s",command.Data()));
2100 gSystem->Exec(command.Data());
81d57268 2101 }
2102 }
4b71572b 2103}
2104
2105//_____________________________________________________________________________
2106void AliReconstruction::Terminate()
2107{
f3a97c86 2108 // Create tags for the events in the ESD tree (the ESD tree is always present)
2109 // In case of empty events the tags will contain dummy values
52dd4a8c 2110 AliCodeTimerAuto("",0);
4b71572b 2111
e6d66370 2112 // Do not call the ESD tag creator in case of PROOF-based reconstruction
2113 if (!fInput) {
2114 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
2115 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData, AliQAv1::Instance()->GetQA(), AliQAv1::Instance()->GetEventSpecies(), AliQAv1::kNDET, AliRecoParam::kNSpecies);
9bcaa1d7 2116 delete esdtagCreator;
e6d66370 2117 }
e84c88f5 2118
795e4a22 2119 // Cleanup of CDB manager: cache and active storages!
2120 AliCDBManager::Instance()->ClearCache();
596a855f 2121}
2122
b26c3770 2123//_____________________________________________________________________________
2124Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
2125{
2126// run the local reconstruction
aa3c69a9 2127
0f88822a 2128 static Int_t eventNr=0;
52dd4a8c 2129 AliCodeTimerAuto("",0)
b26c3770 2130
2131 TString detStr = detectors;
ac4a7581 2132 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b26c3770 2133 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2134 AliReconstructor* reconstructor = GetReconstructor(iDet);
2135 if (!reconstructor) continue;
2136 AliLoader* loader = fLoader[iDet];
f6806ad3 2137 // Matthias April 2008: temporary fix to run HLT reconstruction
2138 // although the HLT loader is missing
2139 if (strcmp(fgkDetectorName[iDet], "HLT")==0) {
2140 if (fRawReader) {
44ed7a66 2141 reconstructor->Reconstruct(fRawReader, NULL);
f6806ad3 2142 } else {
44ed7a66 2143 TTree* dummy=NULL;
2144 reconstructor->Reconstruct(dummy, NULL);
f6806ad3 2145 }
2146 continue;
2147 }
d76c31f4 2148 if (!loader) {
2149 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
2150 continue;
2151 }
b26c3770 2152 // conversion of digits
2153 if (fRawReader && reconstructor->HasDigitConversion()) {
2154 AliInfo(Form("converting raw data digits into root objects for %s",
2155 fgkDetectorName[iDet]));
30bbd491 2156// AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
52dd4a8c 2157// fgkDetectorName[iDet]),0);
b26c3770 2158 loader->LoadDigits("update");
2159 loader->CleanDigits();
2160 loader->MakeDigitsContainer();
2161 TTree* digitsTree = loader->TreeD();
2162 reconstructor->ConvertDigits(fRawReader, digitsTree);
2163 loader->WriteDigits("OVERWRITE");
2164 loader->UnloadDigits();
b26c3770 2165 }
b26c3770 2166 // local reconstruction
b26c3770 2167 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
52dd4a8c 2168 //AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]),0);
b26c3770 2169 loader->LoadRecPoints("update");
2170 loader->CleanRecPoints();
2171 loader->MakeRecPointsContainer();
2172 TTree* clustersTree = loader->TreeR();
2173 if (fRawReader && !reconstructor->HasDigitConversion()) {
2174 reconstructor->Reconstruct(fRawReader, clustersTree);
2175 } else {
2176 loader->LoadDigits("read");
2177 TTree* digitsTree = loader->TreeD();
2178 if (!digitsTree) {
44ed7a66 2179 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
13effe3f 2180 if (fStopOnError)
2181 return kFALSE;
b26c3770 2182 } else {
44ed7a66 2183 reconstructor->Reconstruct(digitsTree, clustersTree);
514cb8c7 2184 if (fRunQA && IsInTasks(AliQAv1::kDIGITSR)) {
eca4fa66 2185 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
2186 AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, digitsTree) ;
44ed7a66 2187 }
b26c3770 2188 }
2189 loader->UnloadDigits();
2190 }
514cb8c7 2191 if (fRunQA && IsInTasks(AliQAv1::kRECPOINTS)) {
eca4fa66 2192 AliQAManager::QAManager()->SetEventSpecie(fRecoParam.GetEventSpecie()) ;
2193 AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, clustersTree) ;
57acd2d2 2194 }
eca4fa66 2195 loader->WriteRecPoints("OVERWRITE");
2196 loader->UnloadRecPoints();
2197 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
a00021a7 2198 }
13effe3f 2199 IsSelected("CTP", detStr);
a00021a7 2200 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
b26c3770 2201 AliError(Form("the following detectors were not found: %s",
2202 detStr.Data()));
13effe3f 2203 if (fStopOnError)
2204 return kFALSE;
b26c3770 2205 }
0f88822a 2206 eventNr++;
b26c3770 2207 return kTRUE;
2208}
58e8dc31 2209//_____________________________________________________________________________
2210Bool_t AliReconstruction::RunSPDTrackleting(AliESDEvent*& esd)
2211{
2212// run the SPD trackleting (for SPD efficiency purpouses)
2213
52dd4a8c 2214 AliCodeTimerAuto("",0)
58e8dc31 2215
2216 Double_t vtxPos[3] = {0, 0, 0};
2217 Double_t vtxErr[3] = {0.0, 0.0, 0.0};
2218/*
2219 TArrayF mcVertex(3);
2220 // if(MC)
2221 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
2222 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
2223 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
2224 }
2225*/
2226 const AliESDVertex *vertex = esd->GetVertex();
2227 if(!vertex){
2228 AliWarning("Vertex not found");
2229 return kFALSE;
2230 }
2231 vertex->GetXYZ(vtxPos);
2232 vertex->GetSigmaXYZ(vtxErr);
2233 if (fSPDTrackleter) {
2234 AliInfo("running the SPD Trackleter for Plane Efficiency Evaluation");
2235
2236 // load clusters
2237 fLoader[0]->LoadRecPoints("read");
2238 TTree* tree = fLoader[0]->TreeR();
2239 if (!tree) {
2240 AliError("Can't get the ITS cluster tree");
2241 return kFALSE;
2242 }
2243 fSPDTrackleter->LoadClusters(tree);
2244 fSPDTrackleter->SetVertex(vtxPos, vtxErr);
2245 // run trackleting
2246 if (fSPDTrackleter->Clusters2Tracks(esd) != 0) {
84290fcc 2247 AliWarning("AliITSTrackleterSPDEff Clusters2Tracks failed");
58e8dc31 2248 // fLoader[0]->UnloadRecPoints();
2249 return kFALSE;
2250 }
2251//fSPDTrackleter->UnloadRecPoints();
2252 } else {
2253 AliWarning("SPDTrackleter not available");
2254 return kFALSE;
2255 }
2256 return kTRUE;
2257}
b26c3770 2258
596a855f 2259//_____________________________________________________________________________
af885e0f 2260Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
596a855f 2261{
2262// run the barrel tracking
2263
52dd4a8c 2264 AliCodeTimerAuto("",0)
030b532d 2265
92bffc4d 2266 AliVertexer *vertexer = CreateVertexer();
2267 if (!vertexer) return kFALSE;
2268
2269 AliInfo("running the ITS vertex finder");
2257f27e 2270 AliESDVertex* vertex = NULL;
92bffc4d 2271 if (fLoader[0]) {
2272 fLoader[0]->LoadRecPoints();
2273 TTree* cltree = fLoader[0]->TreeR();
2274 if (cltree) {
2275 if(fDiamondProfileSPD) vertexer->SetVtxStart(fDiamondProfileSPD);
2276 vertex = vertexer->FindVertexForCurrentEvent(cltree);
308c2f7c 2277 }
2278 else {
92bffc4d 2279 AliError("Can't get the ITS cluster tree");
308c2f7c 2280 }
92bffc4d 2281 fLoader[0]->UnloadRecPoints();
2257f27e 2282 }
92bffc4d 2283 else {
2284 AliError("Can't get the ITS loader");
2285 }
2286 if(!vertex){
2287 AliWarning("Vertex not found");
2288 vertex = new AliESDVertex();
2289 vertex->SetName("default");
2290 }
2291 else {
2292 vertex->SetName("reconstructed");
2257f27e 2293 }
92bffc4d 2294
2295 Double_t vtxPos[3];
2296 Double_t vtxErr[3];
2297 vertex->GetXYZ(vtxPos);
2298 vertex->GetSigmaXYZ(vtxErr);
2299
06cc9d95 2300 esd->SetPrimaryVertexSPD(vertex);
73c51de2 2301 AliESDVertex *vpileup = NULL;
2302 Int_t novertices = 0;
2303 vpileup = vertexer->GetAllVertices(novertices);
2304 if(novertices>1){
2305 for (Int_t kk=1; kk<novertices; kk++)esd->AddPileupVertexSPD(&vpileup[kk]);
2306 }
32e449be 2307 // if SPD multiplicity has been determined, it is stored in the ESD
92bffc4d 2308 AliMultiplicity *mult = vertexer->GetMultiplicity();
32e449be 2309 if(mult)esd->SetMultiplicity(mult);
2310
ac4a7581 2311 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 2312 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
2313 }
2257f27e 2314 delete vertex;
2315
92bffc4d 2316 delete vertexer;
2317
2257f27e 2318 return kTRUE;
2319}
2320
1f46a9ae 2321//_____________________________________________________________________________
af885e0f 2322Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1f46a9ae 2323{
2324// run the HLT barrel tracking
2325
52dd4a8c 2326 AliCodeTimerAuto("",0)
1f46a9ae 2327
2328 if (!fRunLoader) {
2329 AliError("Missing runLoader!");
2330 return kFALSE;
2331 }
2332
2333 AliInfo("running HLT tracking");
2334
2335 // Get a pointer to the HLT reconstructor
ac4a7581 2336 AliReconstructor *reconstructor = GetReconstructor(kNDetectors-1);
1f46a9ae 2337 if (!reconstructor) return kFALSE;
2338
2339 // TPC + ITS
2340 for (Int_t iDet = 1; iDet >= 0; iDet--) {
2341 TString detName = fgkDetectorName[iDet];
2342 AliDebug(1, Form("%s HLT tracking", detName.Data()));
2343 reconstructor->SetOption(detName.Data());
d76c31f4 2344 AliTracker *tracker = reconstructor->CreateTracker();
1f46a9ae 2345 if (!tracker) {
2346 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
2347 if (fStopOnError) return kFALSE;
9dcc06e1 2348 continue;
1f46a9ae 2349 }
2350 Double_t vtxPos[3];
2351 Double_t vtxErr[3]={0.005,0.005,0.010};
2352 const AliESDVertex *vertex = esd->GetVertex();
2353 vertex->GetXYZ(vtxPos);
2354 tracker->SetVertex(vtxPos,vtxErr);
2355 if(iDet != 1) {
2356 fLoader[iDet]->LoadRecPoints("read");
2357 TTree* tree = fLoader[iDet]->TreeR();
2358 if (!tree) {
2359 AliError(Form("Can't get the %s cluster tree", detName.Data()));
2360 return kFALSE;
2361 }
2362 tracker->LoadClusters(tree);
2363 }
2364 if (tracker->Clusters2Tracks(esd) != 0) {
2365 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
2366 return kFALSE;
2367 }
2368 if(iDet != 1) {
2369 tracker->UnloadClusters();
2370 }
2371 delete tracker;
2372 }
2373
1f46a9ae 2374 return kTRUE;
2375}
2376
e66fbafb 2377//_____________________________________________________________________________
af885e0f 2378Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
e66fbafb 2379{
2380// run the muon spectrometer tracking
2381
52dd4a8c 2382 AliCodeTimerAuto("",0)
e66fbafb 2383
2384 if (!fRunLoader) {
2385 AliError("Missing runLoader!");
2386 return kFALSE;
2387 }
2388 Int_t iDet = 7; // for MUON
2389
2390 AliInfo("is running...");
2391
2392 // Get a pointer to the MUON reconstructor
2393 AliReconstructor *reconstructor = GetReconstructor(iDet);
2394 if (!reconstructor) return kFALSE;
2395
2396
2397 TString detName = fgkDetectorName[iDet];
2398 AliDebug(1, Form("%s tracking", detName.Data()));
d76c31f4 2399 AliTracker *tracker = reconstructor->CreateTracker();
e66fbafb 2400 if (!tracker) {
2401 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
2402 return kFALSE;
2403 }
2404
e66fbafb 2405 // read RecPoints
761350a6 2406 fLoader[iDet]->LoadRecPoints("read");
c1954ee5 2407
761350a6 2408 tracker->LoadClusters(fLoader[iDet]->TreeR());
2409
2410 Int_t rv = tracker->Clusters2Tracks(esd);
2411
e66fbafb 2412 fLoader[iDet]->UnloadRecPoints();
2413
c1954ee5 2414 tracker->UnloadClusters();
2415
e66fbafb 2416 delete tracker;
2417
cb23c6ca 2418 if ( rv )
2419 {
2420 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
2421 return kFALSE;
2422 }
2423
e66fbafb 2424 return kTRUE;
2425}
2426
2427
2257f27e 2428//_____________________________________________________________________________
10d100d4 2429Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd,AliESDpid &PID)
2257f27e 2430{
2431// run the barrel tracking
0f88822a 2432 static Int_t eventNr=0;
52dd4a8c 2433 AliCodeTimerAuto("",0)
24f7a148 2434
815c2b38 2435 AliInfo("running tracking");
596a855f 2436
1f26f3e7 2437 // Set the event info which is used
2438 // by the trackers in order to obtain
2439 // information about read-out detectors,
2440 // trigger etc.
2441 AliDebug(1, "Setting event info");
2442 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2443 if (!fTracker[iDet]) continue;
2444 fTracker[iDet]->SetEventInfo(&fEventInfo);
2445 }
2446
91b876d1 2447 //Fill the ESD with the T0 info (will be used by the TOF)
d76c31f4 2448 if (fReconstructor[11] && fLoader[11]) {
2449 fLoader[11]->LoadRecPoints("READ");
2450 TTree *treeR = fLoader[11]->TreeR();
89916438 2451 if (treeR) {
2452 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
2453 }
d76c31f4 2454 }
91b876d1 2455
b8cd5251 2456 // pass 1: TPC + ITS inwards
2457 for (Int_t iDet = 1; iDet >= 0; iDet--) {
2458 if (!fTracker[iDet]) continue;
2459 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
24f7a148 2460
b8cd5251 2461 // load clusters
2462 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2463 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
b8cd5251 2464 TTree* tree = fLoader[iDet]->TreeR();
2465 if (!tree) {
2466 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
24f7a148 2467 return kFALSE;
2468 }
b8cd5251 2469 fTracker[iDet]->LoadClusters(tree);
6efecea1 2470 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2471 // run tracking
2472 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
2473 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
24f7a148 2474 return kFALSE;
2475 }
878e1fe1 2476 // preliminary PID in TPC needed by the ITS tracker
2477 if (iDet == 1) {
b26c3770 2478 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
10d100d4 2479 PID.MakePID(esd,kTRUE);
0f88822a 2480 }
6efecea1 2481 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
b8cd5251 2482 }
596a855f 2483
b8cd5251 2484 // pass 2: ALL backwards
aa3c69a9 2485
ac4a7581 2486 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 2487 if (!fTracker[iDet]) continue;
2488 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
2489
2490 // load clusters
2491 if (iDet > 1) { // all except ITS, TPC
2492 TTree* tree = NULL;
7b61cd9c 2493 fLoader[iDet]->LoadRecPoints("read");
6efecea1 2494 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
7b61cd9c 2495 tree = fLoader[iDet]->TreeR();
b8cd5251 2496 if (!tree) {
eca4fa66 2497 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
2498 return kFALSE;
24f7a148 2499 }
0f88822a 2500 fTracker[iDet]->LoadClusters(tree);
6efecea1 2501 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
b8cd5251 2502 }
24f7a148 2503
b8cd5251 2504 // run tracking
283f39c6 2505 if (iDet>1) // start filling residuals for the "outer" detectors
eca4fa66 2506 if (fRunGlobalQA) {
2507 AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kTRUE);
2508 TObjArray ** arr = AliTracker::GetResidualsArray() ;
c9526f68 2509 if (arr) {
0a349581 2510 AliRecoParam::EventSpecie_t es=fRecoParam.GetEventSpecie();
2511 TObjArray * elem = arr[AliRecoParam::AConvert(es)];
c9526f68 2512 if ( elem && (! elem->At(0)) ) {
2513 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
2514 if (qadm) qadm->InitRecPointsForTracker() ;
2515 }
2516 }
eca4fa66 2517 }
b8cd5251 2518 if (fTracker[iDet]->PropagateBack(esd) != 0) {
2519 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
49dfd67a 2520 // return kFALSE;
b8cd5251 2521 }
24f7a148 2522
b8cd5251 2523 // unload clusters
6e65648b 2524 if (iDet > 3) { // all except ITS, TPC, TRD and TOF
b8cd5251 2525 fTracker[iDet]->UnloadClusters();
7b61cd9c 2526 fLoader[iDet]->UnloadRecPoints();
b8cd5251 2527 }
8f37df88 2528 // updated PID in TPC needed by the ITS tracker -MI
2529 if (iDet == 1) {
10d100d4 2530 //GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
2531 //AliESDpid::MakePID(esd);
2532 PID.MakePID(esd,kTRUE);
8f37df88 2533 }
6efecea1 2534 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
b8cd5251 2535 }
283f39c6 2536 //stop filling residuals for the "outer" detectors
57acd2d2 2537 if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kFALSE);
596a855f 2538
b8cd5251 2539 // pass 3: TRD + TPC + ITS refit inwards
aa3c69a9 2540
b8cd5251 2541 for (Int_t iDet = 2; iDet >= 0; iDet--) {
2542 if (!fTracker[iDet]) continue;
2543 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
596a855f 2544
b8cd5251 2545 // run tracking
283f39c6 2546 if (iDet<2) // start filling residuals for TPC and ITS
eca4fa66 2547 if (fRunGlobalQA) {
2548 AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kTRUE);
2549 TObjArray ** arr = AliTracker::GetResidualsArray() ;
c9526f68 2550 if (arr) {
0a349581 2551 AliRecoParam::EventSpecie_t es=fRecoParam.GetEventSpecie();
2552 TObjArray * elem = arr[AliRecoParam::AConvert(es)];
c9526f68 2553 if ( elem && (! elem->At(0)) ) {
2554 AliQADataMaker *qadm = AliQAManager::QAManager()->GetQADataMaker(AliQAv1::kGLOBAL);
2555 if (qadm) qadm->InitRecPointsForTracker() ;
2556 }
2557 }
eca4fa66 2558 }
2559
b8cd5251 2560 if (fTracker[iDet]->RefitInward(esd) != 0) {
2561 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
49dfd67a 2562 // return kFALSE;
b8cd5251 2563 }
db2368d0 2564 // run postprocessing
2565 if (fTracker[iDet]->PostProcess(esd) != 0) {
2566 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
2567 // return kFALSE;
2568 }
6efecea1 2569 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
6e65648b 2570 }
2571
2572 // write space-points to the ESD in case alignment data output
2573 // is switched on
2574 if (fWriteAlignmentData)
2575 WriteAlignmentData(esd);
2576
2577 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2578 if (!fTracker[iDet]) continue;
b8cd5251 2579 // unload clusters
2580 fTracker[iDet]->UnloadClusters();
6efecea1 2581 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
b8cd5251 2582 fLoader[iDet]->UnloadRecPoints();
6efecea1 2583 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
b8cd5251 2584 }
283f39c6 2585 // stop filling residuals for TPC and ITS
57acd2d2 2586 if (fRunGlobalQA) AliTracker::SetFillResiduals(fRecoParam.GetEventSpecie(), kFALSE);
854c6476 2587
0f88822a 2588 eventNr++;
596a855f 2589 return kTRUE;
2590}
2591
d64bd07d 2592//_____________________________________________________________________________
2593Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
2594 //
2595 // Remove the data which are not needed for the physics analysis.
2596 //
2597
d64bd07d 2598 Int_t nTracks=esd->GetNumberOfTracks();
18571674 2599 Int_t nV0s=esd->GetNumberOfV0s();
cf37fd88 2600 AliInfo
2601 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
d64bd07d 2602
18571674 2603 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
7f68891d 2604 Bool_t rc=esd->Clean(cleanPars);
d64bd07d 2605
7f68891d 2606 nTracks=esd->GetNumberOfTracks();
18571674 2607 nV0s=esd->GetNumberOfV0s();
cf37fd88 2608 AliInfo
ae5d5566 2609 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
d64bd07d 2610
7f68891d 2611 return rc;
d64bd07d 2612}
2613
596a855f 2614//_____________________________________________________________________________
af885e0f 2615Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
596a855f 2616{
2617// fill the event summary data
2618
52dd4a8c 2619 AliCodeTimerAuto("",0)
0f88822a 2620 static Int_t eventNr=0;
596a855f 2621 TString detStr = detectors;
abe0c04e 2622
ac4a7581 2623 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
abe0c04e 2624 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
b8cd5251 2625 AliReconstructor* reconstructor = GetReconstructor(iDet);
2626 if (!reconstructor) continue;
4b71572b 2627 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
2628 TTree* clustersTree = NULL;
2629 if (fLoader[iDet]) {
2630 fLoader[iDet]->LoadRecPoints("read");
2631 clustersTree = fLoader[iDet]->TreeR();
2632 if (!clustersTree) {
2633 AliError(Form("Can't get the %s clusters tree",
2634 fgkDetectorName[iDet]));
2635 if (fStopOnError) return kFALSE;
2636 }
2637 }
2638 if (fRawReader && !reconstructor->HasDigitConversion()) {
2639 reconstructor->FillESD(fRawReader, clustersTree, esd);
2640 } else {
2641 TTree* digitsTree = NULL;
d76c31f4 2642 if (fLoader[iDet]) {
4b71572b 2643 fLoader[iDet]->LoadDigits("read");
2644 digitsTree = fLoader[iDet]->TreeD();
2645 if (!digitsTree) {
2646 AliError(Form("Can't get the %s digits tree",
b26c3770 2647 fgkDetectorName[iDet]));
2648 if (fStopOnError) return kFALSE;
2649 }
2650 }
4b71572b 2651 reconstructor->FillESD(digitsTree, clustersTree, esd);
2652 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
2653 }
2654 if (fLoader[iDet]) {
2655 fLoader[iDet]->UnloadRecPoints();
596a855f 2656 }
2657 }
13effe3f 2658
2659 IsSelected("CTP", detStr);
596a855f 2660 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
815c2b38 2661 AliError(Form("the following detectors were not found: %s",
2662 detStr.Data()));
596a855f 2663 if (fStopOnError) return kFALSE;
2664 }
6efecea1 2665 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
0f88822a 2666 eventNr++;
596a855f 2667 return kTRUE;
2668}
2669
b647652d 2670//_____________________________________________________________________________
af885e0f 2671Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
b647652d 2672{
2673 // Reads the trigger decision which is
2674 // stored in Trigger.root file and fills
2675 // the corresponding esd entries
2676
52dd4a8c 2677 AliCodeTimerAuto("",0)
87932dab 2678
b647652d 2679 AliInfo("Filling trigger information into the ESD");
2680
2681 if (fRawReader) {
2682 AliCTPRawStream input(fRawReader);
2683 if (!input.Next()) {
7e88424f 2684 AliWarning("No valid CTP (trigger) DDL raw data is found ! The trigger info is taken from the event header!");
b647652d 2685 }
2686 else {
7e88424f 2687 if (esd->GetTriggerMask() != input.GetClassMask())
2688 AliError(Form("Invalid trigger pattern found in CTP raw-data: %llx %llx",
2689 input.GetClassMask(),esd->GetTriggerMask()));
2690 if (esd->GetOrbitNumber() != input.GetOrbitID())
2691 AliError(Form("Invalid orbit id found in CTP raw-data: %x %x",
2692 input.GetOrbitID(),esd->GetOrbitNumber()));
2693 if (esd->GetBunchCrossNumber() != input.GetBCID())
2694 AliError(Form("Invalid bunch-crossing id found in CTP raw-data: %x %x",
2695 input.GetBCID(),esd->GetBunchCrossNumber()));
e61ed4b1 2696 AliESDHeader* esdheader = esd->GetHeader();
2697 esdheader->SetL0TriggerInputs(input.GetL0Inputs());
2698 esdheader->SetL1TriggerInputs(input.GetL1Inputs());
2699 esdheader->SetL2TriggerInputs(input.GetL2Inputs());
a6dd87ad 2700 // IR
2701 UInt_t orbit=input.GetOrbitID();
2702 for(Int_t i=0 ; i<input.GetNIRs() ; i++ )
2703 if(TMath::Abs(Int_t(orbit-(input.GetIR(i))->GetOrbit()))<=1){
2704 esdheader->AddTriggerIR(input.GetIR(i));
2705 }
b647652d 2706 }
b024fd7f 2707 }
f7812afc 2708 return kTRUE;
2709}
2710//_____________________________________________________________________________
2711Bool_t AliReconstruction::FillTriggerScalers(AliESDEvent*& esd)
2712{
522fdd91 2713 //Scalers
82ebedd6 2714 //fRunScalers->Print();
2715 if(fRunScalers && fRunScalers->CheckRunScalers()){
a6dd87ad 2716 AliTimeStamp* timestamp = new AliTimeStamp(esd->GetOrbitNumber(), esd->GetPeriodNumber(), esd->GetBunchCrossNumber());
82ebedd6 2717 //AliTimeStamp* timestamp = new AliTimeStamp(10308000, 0, (ULong64_t)486238);
522fdd91 2718 AliESDHeader* esdheader = fesd->GetHeader();
2719 for(Int_t i=0;i<50;i++){
1e78ae8c 2720 if((1ull<<i) & esd->GetTriggerMask()){
6863d231 2721 AliTriggerScalersESD* scalesd = fRunScalers->GetScalersForEventClass( timestamp, i+1);
82ebedd6 2722 if(scalesd)esdheader->SetTriggerScalersRecord(scalesd);
522fdd91 2723 }
2724 }
2725 }
b647652d 2726 return kTRUE;
2727}
001397cd 2728//_____________________________________________________________________________
af885e0f 2729Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
001397cd 2730{
2731 //
2732 // Filling information from RawReader Header
2733 //
2734
151bea4e 2735 if (!fRawReader) return kFALSE;
2736
001397cd 2737 AliInfo("Filling information from RawReader Header");
151bea4e 2738
2739 esd->SetBunchCrossNumber(fRawReader->GetBCID());
2740 esd->SetOrbitNumber(fRawReader->GetOrbitID());
2741 esd->SetPeriodNumber(fRawReader->GetPeriod());
2742
2743 esd->SetTimeStamp(fRawReader->GetTimestamp());
2744 esd->SetEventType(fRawReader->GetType());
001397cd 2745
2746 return kTRUE;
2747}
2748
2749
596a855f 2750//_____________________________________________________________________________
2751Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
2752{
2753// check whether detName is contained in detectors
2754// if yes, it is removed from detectors
2755
2756 // check if all detectors are selected
2757 if ((detectors.CompareTo("ALL") == 0) ||
2758 detectors.BeginsWith("ALL ") ||
2759 detectors.EndsWith(" ALL") ||
2760 detectors.Contains(" ALL ")) {
2761 detectors = "ALL";
2762 return kTRUE;
2763 }
2764
2765 // search for the given detector
2766 Bool_t result = kFALSE;
2767 if ((detectors.CompareTo(detName) == 0) ||
2768 detectors.BeginsWith(detName+" ") ||
2769 detectors.EndsWith(" "+detName) ||
2770 detectors.Contains(" "+detName+" ")) {
2771 detectors.ReplaceAll(detName, "");
2772 result = kTRUE;
2773 }
2774
2775 // clean up the detectors string
2776 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
2777 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
2778 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
2779
2780 return result;
2781}
e583c30d 2782
f08fc9f5 2783//_____________________________________________________________________________
2784Bool_t AliReconstruction::InitRunLoader()
2785{
2786// get or create the run loader
2787
2788 if (gAlice) delete gAlice;
2789 gAlice = NULL;
2790
52dd4a8c 2791 TFile *gafile = TFile::Open(fGAliceFileName.Data());
2792 // if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
2793 if (gafile) { // galice.root exists
2794 gafile->Close();
2795 delete gafile;
2796
b26c3770 2797 // load all base libraries to get the loader classes
2798 TString libs = gSystem->GetLibraries();
ac4a7581 2799 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b26c3770 2800 TString detName = fgkDetectorName[iDet];
2801 if (detName == "HLT") continue;
2802 if (libs.Contains("lib" + detName + "base.so")) continue;
2803 gSystem->Load("lib" + detName + "base.so");
2804 }
f08fc9f5 2805 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
2806 if (!fRunLoader) {
2807 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2808 CleanUp();
2809 return kFALSE;
2810 }
325aa76f 2811
b26c3770 2812 fRunLoader->CdGAFile();
325aa76f 2813 fRunLoader->LoadgAlice();
f08fc9f5 2814
6cae184e 2815 //PH This is a temporary fix to give access to the kinematics
2816 //PH that is needed for the labels of ITS clusters
f2ee4290 2817 fRunLoader->LoadHeader();
6cae184e 2818 fRunLoader->LoadKinematics();
2819
f08fc9f5 2820 } else { // galice.root does not exist
2821 if (!fRawReader) {
2822 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
f08fc9f5 2823 }
2824 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2825 AliConfig::GetDefaultEventFolderName(),
2826 "recreate");
2827 if (!fRunLoader) {
2828 AliError(Form("could not create run loader in file %s",
2829 fGAliceFileName.Data()));
2830 CleanUp();
2831 return kFALSE;
2832 }
21a3aa09 2833 fIsNewRunLoader = kTRUE;
f08fc9f5 2834 fRunLoader->MakeTree("E");
21a3aa09 2835
973388c2 2836 if (fNumberOfEventsPerFile > 0)
2837 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2838 else
21a3aa09 2839 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
f08fc9f5 2840 }
2841
2842 return kTRUE;
2843}
2844
c757bafd 2845//_____________________________________________________________________________
b8cd5251 2846AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
c757bafd 2847{
f08fc9f5 2848// get the reconstructor object and the loader for a detector
c757bafd 2849
7e88424f 2850 if (fReconstructor[iDet]) {
2851 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2852 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2853 fReconstructor[iDet]->SetRecoParam(par);
42ec5d3d 2854 fReconstructor[iDet]->SetRunInfo(fRunInfo);
7e88424f 2855 }
2856 return fReconstructor[iDet];
2857 }
b8cd5251 2858
2859 // load the reconstructor object
2860 TPluginManager* pluginManager = gROOT->GetPluginManager();
2861 TString detName = fgkDetectorName[iDet];
2862 TString recName = "Ali" + detName + "Reconstructor";
f0999a9a 2863
2864 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
b8cd5251 2865
b8cd5251 2866 AliReconstructor* reconstructor = NULL;
2867 // first check if a plugin is defined for the reconstructor
2868 TPluginHandler* pluginHandler =
2869 pluginManager->FindHandler("AliReconstructor", detName);
f08fc9f5 2870 // if not, add a plugin for it
2871 if (!pluginHandler) {
b8cd5251 2872 AliDebug(1, Form("defining plugin for %s", recName.Data()));
b26c3770 2873 TString libs = gSystem->GetLibraries();
2874 if (libs.Contains("lib" + detName + "base.so") ||
2875 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
b8cd5251 2876 pluginManager->AddHandler("AliReconstructor", detName,
2877 recName, detName + "rec", recName + "()");
2878 } else {
2879 pluginManager->AddHandler("AliReconstructor", detName,
2880 recName, detName, recName + "()");
c757bafd 2881 }
b8cd5251 2882 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2883 }
2884 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2885 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
c757bafd 2886 }
b8cd5251 2887 if (reconstructor) {
2888 TObject* obj = fOptions.FindObject(detName.Data());
2889 if (obj) reconstructor->SetOption(obj->GetTitle());
1e500f25 2890 reconstructor->SetRunInfo(fRunInfo);
d76c31f4 2891 reconstructor->Init();
b8cd5251 2892 fReconstructor[iDet] = reconstructor;
2893 }
2894
f08fc9f5 2895 // get or create the loader
2896 if (detName != "HLT") {
2897 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2898 if (!fLoader[iDet]) {
2899 AliConfig::Instance()
2900 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2901 detName, detName);
2902 // first check if a plugin is defined for the loader
bb0901a4 2903 pluginHandler =
f08fc9f5 2904 pluginManager->FindHandler("AliLoader", detName);
2905 // if not, add a plugin for it
2906 if (!pluginHandler) {
2907 TString loaderName = "Ali" + detName + "Loader";
2908 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2909 pluginManager->AddHandler("AliLoader", detName,
2910 loaderName, detName + "base",
2911 loaderName + "(const char*, TFolder*)");
2912 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2913 }
2914 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2915 fLoader[iDet] =
2916 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2917 fRunLoader->GetEventFolder());
2918 }
2919 if (!fLoader[iDet]) { // use default loader
2920 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2921 }
2922 if (!fLoader[iDet]) {
2923 AliWarning(Form("couldn't get loader for %s", detName.Data()));
6667b602 2924 if (fStopOnError) return NULL;
f08fc9f5 2925 } else {
2926 fRunLoader->AddLoader(fLoader[iDet]);
2927 fRunLoader->CdGAFile();
2928 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2929 fRunLoader->Write(0, TObject::kOverwrite);
2930 }
2931 }
2932 }
2933
7e88424f 2934 if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
2935 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2936 reconstructor->SetRecoParam(par);
42ec5d3d 2937 reconstructor->SetRunInfo(fRunInfo);
7e88424f 2938 }
b8cd5251 2939 return reconstructor;
c757bafd 2940}
2941
2257f27e 2942//_____________________________________________________________________________
92bffc4d 2943AliVertexer* AliReconstruction::CreateVertexer()
2257f27e 2944{
2945// create the vertexer
92bffc4d 2946// Please note that the caller is the owner of the
2947// vertexer
2257f27e 2948
92bffc4d 2949 AliVertexer* vertexer = NULL;
b8cd5251 2950 AliReconstructor* itsReconstructor = GetReconstructor(0);
5ec10f5d 2951 if (itsReconstructor && ((fRunLocalReconstruction.Contains("ITS")) || fRunTracking.Contains("ITS"))) {
92bffc4d 2952 vertexer = itsReconstructor->CreateVertexer();
2257f27e 2953 }
92bffc4d 2954 if (!vertexer) {
815c2b38 2955 AliWarning("couldn't create a vertexer for ITS");
2257f27e 2956 }
2957
92bffc4d 2958 return vertexer;
2257f27e 2959}
2960
24f7a148 2961//_____________________________________________________________________________
b8cd5251 2962Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
24f7a148 2963{
f08fc9f5 2964// create the trackers
44e45fac 2965 AliInfo("Creating trackers");
24f7a148 2966
b8cd5251 2967 TString detStr = detectors;
ac4a7581 2968 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 2969 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2970 AliReconstructor* reconstructor = GetReconstructor(iDet);
2971 if (!reconstructor) continue;
2972 TString detName = fgkDetectorName[iDet];
1f46a9ae 2973 if (detName == "HLT") {
2974 fRunHLTTracking = kTRUE;
2975 continue;
2976 }
e66fbafb 2977 if (detName == "MUON") {
2978 fRunMuonTracking = kTRUE;
2979 continue;
2980 }
2981
f08fc9f5 2982
d76c31f4 2983 fTracker[iDet] = reconstructor->CreateTracker();
f08fc9f5 2984 if (!fTracker[iDet] && (iDet < 7)) {
2985 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
8250d5f5 2986 if (fStopOnError) return kFALSE;
2987 }
6efecea1 2988 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
8250d5f5 2989 }
2990
24f7a148 2991 return kTRUE;
2992}
2993
e583c30d 2994//_____________________________________________________________________________
4b71572b 2995void AliReconstruction::CleanUp()
e583c30d 2996{
2997// delete trackers and the run loader and close and delete the file
2998
ac4a7581 2999 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
b8cd5251 3000 delete fReconstructor[iDet];
3001 fReconstructor[iDet] = NULL;
3002 fLoader[iDet] = NULL;
3003 delete fTracker[iDet];
3004 fTracker[iDet] = NULL;
3005 }
4b71572b 3006 delete fRunInfo;
7e88424f 3007 fRunInfo = NULL;
3008
58e8dc31 3009 delete fSPDTrackleter;
3010 fSPDTrackleter = NULL;
3011
4b71572b 3012 delete ftVertexer;
21a3aa09 3013 ftVertexer = NULL;
795e4a22 3014
e583c30d 3015 delete fRunLoader;
3016 fRunLoader = NULL;
b649205a 3017 delete fRawReader;
3018 fRawReader = NULL;
4b71572b 3019 delete fParentRawReader;
cd0b062e 3020 fParentRawReader=NULL;
e583c30d 3021
4b71572b 3022 if (ffile) {
3023 ffile->Close();
3024 delete ffile;
3025 ffile = NULL;
24f7a148 3026 }
87da0921 3027
bf76b847 3028 if (AliQAManager::QAManager())
3029 AliQAManager::QAManager()->ShowQA() ;
eca4fa66 3030 AliQAManager::Destroy() ;
3031
24f7a148 3032}
f3a97c86 3033
af885e0f 3034void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
98937d93 3035{
3036 // Write space-points which are then used in the alignment procedures
6e65648b 3037 // For the moment only ITS, TPC, TRD and TOF
98937d93 3038
98937d93 3039 Int_t ntracks = esd->GetNumberOfTracks();
3040 for (Int_t itrack = 0; itrack < ntracks; itrack++)
3041 {
3042 AliESDtrack *track = esd->GetTrack(itrack);
3043 Int_t nsp = 0;
ef7253ac 3044 Int_t idx[200];
76741755 3045 for (Int_t i=0; i<200; ++i) idx[i] = -1; //PH avoid uninitialized values
81aa7a0d 3046 for (Int_t iDet = 5; iDet >= 0; iDet--) {// TOF, TRD, TPC, ITS clusters
0ad488b0 3047 nsp += (iDet==GetDetIndex("TRD")) ? track->GetTRDntracklets():track->GetNcls(iDet);
6e65648b 3048
0ad488b0 3049 if (iDet==GetDetIndex("ITS")) { // ITS "extra" clusters
6e65648b 3050 track->GetClusters(iDet,idx);
3051 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nsp++;
3052 }
3053 }
3054
98937d93 3055 if (nsp) {
3056 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
3057 track->SetTrackPointArray(sp);
3058 Int_t isptrack = 0;
81aa7a0d 3059 for (Int_t iDet = 5; iDet >= 0; iDet--) {
98937d93 3060 AliTracker *tracker = fTracker[iDet];
3061 if (!tracker) continue;
0ad488b0 3062 Int_t nspdet = (iDet==GetDetIndex("TRD")) ? track->GetTRDtracklets(idx):track->GetClusters(iDet,idx);
6e65648b 3063
0ad488b0 3064 if (iDet==GetDetIndex("ITS")) // ITS "extra" clusters
6e65648b 3065 for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nspdet++;
3066
98937d93 3067 if (nspdet <= 0) continue;
98937d93 3068 AliTrackPoint p;
3069 Int_t isp = 0;
3070 Int_t isp2 = 0;
4ed6fb1c 3071 while (isp2 < nspdet) {
f3c6e4c9 3072 Bool_t isvalid=kTRUE;
3073
3074 Int_t index=idx[isp++];
3075 if (index < 0) continue;
3076
c12b6e44 3077 TString dets = fgkDetectorName[iDet];
3078 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
3079 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
3080 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
3081 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
f3c6e4c9 3082 isvalid = tracker->GetTrackPointTrackingError(index,p,track);
48ce48d1 3083 } else {
f3c6e4c9 3084 isvalid = tracker->GetTrackPoint(index,p);
48ce48d1 3085 }
3086 isp2++;
98937d93 3087 if (!isvalid) continue;
0ad488b0 3088 if (iDet==GetDetIndex("ITS") && (isp-1)>=6) p.SetExtra();
f3c6e4c9 3089 sp->AddPoint(isptrack,&p); isptrack++;
98937d93 3090 }
98937d93 3091 }
3092 }
3093 }
98937d93 3094}
2e3550da 3095
3096//_____________________________________________________________________________
af885e0f 3097void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2e3550da 3098{
3099 // The method reads the raw-data error log
3100 // accumulated within the rawReader.
3101 // It extracts the raw-data errors related to
3102 // the current event and stores them into
3103 // a TClonesArray inside the esd object.
3104
3105 if (!fRawReader) return;
3106
3107 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
3108
3109 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
3110 if (!log) continue;
3111 if (iEvent != log->GetEventNumber()) continue;
3112
3113 esd->AddRawDataErrorLog(log);
3114 }
3115
3116}
46698ae4 3117
8661738e 3118//_____________________________________________________________________________
3119void AliReconstruction::CheckQA()
3120{
3121// check the QA of SIM for this run and remove the detectors
3122// with status Fatal
3123
57acd2d2 3124// TString newRunLocalReconstruction ;
3125// TString newRunTracking ;
3126// TString newFillESD ;
3127//
4e25ac79 3128// for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
3129// TString detName(AliQAv1::GetDetName(iDet)) ;
3130// AliQAv1 * qa = AliQAv1::Instance(AliQAv1::DETECTORINDEX_t(iDet)) ;
3131// if ( qa->IsSet(AliQAv1::DETECTORINDEX_t(iDet), AliQAv1::kSIM, specie, AliQAv1::kFATAL)) {
57acd2d2 3132// AliInfo(Form("QA status for %s %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed",
3133// detName.Data(), AliRecoParam::GetEventSpecieName(es))) ;
3134// } else {
4e25ac79 3135// if ( fRunLocalReconstruction.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3136// fRunLocalReconstruction.Contains("ALL") ) {
3137// newRunLocalReconstruction += detName ;
3138// newRunLocalReconstruction += " " ;
3139// }
4e25ac79 3140// if ( fRunTracking.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3141// fRunTracking.Contains("ALL") ) {
3142// newRunTracking += detName ;
3143// newRunTracking += " " ;
3144// }
4e25ac79 3145// if ( fFillESD.Contains(AliQAv1::GetDetName(iDet)) ||
57acd2d2 3146// fFillESD.Contains("ALL") ) {
3147// newFillESD += detName ;
3148// newFillESD += " " ;
3149// }
3150// }
3151// }
3152// fRunLocalReconstruction = newRunLocalReconstruction ;
3153// fRunTracking = newRunTracking ;
3154// fFillESD = newFillESD ;
a5fa6165 3155}
5b188f2f 3156
3157//_____________________________________________________________________________
3158Int_t AliReconstruction::GetDetIndex(const char* detector)
3159{
3160 // return the detector index corresponding to detector
3161 Int_t index = -1 ;
ac4a7581 3162 for (index = 0; index < kNDetectors ; index++) {
5b188f2f 3163 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
3164 break ;
3165 }
3166 return index ;
3167}
7167ae53 3168//_____________________________________________________________________________
3169Bool_t AliReconstruction::FinishPlaneEff() {
3170 //
3171 // Here execute all the necessary operationis, at the end of the tracking phase,
d7f8fd68 3172 // in case that evaluation of PlaneEfficiencies was required for some detector.
3173 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
7167ae53 3174 //
3175 // This Preliminary version works only FOR ITS !!!!!
3176 // other detectors (TOF,TRD, etc. have to develop their specific codes)
3177 //
3178 // Input: none
d7f8fd68 3179 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
7167ae53 3180 //
3181 Bool_t ret=kFALSE;
5ee13eb5 3182 TString detStr = fLoadCDB;
58e8dc31 3183 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
d7f8fd68 3184 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
5ee13eb5 3185 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
58e8dc31 3186 if(fTracker[iDet] && fTracker[iDet]->GetPlaneEff()) {
d7f8fd68 3187 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
3188 TString name=planeeff->GetName();
3189 name+=".root";
3190 TFile* pefile = TFile::Open(name, "RECREATE");
3191 ret=(Bool_t)planeeff->Write();
3192 pefile->Close();
5fbd4fd6 3193 if(planeeff->GetCreateHistos()) {
d7f8fd68 3194 TString hname=planeeff->GetName();
3195 hname+="Histo.root";
3196 ret*=planeeff->WriteHistosToFile(hname,"RECREATE");
5fbd4fd6 3197 }
3198 }
58e8dc31 3199 if(fSPDTrackleter) {
3200 AliPlaneEff *planeeff=fSPDTrackleter->GetPlaneEff();
3201 TString name="AliITSPlaneEffSPDtracklet.root";
3202 TFile* pefile = TFile::Open(name, "RECREATE");
3203 ret=(Bool_t)planeeff->Write();
3204 pefile->Close();
3205 AliESDEvent *dummy=NULL;
3206 ret=(Bool_t)fSPDTrackleter->PostProcess(dummy); // take care of writing other files
3207 }
7167ae53 3208 }
3209 return ret;
3210}
3211//_____________________________________________________________________________
3212Bool_t AliReconstruction::InitPlaneEff() {
3213//
3214 // Here execute all the necessary operations, before of the tracking phase,
3215 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
58e8dc31 3216 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
7167ae53 3217 // which should be updated/recalculated.
3218 //
3219 // This Preliminary version will work only FOR ITS !!!!!
3220 // other detectors (TOF,TRD, etc. have to develop their specific codes)
3221 //
3222 // Input: none
3223 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
3224 //
58e8dc31 3225 AliWarning(Form("Implementation of this method not yet completed !! Method return kTRUE"));
3226
3227 fSPDTrackleter = NULL;
b8604b34 3228 TString detStr = fLoadCDB;
3229 if (IsSelected(fgkDetectorName[0], detStr)) {
3230 AliReconstructor* itsReconstructor = GetReconstructor(0);
3231 if (itsReconstructor) {
3232 fSPDTrackleter = itsReconstructor->CreateTrackleter(); // this is NULL unless required in RecoParam
3233 }
3234 if (fSPDTrackleter) {
3235 AliInfo("Trackleter for SPD has been created");
3236 }
58e8dc31 3237 }
7167ae53 3238 return kTRUE;
7520312d 3239}
14dd053c 3240
3241//_____________________________________________________________________________
3242Bool_t AliReconstruction::InitAliEVE()
3243{
3244 // This method should be called only in case
3245 // AliReconstruction is run
3246 // within the alieve environment.
3247 // It will initialize AliEVE in a way
3248 // so that it can visualize event processed
3249 // by AliReconstruction.
3250 // The return flag shows whenever the
3251 // AliEVE initialization was successful or not.
3252
3253 TString macroStr;
3254 macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
3255 AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
3256 if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
3257
6a840f1e 3258 gROOT->ProcessLine("if (!AliEveEventManager::GetMaster()){new AliEveEventManager();AliEveEventManager::GetMaster()->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(AliEveEventManager::GetMaster());};");
de33999e 3259 gROOT->ProcessLine("alieve_online_init()");
14dd053c 3260
3261 return kTRUE;
3262}
3263
3264//_____________________________________________________________________________
3265void AliReconstruction::RunAliEVE()
3266{
3267 // Runs AliEVE visualisation of
3268 // the current event.
3269 // Should be executed only after
3270 // successful initialization of AliEVE.
3271
3272 AliInfo("Running AliEVE...");
519975fe 3273 gROOT->ProcessLine(Form("AliEveEventManager::GetMaster()->SetEvent((AliRunLoader*)0x%lx,(AliRawReader*)0x%lx,(AliESDEvent*)0x%lx,(AliESDfriend*)0x%lx);",fRunLoader,fRawReader,fesd,fesdf));
14dd053c 3274 gSystem->Run();
3275}
ce43afbe 3276
3277//_____________________________________________________________________________
3278Bool_t AliReconstruction::SetRunQA(TString detAndAction)
3279{
3280 // Allows to run QA for a selected set of detectors
44ed7a66 3281 // and a selected set of tasks among RAWS, DIGITSR, RECPOINTS and ESDS
ce43afbe 3282 // all selected detectors run the same selected tasks
3283
3284 if (!detAndAction.Contains(":")) {
3285 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
3286 fRunQA = kFALSE ;
3287 return kFALSE ;
3288 }
3289 Int_t colon = detAndAction.Index(":") ;
3290 fQADetectors = detAndAction(0, colon) ;
59b1e631 3291 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
ce43afbe 3292 if (fQATasks.Contains("ALL") ) {
44ed7a66 3293 fQATasks = Form("%d %d %d %d", AliQAv1::kRAWS, AliQAv1::kDIGITSR, AliQAv1::kRECPOINTS, AliQAv1::kESDS) ;
ce43afbe 3294 } else {
3295 fQATasks.ToUpper() ;
3296 TString tempo("") ;
3297 if ( fQATasks.Contains("RAW") )
4e25ac79 3298 tempo = Form("%d ", AliQAv1::kRAWS) ;
44ed7a66 3299 if ( fQATasks.Contains("DIGIT") )
3300 tempo += Form("%d ", AliQAv1::kDIGITSR) ;
ce43afbe 3301 if ( fQATasks.Contains("RECPOINT") )
4e25ac79 3302 tempo += Form("%d ", AliQAv1::kRECPOINTS) ;
ce43afbe 3303 if ( fQATasks.Contains("ESD") )
4e25ac79 3304 tempo += Form("%d ", AliQAv1::kESDS) ;
ce43afbe 3305 fQATasks = tempo ;
3306 if (fQATasks.IsNull()) {
3307 AliInfo("No QA requested\n") ;
3308 fRunQA = kFALSE ;
3309 return kTRUE ;
3310 }
3311 }
3312 TString tempo(fQATasks) ;
4e25ac79 3313 tempo.ReplaceAll(Form("%d", AliQAv1::kRAWS), AliQAv1::GetTaskName(AliQAv1::kRAWS)) ;
44ed7a66 3314 tempo.ReplaceAll(Form("%d", AliQAv1::kDIGITSR), AliQAv1::GetTaskName(AliQAv1::kDIGITSR)) ;
4e25ac79 3315 tempo.ReplaceAll(Form("%d", AliQAv1::kRECPOINTS), AliQAv1::GetTaskName(AliQAv1::kRECPOINTS)) ;
3316 tempo.ReplaceAll(Form("%d", AliQAv1::kESDS), AliQAv1::GetTaskName(AliQAv1::kESDS)) ;
ce43afbe 3317 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
3318 fRunQA = kTRUE ;
3319 return kTRUE;
3320}
3321
7e88424f 3322//_____________________________________________________________________________
3323Bool_t AliReconstruction::InitRecoParams()
3324{
3325 // The method accesses OCDB and retrieves all
3326 // the available reco-param objects from there.
3327
3328 Bool_t isOK = kTRUE;
3329
8b26452d 3330 if (fRecoParam.GetDetRecoParamArray(kNDetectors)) {
3331 AliInfo("Using custom GRP reconstruction parameters");
3332 }
3333 else {
3334 AliInfo("Loading GRP reconstruction parameter objects");
3335
3336 AliCDBPath path("GRP","Calib","RecoParam");
3337 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
3338 if(!entry){
3339 AliWarning("Couldn't find GRP RecoParam entry in OCDB");
3340 isOK = kFALSE;
3341 }
3342 else {
3343 TObject *recoParamObj = entry->GetObject();
3344 if (dynamic_cast<TObjArray*>(recoParamObj)) {
3345 // GRP has a normal TobjArray of AliDetectorRecoParam objects
3346 // Registering them in AliRecoParam
3347 fRecoParam.AddDetRecoParamArray(kNDetectors,dynamic_cast<TObjArray*>(recoParamObj));
3348 }
3349 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
3350 // GRP has only onse set of reco parameters
3351 // Registering it in AliRecoParam
3352 AliInfo("Single set of GRP reconstruction parameters found");
3353 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
3354 fRecoParam.AddDetRecoParam(kNDetectors,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
3355 }
3356 else {
3357 AliError("No valid GRP RecoParam object found in the OCDB");
3358 isOK = kFALSE;
3359 }
3360 entry->SetOwner(0);
3361 }
3362 }
3363
7d566c20 3364 TString detStr = fLoadCDB;
ac4a7581 3365 for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
7e88424f 3366
7d566c20 3367 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
3368
7e88424f 3369 if (fRecoParam.GetDetRecoParamArray(iDet)) {
3370 AliInfo(Form("Using custom reconstruction parameters for detector %s",fgkDetectorName[iDet]));
3371 continue;
3372 }
3373
ac232c75 3374 AliInfo(Form("Loading reconstruction parameter objects for detector %s",fgkDetectorName[iDet]));
7e88424f 3375
3376 AliCDBPath path(fgkDetectorName[iDet],"Calib","RecoParam");
3377 AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
3378 if(!entry){
3379 AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",fgkDetectorName[iDet]));
3380 isOK = kFALSE;
3381 }
3382 else {
3383 TObject *recoParamObj = entry->GetObject();
3384 if (dynamic_cast<TObjArray*>(recoParamObj)) {
3385 // The detector has a normal TobjArray of AliDetectorRecoParam objects
3386 // Registering them in AliRecoParam
3387 fRecoParam.AddDetRecoParamArray(iDet,dynamic_cast<TObjArray*>(recoParamObj));
3388 }
3389 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
3390 // The detector has only onse set of reco parameters
3391 // Registering it in AliRecoParam
ac232c75 3392 AliInfo(Form("Single set of reconstruction parameters found for detector %s",fgkDetectorName[iDet]));
7e88424f 3393 dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
3394 fRecoParam.AddDetRecoParam(iDet,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
3395 }
3396 else {
3397 AliError(Form("No valid RecoParam object found in the OCDB for detector %s",fgkDetectorName[iDet]));
3398 isOK = kFALSE;
3399 }
3400 entry->SetOwner(0);
f168abba 3401 // FIX ME: We have to disable the unloading of reco-param CDB
3402 // entries because QA framework is using them. Has to be fix in
3403 // a way that the QA takes the objects already constructed in
3404 // this method.
3405 // AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
7e88424f 3406 }
3407 }
3408
e30a9b4d 3409 if (AliDebugLevel() > 0) fRecoParam.Print();
ac232c75 3410
7e88424f 3411 return isOK;
3412}
3413
3414//_____________________________________________________________________________
3415Bool_t AliReconstruction::GetEventInfo()
3416{
3417 // Fill the event info object
3418 // ...
52dd4a8c 3419 AliCodeTimerAuto("",0)
7e88424f 3420
3421 AliCentralTrigger *aCTP = NULL;
3422 if (fRawReader) {
3423 fEventInfo.SetEventType(fRawReader->GetType());
3424
3425 ULong64_t mask = fRawReader->GetClassMask();
3426 fEventInfo.SetTriggerMask(mask);
3427 UInt_t clmask = fRawReader->GetDetectorPattern()[0];
3428 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(clmask));
3429
3430 aCTP = new AliCentralTrigger();
3431 TString configstr("");
3432 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
3433 AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
3434 delete aCTP;
3435 return kFALSE;
3436 }
3437 aCTP->SetClassMask(mask);
3438 aCTP->SetClusterMask(clmask);
3439 }
3440 else {
3441 fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
3442
3443 if (fRunLoader && (!fRunLoader->LoadTrigger())) {
3444 aCTP = fRunLoader->GetTrigger();
3445 fEventInfo.SetTriggerMask(aCTP->GetClassMask());
e61ed4b1 3446 // get inputs from actp - just get
3447 AliESDHeader* esdheader = fesd->GetHeader();
3448 esdheader->SetL0TriggerInputs(aCTP->GetL0TriggerInputs());
3449 esdheader->SetL1TriggerInputs(aCTP->GetL1TriggerInputs());
3450 esdheader->SetL2TriggerInputs(aCTP->GetL2TriggerInputs());
7e88424f 3451 fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
3452 }
3453 else {
3454 AliWarning("No trigger can be loaded! The trigger information will not be used!");
3455 return kFALSE;
3456 }
3457 }
3458
3459 AliTriggerConfiguration *config = aCTP->GetConfiguration();
3460 if (!config) {
3461 AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
3462 if (fRawReader) delete aCTP;
3463 return kFALSE;
3464 }
3465
a0c2cf2d 3466 UChar_t clustmask = 0;
7e88424f 3467 TString trclasses;
3468 ULong64_t trmask = fEventInfo.GetTriggerMask();
3469 const TObjArray& classesArray = config->GetClasses();
3470 Int_t nclasses = classesArray.GetEntriesFast();
3471 for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
3472 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
3473 if (trclass) {
a4b0683d 3474 Int_t trindex = TMath::Nint(TMath::Log2(trclass->GetMask()));
7e88424f 3475 fesd->SetTriggerClass(trclass->GetName(),trindex);
8a933107 3476 if (fRawReader) fRawReader->LoadTriggerClass(trclass->GetName(),trindex);
e61ed4b1 3477 if (trmask & (1ull << trindex)) {
7e88424f 3478 trclasses += " ";
3479 trclasses += trclass->GetName();
3480 trclasses += " ";
a0c2cf2d 3481 clustmask |= trclass->GetCluster()->GetClusterMask();
7e88424f 3482 }
3483 }
3484 }
3485 fEventInfo.SetTriggerClasses(trclasses);
3486
6ef9caeb 3487 // Write names of active trigger inputs in ESD Header
3488 const TObjArray& inputsArray = config->GetInputs();
3489 Int_t ninputs = inputsArray.GetEntriesFast();
3490 for( Int_t iinput=0; iinput < ninputs; iinput++ ) {
3491 AliTriggerInput* trginput = (AliTriggerInput*)inputsArray.At(iinput);
3492 if (trginput) {
3493 Int_t inputIndex = (Int_t)TMath::Nint(TMath::Log2(trginput->GetMask()));
3494 AliESDHeader* headeresd = fesd->GetHeader();
3495 Int_t trglevel = (Int_t)trginput->GetLevel();
3496 if (trglevel == 0) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex);
3497 if (trglevel == 1) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+24);
3498 if (trglevel == 2) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+48);
3499 }
3500 }
3501
a0c2cf2d 3502 // Set the information in ESD
3503 fesd->SetTriggerMask(trmask);
3504 fesd->SetTriggerCluster(clustmask);
3505
7e88424f 3506 if (!aCTP->CheckTriggeredDetectors()) {
3507 if (fRawReader) delete aCTP;
3508 return kFALSE;
3509 }
3510
3511 if (fRawReader) delete aCTP;
3512
3513 // We have to fill also the HLT decision here!!
3514 // ...
3515
3516 return kTRUE;
3517}
3518
3519const char *AliReconstruction::MatchDetectorList(const char *detectorList, UInt_t detectorMask)
3520{
3521 // Match the detector list found in the rec.C or the default 'ALL'
3522 // to the list found in the GRP (stored there by the shuttle PP which
3523 // gets the information from ECS)
3524 static TString resultList;
3525 TString detList = detectorList;
3526
3527 resultList = "";
3528
3529 for(Int_t iDet = 0; iDet < (AliDAQ::kNDetectors-1); iDet++) {
3530 if ((detectorMask >> iDet) & 0x1) {
3531 TString det = AliDAQ::OfflineModuleName(iDet);
3532 if ((detList.CompareTo("ALL") == 0) ||
a101e1dd 3533 ((detList.BeginsWith("ALL ") ||
3534 detList.EndsWith(" ALL") ||
3535 detList.Contains(" ALL ")) &&
3536 !(detList.BeginsWith("-"+det+" ") ||
3537 detList.EndsWith(" -"+det) ||
3538 detList.Contains(" -"+det+" "))) ||
7e88424f 3539 (detList.CompareTo(det) == 0) ||
a101e1dd 3540 detList.BeginsWith(det+" ") ||
3541 detList.EndsWith(" "+det) ||
7e88424f 3542 detList.Contains( " "+det+" " )) {
3543 if (!resultList.EndsWith(det + " ")) {
3544 resultList += det;
3545 resultList += " ";
3546 }
3547 }
3548 }
3549 }
3550
3551 // HLT
3552 if ((detectorMask >> AliDAQ::kHLTId) & 0x1) {
3553 TString hltDet = AliDAQ::OfflineModuleName(AliDAQ::kNDetectors-1);
3554 if ((detList.CompareTo("ALL") == 0) ||
a101e1dd 3555 ((detList.BeginsWith("ALL ") ||
3556 detList.EndsWith(" ALL") ||
3557 detList.Contains(" ALL ")) &&
3558 !(detList.BeginsWith("-"+hltDet+" ") ||
3559 detList.EndsWith(" -"+hltDet) ||
3560 detList.Contains(" -"+hltDet+" "))) ||
7e88424f 3561 (detList.CompareTo(hltDet) == 0) ||
a101e1dd 3562 detList.BeginsWith(hltDet+" ") ||
3563 detList.EndsWith(" "+hltDet) ||
7e88424f 3564 detList.Contains( " "+hltDet+" " )) {
3565 resultList += hltDet;
3566 }
3567 }
3568
3569 return resultList.Data();
3570
3571}
4b71572b 3572
3573//______________________________________________________________________________
3574void AliReconstruction::Abort(const char *method, EAbort what)
3575{
3576 // Abort processing. If what = kAbortProcess, the Process() loop will be
3577 // aborted. If what = kAbortFile, the current file in a chain will be
3578 // aborted and the processing will continue with the next file, if there
3579 // is no next file then Process() will be aborted. Abort() can also be
3580 // called from Begin(), SlaveBegin(), Init() and Notify(). After abort
3581 // the SlaveTerminate() and Terminate() are always called. The abort flag
3582 // can be checked in these methods using GetAbort().
3583 //
3584 // The method is overwritten in AliReconstruction for better handling of
3585 // reco specific errors
3586
3587 if (!fStopOnError) return;
3588
3589 CleanUp();
3590
3591 TString whyMess = method;
3592 whyMess += " failed! Aborting...";
3593
3594 AliError(whyMess.Data());
3595
3596 fAbort = what;
3597 TString mess = "Abort";
3598 if (fAbort == kAbortProcess)
3599 mess = "AbortProcess";
3600 else if (fAbort == kAbortFile)
3601 mess = "AbortFile";
3602
3603 Info(mess, whyMess.Data());
3604}
3605
2f954aba 3606//______________________________________________________________________________
3607Bool_t AliReconstruction::ProcessEvent(void* event)
3608{
3609 // Method that is used in case the event loop
3610 // is steered from outside, for example by AMORE
3611 // 'event' is a pointer to the DATE event in the memory
3612
3613 if (fRawReader) delete fRawReader;
3614 fRawReader = new AliRawReaderDate(event);
3615 fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());
3616 delete fRawReader;
3617 fRawReader = NULL;
3618
3619 return fStatus;
3620}
81d57268 3621
3622//______________________________________________________________________________
3623Bool_t AliReconstruction::ParseOutput()
3624{
3625 // The method parses the output file
3626 // location string in order to steer
3627 // properly the selector
3628
3629 TPMERegexp re1("(\\w+\\.zip#\\w+\\.root):([,*\\w+\\.root,*]+)@dataset://(\\w++)");
3630 TPMERegexp re2("(\\w+\\.root)?@?dataset://(\\w++)");
3631
3632 if (re1.Match(fESDOutput) == 4) {
3633 // root archive with output files stored and regustered
3634 // in proof dataset
3635 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",re1[1].Data()));
3636 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",re1[3].Data()));
3637 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_DATASET",""));
3638 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_ARCHIVE",re1[2].Data()));
3639 AliInfo(Form("%s files will be stored within %s in dataset %s",
3640 re1[2].Data(),
3641 re1[1].Data(),
3642 re1[3].Data()));
3643 }
3644 else if (re2.Match(fESDOutput) == 3) {
3645 // output file stored and registered
3646 // in proof dataset
3647 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",(re2[1].IsNull()) ? "AliESDs.root" : re2[1].Data()));
3648 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",re2[2].Data()));
3649 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_DATASET",""));
3650 AliInfo(Form("%s will be stored in dataset %s",
3651 (re2[1].IsNull()) ? "AliESDs.root" : re2[1].Data(),
3652 re2[2].Data()));
3653 }
3654 else {
3655 if (fESDOutput.IsNull()) {
3656 // Output location not given.
3657 // Assuming xrootd has been already started and
3658 // the output file has to be sent back
3659 // to the client machine
3660 TString esdUrl(Form("root://%s/%s/",
3661 TUrl(gSystem->HostName()).GetHostFQDN(),
3662 gSystem->pwd()));
3663 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE","AliESDs.root"));
3664 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",esdUrl.Data()));
3665 AliInfo(Form("AliESDs.root will be stored in %s",
3666 esdUrl.Data()));
3667 }
3668 else {
3669 // User specified an output location.
3670 // Ones has just to parse it here
3671 TUrl outputUrl(fESDOutput.Data());
3672 TString outputFile(gSystem->BaseName(outputUrl.GetFile()));
3673 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",outputFile.IsNull() ? "AliESDs.root" : outputFile.Data()));
3674 TString outputLocation(outputUrl.GetUrl());
3675 outputLocation.ReplaceAll(outputFile.Data(),"");
3676 gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",outputLocation.Data()));
3677 AliInfo(Form("%s will be stored in %s",
3678 outputFile.IsNull() ? "AliESDs.root" : outputFile.Data(),
3679 outputLocation.Data()));
3680 }
3681 }
3682
3683 return kTRUE;
3684}