]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0Align.cxx
Fix for the problem during PbPb run of Nov 2010 (Indra)
[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"
f7350425 31#include "TString.h"
a4c640e1 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"
9dcc11e4 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
a4c640e1 47
48ClassImp(AliT0Align)
49
50AliT0Align::AliT0Align() :
51 TObject(),
9dcc11e4 52 fFileGlob(0x0),
a4c640e1 53 fT0AAlignObj(0x0),
54 fT0CAlignObj(0x0),
9dcc11e4 55 fDebug(0),
81c2ef80 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{
a4c640e1 65 //
66 // default constructor
67 //
68}
69//________________________________________________________________________
81c2ef80 70AliT0Align::AliT0Align(Int_t reportloc, Int_t side, Int_t reportglob) :
a4c640e1 71 TObject(),
9dcc11e4 72 fFileGlob(0x0),
a4c640e1 73 fT0AAlignObj(0x0),
74 fT0CAlignObj(0x0),
9dcc11e4 75 fDebug(0),
81c2ef80 76 fXPosC(0.),
77 fYPosC(0.),
78 fXPosA(0.),
79 fYPosA(0.),
80 fRepLoc(0),
81 fRepGlob(0),
82 fSide(0x0),
83 fUser(0x0)
a4c640e1 84{
85 //
86 // constructor - defines data files
87 //
88 fRepLoc = reportloc;
81c2ef80 89 fRepGlob = reportglob;
90 fSide = side;
769a17f9 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"));
a4c640e1 98 //
99 // sprintf(fFileLoc,"%s/T0/Survey_%d_T0.txt",path,reportloc);
769a17f9 100 // sprintf(fFileGlob,"%s/T0/Survey_%d_V0.txt",path,reportglob);
a4c640e1 101 //
769a17f9 102 // sprintf(fUser,gSystem->Getenv("alien_API_USER"));
a4c640e1 103}
104//_________________________________________________________________________
105AliT0Align::AliT0Align(const AliT0Align &align) :
106 TObject(),
9dcc11e4 107 fFileGlob(0x0),
a4c640e1 108 fT0AAlignObj(0x0),
109 fT0CAlignObj(0x0),
9dcc11e4 110 fDebug(0),
81c2ef80 111 fXPosC(0.),
112 fYPosC(0.),
113 fXPosA(0.),
114 fYPosA(0.),
115 fRepLoc(0),
116 fRepGlob(0),
117 fSide(0x0),
118 fUser(0x0)
a4c640e1 119{
120 //
121 // copy constructor - dummy
122 //
f7350425 123 fDebug = align.fDebug;
a4c640e1 124}
125//__________________________________________________________________________
126AliT0Align & AliT0Align::operator =(const AliT0Align & align)
127{
128 //
129 // assignment operator - dummy
130 //
f7350425 131 fDebug=align.fDebug;
a4c640e1 132 return (*this);
133}
134
135//__________________________________________________________________________
d6ac4d13 136AliT0Align::~AliT0Align()
137{
a4c640e1 138 //
139 // destructor
140 //
141 if(fT0AAlignObj) delete fT0AAlignObj;
142 if(fT0CAlignObj) delete fT0CAlignObj;
203ca5a7 143 if(fFileGlob) delete[] fFileGlob;
d6ac4d13 144 if(fUser) delete[] fUser;
a4c640e1 145}
146//__________________________________________________________________________
147Bool_t AliT0Align::LoadSurveyData()
148{
149 //
150 // Create a new survey object and fill it.
151
152 AliSurveyObj * s1 = new AliSurveyObj();
81c2ef80 153 const int numberPoints = 2;
1e8a79ac 154 TString pointNames[numberPoints]={"Flange_0","C67_6_Beamcircle"};
a4c640e1 155
156 if(fRepLoc == 0)
81c2ef80 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 }
a4c640e1 175 }
a4c640e1 176 else
177 //
178 // Filling from local file
179 //
180 {
181 s1->FillFromLocalFile(fFileGlob);
182 }
183 //
81c2ef80 184 Float_t surveyedPoints [numberPoints][2];
a4c640e1 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 }
81c2ef80 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 }
a4c640e1 220 //
221 delete s1;
222 //
223 return 0;
224}
225//_________________________________________________________________
226
227Double_t AliT0Align::ComputePosition()
228{
229 // Float_t fZPos, shift;
230 // fZPos = surveyedPoints[3] - shift;
a80ab6cd 231 return 0;
a4c640e1 232}
233//_______________________________________________________________________
81c2ef80 234void AliT0Align::CreateAlignObj()
235{
a4c640e1 236 //
a9ab7568 237 // TClonesArray *array = new TClonesArray("AliAlignObjParams",2);
a4c640e1 238 // TClonesArray &alobj = *array;
239
a4c640e1 240 Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
81c2ef80 241 dx=fXPosA;
242 dy=fYPosA;
a4c640e1 243 fT0AAlignObj = new AliAlignObjParams("ALIC_1/0STL_1",0,dx,dy,dz,dpsi,dtheta,dphi,kTRUE);
244
81c2ef80 245 dx=fXPosC;
246 dy=fYPosC;
a4c640e1 247 // dz=surveyedPoints[2];
248 dz=0.;
249 fT0CAlignObj = new AliAlignObjParams("ALIC_1/0STR_1",0,dx,dy,dz,dpsi,dtheta,dphi,kTRUE);
81c2ef80 250
a4c640e1 251}
252
253//______________________________________________________________________
81c2ef80 254void AliT0Align::Run()
255{
a4c640e1 256 //
257 // runs the full chain
258 //
cd2b94bd 259 // SetDebug(0);
a4c640e1 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
272void AliT0Align::StoreAlignObj()
273{
9dcc11e4 274 //
275 // Storing T0 alignment objects
276 //
a4c640e1 277 AliCDBManager* cdb = AliCDBManager::Instance();
162637e4 278 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
a4c640e1 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";
f7350425 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");
a4c640e1 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");
81c2ef80 329 md->SetComment("Position of T0-A and T0-C from survey");
a4c640e1 330 AliCDBId id("T0/Align/Data",0,AliCDBRunRange::Infinity());
331 storage->Put(array,id,md);
332 }
333}
334