]> git.uio.no Git - u/mrichter/AliRoot.git/blame - SHUTTLE/AliSimpleValue.cxx
Improved access to AliITSgeom in reconstruction
[u/mrichter/AliRoot.git] / SHUTTLE / AliSimpleValue.cxx
CommitLineData
73abe331 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$
18Revision 1.1.1.1 2005/09/12 22:11:40 byordano
19SHUTTLE package
20
21Revision 1.2 2005/08/30 10:53:23 byordano
22some more descriptions added
23
24*/
25
26//
27// This class is a simple wrapper of
28// all primitive types used in PVSS SCADA system.
29//
30
31
32#include "AliSimpleValue.h"
33
34#include "AliLog.h"
35#include <TClass.h>
36
37TObject* AliSimpleValue::BoolHolder::Clone(const char* /*name*/) const {
38 return new BoolHolder(fValue);
39}
40
41Bool_t AliSimpleValue::BoolHolder::IsEqual(const TObject* obj) const {
42
43 if (this == obj) {
44 return kTRUE;
45 }
46
47 if (BoolHolder::Class() != obj->IsA()) {
48 return kFALSE;
49 }
50
51 return fValue == ((const BoolHolder*) obj)->fValue;
52}
53
54TObject* AliSimpleValue::ByteHolder::Clone(const char* /*name*/) const {
55 return new ByteHolder(fValue);
56}
57
58Bool_t AliSimpleValue::ByteHolder::IsEqual(const TObject* obj) const {
59
60 if (this == obj) {
61 return kTRUE;
62 }
63
64 if (ByteHolder::Class() != obj->IsA()) {
65 return kFALSE;
66 }
67
68 return fValue == ((const ByteHolder*) obj)->fValue;
69}
70
71TObject* AliSimpleValue::IntHolder::Clone(const char* /*name*/) const {
72 return new IntHolder(fValue);
73}
74
75Bool_t AliSimpleValue::IntHolder::IsEqual(const TObject* obj) const {
76
77 if (this == obj) {
78 return kTRUE;
79 }
80
81 if (IntHolder::Class() != obj->IsA()) {
82 return kFALSE;
83 }
84
85 return fValue == ((const IntHolder*) obj)->fValue;
86}
87
88TObject* AliSimpleValue::UIntHolder::Clone(const char* /*name*/) const {
89 return new UIntHolder(fValue);
90}
91
92Bool_t AliSimpleValue::UIntHolder::IsEqual(const TObject* obj) const {
93
94 if (this == obj) {
95 return kTRUE;
96 }
97
98 if (UIntHolder::Class() != obj->IsA()) {
99 return kFALSE;
100 }
101
102 return fValue == ((const UIntHolder*) obj)->fValue;
103}
104
105TObject* AliSimpleValue::FloatHolder::Clone(const char* /*name*/) const {
106 return new FloatHolder(fValue);
107}
108
109Bool_t AliSimpleValue::FloatHolder::IsEqual(const TObject* obj) const {
110
111 if (this == obj) {
112 return kTRUE;
113 }
114
115 if (FloatHolder::Class() != obj->IsA()) {
116 return kFALSE;
117 }
118
119 return fValue == ((const FloatHolder*) obj)->fValue;
120}
121
122TObject* AliSimpleValue::DynBoolHolder::Clone(const char* /*name*/) const {
123 return new DynBoolHolder(fSize, fValues);
124}
125
126Bool_t AliSimpleValue::DynBoolHolder::IsEqual(const TObject* obj) const {
127
128 if (this == obj) {
129 return kTRUE;
130 }
131
132 if (DynBoolHolder::Class() != obj->IsA()) {
133 return kFALSE;
134 }
135
136 const DynBoolHolder* other = ((const DynBoolHolder*) obj);
137
138 if (fSize != other->fSize) {
139 return kFALSE;
140 }
141
142 return !memcmp(fValues, other->fValues, fSize * sizeof(Bool_t));
143}
144
145TObject* AliSimpleValue::DynByteHolder::Clone(const char* /*name*/) const {
146 return new DynByteHolder(fSize, fValues);
147}
148
149Bool_t AliSimpleValue::DynByteHolder::IsEqual(const TObject* obj) const {
150
151 if (this == obj) {
152 return kTRUE;
153 }
154
155 if (DynByteHolder::Class() != obj->IsA()) {
156 return kFALSE;
157 }
158
159 const DynByteHolder* other = ((const DynByteHolder*) obj);
160
161 if (fSize != other->fSize) {
162 return kFALSE;
163 }
164
165 return !memcmp(fValues, other->fValues, fSize * sizeof(Char_t));
166}
167
168TObject* AliSimpleValue::DynIntHolder::Clone(const char* /*name*/) const {
169 return new DynIntHolder(fSize, fValues);
170}
171
172Bool_t AliSimpleValue::DynIntHolder::IsEqual(const TObject* obj) const {
173
174 if (this == obj) {
175 return kTRUE;
176 }
177
178 if (DynIntHolder::Class() != obj->IsA()) {
179 return kFALSE;
180 }
181
182 const DynIntHolder* other = ((const DynIntHolder*) obj);
183
184 if (fSize != other->fSize) {
185 return kFALSE;
186 }
187
188 return !memcmp(fValues, other->fValues, fSize * sizeof(Int_t));
189}
190
191TObject* AliSimpleValue::DynUIntHolder::Clone(const char* /*name*/) const {
192 return new DynUIntHolder(fSize, fValues);
193}
194
195Bool_t AliSimpleValue::DynUIntHolder::IsEqual(const TObject* obj) const {
196
197 if (this == obj) {
198 return kTRUE;
199 }
200
201 if (DynUIntHolder::Class() != obj->IsA()) {
202 return kFALSE;
203 }
204
205 const DynUIntHolder* other = ((const DynUIntHolder*) obj);
206
207 if (fSize != other->fSize) {
208 return kFALSE;
209 }
210
211 return !memcmp(fValues, other->fValues, fSize * sizeof(UInt_t));
212}
213
214TObject* AliSimpleValue::DynFloatHolder::Clone(const char* /*name*/) const {
215 return new DynFloatHolder(fSize, fValues);
216}
217
218Bool_t AliSimpleValue::DynFloatHolder::IsEqual(const TObject* obj) const {
219
220 if (this == obj) {
221 return kTRUE;
222 }
223
224 if (DynFloatHolder::Class() != obj->IsA()) {
225 return kFALSE;
226 }
227
228 const DynFloatHolder* other = ((const DynFloatHolder*) obj);
229
230 if (fSize != other->fSize) {
231 return kFALSE;
232 }
233
234 return !memcmp(fValues, other->fValues, fSize * sizeof(Float_t));
235}
236
237ClassImp(AliSimpleValue)
238
239AliSimpleValue::AliSimpleValue():
240 fHolder(NULL), fType(kInvalid)
241{
242
243}
244
245AliSimpleValue::AliSimpleValue(const AliSimpleValue& other):
246 TObject(other), fHolder(NULL), fType(other.fType)
247{
248 if (other.fHolder) {
249 fHolder = other.fHolder->Clone();
250 }
251}
252
253AliSimpleValue::AliSimpleValue(AliSimpleValue::Type type, Int_t size):
254 fHolder(NULL), fType(type)
255{
256
257 switch (type) {
258 case kBool:
259 fHolder = new BoolHolder();
260 break;
261 case kByte:
262 fHolder = new ByteHolder();
263 break;
264 case kInt:
265 fHolder = new IntHolder();
266 break;
267 case kUInt:
268 fHolder = new UIntHolder();
269 break;
270 case kFloat:
271 fHolder = new FloatHolder();
272 break;
273 case kDynBool:
274 fHolder = new DynBoolHolder(size);
275 break;
276 case kDynByte:
277 fHolder = new DynByteHolder(size);
278 break;
279 case kDynInt:
280 fHolder = new DynIntHolder(size);
281 break;
282 case kDynUInt:
283 fHolder = new DynUIntHolder(size);
284 break;
285 case kDynFloat:
286 fHolder = new DynFloatHolder(size);
287 break;
288 default:
289 break;
290 }
291}
292
293AliSimpleValue::AliSimpleValue(Bool_t val) {
294
295 fType = kBool;
296 fHolder = new BoolHolder(val);
297}
298
299AliSimpleValue::AliSimpleValue(Char_t val) {
300
301 fType = kByte;
302 fHolder = new ByteHolder(val);
303}
304
305AliSimpleValue::AliSimpleValue(Int_t val) {
306
307 fType = kInt;
308 fHolder = new IntHolder(val);
309}
310
311AliSimpleValue::AliSimpleValue(UInt_t val) {
312
313 fType = kUInt;
314 fHolder = new UIntHolder(val);
315}
316
317AliSimpleValue::AliSimpleValue(Float_t val) {
318
319 fType = kFloat;
320 fHolder = new FloatHolder(val);
321}
322
323AliSimpleValue::AliSimpleValue(Int_t size, const Bool_t* buf) {
324
325 fType = kDynBool;
326 fHolder = new DynBoolHolder(size, buf);
327}
328
329AliSimpleValue::AliSimpleValue(Int_t size, const Char_t* buf) {
330
331 fType = kDynByte;
332 fHolder = new DynByteHolder(size, buf);
333}
334
335AliSimpleValue::AliSimpleValue(Int_t size, const Int_t* buf) {
336
337 fType = kDynInt;
338 fHolder = new DynIntHolder(size, buf);
339}
340
341AliSimpleValue::AliSimpleValue(Int_t size, const UInt_t* buf) {
342
343 fType = kDynUInt;
344 fHolder = new DynUIntHolder(size, buf);
345}
346
347AliSimpleValue::AliSimpleValue(Int_t size, const Float_t* buf) {
348
349 fType = kDynFloat;
350 fHolder = new DynFloatHolder(size, buf);
351}
352
353AliSimpleValue::~AliSimpleValue() {
354
355 if (fHolder) {
356 delete fHolder;
357 }
358}
359
360AliSimpleValue& AliSimpleValue::operator=(const AliSimpleValue& other) {
361
362 if (fHolder) {
363 delete fHolder;
364 }
365
366 fType = other.fType;
367
368 if (other.fHolder) {
369 fHolder = other.fHolder->Clone();
370 } else {
371 fHolder = NULL;
372 }
373
374 return *this;
375}
376
377Bool_t AliSimpleValue::operator==(const AliSimpleValue& other) const {
378
379 if (fType != other.fType) {
380 return kFALSE;
381 }
382
383 if (!(fHolder && other.fHolder)) {
384 return kFALSE;
385 }
386
387 return fHolder->IsEqual(other.fHolder);
388}
389
390void AliSimpleValue::SetBool(Bool_t val) {
391
392 if (!TypeOk(kBool)) {
393 return;
394 }
395
396 ((BoolHolder*) fHolder)->fValue = val;
397}
398
399void AliSimpleValue::SetByte(Char_t val) {
400
401 if (!TypeOk(kByte)) {
402 return;
403 }
404
405 ((ByteHolder*) fHolder)->fValue = val;
406}
407
408void AliSimpleValue::SetInt(Int_t val) {
409
410 if (!TypeOk(kInt)) {
411 return;
412 }
413
414 ((IntHolder*) fHolder)->fValue = val;
415}
416
417void AliSimpleValue::SetUInt(UInt_t val) {
418
419 if (!TypeOk(kUInt)) {
420 return;
421 }
422
423 ((UIntHolder*) fHolder)->fValue = val;
424}
425
426void AliSimpleValue::SetFloat(Float_t val) {
427
428 if (!TypeOk(kFloat)) {
429 return;
430 }
431
432 ((FloatHolder*) fHolder)->fValue = val;
433}
434
435Bool_t AliSimpleValue::GetBool() const {
436
437 if (!TypeOk(kBool)) {
438 return kFALSE;
439 }
440
441 return ((BoolHolder*) fHolder)->fValue;
442}
443
444Char_t AliSimpleValue::GetByte() const {
445
446 if (!TypeOk(kByte)) {
447 return 0;
448 }
449
450 return ((ByteHolder*) fHolder)->fValue;
451}
452
453Int_t AliSimpleValue::GetInt() const {
454
455 if (!TypeOk(kInt)) {
456 return 0;
457 }
458 return ((IntHolder*) fHolder)->fValue;
459}
460
461UInt_t AliSimpleValue::GetUInt() const {
462
463 if (!TypeOk(kUInt)) {
464 return 0;
465 }
466
467 return ((UIntHolder*) fHolder)->fValue;
468}
469
470Float_t AliSimpleValue::GetFloat() const {
471
472 if (!TypeOk(kFloat)) {
473 return 0;
474 }
475
476 return ((FloatHolder*) fHolder)->fValue;
477}
478
479void AliSimpleValue::SetDynBool(Int_t n, Bool_t val) {
480
481 if (!TypeOk(kDynBool)) {
482 return;
483 }
484
485 if (!BoundsOk(n)) {
486 return;
487 }
488
489 ((DynBoolHolder*) fHolder)->fValues[n] = val;
490}
491
492void AliSimpleValue::SetDynByte(Int_t n, Char_t val) {
493
494 if (!TypeOk(kDynByte)) {
495 return;
496 }
497
498 if (!BoundsOk(n)) {
499 return;
500 }
501
502 ((DynByteHolder*) fHolder)->fValues[n] = val;
503}
504
505void AliSimpleValue::SetDynInt(Int_t n, Int_t val) {
506
507 if (!TypeOk(kDynInt)) {
508 return;
509 }
510
511 if (!BoundsOk(n)) {
512 return;
513 }
514
515 ((DynIntHolder*) fHolder)->fValues[n] = val;
516}
517
518void AliSimpleValue::SetDynUInt(Int_t n, UInt_t val) {
519
520 if (!TypeOk(kDynUInt)) {
521 return;
522 }
523
524 if (!BoundsOk(n)) {
525 return;
526 }
527
528 ((DynUIntHolder*) fHolder)->fValues[n] = val;
529}
530
531void AliSimpleValue::SetDynFloat(Int_t n, Float_t val) {
532
533 if (!TypeOk(kDynFloat)) {
534 return;
535 }
536
537 if (!BoundsOk(n)) {
538 return;
539 }
540
541 ((DynFloatHolder*) fHolder)->fValues[n] = val;
542}
543
544Bool_t AliSimpleValue::GetDynBool(Int_t n) const {
545
546 if (!TypeOk(kDynBool)) {
547 return kFALSE;
548 }
549
550 if (!BoundsOk(n)) {
551 return kFALSE;
552 }
553
554 return ((DynBoolHolder*) fHolder)->fValues[n];
555}
556
557Char_t AliSimpleValue::GetDynByte(Int_t n) const {
558
559 if (!TypeOk(kDynByte)) {
560 return 0;
561 }
562
563 if (!BoundsOk(n)) {
564 return 0;
565 }
566
567 return ((DynByteHolder*) fHolder)->fValues[n];
568}
569
570Int_t AliSimpleValue::GetDynInt(Int_t n) const {
571
572 if (!TypeOk(kDynInt)) {
573 return 0;
574 }
575
576 if (!BoundsOk(n)) {
577 return 0;
578 }
579
580 return ((DynIntHolder*) fHolder)->fValues[n];
581}
582
583UInt_t AliSimpleValue::GetDynUInt(Int_t n) const {
584
585 if (!TypeOk(kDynUInt)) {
586 return 0;
587 }
588
589 if (!BoundsOk(n)) {
590 return 0;
591 }
592
593 return ((DynUIntHolder*) fHolder)->fValues[n];
594}
595
596Float_t AliSimpleValue::GetDynFloat(Int_t n) const {
597
598 if (!TypeOk(kDynFloat)) {
599 return 0;
600 }
601
602 if (!BoundsOk(n)) {
603 return 0;
604 }
605
606 return ((DynFloatHolder*) fHolder)->fValues[n];
607}
608
609Bool_t AliSimpleValue::TypeOk(AliSimpleValue::Type type) const {
610
611 if (fType != type) {
612 AliError(Form("SimpleValue type is not %s!",
613 GetTypeString(type)));
614 return kFALSE;
615 }
616
617 return kTRUE;
618}
619
620Bool_t AliSimpleValue::BoundsOk(Int_t n) const {
621
622 switch (fType) {
623 case kDynBool:
624 case kDynByte:
625 case kDynInt:
626 case kDynUInt:
627 case kDynFloat: {
628 Int_t size = ((DynHolder*) fHolder)->fSize;
629 if (n < 0 || n >= size) {
630 AliError(Form("Index %d out of bounds!", n));
631 return kFALSE;
632 }
633 return kTRUE;
634 }
635 case kBool:
636 case kByte:
637 case kInt:
638 case kUInt:
639 case kFloat:
640 AliError(Form("SimpleValue type %s is not dynamic!",
641 GetTypeString(fType)));
642 return kFALSE;
643 default:
644 AliError("Invalid or unknown type!");
645 return kFALSE;
646 }
647}
648
649Int_t AliSimpleValue::GetDynamicSize() const {
650 //
651 // returns the size of dynamic type or 0 in case of
652 // none dynamic type.
653 //
654
655 if (!fHolder) {
656 return 0;
657 }
658
659 if (!fHolder->IsA()->InheritsFrom(DynHolder::Class())) {
660 return 0;
661 }
662
663 return ((DynHolder*) fHolder)->fSize;
664}
665
666TString AliSimpleValue::ToString() const {
667
668 TString result;
669
670 result += "Type: ";
671 result += GetTypeString(fType);
672
673 result += ", Value: ";
674 switch (fType) {
675 case kBool:
676 result += GetBool();
677 break;
678 case kByte:
679 result += (Int_t) GetByte();
680 break;
681 case kInt:
682 result += GetInt();
683 break;
684 case kUInt:
685 result += GetUInt();
686 break;
687 case kFloat:
688 result += GetFloat();
689 break;
690 case kDynBool: {
691 result += "[";
692 Int_t size = GetDynamicSize();
693 for (Int_t k = 0; k < size; k ++) {
694 result += GetDynBool(k);
695 if (k + 1 < size) {
696 result += ", ";
697 }
698 }
699 result += "]";
700 }
701 break;
702 case kDynByte: {
703 result += "[";
704 Int_t size = GetDynamicSize();
705 for (Int_t k = 0; k < size; k ++) {
706 result += GetDynByte(k);
707 if (k + 1 < size) {
708 result += ", ";
709 }
710 }
711 result += "]";
712 }
713 break;
714 case kDynInt: {
715 result += "[";
716 Int_t size = GetDynamicSize();
717 for (Int_t k = 0; k < size; k ++) {
718 result += GetDynInt(k);
719 if (k + 1 < size) {
720 result += ", ";
721 }
722 }
723 result += "]";
724 }
725 break;
726 case kDynUInt: {
727 result += "[";
728 Int_t size = GetDynamicSize();
729 for (Int_t k = 0; k < size; k ++) {
730 result += GetDynUInt(k);
731 if (k + 1 < size) {
732 result += ", ";
733 }
734 }
735 result += "]";
736 }
737 break;
738 case kDynFloat: {
739 result += "[";
740 Int_t size = GetDynamicSize();
741 for (Int_t k = 0; k < size; k ++) {
742 result += GetDynFloat(k);
743 if (k + 1 < size) {
744 result += ", ";
745 }
746 }
747 result += "]";
748 }
749 break;
750 default:
751 result += "Unknown";
752 }
753
754 return result;
755}
756
757Bool_t AliSimpleValue::IsDynamic(AliSimpleValue::Type type) {
758
759 switch (type) {
760 case kDynBool:
761 case kDynByte:
762 case kDynInt:
763 case kDynUInt:
764 case kDynFloat:
765 return kTRUE;
766 default:
767 return kFALSE;
768 }
769}
770
771Int_t AliSimpleValue::GetSize() const {
772 //
773 // return the number of bytes used by this value.
774 // In case of dynamic type it returns dynamic size multiplied
775 // by the size of corresponding primitive type.
776 //
777
778 return IsDynamic(fType) ?
779 GetDynamicSize() * AliSimpleValue::GetPrimitiveSize(fType):
780 AliSimpleValue::GetPrimitiveSize(fType);
781}
782
783Int_t AliSimpleValue::GetPrimitiveSize(AliSimpleValue::Type type) {
784 //
785 // returns the number of bytes used by particular primitive type
786 // or by the corresponding primitive type in case of dynamic type.
787 //
788
789
790 switch (type) {
791
792 case kBool:
793 case kDynBool: return sizeof(Bool_t);
794 case kByte:
795 case kDynByte: return sizeof(Char_t);
796 case kInt:
797 case kDynInt: return sizeof(Int_t);
798 case kUInt:
799 case kDynUInt: return sizeof(UInt_t);
800 case kFloat:
801 case kDynFloat: return sizeof(Float_t);
802 default:
803 return 0;
804 }
805}
806
807const char* AliSimpleValue::GetTypeString(AliSimpleValue::Type type) {
808
809 switch (type) {
810 case kBool: return "Bool";
811 case kByte: return "Byte";
812 case kInt: return "Int";
813 case kUInt: return "UInt";
814 case kFloat: return "Float";
815 case kDynBool: return "DynBool";
816 case kDynByte: return "DynByte";
817 case kDynInt: return "DynInt";
818 case kDynUInt: return "DynUInt";
819 case kDynFloat: return "DynFloat";
820 default:
821 return "Unknown";
822 }
823}