ROOT logo
enum SurveyDataType_t { kSurvey = 0, kDummy = 1};

void MakeEMCALFullMisAlignment(TString geoname = "EMCAL_FIRSTYEARv1",TString surveyFilename = "emcal_survey_FIRSTYEARv1.txt",SurveyDataType_t type = kSurvey){
  // Create TClonesArray of full misalignment objects for EMCAL
  //
  const char* macroname = "MakeEMCALFullMisAlignment.C";
  if(geoname=="")geoname=AliEMCALGeometry::GetDefaultGeometryName();
  const AliEMCALGeometry *emcalGeom = AliEMCALGeometry::GetInstance(geoname,"");
  if(!emcalGeom) {
    Error("MakeEMCALFullMisAlignment","Cannot obtain AliEMCALGeometry singleton\n");
    return;
  }
  TClonesArray *array = new TClonesArray("AliAlignObjParams",emcalGeom->GetNumberOfSuperModules());
  TClonesArray &alobj = *array;

  // Activate CDB storage and load geometry from CDB
  AliCDBManager* cdb = AliCDBManager::Instance();
  if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
  cdb->SetRun(0);
  
  AliCDBStorage* storage;
  
  if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){
    TString Storage = gSystem->Getenv("STORAGE");
    if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
      Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
      return;
    }
    storage = cdb->GetStorage(Storage.Data());
    if(!storage){
      Error(macroname,"Unable to open storage %s\n",Storage.Data());
      return;
    }
    AliCDBPath path("GRP","Geometry","Data");
    AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
    if(!entry) Fatal(macroname,"Could not get the specified CDB entry!");
    entry->SetOwner(0);
    TGeoManager* geom = (TGeoManager*) entry->GetObject();
    AliGeomManager::SetGeometry(geom);
  }else{
    AliGeomManager::LoadGeometry(); //load geom from default CDB
				    //storage
  }    


  AliEMCALSurvey emcalSurvey(surveyFilename,type);
  emcalSurvey.CreateAliAlignObjParams(alobj);

  // *************************    2nd step    ***************

  if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
    // save on file
    const char* filename = "EMCALfullMisalignment.root";
    TFile f(filename,"RECREATE");
    if(!f){
      Error(macroname,"cannot open file for output\n");
      return;
    }
    Info(macroname,"Saving alignment objects to the file %s", filename);
    f.cd();
    f.WriteObject(array,"EMCALAlignObjs","kSingleKey");
    f.Close();
  }else{
    // save in CDB storage
    AliCDBMetaData* md = new AliCDBMetaData();
    md->SetResponsible("Jennifer Klay");
    md->SetComment("Full misalignment for EMCAL_FIRSTYEAR based on survey information");
    md->AddDateToComment();
    md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
    AliCDBId id("EMCAL/Align/Data",0,AliCDBRunRange::Infinity());
    storage->Put(array,id,md);
  }

  array->Delete();

}

 MakeEMCALFullMisAlignment.C:1
 MakeEMCALFullMisAlignment.C:2
 MakeEMCALFullMisAlignment.C:3
 MakeEMCALFullMisAlignment.C:4
 MakeEMCALFullMisAlignment.C:5
 MakeEMCALFullMisAlignment.C:6
 MakeEMCALFullMisAlignment.C:7
 MakeEMCALFullMisAlignment.C:8
 MakeEMCALFullMisAlignment.C:9
 MakeEMCALFullMisAlignment.C:10
 MakeEMCALFullMisAlignment.C:11
 MakeEMCALFullMisAlignment.C:12
 MakeEMCALFullMisAlignment.C:13
 MakeEMCALFullMisAlignment.C:14
 MakeEMCALFullMisAlignment.C:15
 MakeEMCALFullMisAlignment.C:16
 MakeEMCALFullMisAlignment.C:17
 MakeEMCALFullMisAlignment.C:18
 MakeEMCALFullMisAlignment.C:19
 MakeEMCALFullMisAlignment.C:20
 MakeEMCALFullMisAlignment.C:21
 MakeEMCALFullMisAlignment.C:22
 MakeEMCALFullMisAlignment.C:23
 MakeEMCALFullMisAlignment.C:24
 MakeEMCALFullMisAlignment.C:25
 MakeEMCALFullMisAlignment.C:26
 MakeEMCALFullMisAlignment.C:27
 MakeEMCALFullMisAlignment.C:28
 MakeEMCALFullMisAlignment.C:29
 MakeEMCALFullMisAlignment.C:30
 MakeEMCALFullMisAlignment.C:31
 MakeEMCALFullMisAlignment.C:32
 MakeEMCALFullMisAlignment.C:33
 MakeEMCALFullMisAlignment.C:34
 MakeEMCALFullMisAlignment.C:35
 MakeEMCALFullMisAlignment.C:36
 MakeEMCALFullMisAlignment.C:37
 MakeEMCALFullMisAlignment.C:38
 MakeEMCALFullMisAlignment.C:39
 MakeEMCALFullMisAlignment.C:40
 MakeEMCALFullMisAlignment.C:41
 MakeEMCALFullMisAlignment.C:42
 MakeEMCALFullMisAlignment.C:43
 MakeEMCALFullMisAlignment.C:44
 MakeEMCALFullMisAlignment.C:45
 MakeEMCALFullMisAlignment.C:46
 MakeEMCALFullMisAlignment.C:47
 MakeEMCALFullMisAlignment.C:48
 MakeEMCALFullMisAlignment.C:49
 MakeEMCALFullMisAlignment.C:50
 MakeEMCALFullMisAlignment.C:51
 MakeEMCALFullMisAlignment.C:52
 MakeEMCALFullMisAlignment.C:53
 MakeEMCALFullMisAlignment.C:54
 MakeEMCALFullMisAlignment.C:55
 MakeEMCALFullMisAlignment.C:56
 MakeEMCALFullMisAlignment.C:57
 MakeEMCALFullMisAlignment.C:58
 MakeEMCALFullMisAlignment.C:59
 MakeEMCALFullMisAlignment.C:60
 MakeEMCALFullMisAlignment.C:61
 MakeEMCALFullMisAlignment.C:62
 MakeEMCALFullMisAlignment.C:63
 MakeEMCALFullMisAlignment.C:64
 MakeEMCALFullMisAlignment.C:65
 MakeEMCALFullMisAlignment.C:66
 MakeEMCALFullMisAlignment.C:67
 MakeEMCALFullMisAlignment.C:68
 MakeEMCALFullMisAlignment.C:69
 MakeEMCALFullMisAlignment.C:70
 MakeEMCALFullMisAlignment.C:71
 MakeEMCALFullMisAlignment.C:72
 MakeEMCALFullMisAlignment.C:73
 MakeEMCALFullMisAlignment.C:74
 MakeEMCALFullMisAlignment.C:75
 MakeEMCALFullMisAlignment.C:76
 MakeEMCALFullMisAlignment.C:77
 MakeEMCALFullMisAlignment.C:78