add getter for the array with digits and initialization inside, just for analysis...
[u/mrichter/AliRoot.git] / EMCAL / MakeEMCALFullMisAlignment.C
1 enum SurveyDataType_t { kSurvey = 0, kDummy = 1};
2
3 void MakeEMCALFullMisAlignment(TString geoname = "EMCAL_FIRSTYEARv1",TString surveyFilename = "emcal_survey_FIRSTYEARv1.txt",SurveyDataType_t type = kSurvey){
4   // Create TClonesArray of full misalignment objects for EMCAL
5   //
6   const char* macroname = "MakeEMCALFullMisAlignment.C";
7   if(geoname=="")geoname=AliEMCALGeometry::GetDefaultGeometryName();
8   const AliEMCALGeometry *emcalGeom = AliEMCALGeometry::GetInstance(geoname,"");
9   if(!emcalGeom) {
10     Error("MakeEMCALFullMisAlignment","Cannot obtain AliEMCALGeometry singleton\n");
11     return;
12   }
13   TClonesArray *array = new TClonesArray("AliAlignObjParams",emcalGeom->GetNumberOfSuperModules());
14   TClonesArray &alobj = *array;
15
16   // Activate CDB storage and load geometry from CDB
17   AliCDBManager* cdb = AliCDBManager::Instance();
18   if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
19   cdb->SetRun(0);
20   
21   AliCDBStorage* storage;
22   
23   if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){
24     TString Storage = gSystem->Getenv("STORAGE");
25     if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
26       Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
27       return;
28     }
29     storage = cdb->GetStorage(Storage.Data());
30     if(!storage){
31       Error(macroname,"Unable to open storage %s\n",Storage.Data());
32       return;
33     }
34     AliCDBPath path("GRP","Geometry","Data");
35     AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
36     if(!entry) Fatal(macroname,"Could not get the specified CDB entry!");
37     entry->SetOwner(0);
38     TGeoManager* geom = (TGeoManager*) entry->GetObject();
39     AliGeomManager::SetGeometry(geom);
40   }else{
41     AliGeomManager::LoadGeometry(); //load geom from default CDB
42                                     //storage
43   }    
44
45
46   AliEMCALSurvey emcalSurvey(surveyFilename,type);
47   emcalSurvey.CreateAliAlignObjParams(alobj);
48
49   // *************************    2nd step    ***************
50
51   if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
52     // save on file
53     const char* filename = "EMCALfullMisalignment.root";
54     TFile f(filename,"RECREATE");
55     if(!f){
56       Error(macroname,"cannot open file for output\n");
57       return;
58     }
59     Info(macroname,"Saving alignment objects to the file %s", filename);
60     f.cd();
61     f.WriteObject(array,"EMCALAlignObjs","kSingleKey");
62     f.Close();
63   }else{
64     // save in CDB storage
65     AliCDBMetaData* md = new AliCDBMetaData();
66     md->SetResponsible("Jennifer Klay");
67     md->SetComment("Full misalignment for EMCAL_FIRSTYEAR based on survey information");
68     md->AddDateToComment();
69     md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
70     AliCDBId id("EMCAL/Align/Data",0,AliCDBRunRange::Infinity());
71     storage->Put(array,id,md);
72   }
73
74   array->Delete();
75
76 }
77