]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - macros/MakeAlignmentObjs.C
Using detector quality flag (taken from ALICE logbook) to decide whether to rpodcue...
[u/mrichter/AliRoot.git] / macros / MakeAlignmentObjs.C
index 234b1b6da7557c3f745552672f17eb537e9bd423..a7a7f8da1c86d5d2556d1921c707423b5cfa8c7e 100644 (file)
 #include "AliCDBId.h"
 #include "AliCDBMetaData.h"
 #include "AliMisAligner.h"
+#include "AliHMPIDMisAligner.h"
+#include "AliITSMisAligner.h"
+#include "AliPMDMisAligner.h"
+#include "AliT0MisAligner.h"
+#include "AliVZEROMisAligner.h"
 #include "AliZDCMisAligner.h"
 #include <TString.h>
 #endif
 
-void MakeAlignmentObjs(const char* detList="ALL", const char* CDBstorage = "local://$HOME/ResidualMisAlignment", const char* outDir="", const char* misalType="residual", Bool_t partialGeom=kFALSE){
-  // Make residual misalignment objects for all detectors
-  // Pass different "CDBstorage" argument if needed (e.g. to fill
-  // conditions' data base on alien) or set it to null string to have
-  // the objects saved locally on file 
-  // This macro defines the default name and place for the detector-macros
-  // in charge of producing the residual misalignment objects as 
-  // $ALICE_ROOT/DET/MakeDETResidualMisAlignment.C
-  //
+void MakeAlignmentObjs(const char* detList="ALL", const char* ocdbOrDir = "local://$HOME/ResidualMisAlignment", const char* misalType="residual", Bool_t partialGeom=kFALSE){
+       // Make alignment objects for all detectors listed in "detList"
+       // for the misalignment scenario passed as argument "misalType".
+       // "ocdbUriDirPath" argument is used as URI for an OCDB if it contains
+       // either the string "local;//" or the string "alien://folder=",
+       // otherwise it is used as the path of the directory where to
+       // put the files containing the alignment objects.
+       // The geometry used is the one produced with $ALICE_ROOT/macros/Config.C
+       // unless "partialGeom" is set to true (=> $ALICE_ROOT/test/fpprod/Config.C).
+       //
 
-  const char* macroName = "MakeAlignmentObjs";
-  TString cdbStorage(CDBstorage);
-  TString oDir(outDir);
-  if(cdbStorage.IsNull() && oDir.IsNull())
-  {
-    Error(macroName, "Output undefined! Set either the CDB storage or the output directory!");
-    return;
-  }
-  TString fileName;
+       const char* macroName = "MakeAlignmentObjs";
+       Bool_t toOCDB = kFALSE;
+       TString fileName("");
+       TString ocdbUriDirPath(ocdbOrDir);
+       if(ocdbUriDirPath.IsNull() || ocdbUriDirPath.IsWhitespace())
+       {
+               Error(macroName, "Output undefined! Set it either to a valid OCDB storage or to the output directory!");
+               return;
+       }else if(ocdbUriDirPath.Contains("local://") || ocdbUriDirPath.Contains("alien://folder=")){
+               // else ocdbUriDirPath is to be interpreted as an OCDB URI
+               toOCDB=kTRUE;
+               Printf("Objects will be saved in the OCDB %s",ocdbUriDirPath.Data());  
+       }else{ // else ocdbUriDirPath is to be interpreted as a directory path
+               gSystem->ExpandPathName(ocdbUriDirPath);
+               if(gSystem->AccessPathName(ocdbUriDirPath.Data()))
+               {
+                       Printf("Directory \"%s\" where to save files does not yet exist! ... exiting!",ocdbUriDirPath.Data());
+                       return;
+               }else{
+                       Printf("Files with alignment objects will be saved in the directory %s",ocdbUriDirPath.Data());  
+               }
+       }
 
-  TMap misAligners;
-  TString modList(detList);
-  if(modList=="ALL") modList="ACORDE EMCAL FMD HMPID ITS MUON PMD PHOS T0 TRD TPC TOF VZERO ZDC";
-  Info(macroName, "Processing detectors: %s \n", modList.Data());
-  Printf("Creating %s misalignment for detectors: %s \n", misalType, modList.Data());
-  if(modList.Contains("ZDC")){
-    AliZDCMisAligner* misAlignerZDC = new AliZDCMisAligner();
-    misAligners.Add(new TObjString("ZDC"), misAlignerZDC);
-  }
+       TMap misAligners;
+       TString modList(detList);
+       if(modList=="ALL") modList="HMPID ITS PMD T0 VZERO ZDC";
+       Info(macroName, "Processing detectors: %s \n", modList.Data());
+       Printf("Creating %s misalignment for detectors: %s \n", misalType, modList.Data());
+       if(modList.Contains("HMPID")){
+               AliHMPIDMisAligner* misAlignerHMPID = new AliHMPIDMisAligner();
+               misAligners.Add(new TObjString("HMPID"), misAlignerHMPID);
+       }
+       if(modList.Contains("ITS")){
+               AliITSMisAligner* misAlignerITS = new AliITSMisAligner();
+               misAligners.Add(new TObjString("ITS"), misAlignerITS);
+       }
+       if(modList.Contains("PMD")){
+               AliPMDMisAligner* misAlignerPMD = new AliPMDMisAligner();
+               misAligners.Add(new TObjString("PMD"), misAlignerPMD);
+       }
+       if(modList.Contains("T0")){
+               AliT0MisAligner* misAlignerT0 = new AliT0MisAligner();
+               misAligners.Add(new TObjString("T0"), misAlignerT0);
+       }
+       // AliTPCMisAligner is in libTPCcalib, not loaded by default, so let it out for the moment
+       //if(modList.Contains("TPC")){
+       //      AliTPCMisAligner* misAlignerTPC = new AliTPCMisAligner();
+       //      misAligners.Add(new TObjString("TPC"), misAlignerTPC);
+       //}
+       if(modList.Contains("VZERO")){
+               AliVZEROMisAligner* misAlignerVZERO = new AliVZEROMisAligner();
+               misAligners.Add(new TObjString("VZERO"), misAlignerVZERO);
+       }
+       if(modList.Contains("ZDC")){
+               AliZDCMisAligner* misAlignerZDC = new AliZDCMisAligner();
+               misAligners.Add(new TObjString("ZDC"), misAlignerZDC);
+       }
 
-  // Load geometry from CDB; update geometry before loading it if we are going to load
-  // the alignment objects to the CDB
-  AliCDBManager* cdb = AliCDBManager::Instance();
-  if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
-  cdb->SetRun(0);
-  AliCDBStorage* storage = 0;
-  
-  if(cdbStorage.IsNull()){ //if we produce the objects into a file
-    AliGeomManager::LoadGeometry(); //load geom from default CDB storage
-  }else{ // if we produce the objects in a CDB storage
-    // update geometry in it
-    Info(macroName, "Updating geometry in CDB storage %s",cdbStorage.Data());
-    gROOT->ProcessLine(".L $ALICE_ROOT/GRP/UpdateCDBIdealGeom.C");
-    if(partialGeom){
-      UpdateCDBIdealGeom(cdbStorage.Data(),"$ALICE_ROOT/test/fpprod/Config.C");
-    }else{
-      UpdateCDBIdealGeom(cdbStorage.Data(),"$ALICE_ROOT/macros/Config.C");
-    }
-    // load the same geometry from given CDB storage
-    AliCDBPath path("GRP","Geometry","Data");
-    storage = cdb->GetStorage(cdbStorage.Data());
-    AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
-    if(!entry) Fatal(macroName,"Couldn't load geometry data from CDB!");
-    entry->SetOwner(0);
-    TGeoManager* geom = (TGeoManager*) entry->GetObject();
-    if (!geom) Fatal(macroName,"Couldn't find TGeoManager in the specified CDB entry!");
-    AliGeomManager::SetGeometry(geom);
-  }
-  
-  // run macro for non-sensitive modules
-  // (presently generates only FRAME alignment objects)
-  // gSystem->Exec("aliroot -b -q $ALICE_ROOT/GRP/MakeSTRUCTResMisAlignment.C"); !!!!!!!!!!!!!!!!!!!!!!!!!
+       // Load geometry from OCDB; update geometry before loading it if we are going to load
+       // the alignment objects to the OCDB
+       AliCDBManager* cdb = AliCDBManager::Instance();
+       if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+       cdb->SetRun(0);
+       AliCDBStorage* storage = 0;
 
-  // run macros for sensitive modules
-  TObjString *ostr;
-  TString strId;
-  TClonesArray* objsArray = 0;
+       if(!toOCDB || TString(detList)!="ALL"){ //if we produce the objects into a file or just for some detectors
+               AliGeomManager::LoadGeometry(); //load geom from default OCDB storage without remaking it
+       }else{ // if we produce the objects in a OCDB storage
+               // update geometry in it
+               Info(macroName, "Updating geometry in OCDB storage %s",ocdbUriDirPath.Data());
+               gROOT->ProcessLine(".L $ALICE_ROOT/GRP/UpdateCDBIdealGeom.C");
+               if(partialGeom){
+                       UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/test/fpprod/Config.C");
+               }else{
+                       UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/macros/Config.C");
+               }
 
-  TObjArray *detArray = modList.Tokenize(' ');
-  TIter iter(detArray);
+               AliGeomManager::SetGeometry(gGeoManager);
+       }
 
-  while((ostr = (TObjString*) iter.Next())){
-    TString str(ostr->String());
-    if(!oDir.IsNull())
-    {
-      fileName = oDir;
-      fileName += str.Data();
-      fileName += misalType;
-      fileName += "MisAlignment.root";
-    }
-    TString arName(str.Data());
-    arName += "AlignObjs";
-    
-    AliMisAligner* misAligner = dynamic_cast<AliMisAligner*> (misAligners.GetValue(str));
-    misAligner->SetMisalType(misalType);
-    objsArray = misAligner->MakeAlObjsArray();
-    //Printf("objsArray has %d entries",objsArray->GetEntriesFast());
-    //objsArray->Print();
-    if(!cdbStorage.IsNull())
-    {
-      strId=str;
-      strId+="/Align/Data";
-      AliCDBId id(strId.Data(),0,AliCDBRunRange::Infinity());
-      AliCDBMetaData *md = misAligner->GetCDBMetaData();
-      md->SetAliRootVersion(ALIROOT_SVN_BRANCH);
-      storage->Put(objsArray, id, md);
-    }else{
-      // save on file
-      TFile file(fileName.Data(),"RECREATE");
-      if(!file){
-       Error(macroName,"cannot open file for output\n");
-       return;
-      }
-      Info(macroName,"Saving alignment objects to the file %s", fileName);
-      file.cd();
-      file.WriteObject(objsArray,arName.Data(),"kSingleKey");
-      file.Close();
-    }
-  }
+       // run macro for non-sensitive modules
+       // (presently generates only FRAME alignment objects)
+       // gSystem->Exec("aliroot -b -q $ALICE_ROOT/GRP/MakeSTRUCTResMisAlignment.C"); !!!!!!!!!!!!!!!!!!!!!!!!!
+
+       // run macros for sensitive modules
+       TObjString *ostr;
+       TString strId;
+       TClonesArray* objsArray = 0;
+
+       TObjArray *detArray = modList.Tokenize(' ');
+       TIter iter(detArray);
+
+       while((ostr = (TObjString*) iter.Next())){
+               TString str(ostr->String()); // DET
+               Printf("\n   ----  Making alignment objects for \"%s\"  ----",str.Data());
+               TString arName(str.Data());  // name of the array in case saved into the file
+               arName += "AlignObjs";
+               if(gGeoManager->IsLocked()) gGeoManager->UnlockGeometry();
 
-  return;
+               AliMisAligner* misAligner = dynamic_cast<AliMisAligner*> (misAligners.GetValue(str));
+               if(!misAligner){
+                       Printf("Misaligner for %s was not instantiated",str.Data());
+                       continue;
+               }
+               misAligner->SetMisalType(misalType);
+               objsArray = misAligner->MakeAlObjsArray();
+
+               if(toOCDB)
+               {
+                       storage = cdb->GetStorage(ocdbUriDirPath.Data());
+                       strId=str;
+                       strId+="/Align/Data";
+                       AliCDBId id(strId.Data(),0,AliCDBRunRange::Infinity());
+                       AliCDBMetaData *md = misAligner->GetCDBMetaData();
+                       md->SetAliRootVersion(ALIROOT_BRANCH);
+                       md->AddDateToComment();
+                       storage->Put(objsArray, id, md);
+               }else{
+                       // save on file
+                       fileName = ocdbUriDirPath;
+                       fileName += "/";
+                       fileName += str.Data();
+                       fileName += misalType;
+                       fileName += "MisAlignment.root";
+                       TFile file(fileName.Data(),"RECREATE");
+                       if(!file){
+                               Error(macroName,"cannot open file for output\n");
+                               return;
+                       }
+                       Info(macroName,"Saving alignment objects to the file %s", fileName.Data());
+                       file.cd();
+                       file.WriteObject(objsArray,arName.Data(),"kSingleKey");
+                       file.Close();
+               }
+       }
+
+       return;
 }