]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0Align.cxx
Completely reengineered version of CMake build system (Johny)
[u/mrichter/AliRoot.git] / T0 / AliT0Align.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log: AliT0Align.cxx,v $
18  Revision   2008/01/30
19 Removing code violations 
20
21  Version 1.1  2006/10
22 Preliminary test version (T.Malkiewicz)
23 */
24
25 #include "AliT0Align.h"
26 #include "TROOT.h"
27 #include "Riostream.h"
28 #include "TFile.h"
29 #include "TMath.h"
30 #include "TSystem.h"
31 #include "AliSurveyObj.h"
32 #include "AliAlignObjParams.h"
33 #include "AliCDBStorage.h"
34 #include <TClonesArray.h>
35 #include <TFile.h>
36 #include "AliLog.h"
37 #include "AliCDBManager.h"
38 #include "AliSurveyPoint.h" 
39
40 // Class creating the T0 aligmnent objects 
41 // from the surveys done by surveyers at Point2.
42 // Survey results are fetched from 
43 // Survey Depot, based on survey results 
44 // position of T0 alignment objects is computed.
45
46
47 ClassImp(AliT0Align)
48
49 AliT0Align::AliT0Align() :
50   TObject(),
51   fFileGlob(0x0),
52   fT0AAlignObj(0x0),
53   fT0CAlignObj(0x0),
54   fDebug(0),
55   fXPosC(0.),
56   fYPosC(0.),
57   fXPosA(0.),
58   fYPosA(0.),
59   fRepLoc(0),
60   fRepGlob(0),
61   fSide(0x0),
62   fUser(0x0)
63 {
64   //
65   //  default constructor
66   //
67 }   
68 //________________________________________________________________________
69 AliT0Align::AliT0Align(Int_t reportloc, Int_t side, Int_t reportglob) :
70   TObject(),
71   fFileGlob(0x0),
72   fT0AAlignObj(0x0),
73   fT0CAlignObj(0x0),
74   fDebug(0),
75   fXPosC(0.),
76   fYPosC(0.),
77   fXPosA(0.),
78   fYPosA(0.),
79   fRepLoc(0),
80   fRepGlob(0),
81   fSide(0x0),
82   fUser(0x0)
83 {
84   //
85   // constructor - defines data files
86   //
87   fRepLoc = reportloc;
88   fRepGlob = reportglob;
89   fSide = side;
90   Char_t path[50];
91   fFileGlob = new Char_t[80];
92   fUser = new Char_t[10];
93   sprintf(path,gSystem->Getenv("ALICE_ROOT")); 
94   //
95   // sprintf(fFileLoc,"%s/T0/Survey_%d_T0.txt",path,reportloc);
96   sprintf(fFileGlob,"%s/T0/Survey_%d_V0.txt",path,reportglob);
97   //
98   sprintf(fUser,gSystem->Getenv("alien_API_USER"));
99 }
100 //_________________________________________________________________________
101 AliT0Align::AliT0Align(const AliT0Align &align) :
102   TObject(),
103   fFileGlob(0x0),
104   fT0AAlignObj(0x0),
105   fT0CAlignObj(0x0),
106   fDebug(0),
107   fXPosC(0.),
108   fYPosC(0.),
109   fXPosA(0.),
110   fYPosA(0.),
111   fRepLoc(0),
112   fRepGlob(0),
113   fSide(0x0),
114   fUser(0x0)  
115 {
116   //
117   //  copy constructor - dummy
118   //
119   fDebug = align.fDebug;
120 }
121 //__________________________________________________________________________
122 AliT0Align & AliT0Align::operator =(const AliT0Align & align)
123 {
124   //
125   // assignment operator - dummy
126   //
127   fDebug=align.fDebug;
128   return (*this);
129 }
130
131 //__________________________________________________________________________
132 AliT0Align::~AliT0Align()
133 {
134   //
135   // destructor
136   //
137   if(fT0AAlignObj) delete fT0AAlignObj;
138   if(fT0CAlignObj) delete fT0CAlignObj;
139   if(fFileGlob) delete[] fFileGlob;
140   if(fUser) delete[] fUser;
141 }
142 //__________________________________________________________________________
143 Bool_t AliT0Align::LoadSurveyData()
144 {
145   //
146   // Create a new survey object and fill it.
147  
148  AliSurveyObj * s1 = new AliSurveyObj();
149  const int numberPoints = 2;
150  TString pointNames[numberPoints]={"Flange_0","C67_6_Beamcircle"}; 
151  
152  if(fRepLoc == 0) 
153  { 
154    //
155    // Filling from DCDB (via GRID)
156    //
157    s1->SetGridUser(fUser);
158    if(fSide == 0) 
159    {
160      s1->Fill("T0", fRepGlob, fUser);
161    }
162    else if(fSide == 1)
163    {
164      s1->Fill("VZERO", fRepGlob, fUser);
165    }
166    else
167    {
168      cout<<"Enter the side properly: '0'- A side, '1'- C side'" <<endl;
169      return 0;
170    }
171  }
172  else
173  //
174  // Filling from local file
175  //
176  {
177    s1->FillFromLocalFile(fFileGlob);
178  }
179  //
180  Float_t surveyedPoints [numberPoints][2];
181  AliSurveyPoint *currPoint;
182
183  //
184  for(Int_t i=0;i<numberPoints;i++)
185  {
186    currPoint=0;
187    currPoint = (AliSurveyPoint *) s1->GetData()->FindObject(pointNames[i]);
188    //
189    if(currPoint)
190    {
191      surveyedPoints[i][0]=currPoint->GetX();
192      surveyedPoints[i][1]=currPoint->GetY();
193    //  surveyedPoints[i]=currPoint->GetZ();
194      if(fDebug)
195      Printf(Form("INFO: Point \"%s\" coordinates read.", pointNames[i].Data()));
196    }
197    else 
198    {
199      if(fDebug)
200      {
201        Printf(Form("ERROR: Essential point missing: \"%s\"", pointNames[i].Data()));
202        return 1;
203      }
204    }  
205  }
206  if(fSide == 0)
207  {
208    fXPosA = surveyedPoints[0][0];
209    fYPosA = surveyedPoints[0][1];
210  }
211  else if(fSide == 1)
212  {
213    fXPosC = surveyedPoints[1][0]; 
214    fYPosC = surveyedPoints[1][1];
215  }
216  //
217  delete s1;
218  //
219  return 0;
220 }
221 //_________________________________________________________________
222
223 Double_t AliT0Align::ComputePosition()
224 {
225  //  Float_t fZPos, shift;
226  //  fZPos = surveyedPoints[3] - shift;
227   return 0;
228 }
229 //_______________________________________________________________________
230 void AliT0Align::CreateAlignObj()
231 {
232   //
233   //  TClonesArray *array = new TClonesArray("AliAlignObjParams",2);
234   // TClonesArray &alobj = *array;
235   
236   Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
237   dx=fXPosA;
238   dy=fYPosA;
239   fT0AAlignObj = new AliAlignObjParams("ALIC_1/0STL_1",0,dx,dy,dz,dpsi,dtheta,dphi,kTRUE);
240   
241   dx=fXPosC;
242   dy=fYPosC;
243   // dz=surveyedPoints[2];
244   dz=0.;
245   fT0CAlignObj = new AliAlignObjParams("ALIC_1/0STR_1",0,dx,dy,dz,dpsi,dtheta,dphi,kTRUE);
246   
247 }
248
249 //______________________________________________________________________
250 void AliT0Align::Run()
251 {
252   //
253   // runs the full chain
254   //
255   SetDebug(0);
256   Bool_t flag = LoadSurveyData();
257     if(flag) 
258   {
259     cout<<"Missing points"<<endl;
260     return;
261   }
262   // ComputePosition();
263   CreateAlignObj();
264   StoreAlignObj();
265 }
266 //_________________________________________________________________________
267
268 void AliT0Align::StoreAlignObj()
269 {
270  //
271  // Storing T0 alignment objects 
272  //
273  AliCDBManager* cdb = AliCDBManager::Instance();
274  if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
275  //
276  TClonesArray *array = new TClonesArray("AliAlignObjParams",2);
277 //
278  Double_t shifts[3];
279  Double_t rots[3];
280  //
281  fT0AAlignObj->GetPars(shifts,rots);
282  new((*array)[0]) AliAlignObjParams(fT0AAlignObj->GetSymName(),0,shifts[0],
283                    shifts[1],shifts[2],rots[0],rots[1],rots[2],kTRUE);
284  fT0CAlignObj->GetPars(shifts,rots);
285  new((*array)[1]) AliAlignObjParams(fT0CAlignObj->GetSymName(),0,shifts[0],
286                    shifts[1],shifts[2],rots[0],rots[1],rots[2],kTRUE);
287
288
289 //
290 // storing either in the OCDB or local file
291 //
292   if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
293     // save on file
294     const char* filename = "T0SurveyMisalignment.root";
295     Char_t fullname[80];
296     sprintf(fullname,"%s/T0/Align/Data/%s",gSystem->Getenv("ALICE_ROOT"),filename);
297     TFile *f = new TFile(fullname,"RECREATE");
298     if(!f){
299       AliError("cannot open file for output\n");
300       return;
301     }
302     AliInfo(Form("Saving alignment objects to the file %s", filename));
303     f->cd();
304     f->WriteObject(array,"T0AlignObjs","kSingleKey");
305     f->Close();
306   }else{
307     // save in CDB storage
308     AliCDBStorage* storage;
309     //
310    TString Storage = gSystem->Getenv("STORAGE");
311     if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
312       AliError(Form(
313       "STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()));
314       return;
315     }
316     storage = cdb->GetStorage(Storage.Data());
317     if(!storage){
318       AliError(Form("Unable to open storage %s\n",Storage.Data()));
319       return;
320     }
321     //
322     AliCDBMetaData* md = new AliCDBMetaData();
323     md->SetResponsible("Tomasz Malkiewicz");
324     md->SetComment("Position of T0-A and T0-C from survey");
325     AliCDBId id("T0/Align/Data",0,AliCDBRunRange::Infinity());
326     storage->Put(array,id,md);
327   }
328 }
329