Added task for CDB connection, loading magnetic field and geometry.
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 1 Oct 2010 08:59:13 +0000 (08:59 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 1 Oct 2010 08:59:13 +0000 (08:59 +0000)
PWG1/AliTaskCDBconnect.cxx [new file with mode: 0644]
PWG1/AliTaskCDBconnect.h [new file with mode: 0644]
PWG1/PWG1LinkDef.h
PWG1/PilotTrain/AddTaskCDBconnect.C [new file with mode: 0644]

diff --git a/PWG1/AliTaskCDBconnect.cxx b/PWG1/AliTaskCDBconnect.cxx
new file mode 100644 (file)
index 0000000..b612a0a
--- /dev/null
@@ -0,0 +1,161 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#include "AliTaskCDBconnect.h"
+
+#include <TChain.h>
+#include <TFile.h>
+#include <TGeoGlobalMagField.h>
+#include "AliAnalysisManager.h"
+#include "AliGeomManager.h"
+#include "AliCDBManager.h"
+#include "AliGRPManager.h"
+#include "AliESDEvent.h"
+#include "AliESDInputHandler.h"
+#include "AliLog.h"
+
+ClassImp(AliTaskCDBconnect)
+
+//______________________________________________________________________________
+AliTaskCDBconnect::AliTaskCDBconnect():
+           AliAnalysisTask(),
+           fRun(0),
+           fRunChanged(kFALSE),
+           fESDhandler(NULL),
+           fESD(NULL),
+           fGRPManager(NULL)
+{
+// Dummy constructor
+}
+
+//______________________________________________________________________________
+AliTaskCDBconnect::AliTaskCDBconnect(const char* name):
+           AliAnalysisTask(name, "ESD analysis tender car"),
+           fRun(0),
+           fRunChanged(kFALSE),
+           fESDhandler(NULL),
+           fESD(NULL),
+           fGRPManager(NULL)
+{
+// Default constructor
+  AliCDBManager *cdb = AliCDBManager::Instance();
+  cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  cdb->SetRun(0);
+  DefineInput (0, TChain::Class());
+//  DefineOutput(0,  AliESDEvent::Class());
+}
+
+//______________________________________________________________________________
+AliTaskCDBconnect::~AliTaskCDBconnect()
+{
+// Destructor
+  if (fGRPManager) delete fGRPManager;
+//  if (gGeoManager) delete gGeoManager;
+}  
+
+//______________________________________________________________________________
+void AliTaskCDBconnect::LocalInit()
+{
+// Init CDB locally if run number is defined.
+  if (!fRun) {
+    AliWarning("AliTaskCDBconnect::LocalInit Run number not defined yet");
+    return;
+  }      
+  // Create CDB manager
+  AliCDBManager *cdb = AliCDBManager::Instance();
+  // SetDefault storage. Specific storages must be set by TaskCDBconnectSupply::Init()
+//  cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  cdb->SetDefaultStorage("raw://");
+  // Set run
+  cdb->SetRun(fRun);
+  // Initialize GRP manager only once
+  InitGRP();
+}
+  
+//______________________________________________________________________________
+void AliTaskCDBconnect::ConnectInputData(Option_t* /*option*/)
+{
+// Connect the input data, create CDB manager.
+  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+  if (!mgr) AliFatal("No analysis manager");
+  fESDhandler = dynamic_cast<AliESDInputHandler *>(mgr->GetInputEventHandler());
+    
+  if (fESDhandler) {
+     fESD = fESDhandler->GetEvent();
+  } else {
+     AliFatal("No ESD input event handler connected") ; 
+  }
+  // Create CDB manager
+  AliCDBManager *cdb = AliCDBManager::Instance();
+  // SetDefault storage. Specific storages must be set by TaskCDBconnectSupply::Init()
+//  cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  cdb->SetDefaultStorage("raw://");
+  Int_t run = fESD->GetRunNumber();
+  if (run != fRun) fRunChanged = kTRUE;
+  else fRunChanged = kFALSE;
+  // Set run
+  if (fRunChanged) cdb->SetRun(fRun);
+  // Initialize GRP manager only once
+  InitGRP();
+}
+
+//______________________________________________________________________________
+void AliTaskCDBconnect::InitGRP()
+{
+// Initialize geometry and mag. field
+  if (!fGRPManager) {
+  // magnetic field
+    if (!TGeoGlobalMagField::Instance()->GetField()) {
+      printf("Loading field map...\n");
+      fGRPManager = new AliGRPManager();
+      if(!fGRPManager->ReadGRPEntry()) { 
+        printf("Cannot get GRP entry\n"); 
+      }
+      if( !fGRPManager->SetMagField() ) { 
+        printf("Problem with magnetic field setup\n"); 
+      }
+    }
+
+    // geometry
+    printf("Loading geometry...\n");
+    AliGeomManager::LoadGeometry();
+    if( !AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC") ) {
+      printf("Problem with align objects\n"); 
+    }
+  }  
+}
+
+//______________________________________________________________________________
+void AliTaskCDBconnect::CreateOutputObjects()
+{
+// Nothing for the moment, but we may need ESD event replication here.
+}
+
+//______________________________________________________________________________
+void AliTaskCDBconnect::Exec(Option_t* /*option*/)
+{
+//
+// Execute all supplied analysis of one event. Notify run change via RunChanged().
+  fESD = fESDhandler->GetEvent();
+
+  // Intercept when the run number changed
+  if (fRun != fESD->GetRunNumber()) {
+    fRunChanged = kTRUE;
+    fRun = fESD->GetRunNumber();
+    AliCDBManager::Instance()->SetRun(fRun);
+  }
+//  PostData(0, fESD);
+}
diff --git a/PWG1/AliTaskCDBconnect.h b/PWG1/AliTaskCDBconnect.h
new file mode 100644 (file)
index 0000000..4e5f69a
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef ALITASKCDBCONNECT_H
+#define ALITASKCDBCONNECT_H
+
+//==============================================================================
+// TaskCDBconnect - task just allowing connection to CDB (no lock)
+//==============================================================================
+
+#ifndef ALIANALYSISTASK_H
+#include "AliAnalysisTask.h"
+#endif
+
+class AliCDBManager;
+class AliGRPManager;
+class AliESDEvent;
+class AliESDInputHandler;
+
+class AliTaskCDBconnect : public AliAnalysisTask {
+private:
+  Int_t                     fRun;            //! Current run
+  Bool_t                    fRunChanged;     //! Flag for run change.
+  AliESDInputHandler       *fESDhandler;     //! Pointer to ESD input handler
+  AliESDEvent              *fESD;            //! Pointer to current ESD event
+  AliGRPManager            *fGRPManager;     //! Pointer to GRP manager
+
+  AliTaskCDBconnect(const AliTaskCDBconnect &other);
+  AliTaskCDBconnect& operator=(const AliTaskCDBconnect &other);
+
+public:
+  AliTaskCDBconnect();
+  AliTaskCDBconnect(const char *name);
+  virtual ~AliTaskCDBconnect();
+  AliESDInputHandler       *GetESDhandler() const {return fESDhandler;}
+  AliESDEvent              *GetEvent() const {return fESD;}
+  Int_t                     GetRun() const {return fRun;}
+  void                      InitGRP();
+  Bool_t                    RunChanged() const {return fRunChanged;}
+  void                      SetRunNumber(Int_t run) {fRun = run;}
+  // Run control
+  virtual void              ConnectInputData(Option_t *option = "");
+  virtual void              CreateOutputObjects();
+  virtual void              LocalInit();
+  virtual Bool_t            Notify() {return kTRUE;}
+  virtual void              Exec(Option_t *option);
+    
+  ClassDef(AliTaskCDBconnect,1)  // Class giving CDB connectivity
+};
+#endif
index 2579432..f8d6c4a 100644 (file)
 // Background and luminosity studies
 #pragma link C++ class  AliAnalysisTaskBGvsTime+;
 #pragma link C++ class  AliHistoListWrapper+;
+// CDB connect
+#pragma link C++ class  AliTaskCDBconnect+;
+
 #endif
diff --git a/PWG1/PilotTrain/AddTaskCDBconnect.C b/PWG1/PilotTrain/AddTaskCDBconnect.C
new file mode 100644 (file)
index 0000000..5f3763d
--- /dev/null
@@ -0,0 +1,19 @@
+AliTaskCDBconnect* AddTaskCDBconnect() 
+{
+    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+    if (!mgr) {
+       ::Error("AddTaskCDBconnect", "No analysis manager to connect to.");
+       return NULL;
+    }   
+    TString inputDataType = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"
+    if (inputDataType != "ESD") {
+       ::Error("AddTaskCDBconnect", "Can only run with ESD input handler");
+       return NULL;
+    }   
+    
+    AliTaskCDBconnect *task= new AliTaskCDBconnect("CDBconnect");
+    mgr->AddTask(task);    
+    AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();    
+    mgr->ConnectInput(task,  0, cinput1);
+    return task;
+}