]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliGRPObject.cxx
Reset of centrality object.
[u/mrichter/AliRoot.git] / STEER / AliGRPObject.cxx
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 /* $Id$ */
17
18 // **********************
19 // Class containing the GRP data that have to be stored in the OCDB.
20 // Data come either from DAQ logbook or from DCS DB.
21 // Processing of the data can also be performed here.
22 // **********************
23
24 #include <TMap.h>
25 #include <TObject.h>
26 #include <TObjString.h>
27
28 #include "AliGRPObject.h"
29 #include "AliDCSSensor.h"
30 #include "AliLog.h"
31
32 ClassImp(AliGRPObject)
33
34 const Double_t kCavernCut = 1.0;           // tolerable difference between cavern pressure sensors
35 const Double_t kSurfaceDifference = 4.5;   //  offset between surface and cavern pressure sensors
36         
37 const Float_t AliGRPObject::fgkInvalidFloat = 1E-33; // value to identify invalid data - float
38 const TString AliGRPObject::fgkInvalidString = "";  // value to identify invalid data - string
39 const Char_t AliGRPObject::fgkInvalidChar = -1;         // value to identify invalid data - uchar
40 const Int_t AliGRPObject::fgkInvalidInt = -1;  // value to identify invalid data - uint
41 const Int_t AliGRPObject::fgkInvalidUInt = 0;  // value to identify invalid data - uint
42 const Int_t AliGRPObject::fgknDCSDPHallProbes = 40;   // number of dcs dps
43 const char* AliGRPObject::fgkDCSDataPointsHallProbes[AliGRPObject::fgknDCSDPHallProbes] = {
44                    "L3_BSF17_H1",
45                    "L3_BSF17_H2",
46                    "L3_BSF17_H3",
47                    "L3_BSF17_Temperature",
48                    "L3_BSF4_H1",
49                    "L3_BSF4_H2",
50                    "L3_BSF4_H3",
51                    "L3_BSF4_Temperature",
52                    "L3_BKF17_H1",
53                    "L3_BKF17_H2",
54                    "L3_BKF17_H3",
55                    "L3_BKF17_Temperature",
56                    "L3_BKF4_H1",
57                    "L3_BKF4_H2",
58                    "L3_BKF4_H3",
59                    "L3_BKF4_Temperature",
60                    "L3_BSF13_H1",
61                    "L3_BSF13_H2",
62                    "L3_BSF13_H3",
63                    "L3_BSF13_Temperature",
64                    "L3_BSF8_H1",
65                    "L3_BSF8_H2",
66                    "L3_BSF8_H3",
67                    "L3_BSF8_Temperature",
68                    "L3_BKF13_H1",
69                    "L3_BKF13_H2",
70                    "L3_BKF13_H3",
71                    "L3_BKF13_Temperature",
72                    "L3_BKF8_H1",
73                    "L3_BKF8_H2",
74                    "L3_BKF8_H3",
75                    "L3_BKF8_Temperature",
76                    "Dipole_Inside_H1",
77                    "Dipole_Inside_H2",
78                    "Dipole_Inside_H3",
79                    "Dipole_Inside_Temperature",
80                    "Dipole_Outside_H1",
81                    "Dipole_Outside_H2",
82                    "Dipole_Outside_H3",
83                    "Dipole_Outside_Temperature",
84                  };
85
86 //-----------------------------------------------------------------------------
87 AliGRPObject::AliGRPObject():
88         TObject(),
89         fPoints(5),
90         fDimension(0),
91         fTimeStart((time_t)fgkInvalidFloat),
92         fTimeEnd((time_t)fgkInvalidFloat),
93         fBeamEnergy(fgkInvalidFloat),
94         fBeamType(fgkInvalidString),
95         fNumberOfDetectors(fgkInvalidChar),
96         fDetectorMask(fgkInvalidUInt),
97         fLHCPeriod(fgkInvalidString),
98         fRunType(fgkInvalidString),
99         fLHCState(fgkInvalidString),
100         fL3Polarity(fgkInvalidChar),
101         fDipolePolarity(fgkInvalidChar),
102         fL3Current(new Float_t[fPoints]),
103         fDipoleCurrent(new Float_t[fPoints]),
104         fCavernTemperature(new Float_t[fPoints]),
105         fCavernAtmosPressure(0x0),
106         fCavernAtmosPressure2(0x0),
107         fSurfaceAtmosPressure(0x0),
108         fHallProbes(0x0),
109         fMachineMode(fgkInvalidString),
110         fLHCStateArray(0x0),
111         fMachineModeArray(0x0),
112         fMaxTimeLHCValidity(0)
113 {
114
115         //
116         // AliGRPObject default ctor
117         //
118
119         fDimension = fgknDCSDPHallProbes*fPoints;
120         fHallProbes = new Float_t[fDimension];
121
122         for (Int_t nhp=0; nhp< fDimension; nhp++){ // setting to zero values for non working HP 
123                 if ((nhp >= 0 && nhp <= 1*fPoints-1) || // L3_BSF17_H1
124                     (nhp >= 1*fPoints && nhp <= 2*fPoints-1) || // L3_BSF17_H2
125                     (nhp >= 2*fPoints && nhp <= 3*fPoints-1) || // L3_BSF17_H3
126                     (nhp >= 3*fPoints && nhp <= 4*fPoints-1) || // L3_BSF17_Temperature
127                     (nhp >= 6*fPoints && nhp <= 7*fPoints-1) ) { // L3_BSF4_H3
128                         fHallProbes[nhp] = 0; // setting to zero values for non working HP 
129                         AliDebug(2,Form("setting hp[%d] to zero = %f", 
130 nhp, fHallProbes[nhp]));
131                 }
132                 else {
133                         fHallProbes[nhp] = fgkInvalidFloat;
134                 }
135         }
136
137
138         for (Int_t i = 0; i < fPoints; i++){
139
140                 fL3Current[i] = fgkInvalidFloat;
141                 fDipoleCurrent[i] = fgkInvalidFloat;
142                 fCavernTemperature[i] = fgkInvalidFloat;
143         }
144 }
145
146 //-----------------------------------------------------------------------------
147
148 AliGRPObject::AliGRPObject(const AliGRPObject &obj):
149         TObject(obj),
150         fPoints(obj.fPoints),
151         fDimension(obj.fDimension),
152         fTimeStart(obj.fTimeStart),
153         fTimeEnd(obj.fTimeEnd),
154         fBeamEnergy(obj.fBeamEnergy),
155         fBeamType(obj.fBeamType),
156         fNumberOfDetectors(obj.fNumberOfDetectors),
157         fDetectorMask(obj.fDetectorMask),
158         fLHCPeriod(obj.fLHCPeriod),
159         fRunType(obj.fRunType),
160         fLHCState(obj.fLHCState),
161         fL3Polarity(obj.fL3Polarity),
162         fDipolePolarity(obj.fDipolePolarity),
163         fL3Current(new Float_t[fPoints]),
164         fDipoleCurrent(new Float_t[fPoints]),
165         fCavernTemperature(new Float_t[fPoints]),
166         fCavernAtmosPressure(obj.fCavernAtmosPressure),
167         fCavernAtmosPressure2(obj.fCavernAtmosPressure2),
168         fSurfaceAtmosPressure(obj.fSurfaceAtmosPressure),
169         fHallProbes(0x0),
170         fMachineMode(obj.fMachineMode),
171         fLHCStateArray(obj.fLHCStateArray),
172         fMachineModeArray(obj.fMachineModeArray),
173         fMaxTimeLHCValidity(obj.fMaxTimeLHCValidity)
174
175 {
176
177         //
178         // AliGRPObject copy ctor
179         //
180
181         fHallProbes = new Float_t[fDimension]; 
182
183         for (Int_t nhp=0; nhp< fDimension; nhp++){
184                 fHallProbes[nhp] = obj.fHallProbes[nhp];
185         }
186
187         for (Int_t i = 0; i < fPoints; i++){
188
189                 fL3Current[i] = obj.fL3Current[i];
190                 fDipoleCurrent[i] = obj.fDipoleCurrent[i];
191                 fCavernTemperature[i] = obj.fCavernTemperature[i];
192         }
193 }
194
195 //-----------------------------------------------------------------------------
196
197 AliGRPObject& AliGRPObject:: operator=(const AliGRPObject & obj) 
198 {
199
200         //
201         // AliGRPObject assignment operator
202         //
203
204         if (&obj == this) return *this; 
205
206         TObject::operator=(obj);
207         this->fTimeStart = obj.GetTimeStart();
208         this->fTimeEnd = obj.GetTimeEnd();
209         this->fBeamEnergy = obj.GetBeamEnergy();
210         this->fBeamType = obj.GetBeamType();
211         this->fNumberOfDetectors = obj.GetNumberOfDetectors();
212         this->fDetectorMask = obj.GetDetectorMask();
213         this->fLHCPeriod = obj.GetLHCPeriod();
214         this->fRunType = obj.GetRunType();
215         this->fLHCState = obj.GetLHCState();
216         this->fL3Polarity = obj.GetL3Polarity();
217         this->fDipolePolarity = obj.GetDipolePolarity();
218         this->fCavernAtmosPressure = obj.GetCavernAtmosPressure();
219         this->fCavernAtmosPressure2 = obj.GetCavernAtmosPressure2();
220         this->fSurfaceAtmosPressure = obj.GetSurfaceAtmosPressure();
221         this->fPoints = obj.GetPoints();
222         this->fDimension = obj.GetDimension();
223
224         this->fL3Current = new Float_t[fPoints];
225         this->fDipoleCurrent = new Float_t[fPoints];
226         this->fCavernTemperature = new Float_t[fPoints];
227         
228         if (this->fHallProbes==NULL) this->fHallProbes = new Float_t[this->fDimension]; 
229         for (Int_t nhp=0; nhp< fDimension; nhp++){
230                 this->fHallProbes[nhp] = obj.GetHallProbes(nhp);
231
232         }
233         for (Int_t i = 0; i < fPoints; i++){
234
235                 this->fL3Current[i] = obj.GetL3Current((Stats)i);
236                 this->fDipoleCurrent[i] = obj.GetDipoleCurrent((Stats)i);
237                 this->fCavernTemperature[i] = obj.GetCavernTemperature((Stats)i);
238         }
239
240         this->fMachineMode = obj.fMachineMode;
241         this->fLHCStateArray = obj.fLHCStateArray;
242         this->fMachineModeArray = obj.fMachineModeArray;
243         this->fMaxTimeLHCValidity = obj.fMaxTimeLHCValidity;
244         return *this;
245 }
246
247 //-----------------------------------------------------------------------------
248
249 AliGRPObject::~AliGRPObject() {
250
251         //
252         // dtor
253         //
254
255         
256         delete [] fHallProbes;
257         delete [] fL3Current;
258         delete [] fDipoleCurrent;
259         delete [] fCavernTemperature;
260
261         if (fCavernAtmosPressure){
262                 delete fCavernAtmosPressure;
263                 fCavernAtmosPressure = 0x0;
264         }
265         if (fCavernAtmosPressure2){
266                 delete fCavernAtmosPressure2;
267                 fCavernAtmosPressure2 = 0x0;
268         }
269         if (fSurfaceAtmosPressure){
270                 delete fSurfaceAtmosPressure;
271                 fSurfaceAtmosPressure = 0x0;
272         }
273         if (fLHCStateArray){
274                 delete fLHCStateArray;
275                 fLHCStateArray = 0x0;
276         }
277         if (fMachineModeArray){
278                 delete fMachineModeArray;
279                 fMachineModeArray = 0x0;
280         }
281 }
282
283 //-----------------------------------------------------------------------------
284 Float_t* AliGRPObject::GetHallProbesArray(DP_HallProbes hp) const {
285
286         //
287         // method to return array of statistical
288         // variables for Hall Probe hp
289         //
290
291         Float_t* array = new Float_t[fPoints];
292         Int_t shift = fPoints*(Int_t)hp; 
293         for (Int_t i=0;i<fPoints; i++){
294
295                 array[i] = fHallProbes[shift+i];
296
297         }
298
299         return array;
300 }
301 //-------------------------------------------------------------------------------
302
303 void AliGRPObject::SetHallProbes(DP_HallProbes hp, const Float_t* hall_probe){
304
305         //
306         // method to set hall probe hp 
307         // from a given array
308         //
309
310         Int_t shift = fPoints*hp;
311         for (Int_t i = 0; i< fPoints; i++){
312
313                 fHallProbes[i+shift] =  hall_probe[i];
314         }
315         return;
316 }
317
318 //-------------------------------------------------------------------------------
319
320 void AliGRPObject::ReadValuesFromMap(const TMap* mapGRP){
321
322         //
323         // method to set the values of the GRP parameters 
324         // reading them from the old format of the GRP 
325         // object, i.e. a TMap
326         //
327
328         if (mapGRP->GetValue("fAliceStartTime")){
329                 SetTimeStart((time_t)(((TObjString*)(mapGRP->GetValue("fAliceStartTime")))->GetString()).Atoi());
330         }
331         else {
332                 AliError(Form("No fAliceStartTime value found in GRP map!"));
333         }
334         if (mapGRP->GetValue("fAliceStopTime")){
335                 SetTimeEnd((time_t)(((TObjString*)(mapGRP->GetValue("fAliceStopTime")))->GetString()).Atoi());
336         }
337         
338         else { 
339                 AliError(Form("No fAliceStopTime value found in GRP map!"));
340         }
341
342         if(mapGRP->GetValue("fAliceBeamEnergy")){
343           double be = (((TObjString*)(mapGRP->GetValue("fAliceBeamEnergy")))->GetString()).Atof();
344           if (IsBeamEnergyIsSqrtSHalfGeV()) be/=2;   // old format was storig sqrt(s)
345           SetBeamEnergy(be);
346         }
347         else { 
348                 AliError(Form("No fAliceBeamEnergy value found in GRP map!"));
349         }
350         if(mapGRP->GetValue("fAliceBeamType")){
351                 SetBeamType(((TObjString*)(mapGRP->GetValue("fAliceBeamType")))->GetString());
352         }
353         else { 
354                 AliError(Form("No fAliceBeamType value found in GRP map!"));
355         }
356         if(mapGRP->GetValue("fNumberOfDetectors")){
357                 SetNumberOfDetectors((Char_t)(((TObjString*)(mapGRP->GetValue("fNumberOfDetectors")))->GetString()).Atoi()); 
358         }
359         else { 
360                 AliError(Form("No fNumberOfDetectors value found in GRP map!"));
361         }
362         if(mapGRP->GetValue("fDetectorMask")){
363                 SetDetectorMask((UInt_t)(((TObjString*)(mapGRP->GetValue("fDetectorMask")))->GetString()).Atoi());  
364         }
365         else { 
366                 AliError(Form("No fDetectorMask value found in GRP map!"));
367         }
368         if(mapGRP->GetValue("fLHCPeriod")){
369                 SetLHCPeriod(((TObjString*)(mapGRP->GetValue("fLHCPeriod")))->GetString());
370         }
371         else { 
372                 AliError(Form("No fLHCPeriod value found in GRP map!"));
373         }
374         if(mapGRP->GetValue("fRunType")){
375                 SetRunType(((TObjString*)(mapGRP->GetValue("fRunType")))->GetString());
376         }
377         else { 
378                 AliError(Form("No fRunType value found in GRP map!"));
379         }
380         if(mapGRP->GetValue("fLHCState")){
381                 SetLHCState(((TObjString*)(mapGRP->GetValue("fLHCState")))->GetString());
382         }
383         else { 
384                 AliError(Form("No fLHCState value found in GRP map!"));
385         }
386         if(mapGRP->GetValue("fLHCluminosity")){
387                 AliInfo(Form("fLHCLuminosity found, but not there anymore in the new object"));
388         }       
389         else { 
390                 AliError(Form("No fLHCLuminosity value found in GRP map!"));
391         }
392         if(mapGRP->GetValue("fBeamIntensity")){
393                 AliInfo(Form("fBeamIntensity found, but not there anymore in the new object"));
394         }       
395         else { 
396                 AliError(Form("No fBeamIntensity value found in GRP map!"));
397         }
398         if(mapGRP->GetValue("fL3Polarity")){
399                 SetL3Polarity((Char_t)(((TObjString*)(mapGRP->GetValue("fL3Polarity")))->GetString()).Atoi());
400         }       
401         else { 
402                 AliError(Form("No fL3Polarity value found in GRP map!"));
403         }
404         if(mapGRP->GetValue("fDipolePolarity")){
405                 SetDipolePolarity((Char_t)(((TObjString*)(mapGRP->GetValue("fDipolePolarity")))->GetString()).Atoi());  
406         }       
407         else { 
408                 AliError(Form("No fDipolePolarity value found in GRP map!"));
409         }
410         if(mapGRP->GetValue("fL3Current")){
411                 AliInfo(Form("fL3Current found, but porting only average to the new object, since the other values are not available in the old object"));
412                 SetL3Current((Float_t)(((TObjString*)(mapGRP->GetValue("fL3Current")))->GetString()).Atof(),(Stats)0);
413         }       
414         else { 
415                 AliError(Form("No fL3Current value found in GRP map!"));
416         }
417         if(mapGRP->GetValue("fDipoleCurrent")){
418                 AliInfo(Form("fDipoleCurrent found, but porting only average to the new object, since the other values are not available in the old object"));
419                 SetDipoleCurrent((Float_t)(((TObjString*)(mapGRP->GetValue("fDipoleCurrent")))->GetString()).Atof(),(Stats)0);
420         }       
421         else { 
422                 AliError(Form("No fDipoleCurrent value found in GRP map!"));
423         }
424         if(mapGRP->GetValue("fCavernTemperature")){
425                 AliInfo(Form("fCaverntemperature found, but porting only average to the new object, since the other values are not available in the old object"));
426                 SetCavernTemperature((Float_t)(((TObjString*)(mapGRP->GetValue("fCavernTemperature")))->GetString()).Atof(),(Stats)0);
427         }       
428         else { 
429                 AliError(Form("No fCavernTemperature value found in GRP map!"));
430         }
431         if(mapGRP->GetValue("fCavernAtmosPressure")){
432                 AliInfo(Form("fCavernAtmosPressure found, but not ported to the new object since of a different type"));
433         }       
434         else { 
435                 AliError(Form("No fCavernAtmosPressure value found in GRP map!"));
436         }
437         if(mapGRP->GetValue("fP2Pressure")){
438                 SetSurfaceAtmosPressure((AliDCSSensor*)((TObjString*)(mapGRP->GetValue("fP2Pressure"))));
439         }
440         else { 
441                 AliError(Form("No fP2Pressure value found in GRP map!"));
442         }
443         
444         return;
445
446 }
447 //-------------------------------------------------------------------------------
448
449 Float_t AliGRPObject::GetBeamEnergy() const {
450
451         //
452         // Getting the energy
453         // in case of BeamType = A-A, multiplying by 82/208 (for PbPb)
454         //
455
456         Float_t energy = fBeamEnergy;
457         if (fBeamType=="A-A"){
458                 energy = energy*82./208;
459         }
460         return IsBeamEnergyIsSqrtSHalfGeV() ? energy : energy/2;
461 }
462
463 //-------------------------------------------------------------------------------
464
465 Double_t AliGRPObject::EvalCavernPressure(const TTimeStamp& time, Bool_t& inside) const { 
466 //
467 //  Return current pressure value from 'best' cavern sensor
468 //    (default sensor 2. If sensor 1 and sensor 2 are sufficiently different,
469 //     use sensor most compatible with surface sensor
470
471   return EvalCavernPressure(fCavernAtmosPressure,fCavernAtmosPressure2,
472              fSurfaceAtmosPressure,time,inside);
473                                 
474 }
475
476 //-------------------------------------------------------------------------------
477
478 Double_t AliGRPObject::EvalCavernPressure(AliDCSSensor* cavern1, 
479                       AliDCSSensor* cavern2, AliDCSSensor* surface, 
480                       const TTimeStamp& time, Bool_t& inside)  {
481 //
482 //  Return current pressure value from 'best' cavern sensor
483 //    (default sensor 2. If sensor 1 and sensor 2 are sufficiently different,
484 //     use sensor most compatible with surface sensor
485
486      
487     Double_t valueSensor2 = cavern2->Eval(time,inside);
488     Double_t valueSensor1 = cavern1->Eval(time,inside);
489     if (TMath::Abs(valueSensor2-valueSensor1)<kCavernCut) {
490         return valueSensor2;
491     } else { 
492         Double_t valueSurface = surface->Eval(time,inside);
493         Double_t diff1 = TMath::Abs(valueSensor1-valueSurface-kSurfaceDifference);
494         Double_t diff2 = TMath::Abs(valueSensor2-valueSurface-kSurfaceDifference);
495         if (TMath::Abs(diff1)<TMath::Abs(diff2) ) {
496             return valueSensor1;
497         } else {
498             return valueSensor2;
499         }
500      }
501 }
502
503 //-------------------------------------------------------------------------------
504
505 AliDCSSensor* AliGRPObject::GetBestCavernAtmosPressure(AliDCSSensor* cavern1, 
506              AliDCSSensor* cavern2, AliDCSSensor* surface, const TTimeStamp& time) {
507
508 //
509 //  Return pointer to 'best' cavern sensor
510 //    (default sensor 2. If sensor 1 and sensor 2 are sufficiently different,
511 //     use sensor most compatible with surface sensor
512 //    Pressure measuread at time specified by TTimestamp
513
514
515     Bool_t inside; 
516     Double_t valueSensor2 = cavern2->Eval(time,inside);
517     Double_t valueSensor1 = cavern1->Eval(time,inside);
518     if (TMath::Abs(valueSensor2-valueSensor1)<kCavernCut) {
519         return cavern2;
520     } else { 
521         Double_t valueSurface = surface->Eval(time,inside);
522         Double_t diff1 = TMath::Abs(valueSensor1-valueSurface-kSurfaceDifference);
523         Double_t diff2 = TMath::Abs(valueSensor2-valueSurface-kSurfaceDifference);
524         if (TMath::Abs(diff1)<TMath::Abs(diff2) ) {
525             return cavern1;
526         } else {
527             return cavern2;
528         }
529      }
530 }
531
532 //-------------------------------------------------------------------------------
533
534 AliDCSSensor*   AliGRPObject::GetBestCavernAtmosPressure(const TTimeStamp& time) const {
535 //
536 //  Return pointer to 'best' cavern sensor
537 //    (default sensor 2. If sensor 1 and sensor 2 are sufficiently different,
538 //     use sensor most compatible with surface sensor
539 //    Pressure measuread at time specified by TTimestamp
540
541
542    return GetBestCavernAtmosPressure(fCavernAtmosPressure,
543         fCavernAtmosPressure2, fSurfaceAtmosPressure, time);
544
545 }
546     
547 //-------------------------------------------------------------------------------
548
549 AliDCSSensor*   AliGRPObject::GetBestCavernAtmosPressure() const {
550 //
551 //  Return pointer to 'best' cavern sensor
552 //    (default sensor 2. If sensor 1 and sensor 2 are sufficiently different,
553 //     use sensor most compatible with surface sensor
554 //    Pressure measuread at start-of-run
555
556    return GetBestCavernAtmosPressure(TTimeStamp(fTimeStart));
557 }
558