ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

#include "Riostream.h"
#include "TFile.h"
#include "TSystem.h"
#include "TClonesArray.h"

#include "AliSurveyToAlignObjs.h"
#include "AliSurveyPoint.h"
#include "AliAlignObjParams.h"

#include "AliLog.h"

#include "AliCDBManager.h"
#include "AliCDBEntry.h"
#include "AliCDBStorage.h"
#include "AliCDBMetaData.h"

ClassImp(AliSurveyToAlignObjs)

//________________________________________________________________________
AliSurveyToAlignObjs::AliSurveyToAlignObjs() :
  TObject(),
  fSurveyObj(new AliSurveyObj()),
  fSurveyPoints(NULL),
  fAlignObjArray(new TClonesArray("AliAlignObjParams",10)),
  fAlignObj(0)
{
  //
  //  default constructor
  //
}   

//_________________________________________________________________________
AliSurveyToAlignObjs::AliSurveyToAlignObjs(const AliSurveyToAlignObjs &s2aObj) :
  TObject(s2aObj),
  fSurveyObj(s2aObj.fSurveyObj),
  fSurveyPoints(NULL),
  fAlignObjArray(NULL),
  fAlignObj(s2aObj.fAlignObj)
{
  // copy constructor
	fSurveyPoints = (TObjArray*)(s2aObj.fSurveyObj->Clone());
	fAlignObjArray = (TClonesArray*) (s2aObj.fAlignObjArray->Clone());
}

//__________________________________________________________________________
AliSurveyToAlignObjs & AliSurveyToAlignObjs::operator= (const AliSurveyToAlignObjs &s2aObj) {
  //
  // assignment operator
  //
    if(this != &s2aObj) {
	//if(s2aObj.fSurveyObj){
	    //delete fSurveyObj;
	    this->fSurveyObj = s2aObj.fSurveyObj;
	//}
	//if(s2aObj.fSurveyPoints){
	    //fSurveyPoints->Delete();
	    //delete fSurveyPoints;
	    fSurveyPoints = (TObjArray*)(s2aObj.fSurveyObj->Clone());
	//}
	//if(s2aObj.fAlignObjArray){
	    //fAlignObjArray->Delete();
	    //delete fAlignObjArray;
	    fAlignObjArray = (TClonesArray*) (s2aObj.fAlignObjArray->Clone());
	//}
	//if(s2aObj.fAlignObj){
	    //delete fAlignObj;
	    this->fAlignObj = s2aObj.fAlignObj;
	//}
    }
    return *this;
}

//__________________________________________________________________________
AliSurveyToAlignObjs::~AliSurveyToAlignObjs() 
{
  //
  // destructor
  //
  delete fSurveyObj;
  delete fSurveyPoints;
  delete fAlignObjArray;
  delete fAlignObj;
}

//__________________________________________________________________________
Bool_t AliSurveyToAlignObjs::LoadSurveyFromLocalFile(const char* filename) {
  // Load survey data from a formatted text file
  // residing locally
  //
  
  //Load survey data from the local file
  if(fSurveyObj->FillFromLocalFile(filename))
    fSurveyPoints = fSurveyObj->GetData();
  else 
    return kFALSE;
  
  AliInfo(Form("%d survey points read",fSurveyPoints->GetEntries()));  
  
  return kTRUE;
}

//__________________________________________________________________________
Bool_t AliSurveyToAlignObjs::LoadSurveyFromAlienFile(const char* det, Int_t repNum, Int_t repVersion) {
  // Load survey data from the formatted text file
  // residing in the default location in alien
  //
  
  const char* alienUser=gSystem->Getenv("alien_API_USER");
  if(fSurveyObj->Fill(det, repNum, repVersion, alienUser))
  {
    fSurveyPoints = fSurveyObj->GetData();
  }else{
    AliError("Error reading survey file from alien!");
    return kFALSE;
  }
  
  AliInfo(Form("%d survey points read",fSurveyPoints->GetEntries()));  
  
  return kTRUE;
}

//_________________________________________________________________________
Bool_t AliSurveyToAlignObjs::StoreAlignObjToFile(const char* filename, const char* det){
  // Stores the TClonesArray of alignment objects into the
  // file specified as argument
  //
  TFile *f = TFile::Open(filename,"RECREATE");
  if(!f){
    AliError(Form("cannot open file %s\n",filename));
    return kFALSE;
  }
  AliInfo(Form("Saving alignment objects into the file %s",filename));
  TString arrayname(det);
  arrayname+="AlignObjs";
      
  f->cd();
  f->WriteObject(fAlignObjArray,arrayname,"kSingleKey");
  f->Close();

  return kTRUE;
}

//_________________________________________________________________________
Bool_t AliSurveyToAlignObjs::StoreAlignObjToCDB(const char* cdbFolder, const char* det){
  // Stores the TClonesArray of alignment objects into a
  // CDB entry in the CDB folder specified by the argument
  //

  AliCDBManager* cdb = AliCDBManager::Instance();
  cdb->SetDefaultStorage(cdbFolder);
  cdb->SetRun(0);

  AliCDBMetaData* md = new AliCDBMetaData();
  md->SetComment(Form("Misalignment for subdetector %s from survey",det));
  TString path(det);
  path+="/Align/Data";
  AliCDBId id(path.Data(),0,AliCDBRunRange::Infinity());
  cdb->Put(fAlignObjArray,id,md);

  return kTRUE;
}


 AliSurveyToAlignObjs.cxx:1
 AliSurveyToAlignObjs.cxx:2
 AliSurveyToAlignObjs.cxx:3
 AliSurveyToAlignObjs.cxx:4
 AliSurveyToAlignObjs.cxx:5
 AliSurveyToAlignObjs.cxx:6
 AliSurveyToAlignObjs.cxx:7
 AliSurveyToAlignObjs.cxx:8
 AliSurveyToAlignObjs.cxx:9
 AliSurveyToAlignObjs.cxx:10
 AliSurveyToAlignObjs.cxx:11
 AliSurveyToAlignObjs.cxx:12
 AliSurveyToAlignObjs.cxx:13
 AliSurveyToAlignObjs.cxx:14
 AliSurveyToAlignObjs.cxx:15
 AliSurveyToAlignObjs.cxx:16
 AliSurveyToAlignObjs.cxx:17
 AliSurveyToAlignObjs.cxx:18
 AliSurveyToAlignObjs.cxx:19
 AliSurveyToAlignObjs.cxx:20
 AliSurveyToAlignObjs.cxx:21
 AliSurveyToAlignObjs.cxx:22
 AliSurveyToAlignObjs.cxx:23
 AliSurveyToAlignObjs.cxx:24
 AliSurveyToAlignObjs.cxx:25
 AliSurveyToAlignObjs.cxx:26
 AliSurveyToAlignObjs.cxx:27
 AliSurveyToAlignObjs.cxx:28
 AliSurveyToAlignObjs.cxx:29
 AliSurveyToAlignObjs.cxx:30
 AliSurveyToAlignObjs.cxx:31
 AliSurveyToAlignObjs.cxx:32
 AliSurveyToAlignObjs.cxx:33
 AliSurveyToAlignObjs.cxx:34
 AliSurveyToAlignObjs.cxx:35
 AliSurveyToAlignObjs.cxx:36
 AliSurveyToAlignObjs.cxx:37
 AliSurveyToAlignObjs.cxx:38
 AliSurveyToAlignObjs.cxx:39
 AliSurveyToAlignObjs.cxx:40
 AliSurveyToAlignObjs.cxx:41
 AliSurveyToAlignObjs.cxx:42
 AliSurveyToAlignObjs.cxx:43
 AliSurveyToAlignObjs.cxx:44
 AliSurveyToAlignObjs.cxx:45
 AliSurveyToAlignObjs.cxx:46
 AliSurveyToAlignObjs.cxx:47
 AliSurveyToAlignObjs.cxx:48
 AliSurveyToAlignObjs.cxx:49
 AliSurveyToAlignObjs.cxx:50
 AliSurveyToAlignObjs.cxx:51
 AliSurveyToAlignObjs.cxx:52
 AliSurveyToAlignObjs.cxx:53
 AliSurveyToAlignObjs.cxx:54
 AliSurveyToAlignObjs.cxx:55
 AliSurveyToAlignObjs.cxx:56
 AliSurveyToAlignObjs.cxx:57
 AliSurveyToAlignObjs.cxx:58
 AliSurveyToAlignObjs.cxx:59
 AliSurveyToAlignObjs.cxx:60
 AliSurveyToAlignObjs.cxx:61
 AliSurveyToAlignObjs.cxx:62
 AliSurveyToAlignObjs.cxx:63
 AliSurveyToAlignObjs.cxx:64
 AliSurveyToAlignObjs.cxx:65
 AliSurveyToAlignObjs.cxx:66
 AliSurveyToAlignObjs.cxx:67
 AliSurveyToAlignObjs.cxx:68
 AliSurveyToAlignObjs.cxx:69
 AliSurveyToAlignObjs.cxx:70
 AliSurveyToAlignObjs.cxx:71
 AliSurveyToAlignObjs.cxx:72
 AliSurveyToAlignObjs.cxx:73
 AliSurveyToAlignObjs.cxx:74
 AliSurveyToAlignObjs.cxx:75
 AliSurveyToAlignObjs.cxx:76
 AliSurveyToAlignObjs.cxx:77
 AliSurveyToAlignObjs.cxx:78
 AliSurveyToAlignObjs.cxx:79
 AliSurveyToAlignObjs.cxx:80
 AliSurveyToAlignObjs.cxx:81
 AliSurveyToAlignObjs.cxx:82
 AliSurveyToAlignObjs.cxx:83
 AliSurveyToAlignObjs.cxx:84
 AliSurveyToAlignObjs.cxx:85
 AliSurveyToAlignObjs.cxx:86
 AliSurveyToAlignObjs.cxx:87
 AliSurveyToAlignObjs.cxx:88
 AliSurveyToAlignObjs.cxx:89
 AliSurveyToAlignObjs.cxx:90
 AliSurveyToAlignObjs.cxx:91
 AliSurveyToAlignObjs.cxx:92
 AliSurveyToAlignObjs.cxx:93
 AliSurveyToAlignObjs.cxx:94
 AliSurveyToAlignObjs.cxx:95
 AliSurveyToAlignObjs.cxx:96
 AliSurveyToAlignObjs.cxx:97
 AliSurveyToAlignObjs.cxx:98
 AliSurveyToAlignObjs.cxx:99
 AliSurveyToAlignObjs.cxx:100
 AliSurveyToAlignObjs.cxx:101
 AliSurveyToAlignObjs.cxx:102
 AliSurveyToAlignObjs.cxx:103
 AliSurveyToAlignObjs.cxx:104
 AliSurveyToAlignObjs.cxx:105
 AliSurveyToAlignObjs.cxx:106
 AliSurveyToAlignObjs.cxx:107
 AliSurveyToAlignObjs.cxx:108
 AliSurveyToAlignObjs.cxx:109
 AliSurveyToAlignObjs.cxx:110
 AliSurveyToAlignObjs.cxx:111
 AliSurveyToAlignObjs.cxx:112
 AliSurveyToAlignObjs.cxx:113
 AliSurveyToAlignObjs.cxx:114
 AliSurveyToAlignObjs.cxx:115
 AliSurveyToAlignObjs.cxx:116
 AliSurveyToAlignObjs.cxx:117
 AliSurveyToAlignObjs.cxx:118
 AliSurveyToAlignObjs.cxx:119
 AliSurveyToAlignObjs.cxx:120
 AliSurveyToAlignObjs.cxx:121
 AliSurveyToAlignObjs.cxx:122
 AliSurveyToAlignObjs.cxx:123
 AliSurveyToAlignObjs.cxx:124
 AliSurveyToAlignObjs.cxx:125
 AliSurveyToAlignObjs.cxx:126
 AliSurveyToAlignObjs.cxx:127
 AliSurveyToAlignObjs.cxx:128
 AliSurveyToAlignObjs.cxx:129
 AliSurveyToAlignObjs.cxx:130
 AliSurveyToAlignObjs.cxx:131
 AliSurveyToAlignObjs.cxx:132
 AliSurveyToAlignObjs.cxx:133
 AliSurveyToAlignObjs.cxx:134
 AliSurveyToAlignObjs.cxx:135
 AliSurveyToAlignObjs.cxx:136
 AliSurveyToAlignObjs.cxx:137
 AliSurveyToAlignObjs.cxx:138
 AliSurveyToAlignObjs.cxx:139
 AliSurveyToAlignObjs.cxx:140
 AliSurveyToAlignObjs.cxx:141
 AliSurveyToAlignObjs.cxx:142
 AliSurveyToAlignObjs.cxx:143
 AliSurveyToAlignObjs.cxx:144
 AliSurveyToAlignObjs.cxx:145
 AliSurveyToAlignObjs.cxx:146
 AliSurveyToAlignObjs.cxx:147
 AliSurveyToAlignObjs.cxx:148
 AliSurveyToAlignObjs.cxx:149
 AliSurveyToAlignObjs.cxx:150
 AliSurveyToAlignObjs.cxx:151
 AliSurveyToAlignObjs.cxx:152
 AliSurveyToAlignObjs.cxx:153
 AliSurveyToAlignObjs.cxx:154
 AliSurveyToAlignObjs.cxx:155
 AliSurveyToAlignObjs.cxx:156
 AliSurveyToAlignObjs.cxx:157
 AliSurveyToAlignObjs.cxx:158
 AliSurveyToAlignObjs.cxx:159
 AliSurveyToAlignObjs.cxx:160
 AliSurveyToAlignObjs.cxx:161
 AliSurveyToAlignObjs.cxx:162
 AliSurveyToAlignObjs.cxx:163
 AliSurveyToAlignObjs.cxx:164
 AliSurveyToAlignObjs.cxx:165
 AliSurveyToAlignObjs.cxx:166
 AliSurveyToAlignObjs.cxx:167
 AliSurveyToAlignObjs.cxx:168
 AliSurveyToAlignObjs.cxx:169
 AliSurveyToAlignObjs.cxx:170
 AliSurveyToAlignObjs.cxx:171
 AliSurveyToAlignObjs.cxx:172
 AliSurveyToAlignObjs.cxx:173
 AliSurveyToAlignObjs.cxx:174
 AliSurveyToAlignObjs.cxx:175
 AliSurveyToAlignObjs.cxx:176
 AliSurveyToAlignObjs.cxx:177
 AliSurveyToAlignObjs.cxx:178