3 #if !defined(__CINT__) || defined(__MAKECINT__)
6 #include "TGeoManager.h"
7 #include "TObjString.h"
8 #include "TClonesArray.h"
10 #include "AliGeomManager.h"
11 #include "AliCDBManager.h"
12 #include "AliCDBStorage.h"
13 #include "AliCDBPath.h"
14 #include "AliCDBEntry.h"
16 #include "AliCDBMetaData.h"
17 #include "AliMisAligner.h"
18 #include "AliHMPIDMisAligner.h"
19 #include "AliITSMisAligner.h"
20 #include "AliPMDMisAligner.h"
21 #include "AliT0MisAligner.h"
22 #include "AliTPCMisAligner.h"
23 #include "AliVZEROMisAligner.h"
24 #include "AliZDCMisAligner.h"
28 void 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).
39 const char* macroName = "MakeAlignmentObjs";
40 Bool_t toOCDB = kFALSE;
42 TString ocdbUriDirPath(ocdbOrDir);
43 if(ocdbUriDirPath.IsNull() || ocdbUriDirPath.IsWhitespace())
45 Error(macroName, "Output undefined! Set it either to a valid OCDB storage or to the output directory!");
47 }else if(ocdbUriDirPath.Contains("local://") || ocdbUriDirPath.Contains("alien://folder=")){
48 // else ocdbUriDirPath is to be interpreted as an OCDB URI
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());
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());
60 if(modList.Contains("EMCAL")){
61 AliEMCALMisAligner* misAlignerEMCAL = new AliEMCALMisAligner();
62 misAligners.Add(new TObjString("EMCAL"), misAlignerEMCAL);
64 if(modList.Contains("HMPID")){
65 AliHMPIDMisAligner* misAlignerHMPID = new AliHMPIDMisAligner();
66 misAligners.Add(new TObjString("HMPID"), misAlignerHMPID);
68 if(modList.Contains("ITS")){
69 AliITSMisAligner* misAlignerITS = new AliITSMisAligner();
70 misAligners.Add(new TObjString("ITS"), misAlignerITS);
72 if(modList.Contains("PMD")){
73 AliPMDMisAligner* misAlignerPMD = new AliPMDMisAligner();
74 misAligners.Add(new TObjString("PMD"), misAlignerPMD);
76 if(modList.Contains("T0")){
77 AliT0MisAligner* misAlignerT0 = new AliT0MisAligner();
78 misAligners.Add(new TObjString("T0"), misAlignerT0);
80 if(modList.Contains("TPC")){
81 AliTPCMisAligner* misAlignerTPC = new AliTPCMisAligner();
82 misAligners.Add(new TObjString("TPC"), misAlignerTPC);
84 if(modList.Contains("VZERO")){
85 AliVZEROMisAligner* misAlignerVZERO = new AliVZEROMisAligner();
86 misAligners.Add(new TObjString("VZERO"), misAlignerVZERO);
88 if(modList.Contains("ZDC")){
89 AliZDCMisAligner* misAlignerZDC = new AliZDCMisAligner();
90 misAligners.Add(new TObjString("ZDC"), misAlignerZDC);
93 // Load geometry from OCDB; update geometry before loading it if we are going to load
94 // the alignment objects to the OCDB
95 AliCDBManager* cdb = AliCDBManager::Instance();
96 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
98 AliCDBStorage* storage = 0;
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
103 // update geometry in it
104 Info(macroName, "Updating geometry in OCDB storage %s",ocdbUriDirPath.Data());
105 gROOT->ProcessLine(".L $ALICE_ROOT/GRP/UpdateCDBIdealGeom.C");
107 UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/test/fpprod/Config.C");
109 UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/macros/Config.C");
111 // load the same geometry from given OCDB storage
112 AliCDBPath path("GRP","Geometry","Data");
113 storage = cdb->GetStorage(ocdbUriDirPath.Data());
114 AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
115 if(!entry) Fatal(macroName,"Couldn't load geometry data from OCDB!");
117 TGeoManager* geom = (TGeoManager*) entry->GetObject();
118 if (!geom) Fatal(macroName,"Couldn't find TGeoManager in the specified OCDB entry!");
119 AliGeomManager::SetGeometry(geom);
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"); !!!!!!!!!!!!!!!!!!!!!!!!!
126 // run macros for sensitive modules
129 TClonesArray* objsArray = 0;
131 TObjArray *detArray = modList.Tokenize(' ');
132 TIter iter(detArray);
134 while((ostr = (TObjString*) iter.Next())){
135 TString str(ostr->String()); // DET
136 TString arName(str.Data()); // name of the array in case saved into the file
137 arName += "AlignObjs";
139 AliMisAligner* misAligner = dynamic_cast<AliMisAligner*> (misAligners.GetValue(str));
140 misAligner->SetMisalType(misalType);
141 objsArray = misAligner->MakeAlObjsArray();
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);
153 fileName = ocdbUriDirPath;
154 fileName += str.Data();
155 fileName += misalType;
156 fileName += "MisAlignment.root";
157 TFile file(fileName.Data(),"RECREATE");
159 Error(macroName,"cannot open file for output\n");
162 Info(macroName,"Saving alignment objects to the file %s", fileName);
164 file.WriteObject(objsArray,arName.Data(),"kSingleKey");