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 "AliVZEROMisAligner.h"
23 #include "AliZDCMisAligner.h"
27 void MakeAlignmentObjs(const char* detList="ALL", const char* ocdbOrDir = "local://$HOME/ResidualMisAlignment", const char* misalType="residual", Bool_t partialGeom=kFALSE){
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).
38 const char* macroName = "MakeAlignmentObjs";
39 Bool_t toOCDB = kFALSE;
41 TString ocdbUriDirPath(ocdbOrDir);
42 if(ocdbUriDirPath.IsNull() || ocdbUriDirPath.IsWhitespace())
44 Error(macroName, "Output undefined! Set it either to a valid OCDB storage or to the output directory!");
46 }else if(ocdbUriDirPath.Contains("local://") || ocdbUriDirPath.Contains("alien://folder=")){
47 // else ocdbUriDirPath is to be interpreted as an OCDB URI
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()))
54 Printf("Directory \"%s\" where to save files does not yet exist! ... exiting!",ocdbUriDirPath.Data());
57 Printf("Files with alignment objects will be saved in the directory %s",ocdbUriDirPath.Data());
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);
70 if(modList.Contains("ITS")){
71 AliITSMisAligner* misAlignerITS = new AliITSMisAligner();
72 misAligners.Add(new TObjString("ITS"), misAlignerITS);
74 if(modList.Contains("PMD")){
75 AliPMDMisAligner* misAlignerPMD = new AliPMDMisAligner();
76 misAligners.Add(new TObjString("PMD"), misAlignerPMD);
78 if(modList.Contains("T0")){
79 AliT0MisAligner* misAlignerT0 = new AliT0MisAligner();
80 misAligners.Add(new TObjString("T0"), misAlignerT0);
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);
87 if(modList.Contains("VZERO")){
88 AliVZEROMisAligner* misAlignerVZERO = new AliVZEROMisAligner();
89 misAligners.Add(new TObjString("VZERO"), misAlignerVZERO);
91 if(modList.Contains("ZDC")){
92 AliZDCMisAligner* misAlignerZDC = new AliZDCMisAligner();
93 misAligners.Add(new TObjString("ZDC"), misAlignerZDC);
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");
101 AliCDBStorage* storage = 0;
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");
110 UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/test/fpprod/Config.C");
112 UpdateCDBIdealGeom(ocdbUriDirPath.Data(),"$ALICE_ROOT/macros/Config.C");
115 AliGeomManager::SetGeometry(gGeoManager);
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"); !!!!!!!!!!!!!!!!!!!!!!!!!
122 // run macros for sensitive modules
125 TClonesArray* objsArray = 0;
127 TObjArray *detArray = modList.Tokenize(' ');
128 TIter iter(detArray);
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();
137 AliMisAligner* misAligner = dynamic_cast<AliMisAligner*> (misAligners.GetValue(str));
139 Printf("Misaligner for %s was not instantiated",str.Data());
142 misAligner->SetMisalType(misalType);
143 objsArray = misAligner->MakeAlObjsArray();
147 storage = cdb->GetStorage(ocdbUriDirPath.Data());
149 strId+="/Align/Data";
150 AliCDBId id(strId.Data(),0,AliCDBRunRange::Infinity());
151 AliCDBMetaData *md = misAligner->GetCDBMetaData();
152 md->SetAliRootVersion(ALIROOT_SVN_BRANCH);
153 md->AddDateToComment();
154 storage->Put(objsArray, id, md);
157 fileName = ocdbUriDirPath;
159 fileName += str.Data();
160 fileName += misalType;
161 fileName += "MisAlignment.root";
162 TFile file(fileName.Data(),"RECREATE");
164 Error(macroName,"cannot open file for output\n");
167 Info(macroName,"Saving alignment objects to the file %s", fileName.Data());
169 file.WriteObject(objsArray,arName.Data(),"kSingleKey");