]> git.uio.no Git - u/mrichter/AliRoot.git/blame - macros/MakeAlignmentObjs.C
Summary of 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"
18#include "AliZDCMisAligner.h"
19#include <TString.h>
20#endif
21
22void MakeAlignmentObjs(const char* detList="ALL", const char* CDBstorage = "local://$HOME/ResidualMisAlignment", const char* outDir="", const char* misalType="residual", Bool_t partialGeom=kFALSE){
23 // Make residual misalignment objects for all detectors
24 // Pass different "CDBstorage" argument if needed (e.g. to fill
25 // conditions' data base on alien) or set it to null string to have
26 // the objects saved locally on file
27 // This macro defines the default name and place for the detector-macros
28 // in charge of producing the residual misalignment objects as
29 // $ALICE_ROOT/DET/MakeDETResidualMisAlignment.C
30 //
31
32 const char* macroName = "MakeAlignmentObjs";
33 TString cdbStorage(CDBstorage);
34 TString oDir(outDir);
35 if(cdbStorage.IsNull() && oDir.IsNull())
36 {
37 Error(macroName, "Output undefined! Set either the CDB storage or the output directory!");
38 return;
39 }
40 TString fileName;
41
42 TMap misAligners;
43 TString modList(detList);
44 if(modList=="ALL") modList="ACORDE EMCAL FMD HMPID ITS MUON PMD PHOS T0 TRD TPC TOF VZERO ZDC";
45 Info(macroName, "Processing detectors: %s \n", modList.Data());
46 Printf("Creating %s misalignment for detectors: %s \n", misalType, modList.Data());
47 if(modList.Contains("ZDC")){
48 AliZDCMisAligner* misAlignerZDC = new AliZDCMisAligner();
49 misAligners.Add(new TObjString("ZDC"), misAlignerZDC);
50 }
51
52 // Load geometry from CDB; update geometry before loading it if we are going to load
53 // the alignment objects to the CDB
54 AliCDBManager* cdb = AliCDBManager::Instance();
55 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
56 cdb->SetRun(0);
57 AliCDBStorage* storage = 0;
58
59 if(cdbStorage.IsNull()){ //if we produce the objects into a file
60 AliGeomManager::LoadGeometry(); //load geom from default CDB storage
61 }else{ // if we produce the objects in a CDB storage
62 // update geometry in it
63 Info(macroName, "Updating geometry in CDB storage %s",cdbStorage.Data());
64 gROOT->ProcessLine(".L $ALICE_ROOT/GRP/UpdateCDBIdealGeom.C");
65 if(partialGeom){
66 UpdateCDBIdealGeom(cdbStorage.Data(),"$ALICE_ROOT/test/fpprod/Config.C");
67 }else{
68 UpdateCDBIdealGeom(cdbStorage.Data(),"$ALICE_ROOT/macros/Config.C");
69 }
70 // load the same geometry from given CDB storage
71 AliCDBPath path("GRP","Geometry","Data");
72 storage = cdb->GetStorage(cdbStorage.Data());
73 AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
74 if(!entry) Fatal(macroName,"Couldn't load geometry data from CDB!");
75 entry->SetOwner(0);
76 TGeoManager* geom = (TGeoManager*) entry->GetObject();
77 if (!geom) Fatal(macroName,"Couldn't find TGeoManager in the specified CDB entry!");
78 AliGeomManager::SetGeometry(geom);
79 }
80
81 // run macro for non-sensitive modules
82 // (presently generates only FRAME alignment objects)
83 // gSystem->Exec("aliroot -b -q $ALICE_ROOT/GRP/MakeSTRUCTResMisAlignment.C"); !!!!!!!!!!!!!!!!!!!!!!!!!
84
85 // run macros for sensitive modules
86 TObjString *ostr;
87 TString strId;
88 TClonesArray* objsArray = 0;
89
90 TObjArray *detArray = modList.Tokenize(' ');
91 TIter iter(detArray);
92
93 while((ostr = (TObjString*) iter.Next())){
94 TString str(ostr->String());
95 if(!oDir.IsNull())
96 {
97 fileName = oDir;
98 fileName += str.Data();
99 fileName += misalType;
100 fileName += "MisAlignment.root";
101 }
102 TString arName(str.Data());
103 arName += "AlignObjs";
104
105 AliMisAligner* misAligner = dynamic_cast<AliMisAligner*> (misAligners.GetValue(str));
106 misAligner->SetMisalType(misalType);
107 objsArray = misAligner->MakeAlObjsArray();
108 //Printf("objsArray has %d entries",objsArray->GetEntriesFast());
109 //objsArray->Print();
110 if(!cdbStorage.IsNull())
111 {
112 strId=str;
113 strId+="/Align/Data";
114 AliCDBId id(strId.Data(),0,AliCDBRunRange::Infinity());
115 AliCDBMetaData *md = misAligner->GetCDBMetaData();
116 md->SetAliRootVersion(ALIROOT_SVN_BRANCH);
117 storage->Put(objsArray, id, md);
118 }else{
119 // save on file
120 TFile file(fileName.Data(),"RECREATE");
121 if(!file){
122 Error(macroName,"cannot open file for output\n");
123 return;
124 }
125 Info(macroName,"Saving alignment objects to the file %s", fileName);
126 file.cd();
127 file.WriteObject(objsArray,arName.Data(),"kSingleKey");
128 file.Close();
129 }
130 }
131
132 return;
133}