]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/MakeMUONZeroMisAlignment.C
Added protection and 2 levels for problems
[u/mrichter/AliRoot.git] / MUON / MakeMUONZeroMisAlignment.C
index 6f4c92432ec9ced47a2ab359842ee89ec68b2cd3..35b0bfcbcfad00c468b3ec244b7ca1aa6237cf49 100644 (file)
@@ -1,73 +1,80 @@
-void MakeMUONZeroMisAlignment(Bool_t volpaths = false,
-                             Bool_t transforms = false, 
-                             Bool_t svmaps = false)
-// Macro for generating the geometry data files:
-// (volpath.dat, transform.dat, svmap.dat)
-// and local CDB storage with zero, residual and full misalignment
-//
-// The generated files do not replace the existing ones
-// but have different names (with extension ".out").
-//
-//  Author: I. Hrivnacova, IPN Orsay
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+// $Id$
+
+// Macro for generating the zero misalignment data.
 //
-{
-  // Initialize
-  gAlice->Init("$ALICE_ROOT/MUON/Config.C");
-  cout << "Init done " << endl;
+// Author: I. Hrivnacova, IPN Orsay
 
-  // Get MUON detector
-  AliMUON* muon = (AliMUON*)gAlice->GetModule("MUON");
-  if (!muon) {
-    AliFatal("MUON detector not defined.");
-    return 0;
-  }  
+#if !defined(__CINT__) || defined(__MAKECINT__)
 
-  // Get geometry builder
-  AliMUONGeometryBuilder* builder = muon ->GetGeometryBuilder();
-  
-  if (volpaths) {
-    cout << "Generating volpath file ..." << endl;
-    builder->GetTransformer()->WriteVolumePaths("volpath.dat.out");
-  }  
+#include "AliMUONGeometryTransformer.h"
 
-  if (transforms) {
-    cout << "Generating transformation file ..." << endl;
-    builder->GetTransformer()->WriteTransformations("transform.dat.out");
-  }  
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "AliCDBId.h"
+
+#include <TGeoManager.h>
+#include <TClonesArray.h>
+#include <TString.h>
+#include <TFile.h>
+#include <Riostream.h>
 
-  if (svmaps) {
-    cout << "Generating svmaps file ..." << endl;
-    builder->WriteSVMaps();
+#endif
+
+void MakeMUONZeroMisAlignment()
+{
+  // Check first if geometry is loaded,
+  // if not loaded try to load it from galice.root file
+  if ( ! gGeoManager && ! TGeoManager::Import("geometry.root") )  {
+    cerr << "Loading geometry failed." << endl;
+    return;
   }  
 
-  cout << "Generating residual misalignment data in  MUON/ZeroMisAlignCDB/Data..." << endl;
-  
-  AliMUONGeometryMisAligner misAligner(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
-  AliMUONGeometryTransformer* newTransform 
-    = misAligner.MisAlign(builder->GetTransformer(), true);
-  TClonesArray* array = newTransform->GetMisAlignmentData();
+  AliMUONGeometryTransformer transformer(true);
+  transformer.ReadGeometryData("volpath.dat", gGeoManager);
+  TClonesArray* array = transformer.CreateZeroAlignmentData();;
 
-  if(!gSystem->Getenv("$TOCDB")){
-    // Create a File to store the alignment data
-    TFile f("MUONresidualMisalignment.root","RECREATE");
-    if(!f) {cerr<<"cannot open file for output\n";}
+  if ( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ) {
+    // save in file
+    cout << "Generating zero misalignment data in a file ..." << endl;
+
+    // Create a file to store the alignment data
+    TFile f("MUONzeroMisalignment.root", "RECREATE");
+    if( !f.IsOpen() ) {
+      cerr<<"cannot open file for output\n";
+    }
     
     f.cd();
     f.WriteObject(array,"MUONAlignObjs ","kSingleKey");
     f.Close();
-  }else{
+  }
+  else {
+    cout << "Generating zero misalignment data in CDB ..." << endl;
+
     // save in CDB storage
-    const char* Storage = gSystem->Getenv("$STORAGE");
+    const char* Storage = gSystem->Getenv("STORAGE");
     AliCDBManager* cdbManager = AliCDBManager::Instance();
     AliCDBStorage* storage = cdbManager->GetStorage(Storage);
     AliCDBMetaData* cdbData = new AliCDBMetaData();
     cdbData->SetResponsible("Dimuon Offline project");
-    cdbData->SetComment("MUON alignment objects with residual misalignment");
-    cdbData->SetAliRootVersion(gSystem->Getenv("$ARVERSION"));
+    cdbData->SetComment("MUON alignment objects with zero misalignment");
+    cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
     AliCDBId id("MUON/Align/Data", 0, 9999999); 
     storage->Put(array, id, cdbData);
   }
-  
-  delete newTransform;
 }