]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDAlignFaker.cxx
Coding conventions
[u/mrichter/AliRoot.git] / FMD / AliFMDAlignFaker.cxx
index 97931d79ec9e081c87ed5c212429e20e9395f5dd..fa4f98cc4ab2b5f0c6a048c73096f2961fea4ad3 100644 (file)
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
-
 /* $Id$ */
-
+/** 
+ * @file    AliFMDAlignFaker.cxx
+ * @author  Christian Holm Christensen <cholm@nbi.dk>
+ * @date    Sun Mar 26 17:57:55 2006
+ * @brief   Implementation of AliFMDAlignFaker 
+ */
+//____________________________________________________________________
+//
+//  Class 
+//  to 
+//  make 
+//  fake 
+//  alignment
+//  parameters 
+//
 //____________________________________________________________________
 //                                                                          
 // Forward Multiplicity Detector based on Silicon wafers. 
 //
-// This task creates fake alignrations. Which alignration, depends on
+// This task creates fake alignment. Which alignment, depends on
 // the bit mask passed to the constructor, or added by `AddAlign'.
 //
-// The default is to write all alignration parameters to a local
+// The default is to write all alignment parameters to a local
 // storage `local://cdb' which is a directory in the current
 // directory. 
 //                                                       
-#include "AliLog.h"               // ALILOG_H
+#include "AliFMDDebug.h"               // ALIFMDDEBUG_H ALILOG_H
 #include "AliFMDAlignFaker.h"      // ALIFMDALIGNFAKER_H
 #include <AliCDBManager.h>         // ALICDBMANAGER_H
+#include <AliCDBStorage.h>         // ALICDBSTORAGE_H
 #include <AliCDBEntry.h>           // ALICDBMANAGER_H
-#include <AliAlignObj.h>
-#include <AliAlignObjAngles.h>
-#include <Riostream.h>
+// #include <AliAlignObj.h>
+#include <AliAlignObjParams.h>
+// #include <Riostream.h>
 #include <TSystem.h>
-#include <TMath.h>
+// #include <TMath.h>
 #include <TRandom.h>
 #include <TClonesArray.h>
 #include <TString.h>
 #include <TFile.h>
 #include <TGeoManager.h>
 #include <TGeoNode.h>
-#include <TGeoVolume.h>
+// #include <TGeoVolume.h>
+#include <TROOT.h>
+#include <TClass.h>
 
 //====================================================================
 ClassImp(AliFMDAlignFaker)
@@ -54,15 +70,31 @@ AliFMDAlignFaker::AliFMDAlignFaker(Int_t mask, const char* geo,
                                   const char* loc) 
   : TTask(geo, loc),
     fMask(mask),
+    fSensorTransMin(0,0,0),
+    fSensorTransMax(0,0,0),
+    fSensorRotMin(0,0,0),
+    fSensorRotMax(0,0,0),
+    fHalfTransMin(0,0,0),
+    fHalfTransMax(0,0,0),
+    fHalfRotMin(0,0,0),
+    fHalfRotMax(0,0,0),
     fRunMin(0),
-    fRunMax(10), 
-    fArray(0)
+    fRunMax(AliCDBRunRange::Infinity()), 
+    fArray(0),
+    fComment("")
 {
   // Default constructor 
+  if (!loc) { 
+    AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
+    if (!storage) AliFatal("Default Storage not set");
+    const TString& uri = storage->GetURI();
+    fTitle = uri;
+  }
   SetSensorDisplacement();
   SetSensorRotation();
   SetHalfDisplacement();
   SetHalfRotation();
+  SetComment();
 }
 
 //__________________________________________________________________
@@ -111,6 +143,52 @@ AliFMDAlignFaker::SetHalfRotation(Double_t x1, Double_t y1, Double_t z1,
 #define IS_NODE_SENSOR(name) \
   (name[0] == 'F' && name[2] == 'S' && name[3] == 'E')
 
+//__________________________________________________________________
+Bool_t
+AliFMDAlignFaker::GetGeometry(Bool_t toCdb, const TString& storage)
+{
+  // 
+  // Get the geometry
+  // 
+  // Parameters:
+  //    toCdb   Whether to store in CDB
+  //    storage Storage element to use 
+  // 
+  // Return:
+  //    true on success 
+  //
+  if (!toCdb) { 
+     //load geom from default CDB storage
+    AliGeomManager::LoadGeometry(); 
+    return kTRUE;
+  }
+  if(!storage.BeginsWith("local://") && 
+     !storage.BeginsWith("alien://")) {
+    AliErrorClass(Form("STORAGE=\"%s\" invalid. Exiting\n", storage.Data()));
+    return kFALSE;
+  }
+
+  AliCDBManager* cdb   = AliCDBManager::Instance();
+  AliCDBStorage* store = cdb->GetStorage(storage.Data());
+  if(!store){
+    AliErrorClass(Form("Unable to open storage %s\n", storage.Data()));
+    return kFALSE;
+  }
+
+  AliCDBPath   path("GRP","Geometry","Data");
+  AliCDBEntry* entry = store->Get(path.GetPath(),cdb->GetRun());
+  if(!entry) {
+    AliErrorClass("Could not get the specified CDB entry!");
+    return kFALSE;
+  }
+  
+
+  entry->SetOwner(0);
+  TGeoManager* geom = static_cast<TGeoManager*>(entry->GetObject());
+  AliGeomManager::SetGeometry(geom);
+  return kTRUE;
+}
+  
 //__________________________________________________________________
 void
 AliFMDAlignFaker::Exec(Option_t*)
@@ -131,38 +209,75 @@ AliFMDAlignFaker::Exec(Option_t*)
     return;
   }
   // Make container of transforms 
-  if (!fArray) fArray = new TClonesArray("AliAlignObjAngles");
+  if (!fArray) fArray = new TClonesArray("AliAlignObjParams");
   fArray->Clear();
   
   // Make an iterator
   TGeoIterator next(topVolume);
+  next.SetTopName(Form("/%s_1", topVolume->GetName()));
   TGeoNode* node = 0;
-
+  
+  Char_t currentDet  = '\0';
+  Char_t currentHalf = '\0';
   // Loop over all entries in geometry to find our nodes. 
   while ((node = static_cast<TGeoNode*>(next()))) {
     const char* name =  node->GetName();
-    if (IS_NODE_HALF(name) && TESTBIT(fMask, kHalves) ||
-       IS_NODE_SENSOR(name) && TESTBIT(fMask, kSensors)) {
-      // Get the path 
-      TString path(Form("/%s", gGeoManager->GetNode(0)->GetName()));
-      Int_t nLevel = next.GetLevel();
-      for (Int_t lvl = 0; lvl <= nLevel; lvl++) {
-       TGeoNode* p = next.GetNode(lvl);
-       if (!p && lvl != 0) {
-         AliWarning(Form("No node at level %d in path %s", lvl, path.Data()));
-         continue;
-       }
-       if (!path.IsNull()) path.Append("/");
-       path.Append(p->GetName());
+    if (!(IS_NODE_HALF(name) && TESTBIT(fMask, kHalves)) &&
+       !(IS_NODE_SENSOR(name) && TESTBIT(fMask, kSensors))) 
+      continue;
+
+    TString path, alignName;
+    next.GetPath(path);
+    Int_t id = node->GetVolume()->GetNumber();
+    if (IS_NODE_HALF(name))   { 
+      currentDet    = name[1];
+      currentHalf   = name[3];
+      alignName     = Form("FMD/FMD%c_%c", currentDet, currentHalf);
+    }
+    if (IS_NODE_SENSOR(name)) {
+      Char_t ring      = name[1];
+      Int_t  lvl       = next.GetLevel();
+      TGeoNode* parent = next.GetNode(lvl-1);
+      Int_t     copy   = parent->GetNumber();
+      alignName        = Form("FMD/FMD%c_%c/FMD%c_%02d", 
+                         currentDet, currentHalf, ring, copy);
+    }
+    if (alignName.IsNull()) continue;
+    if (!gGeoManager->GetAlignableEntry(alignName.Data())) {
+      AliWarning(Form("No alignable entry for %s, using path %s",
+                     alignName.Data(), path.Data()));
+      alignName = path;
+    }
+    AliFMDDebug(1, ("Making alignment for %s -> %s (%d)", 
+                    alignName.Data(), path.Data(), id));
+    if (IS_NODE_HALF(name))   MakeAlignHalf(alignName, id);
+    if (IS_NODE_SENSOR(name)) MakeAlignSensor(alignName, id);
+#if 0    
+    if (!(IS_NODE_HALF(name) && TESTBIT(fMask, kHalves)) &&
+       !(IS_NODE_SENSOR(name) && TESTBIT(fMask, kSensors))) 
+      continue;
+
+    // Get the path 
+    TString path(Form("/%s", gGeoManager->GetNode(0)->GetName()));
+    Int_t nLevel = next.GetLevel();
+    for (Int_t lvl = 0; lvl <= nLevel; lvl++) {
+      TGeoNode* p = next.GetNode(lvl);
+      if (!p) {
+       if (lvl != 0)
+         AliWarning(Form("No node at level %d in path %s",lvl,path.Data()));
+       continue;
       }
-      Int_t id = node->GetVolume()->GetNumber();
-      if (IS_NODE_HALF(name))   MakeAlignHalf(path, id);
-      if (IS_NODE_SENSOR(name)) MakeAlignSensor(path, id);
+      if (!path.IsNull()) path.Append("/");
+      path.Append(p->GetName());
     }
+    Int_t id = node->GetVolume()->GetNumber();
+    if (IS_NODE_HALF(name))   MakeAlignHalf(path, id);
+    if (IS_NODE_SENSOR(name)) MakeAlignSensor(path, id);
+#endif 
   }
 
   TString t(GetTitle());
-  if (t.Contains("local://") || t.Contains("alien://")) 
+  if (t.IsNull() || t.Contains("local://") || t.Contains("alien://")) 
     WriteToCDB();
   else 
     WriteToFile();
@@ -174,10 +289,23 @@ AliFMDAlignFaker::MakeAlign(const TString& path, Int_t id,
                            Double_t transX, Double_t transY, Double_t transZ,
                            Double_t rotX,   Double_t rotY, Double_t rotZ)
 {
-  AliDebug(1, Form("Make alignment for %s (volume %d)", path.Data(), id));
+  // make alignment for a path 
+  // Params: 
+  //   path      Path to node 
+  //   id        Volume number 
+  //   transX    Translation in X
+  //   transZ    Translation in Y
+  //   transZ    Translation in Z
+  //   rotX      Rotation about X-axis 
+  //   rotY      Rotation about Y-axis
+  //   rotZ      Rotation about Z-axis 
+  AliFMDDebug(3, ("Make alignment for %s (volume %d): (%f,%f,%f) (%f,%f,%f)", 
+                  path.Data(), id, transX, transY, transZ, rotX, rotY, rotZ));
   Int_t nAlign = fArray->GetEntries();
-  AliAlignObjAngles* obj = 
-    new ((*fArray)[nAlign]) AliAlignObjAngles(path.Data(), id,0,0,0,0,0,0);
+  id = 0;
+  AliAlignObjParams* obj = 
+    new ((*fArray)[nAlign]) AliAlignObjParams(path.Data(),
+                                             id,0,0,0,0,0,0,kTRUE);
   if (!obj) {
     AliError(Form("Failed to create alignment object for %s", path.Data()));
     return kFALSE;
@@ -193,7 +321,8 @@ AliFMDAlignFaker::MakeAlign(const TString& path, Int_t id,
 Bool_t
 AliFMDAlignFaker::MakeAlignHalf(const TString& path, Int_t id)
 {
-  AliDebug(1, Form("Make alignment for half-ring/cone %s", path.Data()));
+  // Make alignment of a half ring/cone 
+  AliFMDDebug(15, ("Make alignment for half-ring/cone %s", path.Data()));
   Double_t transX = gRandom->Uniform(fHalfTransMin.X(), fHalfTransMax.X());
   Double_t transY = gRandom->Uniform(fHalfTransMin.Y(), fHalfTransMax.Y());
   Double_t transZ = gRandom->Uniform(fHalfTransMin.Z(), fHalfTransMax.Z());
@@ -208,7 +337,8 @@ AliFMDAlignFaker::MakeAlignHalf(const TString& path, Int_t id)
 Bool_t
 AliFMDAlignFaker::MakeAlignSensor(const TString& path, Int_t id)
 {
-  AliDebug(1, Form("Make alignment for sensor %s", path.Data()));
+  // Make alignment of a sensor 
+  AliFMDDebug(15, ("Make alignment for sensor %s", path.Data()));
   Double_t transX = gRandom->Uniform(fSensorTransMin.X(), fSensorTransMax.X());
   Double_t transY = gRandom->Uniform(fSensorTransMin.Y(), fSensorTransMax.Y());
   Double_t transZ = gRandom->Uniform(fSensorTransMin.Z(), fSensorTransMax.Z());
@@ -223,33 +353,33 @@ void
 AliFMDAlignFaker::WriteToCDB()
 {
   // Make the objects. 
-  AliCDBManager*     cdb      = AliCDBManager::Instance();
-  if (GetTitle())    cdb->SetDefaultStorage(GetTitle());
-    
-  AliCDBMetaData* meta = new AliCDBMetaData; 
+  const char* loc = GetTitle();
+  AliCDBManager*     cdb  = AliCDBManager::Instance();
+  AliCDBStorage*  storage = cdb->GetStorage(!loc ? "" : loc);
+  AliCDBMetaData*    meta = new AliCDBMetaData; 
   meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data()); 
   meta->SetAliRootVersion(gROOT->GetVersion()); 
   meta->SetBeamPeriod(1); 
-  meta->SetComment("Dummy data for testing");
+  meta->SetComment(fComment.Data());
 
   AliCDBId id("FMD/Align/Data", fRunMin, fRunMax);
-  cdb->Put(fArray, id, meta);
-  cdb->Destroy();
+  storage->Put(fArray, id, meta);
 }
 
 //__________________________________________________________________
 void
 AliFMDAlignFaker::WriteToFile()
 {
+  // Write to a local file 
   TFile* file = TFile::Open(GetTitle(), "RECREATE");
   if (!file) {
     AliFatal(Form("Failed to open file '%s' for output", GetTitle()));
     return;
   }
   file->cd();
-  fArray->Write("FMDAlignment");
-  file->Close();
+  fArray->Write("FMDAlignment",TObject::kSingleKey);
   file->Write();
+  file->Close();
 }