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