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