]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/Tender/AliTender.cxx
Fixed format in printouts. Changed temp directory in merging to be current directory
[u/mrichter/AliRoot.git] / ANALYSIS / Tender / AliTender.cxx
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$ */
17
18 #include <TChain.h>
19 #include <TFile.h>
20  
21 #include "AliTender.h"
22 #include "AliTenderSupply.h"
23 #include "AliAnalysisManager.h"
24 #include "AliCDBManager.h"
25 #include "AliESDEvent.h"
26 #include "AliESDInputHandler.h"
27 #include "AliLog.h"
28
29
30 ClassImp(AliTender)
31
32 //______________________________________________________________________________
33 AliTender::AliTender():
34            AliAnalysisTaskSE(),
35            fRun(0),
36            fRunChanged(kFALSE),
37            fCDBkey(0),
38            fDefaultStorage(),
39            fCDB(NULL),
40            fESDhandler(NULL),
41            fESD(NULL),
42            fSupplies(NULL),
43            fCDBSettings(NULL)
44 {
45 // Dummy constructor
46 }
47
48 //______________________________________________________________________________
49 AliTender::AliTender(const char* name):
50            AliAnalysisTaskSE(name),
51            fRun(0),
52            fRunChanged(kFALSE),
53            fCDBkey(0),
54            fDefaultStorage(),
55            fCDB(NULL),
56            fESDhandler(NULL),
57            fESD(NULL),
58            fSupplies(NULL),
59            fCDBSettings(NULL)
60 {
61 // Default constructor
62   DefineOutput(1,  AliESDEvent::Class());
63 }
64
65 //______________________________________________________________________________
66 AliTender::~AliTender()
67 {
68 // Destructor
69   if (fSupplies) {
70     fSupplies->Delete();
71     delete fSupplies;
72   }
73 }
74
75 //______________________________________________________________________________
76 void AliTender::AddSupply(AliTenderSupply *supply)
77 {
78 // Addition of supplies.
79   if (!fSupplies) fSupplies = new TObjArray();
80   if (fSupplies->FindObject(supply)) {
81      Error("AddSupply", "Tender supply %s already connected.", supply->GetName());
82      return;
83   }   
84   fSupplies->Add(supply);
85   supply->SetTender(this);
86 }
87    
88 //______________________________________________________________________________
89 void AliTender::ConnectInputData(Option_t* option)
90 {
91 // Connect the input data, create CDB manager.
92   if (fDebug > 1) Printf("AliTender::ConnectInputData()\n");
93   AliAnalysisTaskSE::ConnectInputData(option);
94   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
95   if (!mgr) AliFatal("No tender without an analysis manager");
96   fESDhandler = dynamic_cast<AliESDInputHandler *>(mgr->GetInputEventHandler());
97     
98   if (fESDhandler) {
99      fESD = fESDhandler->GetEvent();
100   } else {
101      AliFatal("No ESD input event handler connected") ; 
102   }
103   // Create CDB manager
104   if (!fDefaultStorage.Length()) AliFatal("Default CDB storage not set.");
105   fCDB = AliCDBManager::Instance();
106   // SetDefault storage. Specific storages must be set by AliTenderSupply::Init()
107   fCDB->SetDefaultStorage(fDefaultStorage);
108   fRun = fESD->GetRunNumber();
109   // Unlock CDB
110   fCDBkey = fCDB->SetLock(kFALSE, fCDBkey);
111   fCDB->SetRun(fRun);
112   TIter next(fSupplies);
113   AliTenderSupply *supply;
114   while ((supply=(AliTenderSupply*)next())) supply->Init();
115   // Lock CDB
116   fCDBkey = fCDB->SetLock(kTRUE, fCDBkey);
117 }
118
119 //______________________________________________________________________________
120 void AliTender::UserCreateOutputObjects()
121 {
122 // Nothing for the moment, but we may need ESD event replication here.
123   if (fDebug > 1) Printf("AliTender::CreateOutputObjects()\n");
124 }
125
126 //______________________________________________________________________________
127 void AliTender::UserExec(Option_t* /*option*/)
128 {
129 //
130 // Execute all supplied analysis of one event. Notify run change via RunChanged().
131   if (fDebug > 1) {
132     Long64_t entry = fESDhandler->GetReadEntry();
133     Printf("AliTender::Exec() %s ==> processing event %lld\n", fESDhandler->GetTree()->GetCurrentFile()->GetName(),entry);
134   }  
135   fESD = fESDhandler->GetEvent();
136
137 // Call the user analysis
138   // Unlock CDB
139   fCDBkey = fCDB->SetLock(kFALSE, fCDBkey);
140   // Intercept when the run number changed
141   if (fRun != fESD->GetRunNumber()) {
142     fRunChanged = kTRUE;
143     fRun = fESD->GetRunNumber();
144     fCDB->SetRun(fRun);
145   }
146   TIter next(fSupplies);
147   AliTenderSupply *supply;
148   while ((supply=(AliTenderSupply*)next())) supply->ProcessEvent();
149   fRunChanged = kFALSE;
150   // Lock CDB
151   fCDBkey = fCDB->SetLock(kTRUE, fCDBkey);
152   PostData(1, fESD);
153 }
154
155 //______________________________________________________________________________
156 void AliTender::SetDefaultCDBStorage(const char *dbString)
157 {
158 // Set default CDB storage
159    fDefaultStorage = dbString;
160 }