some coverity warnings fixed
[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 //
cd2b94bd 119 // fDebug = align.fDebug;
a4c640e1 120}
121//__________________________________________________________________________
122AliT0Align & AliT0Align::operator =(const AliT0Align & align)
123{
124 //
125 // assignment operator - dummy
126 //
cd2b94bd 127 // fDebug=align.fDebug;
a4c640e1 128 return (*this);
129}
130
131//__________________________________________________________________________
d6ac4d13 132AliT0Align::~AliT0Align()
133{
a4c640e1 134 //
135 // destructor
136 //
137 if(fT0AAlignObj) delete fT0AAlignObj;
138 if(fT0CAlignObj) delete fT0CAlignObj;
203ca5a7 139 if(fFileGlob) delete[] fFileGlob;
d6ac4d13 140 if(fUser) delete[] fUser;
a4c640e1 141}
142//__________________________________________________________________________
143Bool_t AliT0Align::LoadSurveyData()
144{
145 //
146 // Create a new survey object and fill it.
147
148 AliSurveyObj * s1 = new AliSurveyObj();
81c2ef80 149 const int numberPoints = 2;
1e8a79ac 150 TString pointNames[numberPoints]={"Flange_0","C67_6_Beamcircle"};
a4c640e1 151
152 if(fRepLoc == 0)
81c2ef80 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 }
a4c640e1 171 }
a4c640e1 172 else
173 //
174 // Filling from local file
175 //
176 {
177 s1->FillFromLocalFile(fFileGlob);
178 }
179 //
81c2ef80 180 Float_t surveyedPoints [numberPoints][2];
a4c640e1 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 }
81c2ef80 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 }
a4c640e1 216 //
217 delete s1;
218 //
219 return 0;
220}
221//_________________________________________________________________
222
223Double_t AliT0Align::ComputePosition()
224{
225 // Float_t fZPos, shift;
226 // fZPos = surveyedPoints[3] - shift;
a80ab6cd 227 return 0;
a4c640e1 228}
229//_______________________________________________________________________
81c2ef80 230void AliT0Align::CreateAlignObj()
231{
a4c640e1 232 //
a9ab7568 233 // TClonesArray *array = new TClonesArray("AliAlignObjParams",2);
a4c640e1 234 // TClonesArray &alobj = *array;
235
a4c640e1 236 Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
81c2ef80 237 dx=fXPosA;
238 dy=fYPosA;
a4c640e1 239 fT0AAlignObj = new AliAlignObjParams("ALIC_1/0STL_1",0,dx,dy,dz,dpsi,dtheta,dphi,kTRUE);
240
81c2ef80 241 dx=fXPosC;
242 dy=fYPosC;
a4c640e1 243 // dz=surveyedPoints[2];
244 dz=0.;
245 fT0CAlignObj = new AliAlignObjParams("ALIC_1/0STR_1",0,dx,dy,dz,dpsi,dtheta,dphi,kTRUE);
81c2ef80 246
a4c640e1 247}
248
249//______________________________________________________________________
81c2ef80 250void AliT0Align::Run()
251{
a4c640e1 252 //
253 // runs the full chain
254 //
cd2b94bd 255 // SetDebug(0);
a4c640e1 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
268void AliT0Align::StoreAlignObj()
269{
9dcc11e4 270 //
271 // Storing T0 alignment objects
272 //
a4c640e1 273 AliCDBManager* cdb = AliCDBManager::Instance();
162637e4 274 if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
a4c640e1 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");
81c2ef80 324 md->SetComment("Position of T0-A and T0-C from survey");
a4c640e1 325 AliCDBId id("T0/Align/Data",0,AliCDBRunRange::Infinity());
326 storage->Put(array,id,md);
327 }
328}
329