]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
new task to set up the OCDB and GRP for TPC QA in an analysis chain
authormkrzewic <mkrzewic@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 28 Oct 2013 16:46:30 +0000 (16:46 +0000)
committermkrzewic <mkrzewic@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 28 Oct 2013 16:46:30 +0000 (16:46 +0000)
PWGPP/PWGPPLinkDef.h
PWGPP/TPC/AliTaskConfigOCDB.cxx [new file with mode: 0644]
PWGPP/TPC/AliTaskConfigOCDB.h [new file with mode: 0644]

index c43b2f27dbeff46688cebff8d6d9f4e72446a6b9..07100051f79a75093fcc5f964fd75ebf46326096 100644 (file)
@@ -83,6 +83,8 @@
 #pragma link C++ class AliFilteredTreeEventCuts+;
 #pragma link C++ class AliFilteredTreeAcceptanceCuts+;
 
+#pragma link C++ class AliTaskConfigOCDB+;
+
 
 // TRD performance classes
 #pragma link C++ class  AliTenderSupplyTRD+;
diff --git a/PWGPP/TPC/AliTaskConfigOCDB.cxx b/PWGPP/TPC/AliTaskConfigOCDB.cxx
new file mode 100644 (file)
index 0000000..4d069f0
--- /dev/null
@@ -0,0 +1,178 @@
+/**************************************************************************
+ * 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 "AliTaskConfigOCDB.h"
+
+#include <TChain.h>
+#include <TFile.h>
+#include <TGeoGlobalMagField.h>
+#include "TGeoManager.h"
+#include "AliAnalysisManager.h"
+#include "AliGeomManager.h"
+#include "AliCDBManager.h"
+#include "AliGRPManager.h"
+#include "AliESDEvent.h"
+#include "AliESDInputHandler.h"
+#include "AliLog.h"
+
+ClassImp(AliTaskConfigOCDB)
+
+//______________________________________________________________________________
+AliTaskConfigOCDB::AliTaskConfigOCDB():
+           AliAnalysisTask(),
+           fRun(0),
+           fRunChanged(kFALSE),
+           fESDhandler(NULL),
+           fESD(NULL),
+           fGRPManager(NULL)
+{
+// Dummy constructor
+}
+
+//______________________________________________________________________________
+AliTaskConfigOCDB::AliTaskConfigOCDB(const char* name, const char *storage, Int_t run)
+          :AliAnalysisTask(name, "configure OCDB field geom"),
+           fRun(run),
+           fRunChanged(kFALSE),
+           fESDhandler(NULL),
+           fESD(NULL),
+           fGRPManager(NULL)
+{
+// Default constructor
+  AliCDBManager *cdb = AliCDBManager::Instance();
+  cdb->SetDefaultStorage(storage);
+  cdb->SetRun(run);
+  DefineInput (0, TChain::Class());
+}
+
+//______________________________________________________________________________
+AliTaskConfigOCDB::~AliTaskConfigOCDB()
+{
+// Destructor
+  delete fGRPManager;
+}  
+
+//______________________________________________________________________________
+void AliTaskConfigOCDB::LocalInit()
+{
+// Init CDB locally if run number is defined.
+}
+  
+//______________________________________________________________________________
+void AliTaskConfigOCDB::ConnectInputData(Option_t* /*option*/)
+{
+// Connect the input data, create CDB manager.
+}
+
+//______________________________________________________________________________
+void AliTaskConfigOCDB::InitGRP()
+{
+// Initialize geometry and mag. field
+  if (!fGRPManager) {
+  // magnetic field
+    if (!TGeoGlobalMagField::Instance()->GetField()) {
+      printf("AliCDBconnect: #### Loading field map...\n");
+      fGRPManager = new AliGRPManager();
+      if(!fGRPManager->ReadGRPEntry()) { 
+        AliError("Cannot get GRP entry"); 
+      }
+      if( !fGRPManager->SetMagField() ) { 
+        AliError("Problem with magnetic field setup"); 
+      }
+    }
+
+    // geometry
+    if (!gGeoManager) {
+      printf("AliCDBconnect: #### Loading geometry...\n");
+      AliGeomManager::LoadGeometry();
+      if( !AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC TRD") ) {
+        AliError("Problem with align objects"); 
+      }
+    }  
+  }  
+}
+
+//______________________________________________________________________________
+void AliTaskConfigOCDB::CreateOutputObjects()
+{
+// Init CDB locally if run number is defined.
+  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+  if (!mgr) AliFatal("No analysis manager");
+  fESDhandler = dynamic_cast<AliESDInputHandler *>(mgr->GetInputEventHandler());
+    
+  if (!fESDhandler) {
+     AliFatal("No ESD input event handler connected");
+     return;
+  }   
+  // Try to get event number before the first event is read (this has precedence
+  // over existing fRun)
+  Int_t run = mgr->GetRunFromPath();
+  if (!run && !fRun) {
+     AliError("AliTaskConfigOCDB: Run not set - no CDB connection");
+     return;
+  }
+  // Create CDB manager
+  AliCDBManager *cdb = AliCDBManager::Instance();
+  // If CDB is already locked, return
+  if (cdb->GetLock()) return;
+  // SetDefault storage. Specific storages must be set by TaskCDBconnectSupply::Init()
+  //  cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+//  if (!cdb->GetRaw()) {
+//     cdb->SetDefaultStorage("raw://");
+//  }   
+  if (run && (run != fRun)) {
+     fRunChanged = kTRUE;
+     fRun = run;
+  } else {
+     fRunChanged = kFALSE;
+  }
+  // Set run
+  if (fRunChanged || !fGRPManager) {
+     printf("AliCDBconnect: #### Setting run to: %d\n", fRun);
+     cdb->SetRun(fRun);
+     // Initialize GRP manager only once
+     if (fRun) InitGRP();
+  }   
+}
+
+//______________________________________________________________________________
+Bool_t AliTaskConfigOCDB::Notify()
+{
+// Init CDB locally if run number is defined.
+  CreateOutputObjects();
+  return kTRUE;
+}
+
+//______________________________________________________________________________
+void AliTaskConfigOCDB::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();
+    CreateOutputObjects();
+  }
+}
+
+//______________________________________________________________________________
+void AliTaskConfigOCDB::Terminate(Option_t *)
+{
+// Initialize CDB also in Terminate
+//   CreateOutputObjects();
+}
diff --git a/PWGPP/TPC/AliTaskConfigOCDB.h b/PWGPP/TPC/AliTaskConfigOCDB.h
new file mode 100644 (file)
index 0000000..393de3b
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef ALITASKCONFIGOCDB_H
+#define ALITASKCONFIGOCDB_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 AliTaskConfigOCDB : 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
+
+  AliTaskConfigOCDB(const AliTaskConfigOCDB &other);
+  AliTaskConfigOCDB& operator=(const AliTaskConfigOCDB &other);
+
+public:
+  AliTaskConfigOCDB();
+  AliTaskConfigOCDB(const char *name, const char *storage="raw://", Int_t run=0);
+  virtual ~AliTaskConfigOCDB();
+  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();
+  virtual void              Exec(Option_t *option);
+  virtual void              Terminate(Option_t *option);
+    
+  ClassDef(AliTaskConfigOCDB,1)  // Class giving CDB connectivity
+};
+#endif