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