]> git.uio.no Git - u/mrichter/AliRoot.git/blame - macros/MakeAlignmentObjs.C
o First Version of TRDnSigma implementation (Xianguo) o still requires some catching...
[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"
614b514a 22#include "AliVZEROMisAligner.h"
df797e22 23#include "AliZDCMisAligner.h"
24#include <TString.h>
25#endif
26
614b514a 27void MakeAlignmentObjs(const char* detList="ALL", const char* ocdbOrDir = "local://$HOME/ResidualMisAlignment", const char* misalType="residual", Bool_t partialGeom=kFALSE){
a77a1414 28 // Make alignment objects for all detectors listed in "detList"
29 // for the misalignment scenario passed as argument "misalType".
30 // "ocdbUriDirPath" argument is used as URI for an OCDB if it contains
31 // either the string "local;//" or the string "alien://folder=",
32 // otherwise it is used as the path of the directory where to
33 // put the files containing the alignment objects.
34 // The geometry used is the one produced with $ALICE_ROOT/macros/Config.C
35 // unless "partialGeom" is set to true (=> $ALICE_ROOT/test/fpprod/Config.C).
36 //
df797e22 37
a77a1414 38 const char* macroName = "MakeAlignmentObjs";
39 Bool_t toOCDB = kFALSE;
40 TString fileName("");
41 TString ocdbUriDirPath(ocdbOrDir);
42 if(ocdbUriDirPath.IsNull() || ocdbUriDirPath.IsWhitespace())
43 {
44 Error(macroName, "Output undefined! Set it either to a valid OCDB storage or to the output directory!");
45 return;
46 }else if(ocdbUriDirPath.Contains("local://") || ocdbUriDirPath.Contains("alien://folder=")){
47 // else ocdbUriDirPath is to be interpreted as an OCDB URI
48 toOCDB=kTRUE;
49 Printf("Objects will be saved in the OCDB %s",ocdbUriDirPath.Data());
50 }else{ // else ocdbUriDirPath is to be interpreted as a directory path
51 gSystem->ExpandPathName(ocdbUriDirPath);
52 if(gSystem->AccessPathName(ocdbUriDirPath.Data()))
53 {
54 Printf("Directory \"%s\" where to save files does not yet exist! ... exiting!",ocdbUriDirPath.Data());
55 return;
56 }else{
57 Printf("Files with alignment objects will be saved in the directory %s",ocdbUriDirPath.Data());
58 }
59 }
df797e22 60
a77a1414 61 TMap misAligners;
62 TString modList(detList);
63 if(modList=="ALL") modList="HMPID ITS PMD T0 VZERO ZDC";
64 Info(macroName, "Processing detectors: %s \n", modList.Data());
65 Printf("Creating %s misalignment for detectors: %s \n", misalType, modList.Data());
66 if(modList.Contains("HMPID")){
67 AliHMPIDMisAligner* misAlignerHMPID = new AliHMPIDMisAligner();
68 misAligners.Add(new TObjString("HMPID"), misAlignerHMPID);
69 }
70 if(modList.Contains("ITS")){
71 AliITSMisAligner* misAlignerITS = new AliITSMisAligner();
72 misAligners.Add(new TObjString("ITS"), misAlignerITS);
73 }
74 if(modList.Contains("PMD")){
75 AliPMDMisAligner* misAlignerPMD = new AliPMDMisAligner();
76 misAligners.Add(new TObjString("PMD"), misAlignerPMD);
77 }
78 if(modList.Contains("T0")){
79 AliT0MisAligner* misAlignerT0 = new AliT0MisAligner();
80 misAligners.Add(new TObjString("T0"), misAlignerT0);
81 }
82 // AliTPCMisAligner is in libTPCcalib, not loaded by default, so let it out for the moment
83 //if(modList.Contains("TPC")){
84 // AliTPCMisAligner* misAlignerTPC = new AliTPCMisAligner();
85 // misAligners.Add(new TObjString("TPC"), misAlignerTPC);
86 //}
87 if(modList.Contains("VZERO")){
88 AliVZEROMisAligner* misAlignerVZERO = new AliVZEROMisAligner();
89 misAligners.Add(new TObjString("VZERO"), misAlignerVZERO);
90 }
91 if(modList.Contains("ZDC")){
92 AliZDCMisAligner* misAlignerZDC = new AliZDCMisAligner();
93 misAligners.Add(new TObjString("ZDC"), misAlignerZDC);
94 }
df797e22 95
a77a1414 96 // Load geometry from OCDB; update geometry before loading it if we are going to load
97 // the alignment objects to the OCDB
98 AliCDBManager* cdb = AliCDBManager::Instance();
99 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
100 cdb->SetRun(0);
101 AliCDBStorage* storage = 0;
df797e22 102
a77a1414 103 if(!toOCDB || TString(detList)!="ALL"){ //if we produce the objects into a file or just for some detectors
104 AliGeomManager::LoadGeometry(); //load geom from default OCDB storage without remaking it
105 }else{ // if we produce the objects in a OCDB storage
106 // update geometry in it
107 Info(macroName, "Updating geometry in OCDB storage %s",ocdbUriDirPath.Data());
108 gROOT->ProcessLine(".L $ALICE_ROOT/GRP/UpdateCDBIdealGeom.C");
109 if(partialGeom){
110 UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/test/fpprod/Config.C");
111 }else{
112 UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/macros/Config.C");
113 }
df797e22 114
a77a1414 115 AliGeomManager::SetGeometry(gGeoManager);
116 }
614b514a 117
a77a1414 118 // run macro for non-sensitive modules
119 // (presently generates only FRAME alignment objects)
120 // gSystem->Exec("aliroot -b -q $ALICE_ROOT/GRP/MakeSTRUCTResMisAlignment.C"); !!!!!!!!!!!!!!!!!!!!!!!!!
121
122 // run macros for sensitive modules
123 TObjString *ostr;
124 TString strId;
125 TClonesArray* objsArray = 0;
126
127 TObjArray *detArray = modList.Tokenize(' ');
128 TIter iter(detArray);
129
130 while((ostr = (TObjString*) iter.Next())){
131 TString str(ostr->String()); // DET
132 Printf("\n ---- Making alignment objects for \"%s\" ----",str.Data());
133 TString arName(str.Data()); // name of the array in case saved into the file
134 arName += "AlignObjs";
135 if(gGeoManager->IsLocked()) gGeoManager->UnlockGeometry();
df797e22 136
a77a1414 137 AliMisAligner* misAligner = dynamic_cast<AliMisAligner*> (misAligners.GetValue(str));
138 if(!misAligner){
139 Printf("Misaligner for %s was not instantiated",str.Data());
140 continue;
141 }
142 misAligner->SetMisalType(misalType);
143 objsArray = misAligner->MakeAlObjsArray();
144
145 if(toOCDB)
146 {
147 storage = cdb->GetStorage(ocdbUriDirPath.Data());
148 strId=str;
149 strId+="/Align/Data";
150 AliCDBId id(strId.Data(),0,AliCDBRunRange::Infinity());
151 AliCDBMetaData *md = misAligner->GetCDBMetaData();
0492edf5 152 md->SetAliRootVersion(ALIROOT_BRANCH);
a77a1414 153 md->AddDateToComment();
154 storage->Put(objsArray, id, md);
155 }else{
156 // save on file
157 fileName = ocdbUriDirPath;
158 fileName += "/";
159 fileName += str.Data();
160 fileName += misalType;
161 fileName += "MisAlignment.root";
162 TFile file(fileName.Data(),"RECREATE");
163 if(!file){
164 Error(macroName,"cannot open file for output\n");
165 return;
166 }
167 Info(macroName,"Saving alignment objects to the file %s", fileName.Data());
168 file.cd();
169 file.WriteObject(objsArray,arName.Data(),"kSingleKey");
170 file.Close();
171 }
172 }
173
174 return;
df797e22 175}