AliRoot Core  3dc7879 (3dc7879)
AliReconstruction.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
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: AliReconstruction.cxx 63911 2013-08-19 16:46:41Z hristov $ */
17 
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. //
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 // //
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 // //
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 // //
59 // The name of the galice file can be changed from the default //
60 // "galice.root" by passing it as argument to the AliReconstruction //
61 // constructor or by //
62 // //
63 // rec.SetGAliceFile("..."); //
64 // //
65 // The local reconstruction can be switched on or off for individual //
66 // detectors by //
67 // //
68 // rec.SetRunLocalReconstruction("..."); //
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 // //
74 // The reconstruction of the primary vertex position can be switched off by //
75 // //
76 // rec.SetRunVertexFinder(kFALSE); //
77 // //
78 // The tracking and the creation of ESD tracks can be switched on for //
79 // selected detectors by //
80 // //
81 // rec.SetRunTracking("..."); //
82 // //
83 // Uniform/nonuniform field tracking switches (default: uniform field) //
84 // //
85 // rec.SetUniformFieldTracking(); ( rec.SetUniformFieldTracking(kFALSE); ) //
86 // //
87 // The filling of additional ESD information can be steered by //
88 // //
89 // rec.SetFillESD("..."); //
90 // //
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. //
100 // //
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. //
103 // //
104 // The input data of a detector can be replaced by the corresponding HLT //
105 // data by calling (usual detector string) //
106 // SetUseHLTData("..."); //
107 // //
108 // //
110 #include <TArrayD.h>
111 #include <TArrayF.h>
112 #include <TArrayS.h>
113 #include <TChain.h>
114 #include <TFile.h>
115 #include <TGeoGlobalMagField.h>
116 #include <TGeoManager.h>
117 #include <TList.h>
118 #include <TLorentzVector.h>
119 #include <TMap.h>
120 #include <TObjArray.h>
121 #include <TPRegexp.h>
122 #include <TParameter.h>
123 #include <TPluginManager.h>
124 #include <TProof.h>
125 #include <TProofOutputFile.h>
126 #include <TROOT.h>
127 #include <TSystem.h>
128 #include <THashTable.h>
129 #include <TGrid.h>
130 #include <TMessage.h>
131 #include <TUrl.h>
132 #include <TRandom.h>
133 #include <THashList.h>
134 
135 #include "AliAlignObj.h"
136 #include "AliAnalysisManager.h"
138 #include "AliCDBEntry.h"
139 #include "AliCDBManager.h"
140 #include "AliCDBStorage.h"
141 #include "AliCTPRawStream.h"
142 #include "AliCascadeVertexer.h"
143 #include "AliCentralTrigger.h"
144 #include "AliCodeTimer.h"
145 #include "AliDAQ.h"
146 #include "AliDetectorRecoParam.h"
147 #include "AliESDCaloCells.h"
148 #include "AliESDCaloCluster.h"
149 #include "AliESDEvent.h"
150 #include "AliESDMuonTrack.h"
151 #include "AliESDPmdTrack.h"
152 #include "AliESDTagCreator.h"
153 #include "AliESDVertex.h"
154 #include "AliESDcascade.h"
155 #include "AliESDfriend.h"
156 #include "AliESDkink.h"
157 #include "AliESDpid.h"
158 #include "AliESDtrack.h"
159 #include "AliESDtrack.h"
160 #include "AliEventInfo.h"
161 #include "AliGRPObject.h"
162 #include "AliGRPRecoParam.h"
163 #include "AliGenEventHeader.h"
164 #include "AliGeomManager.h"
165 #include "AliGlobalQADataMaker.h"
166 #include "AliHeader.h"
167 #include "AliLog.h"
168 #include "AliMagF.h"
169 #include "AliMultiplicity.h"
170 #include "AliPID.h"
171 #include "AliPlaneEff.h"
172 #include "AliQAv1.h"
173 #include "AliQADataMakerRec.h"
174 #include "AliQAManager.h"
175 #include "AliRawVEvent.h"
176 #include "AliRawEventHeaderBase.h"
177 #include "AliRawHLTManager.h"
178 #include "AliRawReaderDate.h"
179 #include "AliRawReaderFile.h"
180 #include "AliRawReaderRoot.h"
181 #include "AliRecoInputHandler.h"
182 #include "AliReconstruction.h"
183 #include "AliReconstructor.h"
184 #include "AliRun.h"
185 #include "AliRunInfo.h"
186 #include "AliRunLoader.h"
187 #include "AliSysInfo.h" // memory snapshots
188 #include "AliTrackPointArray.h"
189 #include "AliTracker.h"
190 #include "AliTriggerClass.h"
191 #include "AliTriggerCluster.h"
192 #include "AliTriggerIR.h"
193 #include "AliTriggerConfiguration.h"
194 #include "AliV0vertexer.h"
195 #include "AliVertexer.h"
196 #include "AliTrackleter.h"
197 #include "AliVertexerTracks.h"
198 #include "AliTriggerRunScalers.h"
199 #include "AliTriggerScalersRecord.h"
200 #include "AliCTPTimeParams.h"
201 #include "AliESDHLTDecision.h"
202 #include "AliTriggerInput.h"
203 #include "AliLHCData.h"
204 #include "ARVersion.h"
205 #include "AliMCEventHandler.h"
206 #include "AliMCEvent.h"
207 #include <RVersion.h>
208 #include <stdlib.h>
209 #include <unistd.h>
210 #include <sys/resource.h>
211 ClassImp(AliReconstruction)
212 
213 using std::endl;
214 
215 //_____________________________________________________________________________
216 const char* AliReconstruction::fgkStopEvFName = "_stopEvent_";
217 const char* AliReconstruction::fgkDetectorName[AliReconstruction::kNDetectors] = {"ITS", "TPC", "TRD",
218 "TOF", "PHOS",
219 "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE","AD","FIT","MFT", "HLT"};
220 
221 //_____________________________________________________________________________
222 AliReconstruction::AliReconstruction(const char* gAliceFilename) :
223  TSelector(),
224  fRunVertexFinder(kTRUE),
225  fRunVertexFinderTracks(kTRUE),
226  fRunMuonTracking(kFALSE),
227  fRunMFTTrackingMU(kFALSE),
228  fRunV0Finder(kTRUE),
229  fRunCascadeFinder(kTRUE),
230  fRunMultFinder(kTRUE),
231  fStopOnError(kTRUE),
233  fWriteAlignmentData(kFALSE),
234  fWriteESDfriend(kFALSE),
235  fWriteHLTESD(kTRUE),
236  fFillTriggerESD(kTRUE),
237  //
238  fWriteThisFriend(kFALSE),
239  fSkipFriendsForLargeZ(kFALSE),
240  fMaxFriendTracks(3000),
241  fFractionFriends(0.03),
242  fFractionHLTESD(0.05),
243  fSkipFriendsCutZ(50),
244  //
245  fSkipIncompleteDAQ(kTRUE),
246  fCleanESD(kTRUE),
247  fV0DCAmax(3.),
248  fV0CsPmin(0.),
249  fDmax(50.),
250  fZmax(50.),
251 
252  fCosmicAlias("kCosmic"),
253  fLaserAlias("kCalibLaser"),
255  fRunTracking("ALL"),
256  fFillESD("ALL"),
257  fDeleteRecPoints(""),
258  fDeleteDigits(""),
259  fLoadCDB(""),
261  fGAliceFileName(gAliceFilename),
262  fRawInput(""),
263  fESDOutput(""),
266  fProofOutputDataset(kFALSE),
268  fEquipIdMap(""),
269  fFirstEvent(0),
270  fLastEvent(-1),
271  fNumberOfEventsPerFile((UInt_t)-1),
272  fOptions(),
273  fLoadAlignFromCDB(kTRUE),
274  fLoadAlignData("ALL"),
275  fUseHLTData(),
276  fRunInfo(NULL),
277  fEventInfo(),
278  fRunScalers(NULL),
279  fCTPTimeParams(NULL),
280  fCTPTimeAlign(NULL),
281 
282  fRunLoader(NULL),
283  fRawReader(NULL),
284  fParentRawReader(NULL),
285 
286  fRecoParam(),
287 
288  fSPDTrackleter(NULL),
289 
290  fDiamondProfileSPD(NULL),
291  fDiamondProfile(NULL),
292  fDiamondProfileTPC(NULL),
293  fListOfCosmicTriggers(NULL), //RS for BWD comp.
294  fAlias2Trigger(NULL),
295 
296  fGRPData(NULL),
297 
298  fAlignObjArray(NULL),
299  fCDBUri(),
300  fQARefUri(),
301  fSpecCDBUri(),
303  fInitCDBCalled(kFALSE),
304  fCDBSnapshotMode(kFALSE),
306  fQADetectors("ALL"),
307  fQATasks("ALL"),
308  fRunQA(kTRUE),
309  fRunGlobalQA(kTRUE),
310  fSameQACycle(kFALSE),
311  fInitQACalled(kFALSE),
312  fWriteQAExpertData(kTRUE),
313  fRunPlaneEff(kFALSE),
314 
315  fESDpid(NULL),
316 
317  fesd(NULL),
318  fhltesd(NULL),
319  fesdf(NULL),
320  fesdfDummy(NULL),
321  ffile(NULL),
322  ffileF(NULL),
323  ftree(NULL),
324  ftreeF(NULL),
325  fhlttree(NULL),
326  ftVertexer(NULL),
327  fIsNewRunLoader(kFALSE),
328  fRunAliEVE(kFALSE),
329  fChain(NULL),
330  fNall(0),
331  fNspecie(0),
332  fSspecie(0),
333  fNhighPt(0),
334  fShighPt(0),
335  //
336  fTreeBuffSize(30000000),
337  fMemCountESD(0),
338  fMemCountESDF(0),
339  fMemCountESDHLT(0),
340  //
341  fUpgradeModule(""),
343  fAnalysisMacro(),
344  fAnalysis(0),
345  fRecoHandler(0),
347  fStopped(kFALSE),
348  fMaxRSS(0),
349  fMaxVMEM(0),
350  fNAbandonedEv(0)
351 {
352 // create reconstruction object with default parameters
354 
355  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
356  fReconstructor[iDet] = NULL;
357  fUpgradeMask[iDet]=kFALSE;
358  fLoader[iDet] = NULL;
359  fTracker[iDet] = NULL;
360  }
361  for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
362  fQACycles[iDet] = 999999 ;
363  fQAWriteExpert[iDet] = kFALSE ;
364  }
365  fBeamInt[0][0]=fBeamInt[0][1]=fBeamInt[1][0]=fBeamInt[1][1] = -1;
366  //
367  AddCheckRecoCDBvsSimuCDB("TPC/Calib/RecoParam"); // check for similarity in the sim and rec
368  //
369  AliPID pid;
370 }
371 
372 //_____________________________________________________________________________
374  TSelector(),
388  //
395  //
397  fCleanESD(rec.fCleanESD),
398  fV0DCAmax(rec.fV0DCAmax),
399  fV0CsPmin(rec.fV0CsPmin),
400  fDmax(rec.fDmax),
401  fZmax(rec.fZmax),
402 
407  fFillESD(rec.fFillESD),
408  fDeleteRecPoints(""),
409  fDeleteDigits(""),
410  fLoadCDB(rec.fLoadCDB),
413  fRawInput(rec.fRawInput),
414  fESDOutput(rec.fESDOutput),
421  fLastEvent(rec.fLastEvent),
423  fOptions(),
427  fRunInfo(NULL),
428  fEventInfo(),
429  fRunScalers(NULL),
430  fCTPTimeParams(NULL),
431  fCTPTimeAlign(NULL),
432 
433  fRunLoader(NULL),
434  fRawReader(NULL),
435  fParentRawReader(NULL),
436 
437  fRecoParam(rec.fRecoParam),
438 
439  fSPDTrackleter(NULL),
440 
444  fListOfCosmicTriggers(NULL), //RS for BWD comp.
445  fAlias2Trigger(NULL),
446 
447  fGRPData(NULL),
448 
450  fCDBUri(rec.fCDBUri),
451  fQARefUri(rec.fQARefUri),
452  fSpecCDBUri(),
458  fQATasks(rec.fQATasks),
459  fRunQA(rec.fRunQA),
465 
466  fESDpid(NULL),
467 
468  fesd(NULL),
469  fhltesd(NULL),
470  fesdf(NULL),
471  fesdfDummy(NULL),
472  ffile(NULL),
473  ffileF(NULL),
474  ftree(NULL),
475  ftreeF(NULL),
476  fhlttree(NULL),
477  ftVertexer(NULL),
479  fRunAliEVE(kFALSE),
480  fChain(NULL),
481  fNall(0),
482  fNspecie(0),
483  fSspecie(0),
484  fNhighPt(0),
485  fShighPt(0),
486  //
488  fMemCountESD(0),
489  fMemCountESDF(0),
490  fMemCountESDHLT(0),
491  //
492  fUpgradeModule(""),
495  fAnalysis(0),
496  fRecoHandler(0),
498  fStopped(kFALSE),
499  fMaxRSS(0),
500  fMaxVMEM(0),
501  fNAbandonedEv(0)
502 {
503 // copy constructor
504 
505  for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
506  if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
507  }
508  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
509  fReconstructor[iDet] = NULL;
510  fUpgradeMask[iDet] = kFALSE;
511  fLoader[iDet] = NULL;
512  fTracker[iDet] = NULL;
513  }
514 
515  for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
516  fQACycles[iDet] = rec.fQACycles[iDet];
517  fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ;
518  }
519 
520  for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
521  if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
522  }
523 
524  for (Int_t i = 0; i < rec.fCheckRecoCDBvsSimuCDB.GetEntriesFast(); i++) {
525  if (rec.fCheckRecoCDBvsSimuCDB[i]) fCheckRecoCDBvsSimuCDB.AddLast(rec.fCheckRecoCDBvsSimuCDB[i]->Clone());
526  }
527 
528  for (int i=2;i--;) for (int j=2;j--;) fBeamInt[i][j] = rec.fBeamInt[i][j];
529 
530 }
531 
532 //_____________________________________________________________________________
534 {
535 // assignment operator
536 // Used in PROOF mode
537 // Be very careful while modifing it!
538 // Simple rules to follow:
539 // for persistent data members - use their assignment operators
540 // for non-persistent ones - do nothing or take the default values from constructor
541 // TSelector members should not be touched
542  if(&rec == this) return *this;
543 
557  //
558  //
565  //
567  fCleanESD = rec.fCleanESD;
568  fV0DCAmax = rec.fV0DCAmax;
569  fV0CsPmin = rec.fV0CsPmin;
570  fDmax = rec.fDmax;
571  fZmax = rec.fZmax;
572 
574  fLaserAlias = rec.fLaserAlias;
575 
578  fFillESD = rec.fFillESD;
581  fLoadCDB = rec.fLoadCDB;
584  fRawInput = rec.fRawInput;
585  fESDOutput = rec.fESDOutput;
590  fEquipIdMap = rec.fEquipIdMap;
591  fFirstEvent = rec.fFirstEvent;
592  fLastEvent = rec.fLastEvent;
594 
595  for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
596  if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
597  }
598 
601  fUseHLTData = rec.fUseHLTData;
602 
603  delete fRunInfo; fRunInfo = NULL;
604  if (rec.fRunInfo) fRunInfo = new AliRunInfo(*rec.fRunInfo);
605 
606  fEventInfo = rec.fEventInfo;
607 
608  delete fRunScalers; fRunScalers = NULL;
610 
611  delete fCTPTimeParams; fCTPTimeParams = NULL;
613  delete fCTPTimeAlign; fCTPTimeAlign = NULL;
615 
616  fRunLoader = NULL;
617  fRawReader = NULL;
618  fParentRawReader = NULL;
619 
620  fRecoParam = rec.fRecoParam;
621 
622  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
623  fUpgradeMask[iDet] = kFALSE;
624  delete fReconstructor[iDet]; fReconstructor[iDet] = NULL;
625  delete fLoader[iDet]; fLoader[iDet] = NULL;
626  delete fTracker[iDet]; fTracker[iDet] = NULL;
627  }
628 
629  for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
630  fQACycles[iDet] = rec.fQACycles[iDet];
631  fQAWriteExpert[iDet] = rec.fQAWriteExpert[iDet] ;
632  }
633 
634  delete fSPDTrackleter; fSPDTrackleter = NULL;
635 
636  delete fDiamondProfileSPD; fDiamondProfileSPD = NULL;
638  delete fDiamondProfile; fDiamondProfile = NULL;
640  delete fDiamondProfileTPC; fDiamondProfileTPC = NULL;
642 
644  if (rec.fListOfCosmicTriggers) fListOfCosmicTriggers = (THashTable*)((rec.fListOfCosmicTriggers)->Clone());
645  //
646  delete fAlias2Trigger; fAlias2Trigger = NULL;
647  if (rec.fAlias2Trigger) fAlias2Trigger = (THashList*)((rec.fAlias2Trigger)->Clone());
648 
649  delete fGRPData; fGRPData = NULL;
650  // if (rec.fGRPData) fGRPData = (TMap*)((rec.fGRPData)->Clone());
651  if (rec.fGRPData) fGRPData = (AliGRPObject*)((rec.fGRPData)->Clone());
652 
653  delete fAlignObjArray; fAlignObjArray = NULL;
654 
655  fCDBUri = "";
656  fQARefUri = rec.fQARefUri;
657  fSpecCDBUri.Delete();
658  fCheckRecoCDBvsSimuCDB.Delete();
659  //
660  for (Int_t i = 0; i < rec.fCheckRecoCDBvsSimuCDB.GetEntriesFast(); i++) {
661  if (rec.fCheckRecoCDBvsSimuCDB[i]) fCheckRecoCDBvsSimuCDB.AddLast(rec.fCheckRecoCDBvsSimuCDB[i]->Clone());
662  }
663  //
668  fQATasks = rec.fQATasks;
669  fRunQA = rec.fRunQA;
675  for (int i=2;i--;) for (int j=2;j--;) fBeamInt[i][j] = rec.fBeamInt[i][j];
676  fESDpid = NULL;
677  fesd = NULL;
678  fhltesd = NULL;
679  fesdf = NULL;
680  fesdfDummy = NULL;
681  ffile = NULL;
682  ffileF = NULL;
683  ftree = NULL;
684  ftreeF = NULL;
685  fhlttree = NULL;
686  ftVertexer = NULL;
688  fRunAliEVE = kFALSE;
689  fChain = NULL;
690  fNall = 0;
691  fNspecie = 0;
692  fSspecie = 0;
693  fNhighPt = 0;
694  fShighPt = 0;
695  //
697  fMemCountESD = 0;
698  fMemCountESDF = 0;
699  fMemCountESDHLT = 0;
700  //
701  fUpgradeModule="";
704  fAnalysis = 0;
705  fRecoHandler = 0;
707 
708  return *this;
709 }
710 
711 //_____________________________________________________________________________
713 {
714 // clean up
715 
716  CleanUp();
717  if (fListOfCosmicTriggers) {
718  fListOfCosmicTriggers->Delete();
719  delete fListOfCosmicTriggers;
720  }
721  if (fAlias2Trigger) {
722  fAlias2Trigger->Delete();
723  delete fAlias2Trigger;
724  }
725  delete fGRPData;
726  delete fRunScalers;
727  delete fCTPTimeParams;
728  delete fCTPTimeAlign;
729  fOptions.Delete();
730  if (fAlignObjArray) {
731  fAlignObjArray->Delete();
732  delete fAlignObjArray;
733  }
734  fSpecCDBUri.Delete();
735  fCheckRecoCDBvsSimuCDB.Delete();
737 }
738 
739 //_____________________________________________________________________________
741 {
742  //Initialize the QA and start of cycle
743  AliCodeTimerAuto("",0);
744 
745  if (fInitQACalled) return;
746  fInitQACalled = kTRUE;
747 
749 
750 
752  qam->SetSaveData(kTRUE);
753  qam->SetCycleLength(AliQAv1::kITS, 5) ;
754  if (fWriteQAExpertData)
755  qam->SetWriteExpert() ;
756 
757  if (qam->IsDefaultStorageSet()) {
758  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
759  AliWarning("Default QA reference storage has been already set !");
760  AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fQARefUri.Data()));
761  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
762  fQARefUri = qam->GetDefaultStorage()->GetURI();
763  } else {
764  if (fQARefUri.Length() > 0) {
765  AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
766  AliDebug(2, Form("Default QA reference storage is set to: %s", fQARefUri.Data()));
767  AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
768  } else {
769  fQARefUri="local://$ALICE_ROOT/QAref";
770  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
771  AliWarning("Default QA refeference storage not yet set !!!!");
772  AliWarning(Form("Setting it now to: %s", fQARefUri.Data()));
773  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
774 
775  }
776  qam->SetDefaultStorage(fQARefUri);
777  }
778 
779  if (fRunQA) {
780  qam->SetActiveDetectors(fQADetectors) ;
781  qam->SetActiveOnlineDetectors(fRunInfo->GetActiveDetectors());
782 
783  for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++) {
784  qam->SetCycleLength(AliQAv1::DETECTORINDEX_t(det), fQACycles[det]) ;
785  qam->SetWriteExpert(AliQAv1::DETECTORINDEX_t(det)) ;
786  }
787  if (!fRawReader && !fInput && IsInTasks(AliQAv1::kRAWS))
788  fQATasks.ReplaceAll(Form("%d",AliQAv1::kRAWS), "") ;
789  qam->SetTasks(fQATasks) ;
790  qam->InitQADataMaker(AliCDBManager::Instance()->GetRun()) ;
791  }
792  if (fRunGlobalQA) {
793  Bool_t sameCycle = kFALSE ;
794  AliQADataMaker *qadm = qam->GetQADataMaker(AliQAv1::kGLOBAL);
795  AliInfo(Form("Initializing the global QA data maker"));
797  qadm->StartOfCycle(AliQAv1::kRECPOINTS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
798  TObjArray **arr=qadm->Init(AliQAv1::kRECPOINTS);
800  sameCycle = kTRUE ;
801  }
802  if (IsInTasks(AliQAv1::kESDS)) {
803  qadm->StartOfCycle(AliQAv1::kESDS, AliCDBManager::Instance()->GetRun(), sameCycle) ;
804  qadm->Init(AliQAv1::kESDS);
805  }
806  }
807  AliSysInfo::AddStamp("InitQA") ;
808 }
809 
810 //_____________________________________________________________________________
812 {
813  //Initialize the QA and start of cycle
814  AliCodeTimerAuto("",0) ;
815  AliQAManager::QAManager()->Merge(AliCDBManager::Instance()->GetRun(),fileName) ;
816  AliSysInfo::AddStamp("MergeQA") ;
817 }
818 
819 //_____________________________________________________________________________
821 {
822 // activate a default CDB storage
823 // First check if we have any CDB storage set, because it is used
824 // to retrieve the calibration and alignment constants
825  AliCodeTimerAuto("",0);
826 
827  if (fInitCDBCalled) return;
828  fInitCDBCalled = kTRUE;
829 
831  if (man->IsDefaultStorageSet())
832  {
833  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
834  AliWarning("Default CDB storage has been already set !");
835  AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
836  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
837  fCDBUri = man->GetDefaultStorage()->GetURI();
838  }
839  else {
840  if (fCDBUri.Length() > 0)
841  {
842  AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
843  AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
844  AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
846  }
847  else if (!man->GetRaw()){
848  fCDBUri="local://$ALICE_ROOT/OCDB";
849  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
850  AliWarning("Default CDB storage not yet set !!!!");
851  AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
852  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
854  }
855  else {
856  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
857  AliWarning("Default storage will be set after setting the Run Number!!!");
858  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
859  }
860  }
861 
862  // Now activate the detector specific CDB storage locations
863  for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
864  TObject* obj = fSpecCDBUri[i];
865  if (!obj) continue;
866  AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
867  AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
868  AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
869  man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
870  }
871  AliSysInfo::AddStamp("InitCDB");
872 }
873 
874 //_____________________________________________________________________________
875 void AliReconstruction::SetCDBSnapshotMode(const char* snapshotFileName) {
876  if (!AliCDBManager::Instance()->SetSnapshotMode(snapshotFileName))
877  AliFatal("Setting CDB snapshot mode failed.");
878  fCDBSnapshotMode = kTRUE;
879 }
880 
881 //_____________________________________________________________________________
883 // Store the desired default CDB storage location
884 // Activate it later within the Run() method
885 
886  fCDBUri = uri;
887 
888 }
889 
890 //_____________________________________________________________________________
892  // Store the desired default CDB storage location
893  // Activate it later within the Run() method
894 
895  fQARefUri = uri;
897 
898 }
899 
900 //_____________________________________________________________________________
901 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
902 // Store a detector-specific CDB storage location
903 // Activate it later within the Run() method
904 
905  AliCDBPath aPath(calibType);
906  if(!aPath.IsValid()){
907  // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
908  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
909  if(!strcmp(calibType, fgkDetectorName[iDet])) {
910  aPath.SetPath(Form("%s/*", calibType));
911  AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
912  break;
913  }
914  }
915  if(!aPath.IsValid()){
916  AliError(Form("Not a valid path or detector: %s", calibType));
917  return;
918  }
919  }
920 
921 // // check that calibType refers to a "valid" detector name
922 // Bool_t isDetector = kFALSE;
923 // for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
924 // TString detName = fgkDetectorName[iDet];
925 // if(aPath.GetLevel0() == detName) {
926 // isDetector = kTRUE;
927 // break;
928 // }
929 // }
930 //
931 // if(!isDetector) {
932 // AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
933 // return;
934 // }
935 
936  TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
937  if (obj) fSpecCDBUri.Remove(obj);
938  fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
939 
940 }
941 
942 //_____________________________________________________________________________
943 void AliReconstruction::AddCheckRecoCDBvsSimuCDB(const char* cdbpath,const char* comment)
944 {
945  // require the cdb item to be the same in the rec as in the sim
946  // Activate it later within the Run() method
947  TString newent = cdbpath;
948  if (newent.IsNull()) return;
949  TIter nextit(&fCheckRecoCDBvsSimuCDB);
950  TNamed* cdbent=0;
951  while ((cdbent=(TNamed*)nextit())) {
952  TString str = cdbent->GetName();
953  if (str==newent) {
954  AliInfo(Form("%s is already in the list to check",cdbpath));
955  return;
956  }
957  }
958  fCheckRecoCDBvsSimuCDB.AddLast(new TNamed(cdbpath,comment));
959  //
960 }
961 
962 //_____________________________________________________________________________
964 {
965  // require the cdb item to be the same in the rec as in the sim
966  // Activate it later within the Run() method
967  TString newent = cdbpath;
968  if (newent.IsNull()) return;
969  TIter nextit(&fCheckRecoCDBvsSimuCDB);
970  TNamed* cdbent=0;
971  while ((cdbent=(TNamed*)nextit())) {
972  TString str = cdbent->GetName();
973  if (str==newent) {
974  AliInfo(Form("Removing %s from the list to check",cdbpath));
975  delete fCheckRecoCDBvsSimuCDB.Remove(cdbent);
976  fCheckRecoCDBvsSimuCDB.Compress();
977  return;
978  }
979  }
980  AliInfo(Form("%s is not in the list to check",cdbpath));
981  //
982 }
983 
984 //_____________________________________________________________________________
986 {
987  // The method is called in Run() in order
988  // to set a correct run number.
989  // In case of raw data reconstruction the
990  // run number is taken from the raw data header
991 
992  if (fSetRunNumberFromDataCalled) return kTRUE;
994 
996  if(fRawReader) {
997  if(fRawReader->NextEvent()) {
998  if(man->GetRun() > 0) {
999  AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
1000  }
1001  man->SetRun(fRawReader->GetRunNumber());
1002  GetEventInfo();
1003  fRawReader->RewindEvents();
1004  }
1005  else {
1006  if(man->GetRun() > 0) {
1007  AliWarning("No raw-data events are found ! Using settings in AliCDBManager !");
1008  }
1009  else {
1010  AliWarning("Neither raw events nor settings in AliCDBManager are found !");
1011  return kFALSE;
1012  }
1013  }
1014  }
1015  else {
1017  if (!rl) {
1018  AliError(Form("No run loader found in file %s", fGAliceFileName.Data()));
1019  return kFALSE;
1020  }
1021  else {
1022  rl->LoadHeader();
1023  // read run number from gAlice
1024  if(rl->GetHeader()) {
1025  man->SetRun(rl->GetHeader()->GetRun());
1026  rl->UnloadHeader();
1027  delete rl;
1028  }
1029  else {
1030  AliError("Neither run-loader header nor RawReader objects are found !");
1031  delete rl;
1032  return kFALSE;
1033  }
1034  }
1035  }
1036 
1037  man->Print();
1038 
1039  return kTRUE;
1040 }
1041 
1042 //_____________________________________________________________________________
1044  // Set CDB lock: from now on it is forbidden to reset the run number
1045  // or the default storage or to activate any further storage!
1046 
1048 }
1049 
1050 //_____________________________________________________________________________
1052  // Translates detector name in a boolean.
1053  // The boolean is used in GetReconstructor to load the
1054  // upgrade reconstructor instead of the standard one.
1055  for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
1056  if(fUpgradeModule.Contains(fgkDetectorName[iDet])) fUpgradeMask[iDet]=kTRUE;
1057  }
1058 }
1059 //_____________________________________________________________________________
1060 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
1061 {
1062  // Read the alignment objects from CDB.
1063  // Each detector is supposed to have the
1064  // alignment objects in DET/Align/Data CDB path.
1065  // All the detector objects are then collected,
1066  // sorted by geometry level (starting from ALIC) and
1067  // then applied to the TGeo geometry.
1068  // Finally an overlaps check is performed.
1069 
1070  // Load alignment data from CDB and fill fAlignObjArray
1071  if(fLoadAlignFromCDB){
1072 
1073  TString detStr = detectors;
1074  TString loadAlObjsListOfDets = "";
1075 
1076  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
1077  if(!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1078  if(!strcmp(fgkDetectorName[iDet],"HLT")) continue;
1079 
1081  {
1082  loadAlObjsListOfDets += fgkDetectorName[iDet];
1083  loadAlObjsListOfDets += " ";
1084  }
1085  } // end loop over detectors
1086 
1087  if(AliGeomManager::GetNalignable("GRP") != 0)
1088  loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
1089  AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
1090  }else{
1091  // Check if the array with alignment objects was
1092  // provided by the user. If yes, apply the objects
1093  // to the present TGeo geometry
1094  if (fAlignObjArray) {
1095  if (gGeoManager && gGeoManager->IsClosed()) {
1097  AliError("The misalignment of one or more volumes failed!"
1098  "Compare the list of simulated detectors and the list of detector alignment data!");
1099  return kFALSE;
1100  }
1101  }
1102  else {
1103  AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
1104  return kFALSE;
1105  }
1106  }
1107  }
1108 
1109  if (fAlignObjArray) {
1110  fAlignObjArray->Delete();
1111  delete fAlignObjArray; fAlignObjArray=NULL;
1112  }
1113 
1114  return kTRUE;
1115 }
1116 
1117 //_____________________________________________________________________________
1119 {
1120 // set the name of the galice file
1121 
1123 }
1124 
1125 //_____________________________________________________________________________
1126 void AliReconstruction::SetInput(const char* input)
1127 {
1128  // In case the input string starts with 'mem://', we run in an online mode
1129  // and AliRawReaderDateOnline object is created. In all other cases a raw-data
1130  // file is assumed. One can give as an input:
1131  // mem://: - events taken from DAQ monitoring libs online
1132  // or
1133  // mem://<filename> - emulation of the above mode (via DATE monitoring libs)
1134  if (input) fRawInput = input;
1135 }
1136 
1137 //_____________________________________________________________________________
1138 void AliReconstruction::SetOutput(const char* output)
1139 {
1140  // Set the output ESD filename
1141  // 'output' is a normalt ROOT url
1142  // The method is used in case of raw-data reco with PROOF
1143  if (output) fESDOutput = output;
1144 }
1145 
1146 //_____________________________________________________________________________
1147 void AliReconstruction::SetOption(const char* detector, const char* option)
1148 {
1149 // set options for the reconstruction of a detector
1150 
1151  TObject* obj = fOptions.FindObject(detector);
1152  if (obj) fOptions.Remove(obj);
1153  fOptions.Add(new TNamed(detector, option));
1154 }
1155 
1156 //_____________________________________________________________________________
1158 {
1159  // Set custom reconstruction parameters for a given detector
1160  // Single set of parameters for all the events
1161 
1162  // First check if the reco-params are global
1163  if(!strcmp(detector, "GRP")) {
1164  par->SetAsDefault();
1166  return;
1167  }
1168 
1169  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
1170  if(!strcmp(detector, fgkDetectorName[iDet])) {
1171  par->SetAsDefault();
1172  fRecoParam.AddDetRecoParam(iDet,par);
1173  break;
1174  }
1175  }
1176 
1177 }
1178 
1179 //_____________________________________________________________________________
1181  //------------------------------------
1182  // Initialization of the GRP entry
1183  //------------------------------------
1184  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
1185 
1186  if (entry) {
1187 
1188  TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
1189 
1190  if (m) {
1191  AliInfo("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject");
1192  m->Print();
1193  fGRPData = new AliGRPObject();
1195  }
1196 
1197  else {
1198  AliInfo("Found an AliGRPObject in GRP/GRP/Data, reading it");
1199  fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
1200  entry->SetOwner(0); // RS don't manipulate with GRP
1201  entry->SetObject(0); // others will reread the object
1202  AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
1203  }
1204 
1205  // FIX ME: The unloading of GRP entry is temporarily disabled
1206  // because ZDC and VZERO are using it in order to initialize
1207  // their reconstructor objects. In the future one has to think
1208  // of propagating AliRunInfo to the reconstructors.
1209  // AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
1210  }
1211 
1212  if (!fGRPData) {
1213  AliError("No GRP entry found in OCDB!");
1214  return kFALSE;
1215  }
1216 
1217  TString lhcState = fGRPData->GetLHCState();
1218  if (lhcState==AliGRPObject::GetInvalidString()) {
1219  AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
1220  lhcState = "UNKNOWN";
1221  }
1222 
1223  TString beamType = fGRPData->GetBeamType();
1224  if (beamType==AliGRPObject::GetInvalidString()) {
1225  AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
1226  beamType = "UNKNOWN";
1227  }
1228 
1229  Float_t beamEnergy = fGRPData->GetBeamEnergy();
1230  if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
1231  AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
1232  beamEnergy = 0;
1233  }
1234 
1235  TString runType = fGRPData->GetRunType();
1236  if (runType==AliGRPObject::GetInvalidString()) {
1237  AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
1238  runType = "UNKNOWN";
1239  }
1240 
1241  Int_t activeDetectors = fGRPData->GetDetectorMask();
1242  if (activeDetectors==AliGRPObject::GetInvalidUInt()) {
1243  AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
1244  activeDetectors = 1074790399;
1245  }
1246  AliDebug(1, Form("activeDetectors = %d", activeDetectors));
1247 
1248  fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
1249  fRunInfo->Dump();
1250 
1251 
1252  // Process the list of active detectors
1253  if (activeDetectors) {
1254  UInt_t detMask = activeDetectors;
1255  AliDebug(1, Form("Detector List = %s", fRunLocalReconstruction.Data()));
1257  AliDebug(1, Form("Detector List = %s", fRunLocalReconstruction.Data()));
1259  fFillESD = MatchDetectorList(fFillESD,detMask);
1261  AliInfo(Form("fQADetectors=%s",fQADetectors.Data()));
1264  fLoadCDB.Form("%s %s %s %s",
1265  fRunLocalReconstruction.Data(),
1266  fRunTracking.Data(),
1267  fFillESD.Data(),
1268  fQADetectors.Data());
1269  fLoadCDB = MatchDetectorList(fLoadCDB,detMask);
1270  if (!((detMask >> AliDAQ::DetectorID("ITSSPD")) & 0x1) &&
1271  !((detMask >> AliDAQ::DetectorID("ITSSDD")) & 0x1) &&
1272  !((detMask >> AliDAQ::DetectorID("ITSSSD")) & 0x1) ) {
1273  // switch off the vertexer
1274  AliInfo("SPD,SDD,SSD is not in the list of active detectors. Vertexer and Trackleter are switched off.");
1275  fRunVertexFinder = kFALSE;
1276  fRunMultFinder = kFALSE;
1277  }
1278  if (!((detMask >> AliDAQ::DetectorID("TRG")) & 0x1)) {
1279  // switch off the reading of CTP raw-data payload
1280  if (fFillTriggerESD) {
1281  AliInfo("CTP is not in the list of active detectors. CTP data reading switched off.");
1282  fFillTriggerESD = kFALSE;
1283  }
1284  }
1285  }
1286 
1287  AliInfo("===================================================================================");
1288  AliInfo(Form("Running local reconstruction for detectors: %s",fRunLocalReconstruction.Data()));
1289  AliInfo(Form("Running tracking for detectors: %s",fRunTracking.Data()));
1290  AliInfo(Form("Filling ESD for detectors: %s",fFillESD.Data()));
1291  AliInfo(Form("Quality assurance is active for detectors: %s",fQADetectors.Data()));
1292  AliInfo(Form("CDB and reconstruction parameters are loaded for detectors: %s",fLoadCDB.Data()));
1293  AliInfo("===================================================================================");
1294 
1295  //*** Dealing with the magnetic field map
1296  if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
1297  if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
1298  AliInfo("ExpertMode!!! GRP information will be ignored !");
1299  AliInfo("ExpertMode!!! Running with the externally locked B field !");
1300  }
1301  else {
1302  AliInfo("Destroying existing B field instance!");
1303  delete TGeoGlobalMagField::Instance();
1304  }
1305  }
1306  if ( !TGeoGlobalMagField::Instance()->IsLocked() ) {
1307  // Construct the field map out of the information retrieved from GRP.
1308  Bool_t ok = kTRUE;
1309  // L3
1310  Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
1311  if (l3Current == AliGRPObject::GetInvalidFloat()) {
1312  AliError("GRP/GRP/Data entry: missing value for the L3 current !");
1313  ok = kFALSE;
1314  }
1315 
1316  Char_t l3Polarity = fGRPData->GetL3Polarity();
1317  if (l3Polarity == AliGRPObject::GetInvalidChar()) {
1318  AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
1319  ok = kFALSE;
1320  }
1321 
1322  // Dipole
1323  Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
1324  if (diCurrent == AliGRPObject::GetInvalidFloat()) {
1325  AliError("GRP/GRP/Data entry: missing value for the dipole current !");
1326  ok = kFALSE;
1327  }
1328 
1329  Char_t diPolarity = fGRPData->GetDipolePolarity();
1330  if (diPolarity == AliGRPObject::GetInvalidChar()) {
1331  AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
1332  ok = kFALSE;
1333  }
1334 
1335  // read special bits for the polarity convention and map type
1337  Bool_t uniformB = fGRPData->IsUniformBMap();
1338 
1339  int az0 = fGRPData->GetSingleBeamType(0).Atoi();
1340  int az1 = fGRPData->GetSingleBeamType(1).Atoi();
1341 
1342  if (ok) {
1343  AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1),
1344  TMath::Abs(diCurrent) * (diPolarity ? -1:1),
1345  polConvention,uniformB,beamEnergy, beamType.Data(),az0,az1);
1346  if (fld) {
1347  TGeoGlobalMagField::Instance()->SetField( fld );
1348  TGeoGlobalMagField::Instance()->Lock();
1349  AliInfo("Running with the B field constructed out of GRP !");
1350  }
1351  else AliFatal("Failed to create a B field map !");
1352  }
1353  else AliFatal("B field is neither set nor constructed from GRP ! Exitig...");
1354  }
1355 
1356  //*** Get the diamond profiles from OCDB
1357  entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexSPD");
1358  if (entry) {
1359  fDiamondProfileSPD = dynamic_cast<AliESDVertex*> (entry->GetObject());
1360  } else {
1361  AliError("No SPD diamond profile found in OCDB!");
1362  }
1363 
1364  entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertex");
1365  if (entry) {
1366  fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
1367  } else {
1368  AliError("No diamond profile found in OCDB!");
1369  }
1370 
1371  entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexTPC");
1372  if (entry) {
1373  fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
1374  } else {
1375  AliError("No TPC diamond profile found in OCDB!");
1376  }
1377 
1378  return kTRUE;
1379 }
1380 
1381 //_____________________________________________________________________________
1383 {
1384  // Load CDB entries for all active detectors.
1385  // By default we load all the entries in <det>/Calib
1386  // folder.
1387 
1388  AliCodeTimerAuto("",0);
1389 
1390  AliCDBManager::Instance()->Get("GRP/CTP/Config");
1391 
1392  AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
1393 
1394  TString detStr = fLoadCDB;
1395  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
1396  if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1397  AliCDBManager::Instance()->GetAll(Form("%s/Calib/*",fgkDetectorName[iDet]));
1398  AliCDBManager::Instance()->GetAll(Form("%s/Trigger/*",fgkDetectorName[iDet]));
1399  }
1400 
1401  // Temporary fix - one has to define the correct policy in order
1402  // to load the trigger OCDB entries only for the detectors that
1403  // in the trigger or that are needed in order to put correct
1404  // information in ESD
1405  AliCDBManager::Instance()->GetAll("TRIGGER/*/*");
1406  AliCDBManager::Instance()->GetAll("HLT/*/*");
1407 
1408  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/Calib/CosmicTriggers");
1409  if (entry) {
1410  fListOfCosmicTriggers = dynamic_cast<THashTable*>(entry->GetObject());
1411  entry->SetOwner(0);
1412  }
1413  //
1414  if (!fListOfCosmicTriggers) {
1415  AliWarning("Can not get list of cosmic triggers from OCDB! Cosmic event specie will rely on aliases if defined");
1416  }
1417 
1418 
1419  return kTRUE;
1420 }
1421 //_____________________________________________________________________________
1423 {
1424  // Load CTP scalers from OCDB.
1425  // The scalers are checked for consistency.
1426 
1427  AliCodeTimerAuto("",0);
1428 
1429  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/Scalers");
1430 
1431  if (entry) {
1432 
1433  AliInfo("Found an AliTriggerRunScalers in GRP/CTP/Scalers, reading it");
1434  fRunScalers = dynamic_cast<AliTriggerRunScalers*> (entry->GetObject());
1435  entry->SetOwner(0);
1436  if (fRunScalers && (fRunScalers->CorrectScalersOverflow() == 0)) AliInfo("32bit Trigger counters corrected for overflow");
1437 
1438  }
1439  return kTRUE;
1440 }
1441 //_____________________________________________________________________________
1443 {
1444  // Load CTP timing information (alignment)
1445  // from OCDB.
1446 
1447  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
1448  if (!entry) return kFALSE;
1449 
1450  AliInfo("Found an AliCTPTimeParams in GRP/CTP/CTPtiming, reading it");
1451  fCTPTimeParams = dynamic_cast<AliCTPTimeParams*> (entry->GetObject());
1452  entry->SetOwner(0);
1453 
1454  AliCDBEntry* entry2 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
1455  if (!entry2) return kFALSE;
1456 
1457  AliInfo("Found an AliCTPTimeParams in GRP/CTP/TimeAlign, reading it");
1458  fCTPTimeAlign = dynamic_cast<AliCTPTimeParams*> (entry2->GetObject());
1459  entry2->SetOwner(0);
1460 
1461  return kTRUE;
1462 }
1463 
1464 //_____________________________________________________________________________
1466 {
1467  // Load LHC DIP data
1468  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/LHCData");
1469  AliCDBEntry* entryCTP = AliCDBManager::Instance()->Get("GRP/CTP/Config");
1470  //
1471  if (!entry || !entryCTP) {
1472  AliError(Form("Failed to extract CDB objects GRP/GRP/LHCData: %p or GRP/CTP/Config: %p",entry,entryCTP));
1473  return kFALSE;
1474  }
1475  // extract BC masks
1476  enum {kA,kB,kC,kE,kNMasks};
1478  const TObjArray& clArr = conf->GetClasses();
1479  TObjArray masks(kNMasks);
1480  TIter next(&clArr);
1481  AliTriggerClass* trClass = 0;
1482  int nFound = 0;
1483  masks.SetOwner(kFALSE);
1484  //
1485  while ( (trClass=(AliTriggerClass*)next()) ) {
1486  TString trName = trClass->GetName();
1487  int ind = trName.Index("-"); // prefix in front of A,B,C,E
1488  if (ind<1) continue; // anomaly
1489  //
1490  trName = trName.Data() + ind;
1491  AliTriggerBCMask* bcMask = trClass->GetBCMask();
1492  if (!bcMask) continue;
1493  UInt_t which = 0;
1494  if (trName.BeginsWith("-A-")) which |= 0x1<<kA;
1495  else if (trName.BeginsWith("-B-")) which |= 0x1<<kB;
1496  else if (trName.BeginsWith("-C-")) which |= 0x1<<kC;
1497  else if (trName.BeginsWith("-E-")) which |= 0x1<<kE;
1498  else if (trName.BeginsWith("-AC-")) which |= (0x1<<kA) | (0x1<<kC);
1499  else if (trName.BeginsWith("-CA-")) which |= (0x1<<kA) | (0x1<<kC);
1500  else { AliWarning(Form("Unknown trigger type %s\n",trClass->GetName())); continue;}
1501  //
1502  for (int ip=kNMasks;ip--;) {
1503  if ( !(which&(0x1<<ip)) || masks[ip] ) continue; // does not match or already done
1504  masks[ip] = (TObject*)bcMask;
1505  nFound++;
1506  }
1507  if (nFound==kNMasks) break;
1508  }
1509  //
1510  AliInfo("Reading mean bunch intensities from GRP/GRP/LHCData");
1511  AliLHCData* dipData = dynamic_cast<AliLHCData*> (entry->GetObject());
1512  //
1513  for (int ib=2;ib--;) {
1514  double intI,intNI;
1515  if (dipData && (dipData->GetMeanIntensity(ib,intI,intNI,&masks)>=0)) {
1516  fBeamInt[ib][0] = intI;
1517  fBeamInt[ib][1] = intNI;
1518  AliInfo(Form("Mean intensity for beam %d: Interacting:%.2e Non-Interacting:%.2e",ib,intI,intNI));
1519  }
1520  }
1521  return kTRUE;
1522  //
1523 }
1524 
1525 
1526 //_____________________________________________________________________________
1527 Bool_t AliReconstruction::Run(const char* input)
1528 {
1529  // Run Run Run
1530  AliCodeTimerAuto("",0);
1531 
1532  InitRun(input);
1533  if (GetAbort() != TSelector::kContinue) return kFALSE;
1534 
1535  TChain *chain = NULL;
1536  if (fRawReader && (chain = fRawReader->GetChain())) {
1538  Long64_t nEntries = (fLastEvent < 0) ? (TChain::kBigNumber) : (fLastEvent - fFirstEvent + 1);
1539  // Proof mode
1540  if (gProof) {
1541  // Temporary fix for long raw-data runs (until socket timeout handling in PROOF is revised)
1542  gProof->Exec("gEnv->SetValue(\"Proof.SocketActivityTimeout\",-1)", kTRUE);
1543 
1544  if (gGrid)
1545  gProof->Exec("TGrid::Connect(\"alien://\")",kTRUE);
1546 
1547  TMessage::EnableSchemaEvolutionForAll(kTRUE);
1548  gProof->Exec("TMessage::EnableSchemaEvolutionForAll(kTRUE)",kTRUE);
1549 
1550  gProof->AddInput(this);
1551 
1552  if (!ParseOutput()) return kFALSE;
1553 
1554  gProof->SetParameter("PROOF_MaxSlavesPerNode", 9999);
1555  chain->SetProof();
1556  chain->Process("AliReconstruction","",nEntries,fFirstEvent);
1557  }
1558  else {
1559  chain->Process(this,"",nEntries,fFirstEvent);
1560  }
1561  }
1562  else {
1563  Begin(NULL);
1564  if (GetAbort() != TSelector::kContinue) return kFALSE;
1565  SlaveBegin(NULL);
1566  if (GetAbort() != TSelector::kContinue) return kFALSE;
1567  //******* The loop over events
1568  AliInfo("Starting looping over events");
1569  Int_t iEvent = 0;
1570  while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
1571  (fRawReader && fRawReader->NextEvent())) {
1572  //
1573  // check if process has enough resources
1574  if (!HasEnoughResources(iEvent)) break;
1575  if (!ProcessEvent(iEvent)) {
1576  Abort("ProcessEvent",TSelector::kAbortFile);
1577  return kFALSE;
1578  }
1580  iEvent++;
1581  }
1582  if (!iEvent) AliWarning("No events passed trigger selection");
1583  SlaveTerminate();
1584  if (GetAbort() != TSelector::kContinue) return kFALSE;
1585  Terminate();
1586  if (GetAbort() != TSelector::kContinue) return kFALSE;
1587  }
1588 
1589  return kTRUE;
1590 }
1591 
1592 //_____________________________________________________________________________
1593 void AliReconstruction::InitRawReader(const char* input)
1594 {
1595  // Init raw-reader and
1596  // set the input in case of raw data
1597 
1598  AliCodeTimerAuto("",0);
1599 
1600  if (input) fRawInput = input;
1601  fRawReader = AliRawReader::Create(fRawInput.Data());
1602  if (!fRawReader) {
1603  if (fRawInput.IsNull()) {
1604  AliInfo("Reconstruction will run over digits");
1605  }
1606  else {
1607  AliFatal("Can not create raw-data reader ! Exiting...");
1608  }
1609  }
1610 
1611  if (!fEquipIdMap.IsNull() && fRawReader)
1612  fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
1613 
1614  if (!fUseHLTData.IsNull()) {
1615  // create the RawReaderHLT which performs redirection of HLT input data for
1616  // the specified detectors
1617  AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
1618  if (pRawReader) {
1620  fRawReader=pRawReader;
1621  } else {
1622  AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
1623  }
1624  }
1625  AliSysInfo::AddStamp("CreateRawReader");
1626 }
1627 
1628 //_____________________________________________________________________________
1629 void AliReconstruction::InitRun(const char* input)
1630 {
1631  // Initialization of raw-reader,
1632  // run number, CDB etc.
1633  AliCodeTimerAuto("",0);
1634  AliSysInfo::AddStamp("Start");
1635 
1636  // Initialize raw-reader if any
1637  InitRawReader(input);
1638 
1639  // Initialize the CDB storage
1640  InitCDB();
1641 
1642  // Set run number in CDBManager (if it is not already set by the user)
1643  if (!SetRunNumberFromData()) {
1644  Abort("SetRunNumberFromData", TSelector::kAbortProcess);
1645  return;
1646  }
1647 
1648  // Set CDB lock: from now on it is forbidden to reset the run number
1649  // or the default storage or to activate any further storage!
1650  SetCDBLock();
1651  //
1652 }
1653 
1654 //_____________________________________________________________________________
1656 {
1657  // Initialize AlReconstruction before
1658  // going into the event loop
1659  // Should follow the TSelector convention
1660  // i.e. initialize only the object on the client side
1661  AliCodeTimerAuto("",0);
1662 
1663  AliReconstruction *reco = NULL;
1664  if (fInput) {
1665  if ((reco = (AliReconstruction*)fInput->FindObject("AliReconstruction"))) {
1666  *this = *reco;
1667  }
1668  AliSysInfo::AddStamp("ReadInputInBegin");
1669  }
1670 
1671  // Import ideal TGeo geometry and apply misalignment
1672  if (!AliGeomManager::GetGeometry()) {
1673  TString geom(gSystem->DirName(fGAliceFileName));
1674  geom += "/geometry.root";
1675  AliGeomManager::LoadGeometry(geom.Data());
1676  if (!gGeoManager) {
1677  Abort("LoadGeometry", TSelector::kAbortProcess);
1678  return;
1679  }
1680  AliSysInfo::AddStamp("LoadGeom");
1681  TString detsToCheck=fRunLocalReconstruction;
1682  if(!AliGeomManager::CheckSymNamesLUT(detsToCheck.Data())) {
1683  Abort("CheckSymNamesLUT", TSelector::kAbortProcess);
1684  return;
1685  }
1686  AliSysInfo::AddStamp("CheckGeom");
1687  }
1688 
1689  Bool_t toCDBSnapshot=kFALSE;
1690  TString snapshotFileOut(""); // we could use fSnapshotFileName if we are not interested
1691  // in reading from and writing to a snapshot file at the same time
1692  if(TString(getenv("OCDB_SNAPSHOT_CREATE")) == TString("kTRUE")){
1693  toCDBSnapshot=kTRUE;
1694  //fFromCDBSnapshot=kFALSE;
1695  TString snapshotFile(getenv("OCDB_SNAPSHOT_FILENAME"));
1696  if(!(snapshotFile.IsNull() || snapshotFile.IsWhitespace()))
1697  snapshotFileOut = snapshotFile;
1698  else
1699  snapshotFileOut="OCDB.root";
1700  }
1701 
1702  TString detStr(fLoadAlignData);
1703  if (!toCDBSnapshot) {
1705  Abort("MisalignGeometry", TSelector::kAbortProcess);
1706  return;
1707  }
1708  } else {
1709  // when creating the snapshot, load the CDB alignment objects without applying them to the geometry
1710  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
1711  if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1712  if (!strcmp(fgkDetectorName[iDet],"HLT")) continue;
1714  {
1715  TString detAlignPath = fgkDetectorName[iDet];
1716  detAlignPath += "/Align/Data";
1717  AliCDBManager::Instance()->Get(detAlignPath);
1718  }
1719  } // end loop over detectors
1720  if(AliGeomManager::GetNalignable("GRP") != 0)
1721  AliCDBManager::Instance()->Get("GRP/Align/Data");
1722  }
1723 
1724  const TMap* cdbCache = AliCDBManager::Instance()->GetEntryCache();
1725  if(!toCDBSnapshot) {
1726  if(cdbCache->Contains("GRP/Geometry/Data"))
1727  AliCDBManager::Instance()->UnloadFromCache("GRP/Geometry/Data");
1728  AliCDBManager::Instance()->UnloadFromCache("*/Align/*");
1729  }
1730  AliSysInfo::AddStamp("MisalignGeom");
1731 
1732  if (!InitGRP()) {
1733  Abort("InitGRP", TSelector::kAbortProcess);
1734  return;
1735  }
1736  AliSysInfo::AddStamp("InitGRP");
1737  if(!toCDBSnapshot)
1738  if(cdbCache->Contains("GRP/Calib/CosmicTriggers"))
1739  AliCDBManager::Instance()->UnloadFromCache("GRP/Calib/CosmicTriggers");
1740 
1741  if(!fCDBSnapshotMode || toCDBSnapshot){
1742  if (!LoadCDB()) {
1743  Abort("LoadCDB", TSelector::kAbortProcess);
1744  return;
1745  }
1746  AliSysInfo::AddStamp("LoadCDB");
1747  }
1748 
1749  if (!LoadTriggerScalersCDB()) {
1750  Abort("LoadTriggerScalersCDB", TSelector::kAbortProcess);
1751  return;
1752  }
1753  AliSysInfo::AddStamp("LoadTriggerScalersCDB");
1754 
1755  if (!LoadCTPTimeParamsCDB()) {
1756  Abort("LoadCTPTimeParamsCDB", TSelector::kAbortProcess);
1757  return;
1758  }
1759  AliSysInfo::AddStamp("LoadCTPTimeParamsCDB");
1760 
1761  if (!ReadIntensityInfoCDB()) {
1762  Abort("ReadIntensityInfoCDB", TSelector::kAbortProcess);
1763  return;
1764  }
1765  AliSysInfo::AddStamp("ReadIntensityInfoCDB");
1766 
1767  // Read the reconstruction parameters from OCDB
1768  if (!InitRecoParams()) {
1769  AliWarning("Not all detectors have correct RecoParam objects initialized");
1770  }
1771  AliSysInfo::AddStamp("InitRecoParams");
1772 
1773  if(toCDBSnapshot)
1774  {
1775  AliCDBManager::Instance()->DumpToSnapshotFile(snapshotFileOut.Data(),kFALSE);
1776  exit(0);
1777  }
1778 
1779  if (fInput && gProof) {
1780  if (reco) *reco = *this;
1781 
1782  gGeoManager->SetName("Geometry");
1783  gProof->AddInputData(gGeoManager,kTRUE);
1784  gGeoManager = NULL;
1785  gProof->AddInputData(const_cast<TMap*>(AliCDBManager::Instance()->GetEntryCache()),kTRUE);
1786  fInput->Add(new TParameter<Int_t>("RunNumber",AliCDBManager::Instance()->GetRun()));
1787  AliMagF *magFieldMap = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
1788  magFieldMap->SetName("MagneticFieldMap");
1789  gProof->AddInputData(magFieldMap,kTRUE);
1790  if (fAnalysis) {
1791  fAnalysis->SetName("Analysis");
1792  gProof->AddInputData(fAnalysis,kTRUE);
1793  }
1794  }
1795 
1796 }
1797 
1798 //_____________________________________________________________________________
1800 {
1801  // Initialization related to run-loader,
1802  // vertexer, trackers, recontructors
1803  // In proof mode it is executed on the slave
1804  AliCodeTimerAuto("",0);
1805  TProofOutputFile *outProofFile = NULL;
1806  if (fInput) {
1807  if (AliDebugLevel() > 0) fInput->Print();
1808  if (AliDebugLevel() > 10) fInput->Dump();
1809  if (AliReconstruction *reco = (AliReconstruction*)fInput->FindObject("AliReconstruction")) {
1810  *this = *reco;
1811  }
1812  if (TGeoManager *tgeo = (TGeoManager*)fInput->FindObject("Geometry")) {
1813  gGeoManager = tgeo;
1815  }
1816  if (TMap *entryCache = (TMap*)fInput->FindObject("CDBEntryCache")) {
1817  Int_t runNumber = -1;
1818  if (TProof::GetParameter(fInput,"RunNumber",runNumber) == 0) {
1819  AliCDBManager *man = AliCDBManager::Instance(entryCache,runNumber);
1820  man->SetCacheFlag(kTRUE);
1821  man->SetLock(kTRUE);
1822  man->Print();
1823  }
1824  }
1825  if (AliMagF *map = (AliMagF*)fInput->FindObject("MagneticFieldMap")) {
1826  AliMagF *newMap = new AliMagF(*map);
1827  if (!newMap->LoadParameterization()) {
1828  Abort("AliMagF::LoadParameterization", TSelector::kAbortProcess);
1829  return;
1830  }
1831  TGeoGlobalMagField::Instance()->SetField(newMap);
1832  TGeoGlobalMagField::Instance()->Lock();
1833  }
1834  if (!fAnalysis) {
1835  // Attempt to get the analysis manager from the input list
1836  fAnalysis = (AliAnalysisManager*)fInput->FindObject("Analysis");
1837  if (fAnalysis) AliInfo("==== Analysis manager retrieved from input list ====");
1838  }
1839  if (TNamed *outputFileName = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE"))
1840  fProofOutputFileName = outputFileName->GetTitle();
1841  if (TNamed *outputLocation = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE_LOCATION"))
1842  fProofOutputLocation = outputLocation->GetTitle();
1843  if (fInput->FindObject("PROOF_OUTPUTFILE_DATASET"))
1844  fProofOutputDataset = kTRUE;
1845  if (TNamed *archiveList = (TNamed*)fInput->FindObject("PROOF_OUTPUTFILE_ARCHIVE"))
1846  fProofOutputArchive = archiveList->GetTitle();
1847  if (!fProofOutputFileName.IsNull() &&
1848  !fProofOutputLocation.IsNull() &&
1849  fProofOutputArchive.IsNull()) {
1850  if (!fProofOutputDataset) {
1851  outProofFile = new TProofOutputFile(fProofOutputFileName.Data(),"M");
1852  outProofFile->SetOutputFileName(Form("%s%s",fProofOutputLocation.Data(),fProofOutputFileName.Data()));
1853  }
1854  else {
1855  outProofFile = new TProofOutputFile(fProofOutputFileName.Data(),"DROV",fProofOutputLocation.Data());
1856  }
1857  if (AliDebugLevel() > 0) outProofFile->Dump();
1858  fOutput->Add(outProofFile);
1859  }
1860  AliSysInfo::AddStamp("ReadInputInSlaveBegin");
1861  }
1862  // Check if analysis was requested in the reconstruction event loop
1863  if (!fAnalysis) {
1864  // Attempt to connect in-memory singleton
1866  if (fAnalysis) AliInfo(Form("==== Analysis manager <%s> found in memory ====", fAnalysis->GetName()));
1867  // Check if an analysis macro was specified
1868  if (!fAnalysis && !fAnalysisMacro.IsNull()) {
1869  // Run specified analysis macro
1870  gROOT->ProcessLine(Form(".x %s",fAnalysisMacro.Data()));
1872  if (!fAnalysis) AliError(Form("No analysis manager produced by analysis macro %s", fAnalysisMacro.Data()));
1873  else AliInfo(Form("==== Analysis manager <%s> produced by analysis macro <%s> ====",
1874  fAnalysis->GetName(), fAnalysisMacro.Data()));
1875  }
1876  }
1877 
1878  // get the run loader
1879  if (!InitRunLoader()) {
1880  Abort("InitRunLoader", TSelector::kAbortProcess);
1881  return;
1882  }
1883  AliSysInfo::AddStamp("LoadLoader");
1884 
1886 
1888 
1889  // get trackers
1890  if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
1891  Abort("CreateTrackers", TSelector::kAbortProcess);
1892  return;
1893  }
1894  AliSysInfo::AddStamp("CreateTrackers");
1895 
1896  // create the ESD output file and tree
1897  if (!outProofFile) {
1898  ffile = TFile::Open("AliESDs.root", "RECREATE");
1899  ffile->SetCompressionLevel(2);
1900  if (!ffile->IsOpen()) {
1901  Abort("OpenESDFile", TSelector::kAbortProcess);
1902  return;
1903  }
1904  }
1905  else {
1906  AliInfo(Form("Opening output PROOF file: %s/%s",
1907  outProofFile->GetDir(), outProofFile->GetFileName()));
1908  if (!(ffile = outProofFile->OpenFile("RECREATE"))) {
1909  Abort(Form("Problems opening output PROOF file: %s/%s",
1910  outProofFile->GetDir(), outProofFile->GetFileName()),
1911  TSelector::kAbortProcess);
1912  return;
1913  }
1914  }
1915 
1916  ftree = new TTree("esdTree", "Tree with ESD objects");
1917  fesd = new AliESDEvent();
1919  // add a so far non-std object to the ESD, this will
1920  // become part of the std content
1922 
1924  if (fWriteESDfriend) {
1925  ffileF = TFile::Open("AliESDfriends.root", "RECREATE");
1926  ftreeF = new TTree("esdFriendTree", "Tree with ESD Friend objects");
1927  fesdf = new AliESDfriend();
1928  fesdf->SetESDIndicesStored(kTRUE); // new sparse format
1929  fesdfDummy = new AliESDfriend();
1930  fesdf->SetESDIndicesStored(kTRUE);
1931  fesdfDummy->SetSkipBit(kTRUE); // empty copy
1932  ftreeF->Branch("ESDfriend.","AliESDfriend", &fesdf);
1933  fesd->AddObject(fesdf);
1934  ffile->cd();
1935  }
1936  ftree->GetUserInfo()->Add(fesd);
1937 
1938  if (fWriteHLTESD) fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
1939  fhltesd = new AliESDEvent();
1941  // read the ESD template from CDB
1942  // HLT is allowed to put non-std content to its ESD, the non-std
1943  // objects need to be created before invocation of WriteToTree in
1944  // order to create all branches. Initialization is done from an
1945  // ESD layout template in CDB
1947  AliCDBEntry* hltESDConfig = man->Get("HLT/Calib/esdLayout");
1948  if(!hltESDConfig){
1949  AliError(Form("Error getting \"HLT/Calib/esdLayout\""));
1950  return;
1951  }
1952  AliESDEvent* pESDLayout=dynamic_cast<AliESDEvent*>(hltESDConfig->GetObject());
1953  if (pESDLayout) {
1954  // init all internal variables from the list of objects
1955  pESDLayout->GetStdContent();
1956 
1957  // copy content and create non-std objects
1958  *fhltesd=*pESDLayout;
1959  fhltesd->Reset();
1960  } else {
1961  AliError(Form("error setting hltEsd layout from \"HLT/Calib/esdLayout\": invalid object type"));
1962  }
1963  if (fWriteHLTESD) {
1965  fhlttree->GetUserInfo()->Add(fhltesd);
1966  }
1967  else {
1968  AliInfo("HLT ESD tree writing is disabled");
1969  }
1970 
1971  ProcInfo_t procInfo;
1972  gSystem->GetProcInfo(&procInfo);
1973  AliInfo(Form("Current memory usage %ld %ld", procInfo.fMemResident, procInfo.fMemVirtual));
1974 
1975  // PID
1976  fESDpid = new AliESDpid();
1977 
1978  //QA
1979  //Initialize the QA and start of cycle
1980  if (fRunQA || fRunGlobalQA)
1981  InitQA() ;
1982 
1983  //Initialize the Plane Efficiency framework
1984  if (fRunPlaneEff && !InitPlaneEff()) {
1985  Abort("InitPlaneEff", TSelector::kAbortProcess);
1986  return;
1987  }
1988 
1989  if (strcmp(gProgName,"alieve") == 0)
1990  fRunAliEVE = InitAliEVE();
1991  // If we have an analysis manager, connect the AliRecoInputHandler here
1992  if (fAnalysis) {
1993  if (!dynamic_cast<AliRecoInputHandler*>(fAnalysis->GetInputEventHandler())) {
1994  AliError("Analysis manager used in reconstruction should use AliRecoInputHandler - \
1995  \n ->Replacing with AliRecoInputHandler instance.");
1996  delete fAnalysis->GetInputEventHandler();
1997  }
1998  // Set the event and other data pointers
2000 // fRecoHandler->Init(ftree, "LOCAL");
2004  if (fWriteHLTESD) {
2006  }
2008  // Enter external loop mode
2009  fAnalysis->SetExternalLoop(kTRUE);
2010  // Initialize analysis
2012  fAnalysis->StartAnalysis("local", (TTree*)0);
2013  // Connect ESD tree with the input container
2015  }
2016  //
2017  if (fMCEventHandlerExt) {
2018  AliInfo("Externaly supplied MCEventHandler will be used");
2019  if (!fMCEventHandlerExt->InitOk()) {
2020  if ( !fMCEventHandlerExt->Init("") && !fMCEventHandlerExt->InitOk() ) {
2021  Abort("Failed to initialize MCEventHandler", TSelector::kAbortProcess);
2022  return;
2023  }
2024  }
2025  }
2026  //
2028  //
2029  if (!fWriteHLTESD) AliInfo("Writing of HLT ESD tree is disabled");
2030  else AliInfoF("%.2f%% of HLT ESD events will be stored",fFractionHLTESD*100.0);
2031  AliInfoF("%.2f%% of ESD friends will be stored",fFractionFriends*100.0);
2032 
2033  return;
2034 }
2035 
2036 //_____________________________________________________________________________
2037 Bool_t AliReconstruction::Process(Long64_t entry)
2038 {
2039  // run the reconstruction over a single entry
2040  // from the chain with raw data
2041  AliCodeTimerAuto("",0);
2042 
2043  TTree *currTree = fChain->GetTree();
2044  AliRawVEvent *event = NULL;
2045  currTree->SetBranchAddress("rawevent",&event);
2046  currTree->GetEntry(entry);
2047  fRawReader = new AliRawReaderRoot(event,entry);
2048  // check if process has enough resources
2049  if (!HasEnoughResources(entry)) return kFALSE;
2051  delete fRawReader;
2052  fRawReader = NULL;
2053  delete event;
2054 
2055  if (!fStatus) Abort("ProcessEvent",TSelector::kAbortFile);
2057  return fStatus;
2058 }
2059 
2060 //_____________________________________________________________________________
2062 {
2063  // Implementation of TSelector::Init()
2064  // method
2065  if (tree == 0) {
2066  AliError("The input tree is not found!");
2067  return;
2068  }
2069  fChain = tree;
2070 }
2071 
2072 //_____________________________________________________________________________
2074 {
2075  // run the reconstruction over a single event
2076  // The event loop is steered in Run method
2077 
2078 
2079  static Long_t oldMres=0;
2080  static Long_t oldMvir=0;
2081  static Float_t oldCPU=0;
2082  static Long_t aveDMres=0;
2083  static Long_t aveDMvir=0;
2084  static Float_t aveDCPU=0;
2085 
2086  AliCodeTimerAuto("",0);
2087 
2088  if (fRawReader){
2089  // Store DAQ detector pattern and attributes
2090  fesd->SetDAQDetectorPattern(fRawReader->GetDetectorPattern()[0]);
2091  fesd->SetDAQAttributes(fRawReader->GetAttributes()[2]);
2093  AliInfo(" ");
2094  AliInfoF("Abandoning incomplete event with RAW_ID=%d reconstruction: DAQ attr: 0x%08x",iEvent,fesd->GetDAQAttributes());
2095  AliInfoF("ATTENTION: %d events were already abandoned: next stored event will have ID:%d",fNAbandonedEv,iEvent-fNAbandonedEv);
2096  AliInfo(" ");
2097  fNAbandonedEv++;
2098  return kTRUE;
2099  }
2100  }
2101 
2102  iEvent -= fNAbandonedEv;
2103 
2104 
2105  AliSysInfo::AddStamp(Form("StartEv_%d",iEvent), 0,0,iEvent);
2106 
2107  if (iEvent >= fRunLoader->GetNumberOfEvents()) {
2108  fRunLoader->SetEventNumber(iEvent);
2109  if (fRawReader)
2110  fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
2111  iEvent, iEvent);
2112  fRunLoader->TreeE()->Fill();
2113 
2114  if (fRawReader && fRawReader->UseAutoSaveESD())
2115  fRunLoader->TreeE()->AutoSave("SaveSelf");
2116  }
2117 
2118  if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
2119  return kTRUE;
2120  }
2121 
2122 
2123  fRunLoader->GetEvent(iEvent);
2124 
2125  if (fMCEventHandlerExt) {
2127  else {
2128  AliErrorF("Failed to load MCEvent #%d from external handler %p",iEvent,fMCEventHandlerExt);
2129  if (fStopOnError) {CleanUp(); return kFALSE;}
2131  }
2132  }
2133 
2134  // Fill Event-info object
2135  GetEventInfo();
2137 
2138  ProcInfo_t procInfo;
2139  if(iEvent==fFirstEvent) {
2140  gSystem->GetProcInfo(&procInfo);
2141  oldMres=procInfo.fMemResident;
2142  oldMvir=procInfo.fMemVirtual;
2143  oldCPU=procInfo.fCpuUser+procInfo.fCpuSys;
2144  }
2145  AliInfo(Form("================================= Processing event %d of type %-10s ==================================", iEvent,fRecoParam.PrintEventSpecie()));
2146  fEventInfo.Print();
2147 
2148 
2149  AliSysInfo::AddStamp(Form("StartReco_%d",iEvent), 0,0,iEvent);
2150  // Set the reco-params
2151  {
2152  TString detStr = fLoadCDB;
2153  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2154  if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2155  AliReconstructor *reconstructor = GetReconstructor(iDet);
2156  if (reconstructor && fRecoParam.GetDetRecoParamArray(iDet)) {
2157  const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
2158  reconstructor->SetRecoParam(par);
2159  reconstructor->GetPidSettings(fESDpid);
2160  reconstructor->SetEventInfo(&fEventInfo);
2161  if (fRunQA) {
2163  AliQAManager::QAManager()->SetRecoParam(iDet, par) ;
2165  }
2166  }
2167  }
2168  //
2169  if (fRunQA || fRunGlobalQA) AliQADataMaker::SetEventTrigClasses(fEventInfo.GetTriggerClasses()); // RS: select which histo clones are to be filled
2170  //
2171  if (fRunQA) {
2172  const AliDetectorRecoParam *grppar = fRecoParam.GetDetRecoParam(kNDetectors);
2175  }
2176  }
2177 
2178  // QA on single raw
2179  if (fRunQA && IsInTasks(AliQAv1::kRAWS)) {
2182  AliSysInfo::AddStamp(Form("RawQA_%d",iEvent), 0,0,iEvent);
2183  }
2184 
2185  // fill Event header information from the RawEventHeader
2186  if (fRawReader){
2189  }
2190  else { // fill MC info
2193  }
2194 
2197 
2198  ((AliESDRun*)fesd->GetESDRun())->SetDetectorsInDAQ(fRunInfo->GetDetectorMask());
2199  ((AliESDRun*)fhltesd->GetESDRun())->SetDetectorsInDAQ(fRunInfo->GetDetectorMask());
2200  ((AliESDRun*)fesd->GetESDRun())->SetDetectorsInReco(AliDAQ::DetectorPatternOffline(fFillESD.Data()));
2201  ((AliESDRun*)fhltesd->GetESDRun())->SetDetectorsInReco(AliDAQ::DetectorPatternOffline(fFillESD.Data()));
2202 
2205 
2208 
2209  // Set magnetic field from the tracker
2212  //
2213  AliESDRun *esdRun,*esdRunH;
2214  esdRun = (AliESDRun*)fesd->GetESDRun();
2215  esdRunH = (AliESDRun*)fhltesd->GetESDRun();
2216  esdRun->SetBeamEnergyIsSqrtSHalfGeV();
2217  esdRunH->SetBeamEnergyIsSqrtSHalfGeV();
2218  //
2219  for (int ib=2;ib--;) for (int it=2;it--;) {
2220  esdRun->SetMeanIntensity(ib,it, fBeamInt[ib][it]);
2221  esdRunH->SetMeanIntensity(ib,it, fBeamInt[ib][it]);
2222  }
2223  //
2225  fesd->SetBeamType(fGRPData->GetBeamType().Data());
2232  //
2233  AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
2234  if (fld) { // set info needed for field initialization
2235  fesd->SetCurrentL3(fld->GetCurrentSol());
2236  fesd->SetCurrentDip(fld->GetCurrentDip());
2237  fesd->SetUniformBMap(fld->IsUniform());
2238  fesd->SetBInfoStored();
2239  //
2242  fhltesd->SetUniformBMap(fld->IsUniform());
2244  }
2245 
2246  // set CTPstart timestamp of the run
2247  if (fRunScalers&&fRunScalers->GetScalersRecords()->GetEntriesFast()) {
2250  }
2251 
2252  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2253  if (fTracker[iDet]) { // some trackers need details about the run/time
2256  }
2257  //RS also some reconstructructors may need the time stamp
2259  }
2260 
2261  //
2262  // run full HLT reconstruction first
2263  //
2264  {
2265  TString detectors=fRunLocalReconstruction;
2266  if (IsSelected("HLT", detectors) &&
2267  !RunLocalEventReconstruction("HLT")) {
2268  if (fStopOnError) {CleanUp(); return kFALSE;}
2269  }
2270  detectors=fFillESD;
2271  // run HLT on hltesd
2272  if (IsSelected("HLT", detectors) &&
2273  !FillESD(fhltesd, "HLT")) {
2274  if (fStopOnError) {CleanUp(); return kFALSE;}
2275  }
2276  //Reset, since this is overwritten by online HLT esd, which has no idea about number in chunk
2278  }
2279 
2280  // local single event reconstruction
2281  if (!fRunLocalReconstruction.IsNull()) {
2282  TString detectors=fRunLocalReconstruction;
2283  // the logic for selection and correct sequence of reconstruction relies on the
2284  // full list of detectors. Keyword 'ALL' should have been replaced at this point.
2285  if (detectors.Contains("ALL")) {
2286  AliFatal("Keyword 'ALL' needs to be replaced by the full list of detectors in "
2287  "fRunLocalReconstruction. This should have been done by the framework");
2288  }
2289  detectors.ReplaceAll("HLT", "");
2290  if (!RunLocalEventReconstruction(detectors)) {
2291  if (fStopOnError) {
2292  CleanUp();
2293  return kFALSE;
2294  }
2295  }
2296  }
2297 
2298 
2299  //
2300  // Set most probable pt, for B=0 tracking
2301  // Get the global reco-params. They are atposition 16 inside the array of detectors in fRecoParam
2302  const AliGRPRecoParam *grpRecoParam = dynamic_cast<const AliGRPRecoParam*>(fRecoParam.GetDetRecoParam(kNDetectors));
2303  if (grpRecoParam) AliExternalTrackParam::SetMostProbablePt(grpRecoParam->GetMostProbablePt());
2304 
2305  // Fill raw-data error log into the ESD
2306  if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
2307 
2308  AliSysInfo::AddStamp(Form("FillHeadErrs_%d",iEvent), 0,0,iEvent);
2309 
2310  // vertex finder
2311  if (fRunVertexFinder) {
2312  if (!RunVertexFinder(fesd)) {
2313  if (fStopOnError) {CleanUp(); return kFALSE;}
2314  }
2315  AliSysInfo::AddStamp(Form("VtxFinder_%d",iEvent), 0,0,iEvent);
2316  }
2317 
2318  // For Plane Efficiency: run the SPD trackleter
2319  if (fRunPlaneEff && fSPDTrackleter) {
2320  if (!RunSPDTrackleting(fesd)) {
2321  if (fStopOnError) {CleanUp(); return kFALSE;}
2322  }
2323  AliSysInfo::AddStamp(Form("TrackletEff_%d",iEvent), 0,0,iEvent);
2324  }
2325 
2326  // Muon tracking
2327  if (!fRunTracking.IsNull()) {
2328  if (fRunMuonTracking) {
2329  if (!RunMuonTracking(fesd)) {
2330  if (fStopOnError) {CleanUp(); return kFALSE;}
2331  }
2332  }
2333  AliSysInfo::AddStamp(Form("TrackingMUON_%d",iEvent), 0,0,iEvent);
2334  }
2335 
2336  //---------------- AU From here...
2337 
2338  // MFT tracking of MUON tracks
2339  if (!fRunTracking.IsNull()) {
2341  if (!RunMFTTrackingMU(fesd)) {
2342  if (fStopOnError) {CleanUp(); return kFALSE;}
2343  }
2344  }
2345  AliSysInfo::AddStamp(Form("TrackingMFT_MUON_%d",iEvent), 0,0,iEvent);
2346  }
2347 
2348  //---------------- ...to here
2349 
2350  // barrel tracking
2351  if (!fRunTracking.IsNull()) {
2352  if (!RunTracking(fesd,*fESDpid)) {
2353  if (fStopOnError) {CleanUp(); return kFALSE;}
2354  }
2355  }
2356 
2357  // fill ESD
2358  if (!fFillESD.IsNull()) {
2359  TString detectors=fFillESD;
2360  // the logic for selection and correct sequence of reconstruction relies on the
2361  // full list of detectors. Keyword 'ALL' should have been replaced at this point.
2362  if (detectors.Contains("ALL")) {
2363  AliFatal("Keyword 'ALL' needs to be replaced by the full list of detectors in "
2364  "fFillESD. This should have been done by the framework");
2365  }
2366  // remove HLT as this has been executed at the beginning of the event reconstruction
2367  detectors.ReplaceAll("HLT", "");
2368  if (!FillESD(fesd, detectors)) {
2369  if (fStopOnError) {CleanUp(); return kFALSE;}
2370  }
2371  }
2372 
2373  ffile->cd();
2374 
2375  //
2376  // Propagate track to the beam pipe (if not already done by ITS)
2377  //
2378  const Int_t ntracks = fesd->GetNumberOfTracks();
2379  const Double_t kRadius = 2.8; //something less than the beam pipe radius
2380 
2381  TObjArray trkArray;
2382  UShort_t selectedIdx[ntracks];
2383 
2384  for (Int_t itrack=0; itrack<ntracks; itrack++){
2385  const Double_t kMaxStep = 5; //max step over the material
2386  Bool_t ok;
2387 
2388  AliESDtrack *track = fesd->GetTrack(itrack);
2389  if (!track) continue;
2390 
2391  AliExternalTrackParam *tpcTrack =
2393  ok = kFALSE;
2394  if (tpcTrack)
2395  ok = AliTracker::
2396  PropagateTrackToBxByBz(tpcTrack,kRadius,track->GetMassForTracking(),kMaxStep,kFALSE);
2397 
2398  if (ok) {
2399  Int_t n=trkArray.GetEntriesFast();
2400  selectedIdx[n]=track->GetID();
2401  trkArray.AddLast(tpcTrack);
2402  }
2403 
2404  //Tracks refitted by ITS should already be at the SPD vertex
2405  if (track->IsOn(AliESDtrack::kITSrefit)) continue;
2406 
2407  AliTracker::
2408  PropagateTrackToBxByBz(track,kRadius,track->GetMassForTracking(),kMaxStep,kFALSE);
2409  Double_t x[3]; track->GetXYZ(x);
2410  Double_t b[3]; AliTracker::GetBxByBz(x,b);
2412 
2413  }
2414  AliSysInfo::AddStamp(Form("RelToSPDVtx_%d",iEvent), 0,0,iEvent);
2415  //
2416  // Improve the reconstructed primary vertex position using the tracks
2417  //
2418  Bool_t runVertexFinderTracks = fRunVertexFinderTracks;
2419  if(fesd->GetPrimaryVertexSPD()) {
2420  TString vtitle = fesd->GetPrimaryVertexSPD()->GetTitle();
2421  if(vtitle.Contains("cosmics")) {
2422  runVertexFinderTracks=kFALSE;
2423  }
2424  }
2425 
2426  if (runVertexFinderTracks) {
2427  // TPC + ITS primary vertex
2430  // get cuts for vertexer from AliGRPRecoParam
2431  Bool_t constrSPD=kFALSE;
2432  if (grpRecoParam) {
2433  Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
2434  Double_t *cutsVertexer = new Double_t[nCutsVertexer];
2435  grpRecoParam->GetVertexerTracksCutsITS(cutsVertexer,nCutsVertexer);
2436  ftVertexer->SetCuts(cutsVertexer,nCutsVertexer);
2437  delete [] cutsVertexer; cutsVertexer = NULL;
2438  if(grpRecoParam->GetVertexerTracksConstraintITS()) {
2439  if(fDiamondProfile && fDiamondProfile->GetXRes()<kRadius){
2440  ftVertexer->SetVtxStart(fDiamondProfile); // apply constraint only if sigmax is smaller than the beam pipe radius
2441  }else{
2442  if(fDiamondProfileSPD && fDiamondProfileSPD->GetXRes()<kRadius){
2444  constrSPD=kTRUE;
2445  }
2446  }
2447  }
2448  }
2449  Bool_t usePureSA = ftVertexer->GetITSpureSA();
2450  if (!fesd->GetNumberOfTPCClusters()) {
2451  AliInfo("No TPC clusters: VertexerTracks will run with ITSpureSA tracks");
2452  ftVertexer->SetITSpureSA(kTRUE);
2453  }
2455  ftVertexer->SetITSpureSA(usePureSA); // restore use settings
2456  if (pvtx) {
2457  if(constrSPD){
2458  TString title=pvtx->GetTitle();
2459  title.Append("SPD");
2460  pvtx->SetTitle(title);
2461  }
2462  if (pvtx->GetStatus()) {
2464  for (Int_t i=0; i<ntracks; i++) {
2465  AliESDtrack *t = fesd->GetTrack(i);
2466  Double_t x[3]; t->GetXYZ(x);
2467  Double_t b[3]; AliTracker::GetBxByBz(x,b);
2468  t->RelateToVertexBxByBz(pvtx, b, kVeryBig);
2469  }
2470  }
2471  delete pvtx; pvtx=NULL;
2472  }
2473  AliSysInfo::AddStamp(Form("VtxTrk_%d",iEvent), 0,0,iEvent);
2474 
2475  // TPC-only primary vertex
2478  // get cuts for vertexer from AliGRPRecoParam
2479  if (grpRecoParam) {
2480  Int_t nCutsVertexer = grpRecoParam->GetVertexerTracksNCuts();
2481  Double_t *cutsVertexer = new Double_t[nCutsVertexer];
2482  grpRecoParam->GetVertexerTracksCutsTPC(cutsVertexer,nCutsVertexer);
2483  ftVertexer->SetCuts(cutsVertexer,nCutsVertexer);
2484  delete [] cutsVertexer; cutsVertexer = NULL;
2485  if(fDiamondProfileTPC && grpRecoParam->GetVertexerTracksConstraintTPC()) {
2486  if(fDiamondProfileTPC->GetXRes()<kRadius) ftVertexer->SetVtxStart(fDiamondProfileTPC); // apply constraint only if sigmax is smaller than the beam pipe radius
2487  }
2488  }
2489  pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
2490  if (pvtx) {
2491  if (pvtx->GetStatus()) {
2492  fesd->SetPrimaryVertexTPC(pvtx);
2493  for (Int_t i=0; i<ntracks; i++) {
2494  AliESDtrack *t = fesd->GetTrack(i);
2495  Double_t x[3]; t->GetXYZ(x);
2496  Double_t b[3]; AliTracker::GetBxByBz(x,b);
2497  t->RelateToVertexTPCBxByBz(pvtx, b, kVeryBig);
2498  }
2499  }
2500  delete pvtx; pvtx=NULL;
2501  }
2502  AliSysInfo::AddStamp(Form("VtxTPC_%d",iEvent), 0,0,iEvent);
2503 
2504  }
2505 
2508 
2509  if (fRunV0Finder) {
2510  // V0 finding
2511  AliV0vertexer vtxer;
2512  // get cuts for V0vertexer from AliGRPRecoParam
2513  if (grpRecoParam) {
2514  Int_t nCutsV0vertexer = grpRecoParam->GetVertexerV0NCuts();
2515  Double_t cutsV0vertexer[nCutsV0vertexer];
2516  grpRecoParam->GetVertexerV0Cuts(cutsV0vertexer);
2517  vtxer.SetCuts(cutsV0vertexer);
2518  //
2519  vtxer.SetV0HypSel(grpRecoParam->GetV0HypSelArray());
2520  if (iEvent==0 && grpRecoParam->GetV0HypSelArray()) {
2521  AliInfo("V0 selection hypotheses:");
2522  grpRecoParam->GetV0HypSelArray()->Print();
2523  }
2524  }
2525  vtxer.Tracks2V0vertices(fesd);
2526  AliSysInfo::AddStamp(Form("V0Finder_%d",iEvent), 0,0,iEvent);
2527 
2528  if (fRunCascadeFinder) {
2529  // Cascade finding
2530  AliCascadeVertexer cvtxer;
2531  // get cuts for CascadeVertexer from AliGRPRecoParam
2532  if (grpRecoParam) {
2533  Int_t nCutsCascadeVertexer = grpRecoParam->GetVertexerCascadeNCuts();
2534  Double_t cutsCascadeVertexer[nCutsCascadeVertexer];
2535  grpRecoParam->GetVertexerCascadeCuts(cutsCascadeVertexer);
2536  cvtxer.SetCuts(cutsCascadeVertexer);
2537  }
2539  AliSysInfo::AddStamp(Form("CascadeFinder_%d",iEvent), 0,0,iEvent);
2540  }
2541  }
2542 
2543  // AdC+FN
2544  if (fReconstructor[3])
2546 
2547  // combined PID
2548  // fESDpid->MakePID(fesd);
2549 
2550  if (fFillTriggerESD) {
2551  if (!FillTriggerESD(fesd)) {
2552  if (fStopOnError) {CleanUp(); return kFALSE;}
2553  }
2554  }
2555  // Always fill scalers
2556  if (!FillTriggerScalers(fesd)) {
2557  if (fStopOnError) {CleanUp(); return kFALSE;}
2558  }
2559 
2560  AliSysInfo::AddStamp(Form("FillVaria_%d",iEvent), 0,0,iEvent);
2561 
2562  // write ESD
2563  UInt_t specie = fesd->GetEventSpecie();
2564  Bool_t keepAll = (specie==AliRecoParam::kCosmic || specie==AliRecoParam::kCalib);
2565  if (!keepAll) {
2566  fesd->CleanV0s(grpRecoParam);
2567  if (fCleanESD ) {
2568  CleanESD(fesd,grpRecoParam);
2569  AliSysInfo::AddStamp(Form("CleanESD_%d",iEvent), 0,0,iEvent);
2570  }
2571  }
2572  //
2573  // RS run updated trackleter: since we want to mark the clusters used by tracks and also mark the
2574  // tracks interpreted as primary, this step should be done in the very end, when full
2575  // ESD info is available (particulalry, V0s)
2576  // vertex finder
2577  if (fRunMultFinder) {
2578  if (!RunMultFinder(fesd)) {
2579  if (fStopOnError) {CleanUp(); return kFALSE;}
2580  }
2581  AliSysInfo::AddStamp(Form("MultFinder_%d",iEvent), 0,0,iEvent);
2582  }
2583 
2584  if (fRunQA && IsInTasks(AliQAv1::kESDS)) {
2587  AliSysInfo::AddStamp(Form("RunQA_%d",iEvent), 0,0,iEvent);
2588  }
2589  if (fRunGlobalQA) {
2591  if (qadm)
2593  if (qadm && IsInTasks(AliQAv1::kESDS))
2594  qadm->Exec(AliQAv1::kESDS, fesd);
2595  AliSysInfo::AddStamp(Form("RunGlobQA_%d",iEvent), 0,0,iEvent);
2596  }
2597 
2598  // copy HLT decision from HLTesd to esd
2599  // the most relevant information is stored in a reduced container in the esd,
2600  // while the full information can be found in the HLTesd
2601  TObject* pHLTSrc=fhltesd->FindListObject(AliESDHLTDecision::Name());
2602  TObject* pHLTTgt=fesd->FindListObject(AliESDHLTDecision::Name());
2603  if (pHLTSrc && pHLTTgt) {
2604  pHLTSrc->Copy(*pHLTTgt);
2605  }
2606  //
2607  // Perform analysis of this event if requested
2608  // RS: Should be done before WriteESDfriend, since the latter may clean the esdfriend
2609  if (fAnalysis) {
2610  fRecoHandler->BeginEvent(iEvent);
2613  AliSysInfo::AddStamp(Form("Analysis_%d",iEvent), 0,0,iEvent);
2614  }
2615  //
2616  if (fWriteThisFriend) {
2618  AliSysInfo::AddStamp(Form("CreateFriend_%d",iEvent), 0,0,iEvent);
2619  }
2620  //
2621  Long64_t nbf;
2622  nbf = ftree->Fill();
2623  if (fTreeBuffSize>0 && ftree->GetAutoFlush()<0 && (fMemCountESD += nbf)>fTreeBuffSize ) { // default limit is still not reached
2624  nbf = ftree->GetZipBytes();
2625  if (nbf>0) nbf = -nbf;
2626  else nbf = ftree->GetEntries();
2627  ftree->SetAutoFlush(nbf);
2628  AliInfo(Form("Calling ftree->SetAutoFlush(%lld) | W:%lld T:%lld Z:%lld",
2629  nbf,fMemCountESD,ftree->GetTotBytes(),ftree->GetZipBytes()));
2630  }
2631  AliSysInfo::AddStamp(Form("ESDFill_%d",iEvent), 0,0,iEvent);
2632  //
2633  if (fWriteESDfriend) {
2634  WriteESDfriend();
2635  AliSysInfo::AddStamp(Form("WriteFriend_%d",iEvent), 0,0,iEvent);
2636  }
2637  //
2638  // Auto-save the ESD tree in case of prompt reco @P2
2639  if (fRawReader && fRawReader->UseAutoSaveESD()) {
2640  ftree->AutoSave("SaveSelf");
2641  if (fWriteESDfriend) ftreeF->AutoSave("SaveSelf");
2642  }
2643  // write HLT ESD
2644  if (fFractionHLTESD<1.0 && fhltesd->GetESDRun()->TestBit(AliESDRun::kESDDownscaledOnline)) {
2645  AliInfo("HLT ESD online prescaling flag is ON: disabling offline prescaling");
2646  fFractionHLTESD = 1.0;
2647  }
2648  //
2649  if (fWriteHLTESD) {
2650  if (gRandom->Rndm()>fFractionHLTESD) {
2651  AliInfo("HLT ESD for this event will be empty");
2652  fhltesd->Reset();
2653  }
2654  nbf = fhlttree->Fill();
2655  if (fTreeBuffSize>0 && fhlttree->GetAutoFlush()<0 && (fMemCountESDHLT += nbf)>fTreeBuffSize ) { // default limit is still not reached
2656  nbf = fhlttree->GetZipBytes();
2657  if (nbf>0) nbf = -nbf;
2658  else nbf = fhlttree->GetEntries();
2659  fhlttree->SetAutoFlush(nbf);
2660  AliInfo(Form("Calling fhlttree->SetAutoFlush(%lld) | W:%lld T:%lld Z:%lld",
2661  nbf,fMemCountESDHLT,fhlttree->GetTotBytes(),fhlttree->GetZipBytes()));
2662  }
2663  }
2664 
2665  gSystem->GetProcInfo(&procInfo);
2666  Long_t dMres=(procInfo.fMemResident-oldMres)/1024;
2667  Long_t dMvir=(procInfo.fMemVirtual-oldMvir)/1024;
2668  Float_t dCPU=procInfo.fCpuUser+procInfo.fCpuSys-oldCPU;
2669  aveDMres+=(dMres-aveDMres)/(iEvent-fFirstEvent+1);
2670  aveDMvir+=(dMvir-aveDMvir)/(iEvent-fFirstEvent+1);
2671  aveDCPU+=(dCPU-aveDCPU)/(iEvent-fFirstEvent+1);
2672  AliInfo(Form("======================= End Event %d: Res %ld(%3ld <%3ld>) Vir %ld(%3ld <%3ld>) CPU %5.2f <%5.2f> ===================",
2673  iEvent, procInfo.fMemResident/1024, dMres, aveDMres, procInfo.fMemVirtual/1024, dMvir, aveDMvir, dCPU, aveDCPU));
2674  oldMres=procInfo.fMemResident;
2675  oldMvir=procInfo.fMemVirtual;
2676  oldCPU=procInfo.fCpuUser+procInfo.fCpuSys;
2677 
2678  if (fTracker[AliQAv1::kTPC]) {
2680  AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[AliQAv1::kTPC],iEvent), AliQAv1::kTPC,4, iEvent);
2681  }
2682  if (fLoader[AliQAv1::kTPC]) {
2684  AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[AliQAv1::kTPC],iEvent), AliQAv1::kTPC,5, iEvent);
2685  }
2686 
2688 
2689  return kTRUE;
2690 }
2691 
2693 {
2694  //
2695  // if (fWriteESDfriend) ResetFriends();
2696  ResetFriends(); // RS: Important: first reset friends to be sure objects owned by trackers are released
2697 
2698  fesd->Reset();
2699  fhltesd->Reset();
2700 
2701  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2702  if (fReconstructor[iDet]) fReconstructor[iDet]->FinishEvent();
2703  }
2704 
2705  AliInfo("======================= End Event ===================");
2706 
2707 
2708  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2709  if (fReconstructor[iDet]) {
2710  fReconstructor[iDet]->SetRecoParam(NULL);
2711  fReconstructor[iDet]->SetEventInfo(NULL);
2712  }
2713  if (fTracker[iDet]) fTracker[iDet]->SetEventInfo(NULL);
2714  }
2715 
2716  if (fRunQA || fRunGlobalQA)
2718 
2721  //
2722 
2723 }
2724 
2725 //_____________________________________________________________________________
2727 {
2728  // Finalize the run on the slave side
2729  // Called after the exit
2730  // from the event loop
2731  AliCodeTimerAuto("",0);
2732  // If analysis was done during reconstruction, we need to call SlaveTerminate for it
2733  if (fAnalysis) {
2734  fAnalysis->PackOutput(fOutput);
2735  fAnalysis->SetSkipTerminate(kTRUE);
2736  fAnalysis->Terminate();
2737  }
2738 
2739  if (fIsNewRunLoader) { // galice.root didn't exist
2740  fRunLoader->WriteHeader("OVERWRITE");
2741  fRunLoader->WriteTrigger("OVERWRITE");
2742  fRunLoader->CdGAFile();
2743  fRunLoader->Write(0, TObject::kOverwrite);
2744  }
2745 
2746  TMap *cdbMapCopy = new TMap();
2747  cdbMapCopy->SetName("cdbMap");
2748  TList *cdbListCopy = new TList();
2749  cdbListCopy->SetName("cdbList");
2750  // create map/list accounting for eventual snapshot
2751  AliCDBManager::Instance()->CreateMapListCopy(*cdbMapCopy,*cdbListCopy);
2752 
2753  ftree->GetUserInfo()->Add(cdbMapCopy);
2754  ftree->GetUserInfo()->Add(cdbListCopy);
2755 
2756  // Add the AliRoot version that created this file
2757  TString sVersion("aliroot ");
2758  sVersion += ALIROOT_VERSION;
2759  sVersion += ":";
2760  sVersion += ALIROOT_REVISION;
2761  sVersion += "; root ";
2762 #ifdef ROOT_SVN_BRANCH
2763  sVersion += ROOT_SVN_BRANCH;
2764 #elif defined(ROOT_GIT_BRANCH)
2765  sVersion += ROOT_GIT_BRANCH;
2766 #else
2767  sVersion += "?";
2768 #endif
2769  sVersion += ":";
2770 #ifdef ROOT_SVN_REVSION
2771  sVersion += ROOT_SVN_REVISION;
2772 #elif defined(ROOT_GIT_COMMIT)
2773  sVersion += ROOT_GIT_COMMIT;
2774 #else
2775  sVersion += "?";
2776 #endif
2777  sVersion += "; metadata ";
2778  sVersion += getenv("PRODUCTION_METADATA");
2779 
2780 
2781  TNamed * alirootVersion = new TNamed("alirootVersion",sVersion.Data());
2782  ftree->GetUserInfo()->Add(alirootVersion); // The list becomes owner of alirootVersion
2783 
2784  ffile->cd();
2785 
2786  // we want to have only one tree version number
2787  ftree->Write(ftree->GetName(),TObject::kOverwrite);
2788  if (fWriteHLTESD) fhlttree->Write(fhlttree->GetName(),TObject::kOverwrite);
2789 
2790  if (fWriteESDfriend) {
2791  ffileF->cd();
2792  ftreeF->Write(ftreeF->GetName(),TObject::kOverwrite);
2793  }
2794 
2795 // Finish with Plane Efficiency evaluation: before of CleanUp !!!
2796  if (fRunPlaneEff && !FinishPlaneEff()) {
2797  AliWarning("Finish PlaneEff evaluation failed");
2798  }
2799 
2800  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2801  if (fReconstructor[iDet]) fReconstructor[iDet]->Terminate();
2802  }
2803  // End of cycle for the in-loop
2804 
2805  if (fRunQA || fRunGlobalQA) {
2807  if (fInput &&
2808  !fProofOutputLocation.IsNull() &&
2809  fProofOutputArchive.IsNull() &&
2811  TString qaOutputFile(Form("%sMerged.%s.Data.root",
2812  fProofOutputLocation.Data(),
2814  TProofOutputFile *qaProofFile = new TProofOutputFile(Form("Merged.%s.Data.root",
2816  qaProofFile->SetOutputFileName(qaOutputFile.Data());
2817  if (AliDebugLevel() > 0) qaProofFile->Dump();
2818  fOutput->Add(qaProofFile);
2819  MergeQA(qaProofFile->GetFileName());
2820  }
2821  else {
2822  MergeQA();
2823  }
2824  }
2825 
2826  gROOT->cd();
2827  CleanUp();
2828 
2829  if (fInput) {
2830  if (!fProofOutputFileName.IsNull() &&
2831  !fProofOutputLocation.IsNull() &&
2833  !fProofOutputArchive.IsNull()) {
2834  TProofOutputFile *zipProofFile = new TProofOutputFile(fProofOutputFileName.Data(),
2835  "DROV",
2836  fProofOutputLocation.Data());
2837  if (AliDebugLevel() > 0) zipProofFile->Dump();
2838  fOutput->Add(zipProofFile);
2839  TString fileList(fProofOutputArchive.Data());
2840  fileList.ReplaceAll(","," ");
2841  TString command;
2842 #if ROOT_SVN_REVISION >= 30174
2843  command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(kTRUE),zipProofFile->GetFileName(),fileList.Data());
2844 #else
2845  command.Form("zip -n root %s/%s %s",zipProofFile->GetDir(),zipProofFile->GetFileName(),fileList.Data());
2846 #endif
2847  AliInfo(Form("Executing: %s",command.Data()));
2848  gSystem->Exec(command.Data());
2849  }
2850  }
2851 }
2852 
2853 //_____________________________________________________________________________
2855 {
2856  // Create tags for the events in the ESD tree (the ESD tree is always present)
2857  // In case of empty events the tags will contain dummy values
2858  AliCodeTimerAuto("",0);
2859 
2860  // Do not call the ESD tag creator in case of PROOF-based reconstruction
2861  if (!fInput) {
2862  AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
2864  delete esdtagCreator;
2865  }
2866 
2867  // Cleanup of CDB manager: cache and active storages!
2869 }
2870 
2871 //_____________________________________________________________________________
2872 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
2873 {
2874 // run the local reconstruction
2875 
2876  static Int_t eventNr=0;
2877  AliCodeTimerAuto("",0)
2878 
2879  TString detStr = detectors;
2880  // execute HLT reconstruction first since other detector reconstruction
2881  // might depend on HLT data
2882  // key 'HLT' is removed from detStr by IsSelected
2883  if (IsSelected("HLT", detStr)) {
2884  AliReconstructor* reconstructor = GetReconstructor(kNDetectors-1);
2885  if (reconstructor) {
2886  // there is no AliLoader for HLT, see
2887  // https://savannah.cern.ch/bugs/?35473
2888  AliInfo("running reconstruction for HLT");
2889  if (fRawReader) {
2890  AliInfo("reconstructor->Reconstruct(fRawReader, NULL)");
2891  reconstructor->Reconstruct(fRawReader, NULL);
2892  }
2893  else {
2894  AliInfo("reconstructor->Reconstruct(dummy, NULL)");
2895  TTree* dummy=NULL;
2896  reconstructor->Reconstruct(dummy, NULL);
2897  }
2898  }
2899  AliSysInfo::AddStamp(Form("LRecHLT_%d",eventNr), -1,1,eventNr);
2900  }
2901 
2902  AliInfo(Form("kNDetectors = %d",kNDetectors));
2903 
2904  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
2905  if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2906  AliDebug(1, Form("Detector: %s", fgkDetectorName[iDet]));
2907  AliReconstructor* reconstructor = GetReconstructor(iDet);
2908  if (!reconstructor) continue;
2909  AliLoader* loader = fLoader[iDet];
2910  if (!loader) {
2911  AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
2912  continue;
2913  }
2914  // conversion of digits
2915  if (fRawReader && reconstructor->HasDigitConversion()) {
2916  AliInfo(Form("converting raw data digits into root objects for %s",
2917  fgkDetectorName[iDet]));
2918 // AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
2919 // fgkDetectorName[iDet]),0);
2920  loader->LoadDigits("update");
2921  loader->CleanDigits();
2922  loader->MakeDigitsContainer();
2923  TTree* digitsTree = loader->TreeD();
2924  reconstructor->ConvertDigits(fRawReader, digitsTree);
2925  loader->WriteDigits("OVERWRITE");
2926  loader->UnloadDigits();
2927  }
2928  // local reconstruction
2929  AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
2930  //AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]),0);
2931  AliDebug(1, "Loading Rec Points");
2932  loader->LoadRecPoints("update");
2933  AliDebug(1, "Cleaning Rec Points");
2934  loader->CleanRecPoints();
2935  AliDebug(1, "Making Rec Points Container");
2936  loader->MakeRecPointsContainer();
2937  TTree* clustersTree = loader->TreeR();
2938  if (fRawReader && !reconstructor->HasDigitConversion()) {
2939  reconstructor->Reconstruct(fRawReader, clustersTree);
2940  }
2941  else {
2942  AliDebug(1, "Loading Digits");
2943  loader->LoadDigits("read");
2944  TTree* digitsTree = loader->TreeD();
2945  AliDebug(1, Form("Digits Tree = %p",digitsTree));
2946  if (!digitsTree) {
2947  AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
2948  if (fStopOnError)
2949  return kFALSE;
2950  }
2951  else {
2952  AliDebug(1, "Digits -> Clusters");
2953  reconstructor->Reconstruct(digitsTree, clustersTree);
2956  AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, digitsTree) ;
2957  }
2958  }
2959  loader->UnloadDigits();
2960  }
2963  AliQAManager::QAManager()->RunOneEventInOneDetector(iDet, clustersTree) ;
2964  }
2965  loader->WriteRecPoints("OVERWRITE");
2966  loader->UnloadRecPoints();
2967  AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
2968  }
2969  if (!IsSelected("CTP", detStr)) AliDebug(10,"No CTP");
2970  if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
2971  AliError(Form("the following detectors were not found: %s",
2972  detStr.Data()));
2973  if (fStopOnError)
2974  return kFALSE;
2975  }
2976  eventNr++;
2977  return kTRUE;
2978 }
2979 //_____________________________________________________________________________
2981 {
2982 // run the SPD trackleting (for SPD efficiency purpouses)
2983 
2984  AliCodeTimerAuto("",0)
2985 
2986  Double_t vtxPos[3] = {0, 0, 0};
2987  Double_t vtxErr[3] = {0.0, 0.0, 0.0};
2988 /*
2989  TArrayF m
2990 /
2991 cVertex(3);
2992  // if(MC)
2993  if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
2994  fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
2995  for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
2996  }
2997 */
2998  const AliESDVertex *vertex = esd->GetVertex();
2999  if(!vertex){
3000  AliWarning("Vertex not found");
3001  return kFALSE;
3002  }
3003  vertex->GetXYZ(vtxPos);
3004  vertex->GetSigmaXYZ(vtxErr);
3005  if (fSPDTrackleter) {
3006  AliInfo("running the SPD Trackleter for Plane Efficiency Evaluation");
3007 
3008  // load clusters
3009  fLoader[0]->LoadRecPoints("read");
3010  TTree* tree = fLoader[0]->TreeR();
3011  if (!tree) {
3012  AliError("Can't get the ITS cluster tree");
3013  return kFALSE;
3014  }
3016  fSPDTrackleter->SetVertex(vtxPos, vtxErr);
3017  // run trackleting
3018  if (fSPDTrackleter->Clusters2Tracks(esd) != 0) {
3019  AliWarning("AliITSTrackleterSPDEff Clusters2Tracks failed");
3020  // fLoader[0]->UnloadRecPoints();
3021  return kFALSE;
3022  }
3023 //fSPDTrackleter->UnloadRecPoints();
3024  } else {
3025  AliWarning("SPDTrackleter not available");
3026  return kFALSE;
3027  }
3028  return kTRUE;
3029 }
3030 
3031 //_____________________________________________________________________________
3033 {
3034 // run the barrel tracking
3035 
3036  AliCodeTimerAuto("",0)
3037 
3038  AliVertexer *vertexer = CreateVertexer();
3039  if (!vertexer) return kFALSE;
3040 
3041  AliInfo(Form("running the ITS vertex finder: %s",vertexer->ClassName()));
3042  AliESDVertex* vertex = NULL;
3043  if (fLoader[0]) {
3044  fLoader[0]->LoadRecPoints();
3045  TTree* cltree = fLoader[0]->TreeR();
3046  if (cltree) {
3048  vertex = vertexer->FindVertexForCurrentEvent(cltree);
3049  }
3050  else {
3051  AliError("Can't get the ITS cluster tree");
3052  }
3053  fLoader[0]->UnloadRecPoints();
3054  }
3055  else {
3056  AliError("Can't get the ITS loader");
3057  }
3058  if(!vertex){
3059  AliWarning("Vertex not found");
3060  vertex = new AliESDVertex();
3061  vertex->SetName("default");
3062  }
3063  else {
3064  vertex->SetName("reconstructed");
3065  }
3066 
3067  Double_t vtxPos[3];
3068  Double_t vtxErr[3];
3069  vertex->GetXYZ(vtxPos);
3070  vertex->GetSigmaXYZ(vtxErr);
3071 
3072  esd->SetPrimaryVertexSPD(vertex);
3073  AliESDVertex *vpileup = NULL;
3074  Int_t novertices = 0;
3075  vpileup = vertexer->GetAllVertices(novertices);
3076  if(novertices>1){
3077  for (Int_t kk=1; kk<novertices; kk++)esd->AddPileupVertexSPD(&vpileup[kk]);
3078  }
3079  /*
3080  // if SPD multiplicity has been determined, it is stored in the ESD
3081  AliMultiplicity *mult = vertexer->GetMultiplicity();
3082  if(mult)esd->SetMultiplicity(mult);
3083  */
3084  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
3085  if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
3086  }
3087  delete vertex;
3088 
3089  delete vertexer;
3090 
3091  return kTRUE;
3092 }
3093 
3094 //_____________________________________________________________________________
3096 {
3097  // run the trackleter for multiplicity study
3098 
3099  AliCodeTimerAuto("",0)
3100 
3101  AliTrackleter *trackleter = CreateMultFinder();
3102  if (!trackleter) return kFALSE;
3103 
3104  AliInfo(Form("running the ITS multiplicity finder: %s",trackleter->ClassName()));
3105 
3106  if (fLoader[0]) {
3107  fLoader[0]->LoadRecPoints();
3108  TTree* cltree = fLoader[0]->TreeR();
3109  if (cltree) {
3110  trackleter->Reconstruct(esd,cltree);
3111  AliMultiplicity *mult = trackleter->GetMultiplicity();
3112  if(mult) esd->SetMultiplicity(mult);
3113  }
3114  else {
3115  AliError("Can't get the ITS cluster tree");
3116  }
3117  fLoader[0]->UnloadRecPoints();
3118  }
3119  else {
3120  AliError("Can't get the ITS loader");
3121  }
3122 
3123  delete trackleter;
3124 
3125  return kTRUE;
3126 }
3127 
3128 //_____________________________________________________________________________
3130 {
3131 // run the muon spectrometer tracking
3132 
3133  AliCodeTimerAuto("",0)
3134 
3135  if (!fRunLoader) {
3136  AliError("Missing runLoader!");
3137  return kFALSE;
3138  }
3139  Int_t iDet = GetDetIndex("MUON"); // for MUON
3140 
3141  // Get a pointer to the MUON reconstructor
3142  AliReconstructor *reconstructor = GetReconstructor(iDet);
3143  if (!reconstructor) return kFALSE;
3144 
3145 
3146  TString detName = fgkDetectorName[iDet];
3147  AliDebug(1, Form("%s tracking", detName.Data()));
3148  AliTracker *tracker = reconstructor->CreateTracker();
3149  if (!tracker) {
3150  AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
3151  return kFALSE;
3152  }
3153 
3154  // read RecPoints
3155  fLoader[iDet]->LoadRecPoints("read");
3156 
3157  tracker->LoadClusters(fLoader[iDet]->TreeR());
3158 
3159  Int_t rv = tracker->Clusters2Tracks(esd);
3160 
3161  fLoader[iDet]->UnloadRecPoints();
3162 
3163  tracker->UnloadClusters();
3164 
3165  if ( rv )
3166  {
3167  AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
3168  return kFALSE;
3169  }
3170 
3171  return kTRUE;
3172 }
3173 
3174 
3175 //_____________________________________________________________________________
3177 
3178  // AU
3179 
3180  // run the global muon tracking: matching the MUON tracks with the MFT clusters
3181 
3182  AliCodeTimerAuto("",0)
3183 
3184  if (!fRunLoader) {
3185  AliError("Missing runLoader!");
3186  return kFALSE;
3187  }
3188  Int_t iDet = GetDetIndex("MFT"); // for MFT
3189 
3190  // Get a pointer to the MFT reconstructor
3191  AliReconstructor *reconstructor = GetReconstructor(iDet);
3192  if (!reconstructor) return kFALSE;
3193 
3194  TString detName = fgkDetectorName[iDet];
3195  AliDebug(1, Form("%s tracking for muon tracks", detName.Data()));
3196  AliTracker *tracker = reconstructor->CreateTracker();
3197  if (!tracker) {
3198  AliWarning(Form("couldn't create a Muon tracker for %s", detName.Data()));
3199  return kFALSE;
3200  }
3201 
3202  // read RecPoints
3203  fLoader[iDet]->LoadRecPoints("read");
3204 
3205  tracker->LoadClusters(fLoader[iDet]->TreeR());
3206 
3207  Int_t rv = tracker->Clusters2Tracks(esd);
3208 
3209  fLoader[iDet]->UnloadRecPoints();
3210 
3211  tracker->UnloadClusters();
3212 
3213  if (rv) {
3214  AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
3215  return kFALSE;
3216  }
3217 
3218  return kTRUE;
3219 
3220 }
3221 
3222 //_____________________________________________________________________________
3224 {
3225 // run the barrel tracking
3226  static Int_t eventNr=0;
3227  AliCodeTimerAuto("",0)
3228 
3229  AliInfo("running tracking");
3230 
3231  // Set the event info which is used
3232  // by the trackers in order to obtain
3233  // information about read-out detectors,
3234  // trigger etc.
3235  AliDebug(1, "Setting event info");
3236  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
3237  if (!fTracker[iDet]) continue;
3238  fTracker[iDet]->SetEventInfo(&fEventInfo);
3239  }
3240 
3241  //Fill the ESD with the T0 info (will be used by the TOF)
3242  if (fReconstructor[11] && fLoader[11]) {
3243  fLoader[11]->LoadRecPoints("READ");
3244  TTree *treeR = fLoader[11]->TreeR();
3245  if (treeR) {
3246  GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
3247  }
3248  }
3249 
3250  // pass 1: TPC + ITS inwards
3251  for (Int_t iDet = 1; iDet >= 0; iDet--) {
3252  if (!fTracker[iDet]) continue;
3253  AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
3254 
3255  // load clusters
3256  fLoader[iDet]->LoadRecPoints("read");
3257  AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
3258  TTree* tree = fLoader[iDet]->TreeR();
3259  if (!tree) {
3260  AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
3261  return kFALSE;
3262  }
3263  fTracker[iDet]->LoadClusters(tree);
3264  AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
3265  // run tracking
3266  if (fTracker[iDet]->Clusters2TracksHLT(esd, fhltesd) != 0) {
3267  AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
3268  return kFALSE;
3269  }
3270  AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
3271  // preliminary PID in TPC needed by the ITS tracker
3272  if (iDet == 1) {
3273  esd->SetNumberOfTPCClusters(fTracker[iDet]->GetNumberOfClusters());
3274  GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
3275  PID.MakePIDForTracking(esd);
3276  AliSysInfo::AddStamp(Form("MakePID0%s_%d",fgkDetectorName[iDet],eventNr), iDet,4,eventNr);
3277  }
3278  }
3279 
3280  // pass 2: ALL backwards
3281 
3282  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
3283  if (!fTracker[iDet]) continue;
3284  AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
3285 
3286  // load clusters
3287  if (iDet > 1) { // all except ITS, TPC
3288  TTree* tree = NULL;
3289  fLoader[iDet]->LoadRecPoints("read");
3290  AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
3291  tree = fLoader[iDet]->TreeR();
3292  if (!tree) {
3293  AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
3294  return kFALSE;
3295  }
3296  fTracker[iDet]->LoadClusters(tree);
3297  AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
3298  }
3299 
3300  // run tracking
3301  if (iDet>1) // start filling residuals for the "outer" detectors
3302  if (fRunGlobalQA) {
3305  if (arr) {
3307  TObjArray * elem = arr[AliRecoParam::AConvert(es)];
3308  if ( elem && (! elem->At(0)) ) {
3310  if (qadm) qadm->InitRecPointsForTracker() ;
3311  }
3312  }
3313  // AliSysInfo::AddStamp(Form("QAInitResid%s_%d",fgkDetectorName[iDet],eventNr), iDet,0, eventNr);
3314  }
3315  if (fTracker[iDet]->PropagateBack(esd) != 0) {
3316  AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
3317  // return kFALSE;
3318  }
3319  AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
3320 
3321  // unload clusters
3322  if (iDet > 3) { // all except ITS, TPC, TRD and TOF
3323  fTracker[iDet]->UnloadClusters();
3324  fLoader[iDet]->UnloadRecPoints();
3325  }
3326  // updated PID in TPC needed by the ITS tracker -MI
3327  if (iDet == 1) {
3328  //GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
3329  //AliESDpid::MakePID(esd);
3330  PID.MakePIDForTracking(esd);
3331  AliSysInfo::AddStamp(Form("MakePID1%s_%d",fgkDetectorName[iDet],eventNr), iDet,4,eventNr);
3332  }
3333 
3334  }
3335  //stop filling residuals for the "outer" detectors
3337 
3338  // At this moment we decide if the friends need to be stored, since TPC stores heavy calib objects there
3340  if (!fWriteThisFriend) fesd->SetNTPCFriend2Store(0); // don't store TPC seeds
3341 
3342  // pass 3: TRD + TPC + ITS refit inwards
3343 
3344  for (Int_t iDet = 2; iDet >= 0; iDet--) {
3345  if (!fTracker[iDet]) continue;
3346  AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
3347 
3348  // run tracking
3349  if (iDet<2) // start filling residuals for TPC and ITS
3350  if (fRunGlobalQA) {
3353  if (arr) {
3355  TObjArray * elem = arr[AliRecoParam::AConvert(es)];
3356  if ( elem && (! elem->At(0)) ) {
3358  if (qadm) qadm->InitRecPointsForTracker() ;
3359  }
3360  }
3361  }
3362 
3363  if (fTracker[iDet]->RefitInward(esd) != 0) {
3364  AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
3365  // return kFALSE;
3366  }
3367  // run postprocessing
3368  if (fTracker[iDet]->PostProcess(esd) != 0) {
3369  AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
3370  // return kFALSE;
3371  }
3372  AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
3373  }
3374 
3375  // write space-points to the ESD in case alignment data output
3376  // is switched on
3378  WriteAlignmentData(esd);
3379  AliSysInfo::AddStamp(Form("WrtAlignData_%d",eventNr), 0,0, eventNr);
3380  }
3381 
3382  for (Int_t iDet = 3; iDet >= 0; iDet--) {
3383  if (!fTracker[iDet]) continue;
3384  //
3385  // RS: TPC clusters will be unloaded in the end of process event, since used in the friends calib objects
3386  // unload clusters
3387  if (iDet!=AliQAv1::kTPC) {
3388  fTracker[iDet]->UnloadClusters();
3389  AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
3390  fLoader[iDet]->UnloadRecPoints();
3391  AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
3392  }
3393  }
3394  // stop filling residuals for TPC and ITS
3396 
3397  eventNr++;
3398  return kTRUE;
3399 }
3400 
3401 //_____________________________________________________________________________
3402 Bool_t AliReconstruction::CleanESD(AliESDEvent *esd, const AliGRPRecoParam *grpRecoParam) {
3403  //
3404  // Remove the data which are not needed for the physics analysis.
3405  //
3406 
3407  Int_t nTracks=esd->GetNumberOfTracks();
3408  Int_t nV0s=esd->GetNumberOfV0s();
3409  AliInfo
3410  (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
3411  TObjArray tracks2remove;
3412  Bool_t rc=esd->Clean(&tracks2remove,grpRecoParam);
3413  if (rc) { // physically destroy removed tracks
3414  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
3415  if (!fTracker[iDet]) continue;
3416  if (fTracker[iDet]->OwnsESDObjects()) fTracker[iDet]->CleanESDTracksObjects(&tracks2remove);
3417  }
3418  tracks2remove.Delete();
3419  }
3420  nTracks=esd->GetNumberOfTracks();
3421  nV0s=esd->GetNumberOfV0s();
3422  AliInfo
3423  (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
3424 
3425  return rc;
3426 }
3427 
3428 //_____________________________________________________________________________
3429 Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
3430 {
3431 // fill the event summary data
3432 
3433  AliCodeTimerAuto("",0)
3434  static Int_t eventNr=0;
3435  TString detStr = detectors;
3436 
3437  AliSysInfo::AddStamp(Form("FillESDb%d",eventNr), -19,-19, eventNr);
3438  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
3439  if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
3440  AliReconstructor* reconstructor = GetReconstructor(iDet);
3441  if (!reconstructor) continue;
3442  AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
3443  TTree* clustersTree = NULL;
3444  if (fLoader[iDet]) {
3445  fLoader[iDet]->LoadRecPoints("read");
3446  clustersTree = fLoader[iDet]->TreeR();
3447  if (!clustersTree) {
3448  AliError(Form("Can't get the %s clusters tree",
3449  fgkDetectorName[iDet]));
3450  if (fStopOnError) return kFALSE;
3451  }
3452  }
3453  if (fRawReader && !reconstructor->HasDigitConversion()) {
3454  reconstructor->FillESD(fRawReader, clustersTree, esd);
3455  } else {
3456  TTree* digitsTree = NULL;
3457  if (fLoader[iDet]) {
3458  fLoader[iDet]->LoadDigits("read");
3459  digitsTree = fLoader[iDet]->TreeD();
3460  if (!digitsTree) {
3461  AliError(Form("Can't get the %s digits tree",
3462  fgkDetectorName[iDet]));
3463  if (fStopOnError) return kFALSE;
3464  }
3465  }
3466  reconstructor->FillESD(digitsTree, clustersTree, esd);
3467  if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
3468  }
3469  if (fLoader[iDet]) {
3470  fLoader[iDet]->UnloadRecPoints();
3471  }
3472  }
3473 
3474  if (!IsSelected("CTP", detStr)) AliDebug(10,"No CTP");
3475  if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
3476  AliError(Form("the following detectors were not found: %s",
3477  detStr.Data()));
3478  if (fStopOnError) return kFALSE;
3479  }
3480  AliSysInfo::AddStamp(Form("FillESDe%d",eventNr), -20,-20, eventNr);
3481  eventNr++;
3482  return kTRUE;
3483 }
3484 
3485 //_____________________________________________________________________________
3487 {
3488  // Reads the trigger decision which is
3489  // stored in Trigger.root file and fills
3490  // the corresponding esd entries
3491 
3492  AliCodeTimerAuto("",0)
3493 
3494  AliInfo("Filling trigger information into the ESD");
3495 
3496  if (fRawReader) {
3497  AliCTPRawStream input(fRawReader);
3498  if (!input.Next()) {
3499  AliWarning("No valid CTP (trigger) DDL raw data is found ! The trigger info is taken from the event header!");
3500  }
3501  else {
3502  if (esd->GetTriggerMask() != input.GetClassMask())
3503  AliError(Form("Invalid trigger pattern found in CTP raw-data: %llx %llx",
3504  input.GetClassMask(),esd->GetTriggerMask()));
3505  if (esd->GetTriggerMaskNext50() != input.GetClassMaskNext50())
3506  AliError(Form("Invalid trigger pattern found in CTP raw-data Next50: %llx %llx",
3507  input.GetClassMaskNext50(),esd->GetTriggerMaskNext50()));
3508  if (esd->GetOrbitNumber() != input.GetOrbitID())
3509  AliError(Form("Invalid orbit id found in CTP raw-data: %x %x",
3510  input.GetOrbitID(),esd->GetOrbitNumber()));
3511  if (esd->GetBunchCrossNumber() != input.GetBCID())
3512  AliError(Form("Invalid bunch-crossing id found in CTP raw-data: %x %x",
3513  input.GetBCID(),esd->GetBunchCrossNumber()));
3514  AliESDHeader* esdheader = esd->GetHeader();
3515  esdheader->SetL0TriggerInputs(input.GetL0Inputs());
3516  esdheader->SetL1TriggerInputs(input.GetL1Inputs());
3517  esdheader->SetL2TriggerInputs(input.GetL2Inputs());
3518  // IR
3519  // UInt_t orbit=input.GetOrbitID();
3520  for(Int_t i=0 ; i<input.GetNIRs() ; i++ ) {
3521  esdheader->AddTriggerIR(input.GetIR(i));
3522  }
3524  if (rlCTP) {
3525  rlCTP->SetL0TriggerInputs(input.GetL0Inputs());
3526  rlCTP->SetL1TriggerInputs(input.GetL1Inputs());
3527  rlCTP->SetL2TriggerInputs(input.GetL2Inputs());
3528  }
3529  }
3530  if (fIsNewRunLoader) fRunLoader->TreeCT()->Fill();
3531  }
3532  return kTRUE;
3533 }
3534 //_____________________________________________________________________________
3536 {
3537  //Scalers
3538  //fRunScalers->Print();
3540  AliTimeStamp* timestamp = new AliTimeStamp(esd->GetOrbitNumber(), esd->GetPeriodNumber(), esd->GetBunchCrossNumber());
3541  //AliTimeStamp* timestamp = new AliTimeStamp(10308000, 0, (ULong64_t)486238);
3542  AliESDHeader* esdheader = fesd->GetHeader();
3543  for(Int_t i=0;i<50;i++){
3544  if((1ull<<i) & esd->GetTriggerMask()){
3545  AliTriggerScalersESD* scalesd = fRunScalers->GetScalersForEventClass( timestamp, i+1);
3546  if(scalesd)esdheader->SetTriggerScalersRecord(scalesd);
3547  }
3548  }
3549  for(Int_t i=0;i<50;i++){
3550  if((1ull<<i) & esd->GetTriggerMaskNext50()){
3551  AliTriggerScalersESD* scalesd = fRunScalers->GetScalersForEventClass( timestamp, i+51);
3552  if(scalesd)esdheader->SetTriggerScalersRecord(scalesd);
3553  }
3554  }
3555  const AliTriggerScalersRecordESD* scalrecEvent = fRunScalers->GetScalersDeltaForEvent( timestamp);
3557  if (scalrecEvent) esdheader->SetTriggerScalersDeltaEvent(scalrecEvent);
3558  if (scalrecRun) esdheader->SetTriggerScalersDeltaRun(scalrecRun);
3559  }
3560  return kTRUE;
3561 }
3562 
3563 //_____________________________________________________________________________
3565 {
3566  //
3567  // Filling information from RawReader Header
3568  //
3569 
3570  if (!fRawReader) return kFALSE;
3571 
3572  AliInfo("Filling information from RawReader Header");
3573 
3574  esd->SetBunchCrossNumber(fRawReader->GetBCID());
3575  esd->SetOrbitNumber(fRawReader->GetOrbitID());
3576  esd->SetPeriodNumber(fRawReader->GetPeriod());
3577 
3578  esd->SetTimeStamp(fRawReader->GetTimestamp());
3579  esd->SetEventType(fRawReader->GetType());
3580 
3581  return kTRUE;
3582 }
3583 
3584 //_____________________________________________________________________________
3586 {
3587  //
3588  // Filling information from MC Header
3589  //
3590  AliHeader* headerMC = fRunLoader->GetHeader();
3591  if (!headerMC || !esd) return kFALSE;
3592 
3593  AliInfo("Filling information from MC Header");
3594  esd->SetTimeStamp(headerMC->GetTimeStamp());
3595 
3596  return kTRUE;
3597 }
3598 
3599 
3600 //_____________________________________________________________________________
3601 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
3602 {
3603 // check whether detName is contained in detectors
3604 // if yes, it is removed from detectors
3605 
3606  // check if all detectors are selected
3607  if ((detectors.CompareTo("ALL") == 0) ||
3608  detectors.BeginsWith("ALL ") ||
3609  detectors.EndsWith(" ALL") ||
3610  detectors.Contains(" ALL ")) {
3611  detectors = "ALL";
3612  return kTRUE;
3613  }
3614 
3615  // search for the given detector
3616  Bool_t result = kFALSE;
3617  if ((detectors.CompareTo(detName) == 0) ||
3618  detectors.BeginsWith(detName+" ") ||
3619  detectors.EndsWith(" "+detName) ||
3620  detectors.Contains(" "+detName+" ")) {
3621  detectors.ReplaceAll(detName, "");
3622  result = kTRUE;
3623  }
3624 
3625  // clean up the detectors string
3626  while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
3627  while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
3628  while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
3629 
3630  return result;
3631 }
3632 
3633 //_____________________________________________________________________________
3635 {
3636 // get or create the run loader
3637 
3638  if (gAlice) delete gAlice;
3639  gAlice = NULL;
3640 
3641  TFile *gafile = TFile::Open(fGAliceFileName.Data());
3642  // if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
3643  if (gafile) { // galice.root exists
3644 
3645  // check if we are in bg.embedding mode, if needed, add MCHandler
3646  TObjArray* embBKGPaths = 0;
3647  gafile->GetObject(AliStack::GetEmbeddingBKGPathsKey(),embBKGPaths);
3648  if (embBKGPaths) {
3649  AliInfo("Embedding mode autodetected");
3650  if (fMCEventHandlerExt) {
3651  AliInfo("MCEvent handler was set externally, skip internal initialization");
3652  }
3653  else {
3656  mcHandler->SetReadTR(kFALSE);
3657  SetMCEventHandler(mcHandler);
3658  }
3659  delete embBKGPaths;
3660  }
3661 
3662  gafile->Close();
3663  delete gafile;
3664 
3665  // load all base libraries to get the loader classes
3666  TString libs = gSystem->GetLibraries();
3667  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
3668  TString detName = fgkDetectorName[iDet];
3669  if (libs.Contains("lib" + detName + "base.so")) continue;
3670  gSystem->Load("lib" + detName + "base");
3671  }
3673  if (!fRunLoader) {
3674  AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
3675  CleanUp();
3676  return kFALSE;
3677  }
3678 
3679  fRunLoader->CdGAFile();
3681 
3682  //PH This is a temporary fix to give access to the kinematics
3683  //PH that is needed for the labels of ITS clusters
3686 
3687 
3688  } else { // galice.root does not exist
3689  if (!fRawReader) {
3690  AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
3691  }
3694  "recreate");
3695  if (!fRunLoader) {
3696  AliError(Form("could not create run loader in file %s",
3697  fGAliceFileName.Data()));
3698  CleanUp();
3699  return kFALSE;
3700  }
3701  fIsNewRunLoader = kTRUE;
3702  fRunLoader->MakeTree("E");
3703  fRunLoader->MakeTree("GG");
3704 
3705  if (fNumberOfEventsPerFile > 0)
3707  else
3708  fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
3709  }
3710 
3711  return kTRUE;
3712 }
3713 
3714 //_____________________________________________________________________________
3716 {
3717 // get the reconstructor object and the loader for a detector
3718 
3719  if (fReconstructor[iDet]) {
3721  const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
3722  fReconstructor[iDet]->SetRecoParam(par);
3724  }
3725  return fReconstructor[iDet];
3726  }
3727 
3728  // load the reconstructor object
3729  TPluginManager* pluginManager = gROOT->GetPluginManager();
3730  TString detName = fgkDetectorName[iDet];
3731  TString recName = "Ali" + detName + "Reconstructor";
3732 
3733  if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
3734 
3735  AliReconstructor* reconstructor = NULL;
3736  // first check if a plugin is defined for the reconstructor
3737  TPluginHandler* pluginHandler =
3738  pluginManager->FindHandler("AliReconstructor", detName);
3739  // if not, add a plugin for it
3740  if (!pluginHandler) {
3741  AliDebug(1, Form("defining plugin for %s", recName.Data()));
3742  TString libs = gSystem->GetLibraries();
3743  if (libs.Contains("lib" + detName + "base.so") ||
3744  (gSystem->Load("lib" + detName + "base") >= 0)) {
3745  pluginManager->AddHandler("AliReconstructor", detName,
3746  recName, detName + "rec", recName + "()");
3747  } else {
3748  pluginManager->AddHandler("AliReconstructor", detName,
3749  recName, detName, recName + "()");
3750  }
3751  pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
3752  }
3753  if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
3754  reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
3755  }
3756 
3757  // check if the upgrade reconstructor should be used instead of the standard one
3758  if(fUpgradeMask[iDet]) {
3759  if(reconstructor) delete reconstructor;
3760  TClass *cl = new TClass(Form("Ali%sUpgradeReconstructor",fgkDetectorName[iDet]));
3761  reconstructor = (AliReconstructor*)(cl->New());
3762  }
3763 
3764  if (reconstructor) {
3765  TObject* obj = fOptions.FindObject(detName.Data());
3766  if (obj) reconstructor->SetOption(obj->GetTitle());
3767  reconstructor->SetRunInfo(fRunInfo);
3768  reconstructor->SetHLTESD(fhltesd);
3769  reconstructor->Init();
3770  fReconstructor[iDet] = reconstructor;
3771  }
3772 
3773  // get or create the loader
3774  if (detName != "HLT") {
3775  fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
3776  if (!fLoader[iDet]) {
3779  detName, detName);
3780  // first check if a plugin is defined for the loader
3781  pluginHandler =
3782  pluginManager->FindHandler("AliLoader", detName);
3783  // if not, add a plugin for it
3784  if (!pluginHandler) {
3785  TString loaderName = "Ali" + detName + "Loader";
3786  AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
3787  pluginManager->AddHandler("AliLoader", detName,
3788  loaderName, detName + "base",
3789  loaderName + "(const char*, TFolder*)");
3790  pluginHandler = pluginManager->FindHandler("AliLoader", detName);
3791  }
3792  if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
3793  fLoader[iDet] =
3794  (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
3796  }
3797  if (!fLoader[iDet]) { // use default loader
3798  fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
3799  }
3800  if (!fLoader[iDet]) {
3801  AliWarning(Form("couldn't get loader for %s", detName.Data()));
3802  if (fStopOnError) return NULL;
3803  } else {
3804  fRunLoader->AddLoader(fLoader[iDet]);
3805  fRunLoader->CdGAFile();
3806  if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
3807  fRunLoader->Write(0, TObject::kOverwrite);
3808  }
3809  }
3810  }
3811 
3813  const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
3814  if (reconstructor) {
3815  reconstructor->SetRecoParam(par);
3816  reconstructor->SetRunInfo(fRunInfo);
3817  }
3818  }
3819  return reconstructor;
3820 }
3821 
3822 //_____________________________________________________________________________
3824 {
3825 // create the vertexer
3826 // Please note that the caller is the owner of the
3827 // vertexer
3828 
3829  AliVertexer* vertexer = NULL;
3830  AliReconstructor* itsReconstructor = GetReconstructor(0);
3831  if (itsReconstructor && ((fRunLocalReconstruction.Contains("ITS")) ||
3832  fRunTracking.Contains("ITS") || fFillESD.Contains("ITS") )) {
3833  vertexer = itsReconstructor->CreateVertexer();
3834  }
3835  if (!vertexer) {
3836  AliWarning("couldn't create a vertexer for ITS");
3837  }
3838 
3839  return vertexer;
3840 }
3841 
3842 //_____________________________________________________________________________
3844 {
3845 // create the ITS trackleter for mult. estimation
3846 // Please note that the caller is the owner of the
3847 // trackleter
3848 
3849  AliTrackleter* trackleter = NULL;
3850  AliReconstructor* itsReconstructor = GetReconstructor(0);
3851  if (itsReconstructor && ((fRunLocalReconstruction.Contains("ITS")) ||
3852  fRunTracking.Contains("ITS") || fFillESD.Contains("ITS") )) {
3853  trackleter = itsReconstructor->CreateMultFinder();
3854  }
3855  else {
3856  AliWarning("ITS is not in reconstruction, switching off RunMultFinder");
3857  fRunMultFinder = kFALSE;
3858  }
3859 
3860  return trackleter;
3861 }
3862 
3863 //_____________________________________________________________________________
3864 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
3865 {
3866 // create the trackers
3867  AliInfo("Creating trackers");
3868 
3869  TString detStr = detectors;
3870  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
3871  if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
3872  AliReconstructor* reconstructor = GetReconstructor(iDet);
3873  if (!reconstructor) continue;
3874  TString detName = fgkDetectorName[iDet];
3875  if (detName == "MUON") {
3876  fRunMuonTracking = kTRUE;
3877  continue;
3878  }
3879  if (detName == "MFT") { // AU
3880  fRunMFTTrackingMU = kTRUE; // AU
3881  continue; // AU
3882  } // AU
3883 
3884  fTracker[iDet] = reconstructor->CreateTracker();
3885  if (!fTracker[iDet] && (iDet < 7)) {
3886  AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
3887  if (fStopOnError) return kFALSE;
3888  }
3889  AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
3890  }
3891 
3892  return kTRUE;
3893 }
3894 
3895 //_____________________________________________________________________________
3897 {
3898 // delete trackers and the run loader and close and delete the file
3899  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
3900  if (fReconstructor[iDet]) fReconstructor[iDet]->SetRecoParam(NULL);
3901  delete fReconstructor[iDet];
3902  fReconstructor[iDet] = NULL;
3903  fLoader[iDet] = NULL;
3904  delete fTracker[iDet];
3905  fTracker[iDet] = NULL;
3906  }
3907 
3908  delete fRunInfo;
3909  fRunInfo = NULL;
3910 
3911  delete fSPDTrackleter;
3912  fSPDTrackleter = NULL;
3913 
3914  delete ftVertexer;
3915  ftVertexer = NULL;
3916 
3917  delete fRunLoader;
3918  fRunLoader = NULL;
3919  delete fRawReader;
3920  fRawReader = NULL;
3921  delete fParentRawReader;
3922  fParentRawReader=NULL;
3923 
3924  delete fESDpid;
3925  fESDpid = NULL;
3926 
3927  if (ffile) {
3928  ffile->Close();
3929  delete ffile;
3930  ffile = NULL;
3931  }
3932 
3935  // AliQAManager::Destroy() ;
3936  delete fAnalysis;
3937  fAnalysis = NULL;
3938 }
3939 
3941 {
3942  // Write space-points which are then used in the alignment procedures
3943  // For the moment only ITS, TPC, TRD and TOF
3944  if (!fWriteThisFriend) {
3945  AliInfo("Will not write alignment data since the friends are not stored");
3946  return;
3947  }
3948  Int_t ntracks = esd->GetNumberOfTracks();
3949  for (Int_t itrack = 0; itrack < ntracks; itrack++)
3950  {
3951  AliESDtrack *track = esd->GetTrack(itrack);
3952  if (track->GetFriendNotStored()) continue; // no need of alignment data for friends which are not stored
3953  Int_t nsp = 0;
3954  Int_t idx[200];
3955  for (Int_t i=0; i<200; ++i) idx[i] = -1; //PH avoid uninitialized values
3956  for (Int_t iDet = 5; iDet >= 0; iDet--) {// TOF, TRD, TPC, ITS clusters
3957  nsp += (iDet==GetDetIndex("TRD")) ? track->GetTRDntracklets():track->GetNcls(iDet);
3958 
3959  if (iDet==GetDetIndex("ITS")) { // ITS "extra" clusters
3960  track->GetClusters(iDet,idx);
3961  for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nsp++;
3962  }
3963  }
3964 
3965  if (nsp) {
3966  AliTrackPointArray *sp = new AliTrackPointArray(nsp);
3967  track->SetTrackPointArray(sp);
3969  Int_t isptrack = 0;
3970  for (Int_t iDet = 5; iDet >= 0; iDet--) {
3971  AliTracker *tracker = fTracker[iDet];
3972  if (!tracker) continue;
3973  Int_t nspdet = (iDet==GetDetIndex("TRD")) ? track->GetTRDtracklets(idx):track->GetClusters(iDet,idx);
3974 
3975  if (iDet==GetDetIndex("ITS")) // ITS "extra" clusters
3976  for (Int_t i=6; i<12; i++) if(idx[i] >= 0) nspdet++;
3977 
3978  if (nspdet <= 0) continue;
3979  AliTrackPoint p;
3980  Int_t isp = 0;
3981  Int_t isp2 = 0;
3982  while (isp2 < nspdet) {
3983  Bool_t isvalid=kTRUE;
3984 
3985  Int_t index=idx[isp++];
3986  if (index < 0) continue;
3987 
3988  TString dets = fgkDetectorName[iDet];
3989  if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
3990  fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
3991  fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
3992  fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
3993  isvalid = tracker->GetTrackPointTrackingError(index,p,track);
3994  } else {
3995  isvalid = tracker->GetTrackPoint(index,p);
3996  }
3997  isp2++;
3998  if (!isvalid) continue;
3999  if (iDet==GetDetIndex("ITS") && (isp-1)>=6) p.SetExtra();
4000  sp->AddPoint(isptrack,&p); isptrack++;
4001  }
4002  }
4003  }
4004  }
4005 }
4006 
4007 //_____________________________________________________________________________
4009 {
4010  // The method reads the raw-data error log
4011  // accumulated within the rawReader.
4012  // It extracts the raw-data errors related to
4013  // the current event and stores them into
4014  // a TClonesArray inside the esd object.
4015 
4016  if (!fRawReader) return;
4017 
4018  for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
4019 
4020  AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
4021  if (!log) continue;
4022  if (iEvent != log->GetEventNumber()) continue;
4023 
4024  esd->AddRawDataErrorLog(log);
4025  }
4026 
4027 }
4028 
4029 //_____________________________________________________________________________
4030 // void AliReconstruction::CheckQA()
4031 // {
4032 // check the QA of SIM for this run and remove the detectors
4033 // with status Fatal
4034 
4035 // TString newRunLocalReconstruction ;
4036 // TString newRunTracking ;
4037 // TString newFillESD ;
4038 //
4039 // for (Int_t iDet = 0; iDet < AliQAv1::kNDET; iDet++) {
4040 // TString detName(AliQAv1::GetDetName(iDet)) ;
4041 // AliQAv1 * qa = AliQAv1::Instance(AliQAv1::DETECTORINDEX_t(iDet)) ;
4042 // if ( qa->IsSet(AliQAv1::DETECTORINDEX_t(iDet), AliQAv1::kSIM, specie, AliQAv1::kFATAL)) {
4043 // AliInfo(Form("QA status for %s %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed",
4044 // detName.Data(), AliRecoParam::GetEventSpecieName(es))) ;
4045 // } else {
4046 // if ( fRunLocalReconstruction.Contains(AliQAv1::GetDetName(iDet)) ||
4047 // fRunLocalReconstruction.Contains("ALL") ) {
4048 // newRunLocalReconstruction += detName ;
4049 // newRunLocalReconstruction += " " ;
4050 // }
4051 // if ( fRunTracking.Contains(AliQAv1::GetDetName(iDet)) ||
4052 // fRunTracking.Contains("ALL") ) {
4053 // newRunTracking += detName ;
4054 // newRunTracking += " " ;
4055 // }
4056 // if ( fFillESD.Contains(AliQAv1::GetDetName(iDet)) ||
4057 // fFillESD.Contains("ALL") ) {
4058 // newFillESD += detName ;
4059 // newFillESD += " " ;
4060 // }
4061 // }
4062 // }
4063 // fRunLocalReconstruction = newRunLocalReconstruction ;
4064 // fRunTracking = newRunTracking ;
4065 // fFillESD = newFillESD ;
4066 // }
4067 
4068 //_____________________________________________________________________________
4069 Int_t AliReconstruction::GetDetIndex(const char* detector)
4070 {
4071  // return the detector index corresponding to detector
4072  Int_t index = -1 ;
4073  for (index = 0; index < kNDetectors ; index++) {
4074  if ( strcmp(detector, fgkDetectorName[index]) == 0 )
4075  break ;
4076  }
4077  return index ;
4078 }
4079 //_____________________________________________________________________________
4081  //
4082  // Here execute all the necessary operationis, at the end of the tracking phase,
4083  // in case that evaluation of PlaneEfficiencies was required for some detector.
4084  // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
4085  //
4086  // This Preliminary version works only FOR ITS !!!!!
4087  // other detectors (TOF,TRD, etc. have to develop their specific codes)
4088  //
4089  // Input: none
4090  // Return: kTRUE if all operations have been done properly, kFALSE otherwise
4091  //
4092  Bool_t ret=kFALSE;
4093  TString detStr = fLoadCDB;
4094  //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4095  for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
4096  if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
4097  if(fTracker[iDet] && fTracker[iDet]->GetPlaneEff()) {
4098  AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
4099  TString name=planeeff->GetName();
4100  name+=".root";
4101  TFile* pefile = TFile::Open(name, "RECREATE");
4102  ret=(Bool_t)planeeff->Write();
4103  pefile->Close();
4104  if(planeeff->GetCreateHistos()) {
4105  TString hname=planeeff->GetName();
4106  hname+="Histo.root";
4107  ret*=planeeff->WriteHistosToFile(hname,"RECREATE");
4108  }
4109  }
4110  if(fSPDTrackleter) {
4111  AliPlaneEff *planeeff=fSPDTrackleter->GetPlaneEff();
4112  TString name="AliITSPlaneEffSPDtracklet.root";
4113  TFile* pefile = TFile::Open(name, "RECREATE");
4114  ret=(Bool_t)planeeff->Write();
4115  pefile->Close();
4116  AliESDEvent *dummy=NULL;
4117  ret=(Bool_t)fSPDTrackleter->PostProcess(dummy); // take care of writing other files
4118  }
4119  }
4120  return ret;
4121 }
4122 //_____________________________________________________________________________
4124 //
4125  // Here execute all the necessary operations, before of the tracking phase,
4126  // for the evaluation of PlaneEfficiencies, in case required for some detectors.
4127  // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
4128  // which should be updated/recalculated.
4129  //
4130  // This Preliminary version will work only FOR ITS !!!!!
4131  // other detectors (TOF,TRD, etc. have to develop their specific codes)
4132  //
4133  // Input: none
4134  // Return: kTRUE if all operations have been done properly, kFALSE otherwise
4135  //
4136 
4137  fSPDTrackleter = NULL;
4138  TString detStr = fLoadCDB;
4139  if (IsSelected(fgkDetectorName[0], detStr)) {
4140  AliReconstructor* itsReconstructor = GetReconstructor(0);
4141  if (itsReconstructor) {
4142  fSPDTrackleter = itsReconstructor->CreateTrackleter(); // this is NULL unless required in RecoParam
4143  }
4144  if (fSPDTrackleter) {
4145  AliInfo("Trackleter for SPD has been created");
4146  }
4147  }
4148  return kTRUE;
4149 }
4150 
4151 //_____________________________________________________________________________
4153 {
4154  // This method should be called only in case
4155  // AliReconstruction is run
4156  // within the alieve environment.
4157  // It will initialize AliEVE in a way
4158  // so that it can visualize event processed
4159  // by AliReconstruction.
4160  // The return flag shows whenever the
4161  // AliEVE initialization was successful or not.
4162 
4163  TString macroStr(getenv("ALIEVE_ONLINE_MACRO"));
4164 
4165  if (macroStr.IsNull())
4166  macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
4167 
4168  AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
4169 
4170  if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
4171 
4172  gROOT->ProcessLine("if (!AliEveEventManager::GetMaster()){new AliEveEventManager();AliEveEventManager::GetMaster()->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(AliEveEventManager::GetMaster());};");
4173  gROOT->ProcessLine("alieve_online_init()");
4174 
4175  return kTRUE;
4176 }
4177 
4178 //_____________________________________________________________________________
4180 {
4181  // Runs AliEVE visualisation of
4182  // the current event.
4183  // Should be executed only after
4184  // successful initialization of AliEVE.
4185 
4186  AliInfo("Running AliEVE...");
4187  gROOT->ProcessLine(Form("AliEveEventManager::GetMaster()->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p,(AliESDfriend*)%p);",fRunLoader,fRawReader,fesd,fesdf));
4188  gSystem->Run();
4189 }
4190 
4191 //_____________________________________________________________________________
4192 Bool_t AliReconstruction::SetRunQA(TString detAndAction)
4193 {
4194  // Allows to run QA for a selected set of detectors
4195  // and a selected set of tasks among RAWS, DIGITSR, RECPOINTS and ESDS
4196  // all selected detectors run the same selected tasks
4197 
4198  if (!detAndAction.Contains(":")) {
4199  AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
4200  fRunQA = kFALSE ;
4201  return kFALSE ;
4202  }
4203  Int_t colon = detAndAction.Index(":") ;
4204  fQADetectors = detAndAction(0, colon) ;
4205  fQATasks = detAndAction(colon+1, detAndAction.Length() ) ;
4206  if (fQATasks.Contains("ALL") ) {
4208  } else {
4209  fQATasks.ToUpper() ;
4210  TString tempo("") ;
4211  if ( fQATasks.Contains("RAW") )
4212  tempo = Form("%d ", AliQAv1::kRAWS) ;
4213  if ( fQATasks.Contains("DIGIT") )
4214  tempo += Form("%d ", AliQAv1::kDIGITSR) ;
4215  if ( fQATasks.Contains("RECPOINT") )
4216  tempo += Form("%d ", AliQAv1::kRECPOINTS) ;
4217  if ( fQATasks.Contains("ESD") )
4218  tempo += Form("%d ", AliQAv1::kESDS) ;
4219  fQATasks = tempo ;
4220  if (fQATasks.IsNull()) {
4221  AliInfo("No QA requested\n") ;
4222  fRunQA = kFALSE ;
4223  return kTRUE ;
4224  }
4225  }
4226  TString tempo(fQATasks) ;
4227  tempo.ReplaceAll(Form("%d", AliQAv1::kRAWS), AliQAv1::GetTaskName(AliQAv1::kRAWS)) ;
4228  tempo.ReplaceAll(Form("%d", AliQAv1::kDIGITSR), AliQAv1::GetTaskName(AliQAv1::kDIGITSR)) ;
4229  tempo.ReplaceAll(Form("%d", AliQAv1::kRECPOINTS), AliQAv1::GetTaskName(AliQAv1::kRECPOINTS)) ;
4230  tempo.ReplaceAll(Form("%d", AliQAv1::kESDS), AliQAv1::GetTaskName(AliQAv1::kESDS)) ;
4231  AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
4232  fRunQA = kTRUE ;
4233  return kTRUE;
4234 }
4235 
4236 //_____________________________________________________________________________
4238 {
4239  // The method accesses OCDB and retrieves all
4240  // the available reco-param objects from there.
4241 
4242  Bool_t isOK = kTRUE;
4243 
4245  AliInfo("Using custom GRP reconstruction parameters");
4246  }
4247  else {
4248  AliInfo("Loading GRP reconstruction parameter objects");
4249 
4250  AliCDBPath path("GRP","Calib","RecoParam");
4251  AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
4252  if(!entry){
4253  AliWarning("Couldn't find GRP RecoParam entry in OCDB");
4254  isOK = kFALSE;
4255  }
4256  else {
4257  TObject *recoParamObj = entry->GetObject();
4258  if (dynamic_cast<TObjArray*>(recoParamObj)) {
4259  // GRP has a normal TobjArray of AliDetectorRecoParam objects
4260  // Registering them in AliRecoParam
4261  fRecoParam.AddDetRecoParamArray(kNDetectors,dynamic_cast<TObjArray*>(recoParamObj));
4262  }
4263  else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
4264  // GRP has only onse set of reco parameters
4265  // Registering it in AliRecoParam
4266  AliInfo("Single set of GRP reconstruction parameters found");
4267  dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
4268  fRecoParam.AddDetRecoParam(kNDetectors,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
4269  }
4270  else {
4271  AliError("No valid GRP RecoParam object found in the OCDB");
4272  isOK = kFALSE;
4273  }
4274  entry->SetOwner(0);
4275  }
4276  }
4277 
4278  TString detStr = fLoadCDB;
4279  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
4280 
4281  if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
4282 
4283  if (fRecoParam.GetDetRecoParamArray(iDet)) {
4284  AliInfo(Form("Using custom reconstruction parameters for detector %s",fgkDetectorName[iDet]));
4285  continue;
4286  }
4287 
4288  AliInfo(Form("Loading reconstruction parameter objects for detector %s",fgkDetectorName[iDet]));
4289 
4290  AliCDBPath path(fgkDetectorName[iDet],"Calib","RecoParam");
4291  AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
4292  if(!entry){
4293  AliWarning(Form("Couldn't find RecoParam entry in OCDB for detector %s",fgkDetectorName[iDet]));
4294  isOK = kFALSE;
4295  }
4296  else {
4297  TObject *recoParamObj = entry->GetObject();
4298  if (dynamic_cast<TObjArray*>(recoParamObj)) {
4299  // The detector has a normal TobjArray of AliDetectorRecoParam objects
4300  // Registering them in AliRecoParam
4301  fRecoParam.AddDetRecoParamArray(iDet,dynamic_cast<TObjArray*>(recoParamObj));
4302  }
4303  else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
4304  // The detector has only onse set of reco parameters
4305  // Registering it in AliRecoParam
4306  AliInfo(Form("Single set of reconstruction parameters found for detector %s",fgkDetectorName[iDet]));
4307  dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
4308  fRecoParam.AddDetRecoParam(iDet,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
4309  }
4310  else {
4311  AliError(Form("No valid RecoParam object found in the OCDB for detector %s",fgkDetectorName[iDet]));
4312  isOK = kFALSE;
4313  }
4314  entry->SetOwner(0);
4315  // FIX ME: We have to disable the unloading of reco-param CDB
4316  // entries because QA framework is using them. Has to be fix in
4317  // a way that the QA takes the objects already constructed in
4318  // this method.
4319  // AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
4320  }
4321  }
4322 
4323  if (AliDebugLevel() > 0) fRecoParam.Print();
4324 
4325  return isOK;
4326 }
4327 
4328 //_____________________________________________________________________________
4330 {
4331  // Fill the event info object
4332  // ...
4333  AliCodeTimerAuto("",0)
4334 
4335  AliCentralTrigger *aCTP = NULL;
4336  fEventInfo.Reset();
4337  if (fRawReader) {
4338  fEventInfo.SetEventType(fRawReader->GetType());
4339 
4340  ULong64_t mask = fRawReader->GetClassMask();
4341  ULong64_t maskNext50 = fRawReader->GetClassMaskNext50();
4342  fEventInfo.SetTriggerMask(mask);
4343  fEventInfo.SetTriggerMaskNext50(maskNext50);
4344  UInt_t clmask = fRawReader->GetDetectorPattern()[0];
4346 
4347  aCTP = new AliCentralTrigger();
4348  TString configstr("");
4349  if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
4350  AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
4351  delete aCTP;
4352  return kFALSE;
4353  }
4354  aCTP->SetClassMask(mask);
4355  aCTP->SetClusterMask(clmask);
4356 
4357  if (fRunLoader) {
4359  if (rlCTP) {
4360  rlCTP->SetClassMask(mask);
4361  rlCTP->SetClusterMask(clmask);
4362  }
4363  }
4364  }
4365  else {
4366  fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
4367  if (fRunLoader && (!fRunLoader->LoadTrigger())) {
4368  aCTP = fRunLoader->GetTrigger();
4371  // get inputs from actp - just get
4372  AliESDHeader* esdheader = fesd->GetHeader();
4373  esdheader->SetL0TriggerInputs(aCTP->GetL0TriggerInputs());
4374  esdheader->SetL1TriggerInputs(aCTP->GetL1TriggerInputs());
4375  esdheader->SetL2TriggerInputs(aCTP->GetL2TriggerInputs());
4377  }
4378  else {
4379  if (fStopOnMissingTriggerFile) AliFatal("No trigger can be loaded! Stopping reconstruction!");
4380  AliWarning("No trigger can be loaded! The trigger information will not be used!");
4381  return kFALSE;
4382  }
4383  }
4384 
4385  AliTriggerConfiguration *config = aCTP->GetConfiguration();
4386  if (!config) {
4387  AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
4388  if (fRawReader) delete aCTP;
4389  return kFALSE;
4390  }
4391  UChar_t clustmask = 0;
4392  TString trclasses;
4393  ULong64_t trmask = fEventInfo.GetTriggerMask();
4394  ULong64_t trmaskNext50 = fEventInfo.GetTriggerMaskNext50();
4395  const TObjArray& classesArray = config->GetClasses();
4396  Int_t nclasses = classesArray.GetEntriesFast();
4397  for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
4398  AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
4399  Int_t trindex = trclass->GetIndex()-1;
4400  if (fesd) fesd->SetTriggerClass(trclass->GetName(),trindex);
4401  Bool_t match = trindex<50 ? (trmask & (1ull << trindex)) : (trmaskNext50 & (1ull << (trindex-50)));
4402  if (!match) continue;
4403  trclasses += " ";
4404  trclasses += trclass->GetName();
4405  trclasses += " ";
4406  clustmask |= trclass->GetCluster()->GetClusterMask();
4407  if (TriggerMatches2Alias(trclass->GetName(),fCosmicAlias)) fEventInfo.SetCosmicTrigger(kTRUE);
4408  else if (TriggerMatches2Alias(trclass->GetName(),fLaserAlias)) fEventInfo.SetCalibLaserTrigger(kTRUE);
4409  else fEventInfo.SetBeamTrigger(kTRUE);
4410  }
4411  fEventInfo.SetTriggerClasses(trclasses);
4412 
4413  // Write names of active trigger inputs in ESD Header
4414  const TObjArray& inputsArray = config->GetInputs();
4415  Int_t ninputs = inputsArray.GetEntriesFast();
4416  for( Int_t iinput=0; iinput < ninputs; iinput++ ) {
4417  AliTriggerInput* trginput = (AliTriggerInput*)inputsArray.At(iinput);
4418  if (trginput && trginput->GetMask()>0) {
4419  Int_t inputIndex = (Int_t)TMath::Nint(TMath::Log2(trginput->GetMask()));
4420  AliESDHeader* headeresd = 0x0;
4421  if (fesd) headeresd = fesd->GetHeader();
4422  if (headeresd) {
4423  Int_t trglevel = (Int_t)trginput->GetLevel();
4424  if (trglevel == 0) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex);
4425  if (trglevel == 1) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+24);
4426  if (trglevel == 2) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+48);
4427  }
4428  }
4429  }
4430 
4431  // Set the information in ESD
4432  if (fesd) {
4433  fesd->SetTriggerMask(trmask);
4434  fesd->SetTriggerMaskNext50(trmaskNext50);
4435  fesd->SetTriggerCluster(clustmask);
4436  }
4437 
4438  if (!aCTP->CheckTriggeredDetectors()) {
4439  if (fRawReader) delete aCTP;
4440  return kFALSE;
4441  }
4442 
4443  if (fRawReader) delete aCTP;
4444 
4445  // We have to fill also the HLT decision here!!
4446  // ...
4447  // check if event has cosmic or laser alias
4448 
4449 
4450  return kTRUE;
4451 }
4452 
4453 const char *AliReconstruction::MatchDetectorList(const char *detectorList, UInt_t detectorMask)
4454 {
4455  // Match the detector list found in the rec.C or the default 'ALL'
4456  // to the list found in the GRP (stored there by the shuttle PP which
4457  // gets the information from ECS)
4458  static TString resultList;
4459  TString detList = detectorList;
4460 
4461  resultList = "";
4462 
4463  for(Int_t iDet = 0; iDet < (AliDAQ::kNDetectors-1); iDet++) {
4464  if ((detectorMask >> iDet) & 0x1) {
4465  TString det = AliDAQ::OfflineModuleName(iDet);
4466  if ((detList.CompareTo("ALL") == 0) ||
4467  ((detList.BeginsWith("ALL ") ||
4468  detList.EndsWith(" ALL") ||
4469  detList.Contains(" ALL ")) &&
4470  !(detList.BeginsWith("-"+det+" ") ||
4471  detList.EndsWith(" -"+det) ||
4472  detList.Contains(" -"+det+" "))) ||
4473  (detList.CompareTo(det) == 0) ||
4474  detList.BeginsWith(det+" ") ||
4475  detList.EndsWith(" "+det) ||
4476  detList.Contains( " "+det+" " )) {
4477  if (!resultList.EndsWith(det + " ")) {
4478  resultList += det;
4479  resultList += " ";
4480  }
4481  }
4482  }
4483  }
4484 
4485  // HLT
4486  if ((detectorMask >> AliDAQ::kHLTId) & 0x1) {
4487  TString hltDet = AliDAQ::OfflineModuleName(AliDAQ::kNDetectors-1);
4488  if ((detList.CompareTo("ALL") == 0) ||
4489  ((detList.BeginsWith("ALL ") ||
4490  detList.EndsWith(" ALL") ||
4491  detList.Contains(" ALL ")) &&
4492  !(detList.BeginsWith("-"+hltDet+" ") ||
4493  detList.EndsWith(" -"+hltDet) ||
4494  detList.Contains(" -"+hltDet+" "))) ||
4495  (detList.CompareTo(hltDet) == 0) ||
4496  detList.BeginsWith(hltDet+" ") ||
4497  detList.EndsWith(" "+hltDet) ||
4498  detList.Contains( " "+hltDet+" " )) {
4499  resultList += hltDet;
4500  }
4501  }
4502 
4503  return resultList.Data();
4504 
4505 }
4506 
4507 //______________________________________________________________________________
4508 void AliReconstruction::Abort(const char *method, EAbort what)
4509 {
4510  // Abort processing. If what = kAbortProcess, the Process() loop will be
4511  // aborted. If what = kAbortFile, the current file in a chain will be
4512  // aborted and the processing will continue with the next file, if there
4513  // is no next file then Process() will be aborted. Abort() can also be
4514  // called from Begin(), SlaveBegin(), Init() and Notify(). After abort
4515  // the SlaveTerminate() and Terminate() are always called. The abort flag
4516  // can be checked in these methods using GetAbort().
4517  //
4518  // The method is overwritten in AliReconstruction for better handling of
4519  // reco specific errors
4520 
4521  if (!fStopOnError) return;
4522 
4523  CleanUp();
4524 
4525  TString whyMess = method;
4526  whyMess += " failed! Aborting...";
4527 
4528  AliError(whyMess.Data());
4529 
4530  fAbort = what;
4531  TString mess = "Abort";
4532  if (fAbort == kAbortProcess)
4533  mess = "AbortProcess";
4534  else if (fAbort == kAbortFile)
4535  mess = "AbortFile";
4536 
4537  Info(mess.Data(), "%s", whyMess.Data());
4538 }
4539 
4540 //______________________________________________________________________________
4542 {
4543  // Method that is used in case the event loop
4544  // is steered from outside, for example by AMORE
4545  // 'event' is a pointer to the DATE event in the memory
4546 
4547  if (fRawReader) delete fRawReader;
4548  fRawReader = new AliRawReaderDate(event);
4549  fStatus = ProcessEvent(fRunLoader->GetNumberOfEvents());
4550  delete fRawReader;
4551  fRawReader = NULL;
4552 
4553  return fStatus;
4554 }
4555 
4556 //______________________________________________________________________________
4558 {
4559  // The method parses the output file
4560  // location string in order to steer
4561  // properly the selector
4562 
4563  TPMERegexp re1("(\\w+\\.zip#\\w+\\.root):([,*\\w+\\.root,*]+)@dataset://(\\w++)");
4564  TPMERegexp re2("(\\w+\\.root)?@?dataset://(\\w++)");
4565 
4566  if (re1.Match(fESDOutput) == 4) {
4567  // root archive with output files stored and regustered
4568  // in proof dataset
4569  gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",re1[1].Data()));
4570  gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",re1[3].Data()));
4571  gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_DATASET",""));
4572  gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_ARCHIVE",re1[2].Data()));
4573  AliInfo(Form("%s files will be stored within %s in dataset %s",
4574  re1[2].Data(),
4575  re1[1].Data(),
4576  re1[3].Data()));
4577  }
4578  else if (re2.Match(fESDOutput) == 3) {
4579  // output file stored and registered
4580  // in proof dataset
4581  gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",(re2[1].IsNull()) ? "AliESDs.root" : re2[1].Data()));
4582  gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",re2[2].Data()));
4583  gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_DATASET",""));
4584  AliInfo(Form("%s will be stored in dataset %s",
4585  (re2[1].IsNull()) ? "AliESDs.root" : re2[1].Data(),
4586  re2[2].Data()));
4587  }
4588  else {
4589  if (fESDOutput.IsNull()) {
4590  // Output location not given.
4591  // Assuming xrootd has been already started and
4592  // the output file has to be sent back
4593  // to the client machine
4594  TString esdUrl(Form("root://%s/%s/",
4595  TUrl(gSystem->HostName()).GetHostFQDN(),
4596  gSystem->pwd()));
4597  gProof->AddInput(new TNamed("PROOF_OUTPUTFILE","AliESDs.root"));
4598  gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",esdUrl.Data()));
4599  AliInfo(Form("AliESDs.root will be stored in %s",
4600  esdUrl.Data()));
4601  }
4602  else {
4603  // User specified an output location.
4604  // Ones has just to parse it here
4605  TUrl outputUrl(fESDOutput.Data());
4606  TString outputFile(gSystem->BaseName(outputUrl.GetFile()));
4607  gProof->AddInput(new TNamed("PROOF_OUTPUTFILE",outputFile.IsNull() ? "AliESDs.root" : outputFile.Data()));
4608  TString outputLocation(outputUrl.GetUrl());
4609  outputLocation.ReplaceAll(outputFile.Data(),"");
4610  gProof->AddInput(new TNamed("PROOF_OUTPUTFILE_LOCATION",outputLocation.Data()));
4611  AliInfo(Form("%s will be stored in %s",
4612  outputFile.IsNull() ? "AliESDs.root" : outputFile.Data(),
4613  outputLocation.Data()));
4614  }
4615  }
4616 
4617  return kTRUE;
4618 }
4619 
4620 //______________________________________________________________________________
4622  // Selection of events containing "high" pT tracks
4623  // If at least one track is found within 1.5 and 100 GeV (pT)
4624  // that was reconstructed by both ITS and TPC, the event is accepted
4625 
4626  // Track cuts
4627  const Double_t pTmin = 1.5;
4628  const Double_t pTmax = 100;
4629  ULong_t mask = 0;
4630  // mask |= (AliESDtrack::kITSrefit);
4631  // mask |= (AliESDtrack::kTPCrefit);
4632  mask |= (AliESDtrack::kITSin);
4633  mask |= (AliESDtrack::kTPCin);
4634  const Double_t pTminCosmic = 5.;
4635  const Double_t pTmaxCosmic = 100;
4636  ULong_t maskCosmic = 0;
4637  Int_t cosmicCount=0;
4638  // maskCosmic |= (AliESDtrack::kTPCrefit);
4639  maskCosmic |= (AliESDtrack::kTPCin);
4640 
4641  Bool_t isOK = kFALSE;
4642 
4643  if (fesd && fesd->GetEventType()==AliRawEventHeaderBase::kPhysicsEvent) {
4644  // Check if this ia a physics event (code 7)
4645  Int_t ntrk = fesd->GetNumberOfTracks();
4646  for (Int_t itrk=0; itrk<ntrk; ++itrk) {
4647 
4648  AliESDtrack * trk = fesd->GetTrack(itrk);
4649  if (trk
4650  && trk->Pt() > pTmin
4651  && trk->Pt() < pTmax
4652  && (trk->GetStatus() & mask) == mask ) {
4653 
4654  isOK = kTRUE;
4655  break;
4656  }
4657  if (trk
4658  && trk->GetInnerParam()
4659  && trk->GetInnerParam()->Pt() > pTminCosmic
4660  && trk->GetInnerParam()->Pt() < pTmaxCosmic
4661  && (trk->GetStatus() & maskCosmic) == maskCosmic ) {
4662 
4663  cosmicCount++;
4664  break;
4665  }
4666  }
4667  if (cosmicCount>1) isOK=kTRUE;
4668  }
4669  return isOK;
4670 }
4671 
4672 //______________________________________________________________________________
4674  // Select cosmic or calibration events
4675 
4676  Bool_t isOK = kFALSE;
4677 
4678  if (fesd && fesd->GetEventType()==AliRawEventHeaderBase::kPhysicsEvent) {
4679  // Check if this ia a physics event (code 7)
4680 
4681  UInt_t specie = fesd->GetEventSpecie();
4682  if (specie==AliRecoParam::kCosmic || specie==AliRecoParam::kCalib) {
4683  isOK = kTRUE;
4684  }
4685  }
4686  return isOK;
4687 }
4688 
4689 
4690 //______________________________________________________________________________
4692 {
4693  // destroy friends taking care to release objects eventually owned by detectors
4694  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
4695  if (!fTracker[iDet]) continue;
4696  if (fTracker[iDet]->OwnsESDObjects()) fTracker[iDet]->CleanESDFriendsObjects(fesd);
4697  }
4698  //
4699  if (!fesdf) return;
4700  // RS now friends for writing contain shallow copy of non-persistent friend tracks of AliESDtracks
4701  fesdf->ResetSoft(); // soft reset: Tracks are Cleared rather then Deleted
4702  // fesdf->~AliESDfriend();
4703  // new (fesdf) AliESDfriend(); // Reset...
4704 }
4705 
4706 //______________________________________________________________________________
4708 {
4709  // Fill the ESD friend in the tree.
4710  if (!fWriteThisFriend) ftreeF->SetBranchAddress("ESDfriend.",&fesdfDummy);
4711  //
4712  Long64_t nbf = ftreeF->Fill();
4713  if (fTreeBuffSize>0 && ftreeF->GetAutoFlush()<0 && (fMemCountESDF += nbf)>fTreeBuffSize ) { // default limit is still not reached
4714  nbf = ftreeF->GetZipBytes();
4715  if (nbf>0) nbf = -nbf;
4716  else nbf = ftreeF->GetEntries();
4717  ftreeF->SetAutoFlush(nbf);
4718  AliInfo(Form("Calling ftreeF->SetAutoFlush(%lld) | W:%lld T:%lld Z:%lld",
4719  nbf,fMemCountESDF,ftreeF->GetTotBytes(),ftreeF->GetZipBytes()));
4720  }
4721  if (!fWriteThisFriend) ftreeF->SetBranchAddress("ESDfriend.",&fesdf); // restore real friend
4722 }
4723 
4724 //_________________________________________________________________
4725 void AliReconstruction::DeleteDigits(const TString& detectors)
4726 {
4727  // delete requested digit files produced at current event
4728  static int iEvent = 0;
4729  if (detectors.IsNull()) return;
4730  TString detStr = detectors;
4731  AliInfo(Form("Deleting Digits: %s",detectors.Data()));
4732 
4733  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
4734  if(!IsSelected(fgkDetectorName[iDet], detStr)) continue;
4735  unlink(Form("%s.Digits.root",fgkDetectorName[iDet]));
4736  }
4737  AliSysInfo::AddStamp(Form("DelDigits_%d",iEvent), 0,0,iEvent);
4738  iEvent++;
4739 }
4740 
4741 //_________________________________________________________________
4742 void AliReconstruction::DeleteRecPoints(const TString& detectors)
4743 {
4744  // delete requested recpoint files produced at current event
4745  static int iEvent = 0;
4746  if (detectors.IsNull()) return;
4747  TString detStr = detectors;
4748  AliInfo(Form("Deleting Recpoints: %s",detectors.Data()));
4749  //
4750  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
4751  if(!IsSelected(fgkDetectorName[iDet], detStr)) continue;
4752  unlink(Form("%s.RecPoints.root",fgkDetectorName[iDet]));
4753  }
4754  AliSysInfo::AddStamp(Form("DelRecPoints_%d",iEvent), 0,0,iEvent);
4755  iEvent++;
4756 }
4757 
4758 //_________________________________________________________________
4760 {
4761  // require checking the resources left and stopping on excess
4762  // if 0 : no check is done
4763  // if >0 : stop reconstruction if exceeds this value
4764  // if <0 : use as margin to system limits
4765  //
4766  const int kKB2MB = 1024;
4767  const int kInfMem = 9999999;
4768  //
4769  struct rlimit r;
4770  int pgSize = getpagesize();
4771  //
4772  if (vRSS>0) {
4773  fMaxRSS = vRSS;
4774  AliInfo(Form("Setting max. RSS usage to user value %d MB",fMaxRSS));
4775  }
4776  else if (vRSS<0) {
4777  getrlimit(RLIMIT_RSS,&r);
4778  fMaxRSS = r.rlim_max==RLIM_INFINITY ? kInfMem : int(r.rlim_max*pgSize/kKB2MB/kKB2MB) + vRSS;
4779  AliInfo(Form("Setting max. RSS usage to system hard limit %d%s MB (%d margin)",fMaxRSS,r.rlim_max==RLIM_INFINITY ? "(inf)":"",-vRSS));
4780  }
4781  else {AliInfo("No check on RSS memory usage will be applied");}
4782  //
4783  if (vVMEM>0) {
4784  fMaxVMEM = vVMEM;
4785  AliInfo(Form("Setting max. VMEM usage to user value %d MB",fMaxVMEM));
4786  }
4787  else if (vVMEM<0) {
4788  getrlimit(RLIMIT_AS,&r);
4789  fMaxVMEM = r.rlim_max==RLIM_INFINITY ? kInfMem : int(r.rlim_max*pgSize/kKB2MB/kKB2MB) + vVMEM;
4790  AliInfo(Form("Setting max. VMEM usage to system hard limit %d%s MB (%d margin)",fMaxVMEM,r.rlim_max==RLIM_INFINITY ? "(inf)":"",-vVMEM));
4791  }
4792  else {AliInfo("No check on RSS memory usage will be applied");}
4793  //
4794 }
4795 
4796 //_________________________________________________________________
4798 {
4799  // check if process consumed more than allowed resources
4800  const int kKB2MB = 1024;
4801  Bool_t res = kTRUE;
4802  if (!fMaxRSS && !fMaxVMEM) return res;
4803  //
4804  ProcInfo_t procInfo;
4805  gSystem->GetProcInfo(&procInfo);
4806  if (procInfo.fMemResident/kKB2MB > fMaxRSS) res = kFALSE;
4807  if (procInfo.fMemVirtual/kKB2MB > fMaxVMEM) res = kFALSE;
4808  //
4809  if (!res) {
4810  AliInfo(Form("Job exceeded allowed limits: RSS:%d (%d) VMEM:%d (%d), will stop",
4811  int(procInfo.fMemResident/kKB2MB),fMaxRSS,
4812  int(procInfo.fMemVirtual/kKB2MB) ,fMaxVMEM));
4813  //
4814  unlink(Form("%s",fgkStopEvFName));
4815  ofstream outfile(fgkStopEvFName);
4816  outfile << ev << std::endl;
4817  outfile.close();
4818  fStopped = kTRUE;
4819  }
4820  return res;
4821 }
4822 
4824 {
4825  return ( (eventId < fRunLoader->GetNumberOfEvents()) ||
4826  (fRawReader && fRawReader->NextEvent()) );
4827 }
4828 
4829 //_________________________________________________________________
4831 {
4832  // if some CDB entries must be the same in the simulation
4833  // and reconstruction, check here
4834  int nent = fCheckRecoCDBvsSimuCDB.GetEntriesFast();
4835  AliInfo(Form("Check %d entries for matching between sim and rec",nent));
4836  //
4837  // get simulation CDB
4838  fRunLoader->CdGAFile();
4839  TMap* cdbMapSim = (TMap*)gDirectory->Get("cdbMap");
4840  TList* cdbListSim = (TList*)gDirectory->Get("cdbList");
4841  if (!(cdbMapSim && cdbListSim)) {
4842  AliInfo(Form("No CDBMap/List found in %s, nothing to check",fGAliceFileName.Data()));
4843  return;
4844  }
4845  // read the requested objects to make sure they will appear in the reco list
4846  for (Int_t i=0;i<nent;i++) {
4847  TNamed* cdbent = (TNamed*) fCheckRecoCDBvsSimuCDB[i];
4848  if (!cdbent) continue;
4849  AliCDBManager::Instance()->Get(cdbent->GetName());
4850  }
4851  // get default path for simulation
4852  TPair* pair;
4853  TObjString* stro;
4854  pair = (TPair*)cdbMapSim->FindObject("default");
4855  if (!pair) {AliFatal("Did not find default storage used for simulations"); return;}
4856  TString defSimStore = ((TObjString*)pair->Value())->GetString();
4857  RectifyCDBurl(defSimStore);
4858  //
4859  // get reconstruction CDB
4860  TMap cdbMapRecP, *cdbMapRec = &cdbMapRecP;
4861  cdbMapRec->SetName("cdbMap");
4862  TList cdbListRecP, *cdbListRec = &cdbListRecP;
4863  cdbListRec->SetName("cdbList");
4864  // create map/list accounting for eventual snapshot
4865  AliCDBManager::Instance()->CreateMapListCopy(cdbMapRecP,cdbListRecP);
4866  //
4867  // get default path for reconstruction
4868  pair = (TPair*)cdbMapRec->FindObject("default");
4869  if (!pair) {AliFatal("Did not find default storage used for reconstruction"); return;}
4870  TString defRecStore = ((TObjString*)pair->Value())->GetString();
4871  RectifyCDBurl(defRecStore);
4872  //
4873  for (Int_t i=0;i<nent;i++) {
4874  TNamed* cdbent = (TNamed*) fCheckRecoCDBvsSimuCDB[i];
4875  if (!cdbent) continue;
4876  //
4877  AliInfo(Form("#%d Checking %s",i,cdbent->GetName()));
4878  //
4879  // find cdbID used for sim
4880  TString idSim="",storSim="";
4881  TIter nextSim(cdbListSim);
4882  while ((stro=(TObjString*)nextSim())) {
4883  if (stro->GetString().Contains(cdbent->GetName())) {
4884  idSim = stro->GetString();
4885  break;
4886  }
4887  }
4888  // find the storage used for sim
4889  // check in the simuCDB special paths
4890  pair = (TPair*)cdbMapSim->FindObject(cdbent->GetName());
4891  if (pair) { // specific path is used
4892  storSim = ((TObjString*)pair->Value())->GetString();
4893  RectifyCDBurl(storSim);
4894  }
4895  else storSim = defSimStore; // default storage list is used
4896  //
4897  if (!idSim.IsNull()) AliInfo(Form("Sim. used %s from %s",idSim.Data(), storSim.Data()));
4898  else AliInfo("Sim. did not use this object");
4899  //
4900  // find cdbID used for rec
4901  TString idRec="",storRec="";
4902  TIter nextRec(cdbListRec);
4903  while ((stro=(TObjString*)nextRec())) {
4904  if (stro->GetString().Contains(cdbent->GetName())) {
4905  idRec = stro->GetString();
4906  break;
4907  }
4908  }
4909  //
4910  // find storage used for the rec
4911  pair = (TPair*)cdbMapRec->FindObject(cdbent->GetName());
4912  if (pair) { // specific path is used
4913  storRec = ((TObjString*)pair->Value())->GetString();
4914  RectifyCDBurl(storRec);
4915  }
4916  else storRec = defRecStore; // default storage list is used
4917  //
4918  if (!idRec.IsNull()) AliInfo(Form("Rec. used %s from %s",idRec.Data(), storRec.Data()));
4919  else AliInfo("Rec. did not use this object");
4920  //
4921  if (!idSim.IsNull() && !idRec.IsNull() && ((idSim!=idRec) || (storSim!=storRec)) )
4922  AliFatal("Different objects were used in sim and rec");
4923  }
4924 
4925 }
4926 
4927 //_________________________________________________________
4929 {
4930  // TBD RS
4931  // remove everything but the url
4932  TString sbs;
4933  if (!(sbs=url("\\?User=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4934  if (!(sbs=url("\\?DBFolder=[^?]*")).IsNull()) url.ReplaceAll("?DB","");
4935  if (!(sbs=url("\\?SE=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4936  if (!(sbs=url("\\?CacheFolder=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4937  if (!(sbs=url("\\?OperateDisconnected=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4938  if (!(sbs=url("\\?CacheSize=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4939  if (!(sbs=url("\\?CleanupInterval=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
4940  Bool_t slash=kFALSE,space=kFALSE;
4941  while ( (slash=url.EndsWith("/")) || (space=url.EndsWith(" ")) ) {
4942  if (slash) url = url.Strip(TString::kTrailing,'/');
4943  if (space) url = url.Strip(TString::kTrailing,' ');
4944  }
4945  //url.ToLower();
4946  //
4947 }
4948 
4949 //_________________________________________________________
4951 {
4952  // load trigger aliases, attach them to the reader
4953  //
4954  fDeclTriggerClasses.Clear();
4955  AliCentralTrigger *aCTP = NULL;
4956  if (fRawReader) {
4957  aCTP = new AliCentralTrigger();
4958  TString configstr("");
4959  if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
4960  AliError("No trigger configuration found in OCDB! The trigger configuration information will not be used!");
4961  delete aCTP;
4962  return;
4963  }
4964  }
4965  else if (fRunLoader && (!fRunLoader->LoadTrigger())) {
4966  aCTP = fRunLoader->GetTrigger();
4967  }
4968  else {
4969  if (fStopOnMissingTriggerFile) AliFatal("No trigger can be loaded! Stopping reconstruction!");
4970  AliWarning("No trigger can be loaded! The trigger information will not be used!");
4971  return;
4972  }
4973  //
4974  AliTriggerConfiguration *config = aCTP->GetConfiguration();
4975  if (!config) {
4976  AliError("No trigger configuration has been found! The trigger configuration information will not be used!");
4977  if (fRawReader) delete aCTP;
4978  return;
4979  }
4980  //
4981  // here we have list of active triggers
4982  const TObjArray& classesArray = config->GetClasses();
4983  Int_t nclasses = classesArray.GetEntriesFast();
4984  //
4985  fAlias2Trigger = new THashList();
4986  //
4987  AliCDBEntry * entry = AliCDBManager::Instance()->Get("GRP/CTP/Aliases");
4988  if (entry) {
4989  THashList * lst = dynamic_cast<THashList*>(entry->GetObject());
4990  if (lst) {
4991  lst->Sort(kSortDescending); // to avoid problems with substrungs
4992  if (fRawReader) fRawReader->LoadTriggerAlias(lst);
4993  // Now declare all the triggers present in the aliases
4994  TIter iter(lst);
4995  TNamed *nmd = 0;
4996  while((nmd = dynamic_cast<TNamed*>(iter.Next()))) { // account aliases of this trigger >>
4997  fDeclTriggerClasses += " ";
4998  fDeclTriggerClasses += nmd->GetName();
4999  //
5000  if (!classesArray.FindObject(nmd->GetName())) continue;
5001  TString aliasList(nmd->GetTitle());
5002  TObjArray* arrAliases = aliasList.Tokenize(',');
5003  Int_t nAliases = arrAliases->GetEntries();
5004  // Loop on aliases for the current trigger
5005  for(Int_t i=0; i<nAliases; i++){
5006  TObjString *alias = (TObjString*) arrAliases->At(i);
5007  // Find the current alias in the hash list. If it is not there, add TNamed entry
5008  TNamed * inlist = (TNamed*)fAlias2Trigger->FindObject((alias->GetString()).Data());
5009  if (!inlist) {
5010  inlist = new TNamed((alias->GetString()).Data(),Form(" %s ",nmd->GetName()));
5011  fAlias2Trigger->Add(inlist);
5012  }
5013  else {
5014  TString tt(inlist->GetTitle());
5015  tt += "||";
5016  tt += Form(" %s ",nmd->GetName());
5017  inlist->SetTitle(tt.Data());
5018  }
5019  }
5020  delete arrAliases;
5021  } // account aliases of this trigger <<
5022  }
5023  else AliError("Cannot cast the object with trigger aliases to THashList!");
5024  }
5025  else AliError("No OCDB ebtry for the trigger aliases!");
5026  //
5027  AliInfo("Aliases defined:");
5028  fAlias2Trigger->Print();
5029  //
5030  if (fRawReader) {
5031  // active classes mentioned in the alias will be converted to their masks
5032  for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
5033  AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
5034  if (!trclass) continue;
5035  int trindex = trclass->GetIndex()-1;
5036  fRawReader->LoadTriggerClass(trclass->GetName(),trindex);
5037  }
5038  //
5039  // nullify all remaining triggers mentioned in the alias
5040  if (!fDeclTriggerClasses.IsNull()) {
5041  TObjArray *tokens = fDeclTriggerClasses.Tokenize(" ");
5042  Int_t ntokens = tokens->GetEntriesFast();
5043  for (Int_t itoken = 0; itoken < ntokens; ++itoken) {
5044  fRawReader->LoadTriggerClass((((TObjString*)tokens->At(itoken))->String()).Data(),-1);
5045  }
5046  delete tokens;
5047  }
5048  //
5049  // make sure no unparsed triggers names left in the requested triggers
5050  if (TPRegexp("[A-Za-z]").MatchB(fRawReader->GetParsedTriggerExpression())) {
5051  AliFatalF("Unknown triggers found in requested list: %s",fRawReader->GetParsedTriggerExpression().Data());
5052  }
5053  }
5054  //
5055 }
5056 
5057 //___________________________________________________
5058 Bool_t AliReconstruction::TriggerMatches2Alias(const char* trigName, const char* alias)
5059 {
5060  // check if trigger matches to alias
5061  TString trName = trigName;
5062  if (!fAlias2Trigger) return kFALSE;
5063  TNamed* al = (TNamed*)fAlias2Trigger->FindObject(alias);
5064  if (!al) return kFALSE;
5065  TString altrig = al->GetTitle();
5066  return altrig.Contains(Form(" %s ",trigName));
5067  //
5068 }
5069 
5070 //___________________________________________________
5072 {
5073  // Decide if and what should be stored in the friends
5074  // Decision is taken on
5075  // 1) even level: unconditionally for cosmic and calib event,
5076  // priority for events with high pt tracks
5077  // 2) optionally on track level: priority according to kPriority.. flags below
5078  const Double_t pTminHigh = 1.5, pTmaxHigh = 100;
5079  const ULong_t kMaskHighPt = AliESDtrack::kITSout|AliESDtrack::kTPCin;
5080  const ULong_t kPriorityFlag[] =
5090  };
5091  const int kNPrio = sizeof(kPriorityFlag)/sizeof(ULong_t);
5092  const ULong_t highPtMask = AliESDtrack::kITSin|AliESDtrack::kTPCin;
5093  float fracHighPt = 0, nHighPtCheck = 0;
5094  //
5095  Bool_t isSelected = kFALSE;
5096  int ntrk = fesd->GetNumberOfTracks();
5097  fesd->SetNTPCFriend2Store(ntrk); // by default - all tracks
5098  //
5099  // Unconditionally store Field off, Cosmic and Calib events
5100  double bz = AliTrackerBase::GetBz();
5101  if (TMath::Abs(bz)<0.5) {
5102  isSelected=kTRUE;
5103  AliInfo("AliESDfriends event stored: non-standard field event");
5104  return isSelected;
5105  }
5107  // if (IsCosmicOrCalibSpecie()) {
5108  isSelected = kTRUE; // Selection of calib or cosmic events
5109  AliInfo("AliESDfriends event stored: calibration or cosmic event");
5110  return isSelected;
5111  }
5112  //
5113  // analyze event on tracks level
5114  static TArrayS weights;
5115  static TArrayI indices;
5116  Bool_t sparsify =
5117  (fMaxFriendTracks>0 && (ntrk > fMaxFriendTracks)) ||
5118  (fSkipFriendsForLargeZ && fSkipFriendsCutZ>0); // applied to no-its tracks
5119  //
5120  if (sparsify && ntrk>weights.GetSize()) { // arrays are used only in case of sparsification
5121  weights.Set(ntrk+100);
5122  indices.Set(ntrk+100);
5123  }
5124  Short_t *pWeights = weights.GetArray(); // for fast access
5125  Int_t *pIndices = indices.GetArray();
5126  //
5127  for (Int_t itrk=0; itrk<ntrk; ++itrk) {
5128  //
5129  AliESDtrack * trk = fesd->GetTrack(itrk);
5130  ULong64_t status = trk->GetStatus();
5131  //
5132  // tag high pt tracks
5133  Bool_t isHighPt = kFALSE;
5134  if ( (status&kMaskHighPt) == kMaskHighPt ) {
5135  double pt = trk->Pt();
5136  isHighPt = (pt>pTminHigh && pt<pTmaxHigh);
5137  nHighPtCheck++;
5138  if (isHighPt) fracHighPt++;
5139  }
5140  //
5141  if (sparsify) {
5142  int pri = 0; // define track priority
5143  for (pri=kNPrio;pri--;) {
5144  ULong_t priFlags=kPriorityFlag[pri],priFlagsOK = priFlags&status;
5145  // stupidly, from the from the status flags it is not clear if there are TRD tracklets matched
5146  if (priFlags&AliESDtrack::kTRDout && !trk->GetTRDntracklets()) continue;
5147  if (priFlags&AliESDtrack::kTPCout && trk->GetTPCNcls()<16) continue; // disregard TPC tracks with low Nclus
5148  if (priFlagsOK==kPriorityFlag[pri]) break;
5149  }
5150  pWeights[itrk] = ++pri; // to have it positive
5151  if (isHighPt) pWeights[itrk] += kNPrio; // high pt tracks have highest priority
5152  else {
5153  if (fSkipFriendsCutZ>0 && !(status&AliESDtrack::kITSin) && (status&