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 gSystem->ExpandPathName(ocdbUriDirPath);
53 if(gSystem->AccessPathName(ocdbUriDirPath.Data()))
55 Printf("Directory \"%s\" where to save files does not yet exist! ... exiting!",ocdbUriDirPath.Data());
58 Printf("Files with alignment objects will be saved in the directory %s",ocdbUriDirPath.Data());
63 TString modList(detList);
64 if(modList=="ALL") modList="ACORDE EMCAL FMD HMPID ITS MUON PMD PHOS T0 TRD TPC TOF VZERO ZDC";
65 Info(macroName, "Processing detectors: %s \n", modList.Data());
66 Printf("Creating %s misalignment for detectors: %s \n", misalType, modList.Data());
67 if(modList.Contains("EMCAL")){
68 AliEMCALMisAligner* misAlignerEMCAL = new AliEMCALMisAligner();
69 misAligners.Add(new TObjString("EMCAL"), misAlignerEMCAL);
71 if(modList.Contains("HMPID")){
72 AliHMPIDMisAligner* misAlignerHMPID = new AliHMPIDMisAligner();
73 misAligners.Add(new TObjString("HMPID"), misAlignerHMPID);
75 if(modList.Contains("ITS")){
76 AliITSMisAligner* misAlignerITS = new AliITSMisAligner();
77 misAligners.Add(new TObjString("ITS"), misAlignerITS);
79 if(modList.Contains("PMD")){
80 AliPMDMisAligner* misAlignerPMD = new AliPMDMisAligner();
81 misAligners.Add(new TObjString("PMD"), misAlignerPMD);
83 if(modList.Contains("T0")){
84 AliT0MisAligner* misAlignerT0 = new AliT0MisAligner();
85 misAligners.Add(new TObjString("T0"), misAlignerT0);
87 if(modList.Contains("TPC")){
88 AliTPCMisAligner* misAlignerTPC = new AliTPCMisAligner();
89 misAligners.Add(new TObjString("TPC"), misAlignerTPC);
91 if(modList.Contains("VZERO")){
92 AliVZEROMisAligner* misAlignerVZERO = new AliVZEROMisAligner();
93 misAligners.Add(new TObjString("VZERO"), misAlignerVZERO);
95 if(modList.Contains("ZDC")){
96 AliZDCMisAligner* misAlignerZDC = new AliZDCMisAligner();
97 misAligners.Add(new TObjString("ZDC"), misAlignerZDC);
100 // Load geometry from OCDB; update geometry before loading it if we are going to load
101 // the alignment objects to the OCDB
102 AliCDBManager* cdb = AliCDBManager::Instance();
103 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
105 AliCDBStorage* storage = 0;
107 if(!toOCDB){ //if we produce the objects into a file
108 AliGeomManager::LoadGeometry(); //load geom from default OCDB storage
109 }else{ // if we produce the objects in a OCDB storage
110 // update geometry in it
111 Info(macroName, "Updating geometry in OCDB storage %s",ocdbUriDirPath.Data());
112 gROOT->ProcessLine(".L $ALICE_ROOT/GRP/UpdateCDBIdealGeom.C");
114 UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/test/fpprod/Config.C");
116 UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/macros/Config.C");
118 // load the same geometry from given OCDB storage
119 AliCDBPath path("GRP","Geometry","Data");
120 storage = cdb->GetStorage(ocdbUriDirPath.Data());
121 AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
122 if(!entry) Fatal(macroName,"Couldn't load geometry data from OCDB!");
124 TGeoManager* geom = (TGeoManager*) entry->GetObject();
125 if (!geom) Fatal(macroName,"Couldn't find TGeoManager in the specified OCDB entry!");
126 AliGeomManager::SetGeometry(geom);
129 // run macro for non-sensitive modules
130 // (presently generates only FRAME alignment objects)
131 // gSystem->Exec("aliroot -b -q $ALICE_ROOT/GRP/MakeSTRUCTResMisAlignment.C"); !!!!!!!!!!!!!!!!!!!!!!!!!
133 // run macros for sensitive modules
136 TClonesArray* objsArray = 0;
138 TObjArray *detArray = modList.Tokenize(' ');
139 TIter iter(detArray);
141 while((ostr = (TObjString*) iter.Next())){
142 TString str(ostr->String()); // DET
143 TString arName(str.Data()); // name of the array in case saved into the file
144 arName += "AlignObjs";
146 AliMisAligner* misAligner = dynamic_cast<AliMisAligner*> (misAligners.GetValue(str));
147 misAligner->SetMisalType(misalType);
148 objsArray = misAligner->MakeAlObjsArray();
153 strId+="/Align/Data";
154 AliCDBId id(strId.Data(),0,AliCDBRunRange::Infinity());
155 AliCDBMetaData *md = misAligner->GetCDBMetaData();
156 md->SetAliRootVersion(ALIROOT_SVN_BRANCH);
157 storage->Put(objsArray, id, md);
160 fileName = ocdbUriDirPath;
162 fileName += str.Data();
163 fileName += misalType;
164 fileName += "MisAlignment.root";
165 TFile file(fileName.Data(),"RECREATE");
167 Error(macroName,"cannot open file for output\n");
170 Info(macroName,"Saving alignment objects to the file %s", fileName.Data());
172 file.WriteObject(objsArray,arName.Data(),"kSingleKey");