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