Addition of misaligner classes and small changes
[u/mrichter/AliRoot.git] / macros / MakeAlignmentObjs.C
CommitLineData
df797e22 1#include "ARVersion.h"
2
3#if !defined(__CINT__) || defined(__MAKECINT__)
4#include "TSystem.h"
5#include "TROOT.h"
6#include "TGeoManager.h"
7#include "TObjString.h"
8#include "TClonesArray.h"
9#include "TError.h"
10#include "AliGeomManager.h"
11#include "AliCDBManager.h"
12#include "AliCDBStorage.h"
13#include "AliCDBPath.h"
14#include "AliCDBEntry.h"
15#include "AliCDBId.h"
16#include "AliCDBMetaData.h"
17#include "AliMisAligner.h"
614b514a 18#include "AliHMPIDMisAligner.h"
19#include "AliITSMisAligner.h"
20#include "AliPMDMisAligner.h"
21#include "AliT0MisAligner.h"
22#include "AliTPCMisAligner.h"
23#include "AliVZEROMisAligner.h"
df797e22 24#include "AliZDCMisAligner.h"
25#include <TString.h>
26#endif
27
614b514a 28void MakeAlignmentObjs(const char* detList="ALL", const char* ocdbOrDir = "local://$HOME/ResidualMisAlignment", const char* misalType="residual", Bool_t partialGeom=kFALSE){
29 // Make alignment objects for all detectors listed in "detList"
30 // for the misalignment scenario passed as argument "misalType".
31 // "ocdbUriDirPath" argument is used as URI for an OCDB if it contains
32 // either the string "local;//" or the string "alien://folder=",
33 // otherwise it is used as the path of the directory where to
34 // put the files containing the alignment objects.
35 // The geometry used is the one produced with $ALICE_ROOT/macros/Config.C
36 // unless "partialGeom" is set to true (=> $ALICE_ROOT/test/fpprod/Config.C).
df797e22 37 //
38
39 const char* macroName = "MakeAlignmentObjs";
614b514a 40 Bool_t toOCDB = kFALSE;
41 TString fileName("");
42 TString ocdbUriDirPath(ocdbOrDir);
43 if(ocdbUriDirPath.IsNull() || ocdbUriDirPath.IsWhitespace())
df797e22 44 {
614b514a 45 Error(macroName, "Output undefined! Set it either to a valid OCDB storage or to the output directory!");
df797e22 46 return;
614b514a 47 }else if(ocdbUriDirPath.Contains("local://") || ocdbUriDirPath.Contains("alien://folder=")){
48 // else ocdbUriDirPath is to be interpreted as an OCDB URI
49 toOCDB=kTRUE;
50 Printf("Objects will be saved in the OCDB %s",ocdbUriDirPath.Data());
51 }else{ // else ocdbUriDirPath is to be interpreted as a directory path
52 Printf("Objects will be saved in the file %s",ocdbUriDirPath.Data());
df797e22 53 }
614b514a 54
df797e22 55 TMap misAligners;
56 TString modList(detList);
57 if(modList=="ALL") modList="ACORDE EMCAL FMD HMPID ITS MUON PMD PHOS T0 TRD TPC TOF VZERO ZDC";
58 Info(macroName, "Processing detectors: %s \n", modList.Data());
59 Printf("Creating %s misalignment for detectors: %s \n", misalType, modList.Data());
614b514a 60 if(modList.Contains("EMCAL")){
61 AliEMCALMisAligner* misAlignerEMCAL = new AliEMCALMisAligner();
62 misAligners.Add(new TObjString("EMCAL"), misAlignerEMCAL);
63 }
64 if(modList.Contains("HMPID")){
65 AliHMPIDMisAligner* misAlignerHMPID = new AliHMPIDMisAligner();
66 misAligners.Add(new TObjString("HMPID"), misAlignerHMPID);
67 }
68 if(modList.Contains("ITS")){
69 AliITSMisAligner* misAlignerITS = new AliITSMisAligner();
70 misAligners.Add(new TObjString("ITS"), misAlignerITS);
71 }
72 if(modList.Contains("PMD")){
73 AliPMDMisAligner* misAlignerPMD = new AliPMDMisAligner();
74 misAligners.Add(new TObjString("PMD"), misAlignerPMD);
75 }
76 if(modList.Contains("T0")){
77 AliT0MisAligner* misAlignerT0 = new AliT0MisAligner();
78 misAligners.Add(new TObjString("T0"), misAlignerT0);
79 }
80 if(modList.Contains("TPC")){
81 AliTPCMisAligner* misAlignerTPC = new AliTPCMisAligner();
82 misAligners.Add(new TObjString("TPC"), misAlignerTPC);
83 }
84 if(modList.Contains("VZERO")){
85 AliVZEROMisAligner* misAlignerVZERO = new AliVZEROMisAligner();
86 misAligners.Add(new TObjString("VZERO"), misAlignerVZERO);
87 }
df797e22 88 if(modList.Contains("ZDC")){
89 AliZDCMisAligner* misAlignerZDC = new AliZDCMisAligner();
90 misAligners.Add(new TObjString("ZDC"), misAlignerZDC);
91 }
92
614b514a 93 // Load geometry from OCDB; update geometry before loading it if we are going to load
94 // the alignment objects to the OCDB
df797e22 95 AliCDBManager* cdb = AliCDBManager::Instance();
96 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
97 cdb->SetRun(0);
98 AliCDBStorage* storage = 0;
99
614b514a 100 if(!toOCDB){ //if we produce the objects into a file
101 AliGeomManager::LoadGeometry(); //load geom from default OCDB storage
102 }else{ // if we produce the objects in a OCDB storage
df797e22 103 // update geometry in it
614b514a 104 Info(macroName, "Updating geometry in OCDB storage %s",ocdbUriDirPath.Data());
df797e22 105 gROOT->ProcessLine(".L $ALICE_ROOT/GRP/UpdateCDBIdealGeom.C");
106 if(partialGeom){
614b514a 107 UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/test/fpprod/Config.C");
df797e22 108 }else{
614b514a 109 UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/macros/Config.C");
df797e22 110 }
614b514a 111 // load the same geometry from given OCDB storage
df797e22 112 AliCDBPath path("GRP","Geometry","Data");
614b514a 113 storage = cdb->GetStorage(ocdbUriDirPath.Data());
df797e22 114 AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
614b514a 115 if(!entry) Fatal(macroName,"Couldn't load geometry data from OCDB!");
df797e22 116 entry->SetOwner(0);
117 TGeoManager* geom = (TGeoManager*) entry->GetObject();
614b514a 118 if (!geom) Fatal(macroName,"Couldn't find TGeoManager in the specified OCDB entry!");
df797e22 119 AliGeomManager::SetGeometry(geom);
120 }
121
122 // run macro for non-sensitive modules
123 // (presently generates only FRAME alignment objects)
124 // gSystem->Exec("aliroot -b -q $ALICE_ROOT/GRP/MakeSTRUCTResMisAlignment.C"); !!!!!!!!!!!!!!!!!!!!!!!!!
125
126 // run macros for sensitive modules
127 TObjString *ostr;
128 TString strId;
129 TClonesArray* objsArray = 0;
130
131 TObjArray *detArray = modList.Tokenize(' ');
132 TIter iter(detArray);
133
134 while((ostr = (TObjString*) iter.Next())){
614b514a 135 TString str(ostr->String()); // DET
136 TString arName(str.Data()); // name of the array in case saved into the file
df797e22 137 arName += "AlignObjs";
138
139 AliMisAligner* misAligner = dynamic_cast<AliMisAligner*> (misAligners.GetValue(str));
140 misAligner->SetMisalType(misalType);
141 objsArray = misAligner->MakeAlObjsArray();
614b514a 142
143 if(toOCDB)
df797e22 144 {
145 strId=str;
146 strId+="/Align/Data";
147 AliCDBId id(strId.Data(),0,AliCDBRunRange::Infinity());
148 AliCDBMetaData *md = misAligner->GetCDBMetaData();
149 md->SetAliRootVersion(ALIROOT_SVN_BRANCH);
150 storage->Put(objsArray, id, md);
151 }else{
152 // save on file
614b514a 153 fileName = ocdbUriDirPath;
154 fileName += str.Data();
155 fileName += misalType;
156 fileName += "MisAlignment.root";
df797e22 157 TFile file(fileName.Data(),"RECREATE");
158 if(!file){
159 Error(macroName,"cannot open file for output\n");
160 return;
161 }
162 Info(macroName,"Saving alignment objects to the file %s", fileName);
163 file.cd();
164 file.WriteObject(objsArray,arName.Data(),"kSingleKey");
165 file.Close();
166 }
167 }
168
169 return;
170}