NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcAttrib.cxx
Go to the documentation of this file.
1
31
33
62
63#include "NcAttrib.h"
64#include "Riostream.h"
65
66ClassImp(NcAttrib); // Class implementation to enable ROOT I/O
67
70{
79
80 fGains=0;
81 fOffsets=0;
82 fCalflags=0;
83 fNames=0;
84 fCalfuncs=0;
86}
87
89{
95
96 if (fGains)
97 {
98 delete fGains;
99 fGains=0;
100 }
101 if (fOffsets)
102 {
103 delete fOffsets;
104 fOffsets=0;
105 }
106 if (fCalflags)
107 {
108 delete fCalflags;
109 fCalflags=0;
110 }
111 if (fNames)
112 {
113 delete fNames;
114 fNames=0;
115 }
116 if (fCalfuncs)
117 {
118 delete fCalfuncs;
119 fCalfuncs=0;
120 }
121 if (fDecalfuncs)
122 {
123 delete fDecalfuncs;
124 fDecalfuncs=0;
125 }
126}
127
129{
135
136 fGains=0;
137 fOffsets=0;
138 fCalflags=0;
139 fNames=0;
140 fCalfuncs=0;
141 fDecalfuncs=0;
142
143 Int_t n=0;
144 Double_t val=0;
145
146 n=a.GetNgains();
147 for (Int_t ig=1; ig<=n; ig++)
148 {
149 val=a.GetGain(ig);
150 if (a.GetGainFlag(ig)) SetGain(val,ig);
151 }
152
153 n=a.GetNoffsets();
154 for (Int_t io=1; io<=n; io++)
155 {
156 val=a.GetOffset(io);
157 if (a.GetOffsetFlag(io)) SetOffset(val,io);
158 }
159
160 n=a.GetNcalflags();
161 for (Int_t ic=1; ic<=n; ic++)
162 {
163 SetEdgeValue(a.GetEdgeValue(ic),ic);
164 if (a.GetLockValue(ic)) Lock(ic);
165 if (a.GetDeadValue(ic)) SetDead(ic);
166 }
167
168 n=a.GetNnames();
169 TString s;
170 for (Int_t in=1; in<=n; in++)
171 {
172 s=a.GetSlotName(in);
173 if (s!="") SetSlotName(s,in);
174 }
175
176 n=a.GetNcalfuncs();
177 for (Int_t icalf=1; icalf<=n; icalf++)
178 {
179 TF1* f=a.GetCalFunction(icalf);
180 if (f) SetCalFunction(f,icalf);
181 }
182
183 n=a.GetNdecalfuncs();
184 for (Int_t idecalf=1; idecalf<=n; idecalf++)
185 {
186 TF1* f=a.GetDecalFunction(idecalf);
187 if (f) SetDecalFunction(f,idecalf);
188 }
189}
190
192{
198
199 if (!fGains) return 0;
200
201 Int_t n=0;
202 for (Int_t i=1; i<=fGains->GetSize(); i++)
203 {
204 if (GetGainFlag(i)) n=i;
205 }
206
207 return n;
208}
209
211{
217
218 if (!fOffsets) return 0;
219
220 Int_t n=0;
221 for (Int_t i=1; i<=fOffsets->GetSize(); i++)
222 {
223 if (GetOffsetFlag(i)) n=i;
224 }
225
226 return n;
227}
228
230{
236
237 if (!fCalflags) return 0;
238
239 Int_t n=0;
240 for (Int_t i=1; i<=fCalflags->GetSize(); i++)
241 {
242 if (fCalflags->At(i-1)) n=i;
243 }
244
245 return n;
246}
247
249{
255
256 if (!fNames) return 0;
257
258 Int_t n=0;
259 for (Int_t i=1; i<=fNames->GetSize(); i++)
260 {
261 if (fNames->At(i-1)) n=i;
262 }
263
264 return n;
265}
266
267void NcAttrib::SetGain(Double_t gain,Int_t j)
268{
278
279 if (j<1)
280 {
281 cout << " *NcAttrib::SetGain* Invalid argument j = " << j << endl;
282 return;
283 }
284
285 if (!fGains)
286 {
287 fGains=new TArrayF(j);
288 }
289
290 Int_t size=fGains->GetSize();
291
292 if (j>size)
293 {
294 fGains->Set(j);
295 }
296
297 fGains->AddAt(float(gain),j-1);
298
299 Int_t oflag=GetOffsetFlag(j);
300
301 SetCalFlags(1,oflag,j);
302}
303
304void NcAttrib::SetGain(Double_t gain,TString name)
305{
317
318 Int_t j=GetSlotIndex(name);
319 if (j>0) SetGain(gain,j);
320}
321
322void NcAttrib::SetOffset(Double_t off,Int_t j)
323{
333
334 if (j<1)
335 {
336 cout << " *NcAttrib::GetOffset* Invalid argument j = " << j << endl;
337 return;
338 }
339
340 if (!fOffsets)
341 {
342 fOffsets=new TArrayF(j);
343 }
344
345 Int_t size=fOffsets->GetSize();
346
347 if (j>size)
348 {
349 fOffsets->Set(j);
350 }
351
352 fOffsets->AddAt(float(off),j-1);
353
354 Int_t gflag=GetGainFlag(j);
355
356 SetCalFlags(gflag,1,j);
357}
358
359void NcAttrib::SetOffset(Double_t off,TString name)
360{
372
373 Int_t j=GetSlotIndex(name);
374 if (j>0) SetOffset(off,j);
375}
376
377void NcAttrib::SetCalFlags(Int_t gainflag,Int_t offsetflag,Int_t j)
378{
389
390 if (j<1)
391 {
392 cout << " *NcAttrib::GetCalFlags* Invalid argument j = " << j << endl;
393 return;
394 }
395
396 if (!fCalflags)
397 {
398 fCalflags=new TArrayI(j);
399 }
400
401 Int_t size=fCalflags->GetSize();
402
403 if (j>size)
404 {
405 fCalflags->Set(j);
406 }
407
408 Int_t edge=GetEdgeValue(j);
409 Int_t lock=GetLockValue(j);
410 Int_t dead=GetDeadValue(j);
411
412 Int_t word=10000*edge+1000*lock+100*dead+10*gainflag+offsetflag;
413
414 fCalflags->AddAt(word,j-1);
415}
416
417Int_t NcAttrib::GetGainFlag(Int_t j) const
418{
430
431 if (j<1)
432 {
433 cout << " *NcAttrib::GetGainFlag* Invalid argument j = " << j << endl;
434 return 0;
435 }
436 Int_t gflag=0;
437 if (fCalflags)
438 {
439 if (j>0 && j<=(fCalflags->GetSize()))
440 {
441 Int_t word=fCalflags->At(j-1);
442 word=word%100;
443 gflag=word/10;
444 }
445 }
446 return gflag;
447}
448
449Int_t NcAttrib::GetGainFlag(TString name) const
450{
466
467 Int_t j=GetSlotIndex(name);
468 Int_t flag=0;
469 if (j>0) flag=GetGainFlag(j);
470 return flag;
471}
472
473Int_t NcAttrib::GetOffsetFlag(Int_t j) const
474{
486
487 if (j<1)
488 {
489 cout << " *NcAttrib::GetOffsetFlag* Invalid argument j = " << j << endl;
490 return 0;
491 }
492
493 Int_t oflag=0;
494 if (fCalflags)
495 {
496 if (j>0 && j<=(fCalflags->GetSize()))
497 {
498 Int_t word=fCalflags->At(j-1);
499 oflag=word%10;
500 }
501 }
502 return oflag;
503}
504
505Int_t NcAttrib::GetOffsetFlag(TString name) const
506{
522
523 Int_t j=GetSlotIndex(name);
524 Int_t flag=0;
525 if (j>0) flag=GetOffsetFlag(j);
526 return flag;
527}
528
529Int_t NcAttrib::GetCalWord(Int_t j) const
530{
540
541 if (j<1)
542 {
543 cout << " *NcAttrib::GetCalWord* Invalid argument j = " << j << endl;
544 return 0;
545 }
546
547 Int_t word=0;
548 if (fCalflags)
549 {
550 if (j>0 && j<=(fCalflags->GetSize())) word=fCalflags->At(j-1);
551 }
552 return word;
553}
554
555Int_t NcAttrib::GetCalWord(TString name) const
556{
569
570 Int_t j=GetSlotIndex(name);
571 Int_t word=0;
572 if (j>0) word=GetCalWord(j);
573 return word;
574}
575
576Float_t NcAttrib::GetGain(Int_t j) const
577{
586
587 if (j<1)
588 {
589 cout << " *NcAttrib::GetGain* Invalid argument j = " << j << endl;
590 return 0;
591 }
592
593 Float_t gain=0;
594 if (fGains)
595 {
596 if (j>0 && j<=(fGains->GetSize()))
597 {
598 if (GetGainFlag(j)) gain=fGains->At(j-1);
599 }
600 }
601 return gain;
602}
603
604Float_t NcAttrib::GetGain(TString name) const
605{
617
618 Int_t j=GetSlotIndex(name);
619 Float_t gain=0;
620 if (j>0) gain=GetGain(j);
621 return gain;
622}
623
624Float_t NcAttrib::GetOffset(Int_t j) const
625{
634
635 if (j<1)
636 {
637 cout << " *NcAttrib::GetOffset* Invalid argument j = " << j << endl;
638 return 0;
639 }
640
641 Float_t offset=0;
642 if (fOffsets)
643 {
644 if (j>0 && j<=(fOffsets->GetSize()))
645 {
646 if (GetOffsetFlag(j)) offset=fOffsets->At(j-1);
647 }
648 }
649 return offset;
650}
651
652Float_t NcAttrib::GetOffset(TString name) const
653{
665
666 Int_t j=GetSlotIndex(name);
667 Float_t offset=0;
668 if (j>0) offset=GetOffset(j);
669 return offset;
670}
671
673{
681
682 if (!fGains) return;
683
684 Int_t size=fGains->GetSize();
685
686 if ((j>=0) && (j<=size))
687 {
688 if (j)
689 {
690 fGains->AddAt(0,j-1);
691 Int_t oflag=GetOffsetFlag(j);
692 SetCalFlags(0,oflag,j);
693 }
694 else
695 {
696 for (Int_t i=0; i<size; i++)
697 {
698 fGains->AddAt(0,i);
699 Int_t oflag=GetOffsetFlag(i);
700 SetCalFlags(0,oflag,i);
701 }
702 }
703 }
704 else
705 {
706 cout << " *NcAttrib::ResetGain* Index j = " << j << " invalid." << endl;
707 return;
708 }
709}
710
711void NcAttrib::ResetGain(TString name)
712{
724
725 Int_t j=GetSlotIndex(name);
726 if (j>0) ResetGain(j);
727}
728
730{
738
739 if (!fOffsets) return;
740
741 Int_t size=fOffsets->GetSize();
742
743 if ((j>=0) && (j<=size))
744 {
745 if (j)
746 {
747 fOffsets->AddAt(0,j-1);
748 Int_t gflag=GetGainFlag(j);
749 SetCalFlags(gflag,0,j);
750 }
751 else
752 {
753 for (Int_t i=0; i<size; i++)
754 {
755 fOffsets->AddAt(0,i);
756 Int_t gflag=GetGainFlag(i);
757 SetCalFlags(gflag,0,i);
758 }
759 }
760 }
761 else
762 {
763 cout << " *NcAttrib::ResetOffset* Index j = " << j << " invalid." << endl;
764 return;
765 }
766}
767
768void NcAttrib::ResetOffset(TString name)
769{
781
782 Int_t j=GetSlotIndex(name);
783 if (j>0) ResetOffset(j);
784}
785
787{
802
803 if (mode<0 || mode>6)
804 {
805 cout << " *NcAttrib::DeleteCalibrations* Unknown mode : " << mode << endl;
806 cout << " Default mode=0 will be used." << endl;
807 mode=0;
808 }
809
810 if (mode==0 || mode==3)
811 {
812 ResetGain(0);
813 if (fGains)
814 {
815 delete fGains;
816 fGains=0;
817 }
818 ResetOffset(0);
819 if (fOffsets)
820 {
821 delete fOffsets;
822 fOffsets=0;
823 }
824 if (fCalflags && mode==0)
825 {
826 delete fCalflags;
827 fCalflags=0;
828 }
829 if (fNames && mode==0)
830 {
831 delete fNames;
832 fNames=0;
833 }
834 if (fCalfuncs)
835 {
836 delete fCalfuncs;
837 fCalfuncs=0;
838 }
839 if (fDecalfuncs)
840 {
841 delete fDecalfuncs;
842 fDecalfuncs=0;
843 }
844 return;
845 }
846
847 if (mode==1)
848 {
849 ResetGain(0);
850 if (fGains)
851 {
852 delete fGains;
853 fGains=0;
854 }
855 }
856
857 if (mode==2)
858 {
859 ResetOffset(0);
860 if (fOffsets)
861 {
862 delete fOffsets;
863 fOffsets=0;
864 }
865 }
866
867 if (mode==4 || mode==6)
868 {
869 if (fCalfuncs)
870 {
871 delete fCalfuncs;
872 fCalfuncs=0;
873 }
874 }
875
876 if (mode==5 || mode==6)
877 {
878 if (fDecalfuncs)
879 {
880 delete fDecalfuncs;
881 fDecalfuncs=0;
882 }
883 }
884}
885
886void NcAttrib::SetDead(Int_t j)
887{
898
899 if (j<1)
900 {
901 cout << " *NcAttrib::SetDead* Invalid argument j = " << j << endl;
902 return;
903 }
904
905 if (!fCalflags)
906 {
907 fCalflags=new TArrayI(j);
908 }
909
910 Int_t size=fCalflags->GetSize();
911
912 if (j>size)
913 {
914 fCalflags->Set(j);
915 }
916
917 Int_t dead=1;
918 Int_t oflag=GetOffsetFlag(j);
919 Int_t gflag=GetGainFlag(j);
920 Int_t lock=GetLockValue(j);
921 Int_t edge=GetEdgeValue(j);
922
923 Int_t word=10000*edge+1000*lock+100*dead+10*gflag+oflag;
924
925 fCalflags->AddAt(word,j-1);
926}
927
928void NcAttrib::SetDead(TString name)
929{
941
942 Int_t j=GetSlotIndex(name);
943 if (j>0) SetDead(j);
944}
945
947{
957
958 if (j<1)
959 {
960 cout << " *NcAttrib::SetAlive* Invalid argument j = " << j << endl;
961 return;
962 }
963
964 if (!fCalflags || j>fCalflags->GetSize()) return;
965
966 Int_t dead=0;
967 Int_t oflag=GetOffsetFlag(j);
968 Int_t gflag=GetGainFlag(j);
969 Int_t lock=GetLockValue(j);
970 Int_t edge=GetEdgeValue(j);
971
972 Int_t word=10000*edge+1000*lock+100*dead+10*gflag+oflag;
973
974 fCalflags->AddAt(word,j-1);
975}
976
977void NcAttrib::SetAlive(TString name)
978{
990
991 Int_t j=GetSlotIndex(name);
992 if (j>0) SetAlive(j);
993}
994
995void NcAttrib::Lock(Int_t j)
996{
1007
1008 if (j<1)
1009 {
1010 cout << " *NcAttrib::Lock* Invalid argument j = " << j << endl;
1011 return;
1012 }
1013
1014 if (!fCalflags)
1015 {
1016 fCalflags=new TArrayI(j);
1017 }
1018
1019 Int_t size=fCalflags->GetSize();
1020
1021 if (j>size)
1022 {
1023 fCalflags->Set(j);
1024 }
1025
1026 Int_t lock=1;
1027 Int_t dead=GetDeadValue(j);
1028 Int_t oflag=GetOffsetFlag(j);
1029 Int_t gflag=GetGainFlag(j);
1030 Int_t edge=GetEdgeValue(j);
1031
1032 Int_t word=10000*edge+1000*lock+100*dead+10*gflag+oflag;
1033
1034 fCalflags->AddAt(word,j-1);
1035}
1036
1037void NcAttrib::Lock(TString name)
1038{
1050
1051 Int_t j=GetSlotIndex(name);
1052 if (j>0) Lock(j);
1053}
1054
1055void NcAttrib::Unlock(Int_t j)
1056{
1066
1067 if (j<1)
1068 {
1069 cout << " *NcAttrib::Unlock* Invalid argument j = " << j << endl;
1070 return;
1071 }
1072
1073 if (!fCalflags || j>fCalflags->GetSize()) return;
1074
1075 Int_t lock=0;
1076 Int_t dead=GetDeadValue();
1077 Int_t oflag=GetOffsetFlag(j);
1078 Int_t gflag=GetGainFlag(j);
1079 Int_t edge=GetEdgeValue(j);
1080
1081 Int_t word=10000*edge+1000*lock+100*dead+10*gflag+oflag;
1082
1083 fCalflags->AddAt(word,j-1);
1084}
1085
1086void NcAttrib::Unlock(TString name)
1087{
1099
1100 Int_t j=GetSlotIndex(name);
1101 if (j>0) Unlock(j);
1102}
1103
1105{
1116
1117 if (j<1)
1118 {
1119 cout << " *NcAttrib::SetEdgeOn* Invalid argument j = " << j << endl;
1120 return;
1121 }
1122
1123 SetEdgeValue(1,j);
1124}
1125
1126void NcAttrib::SetEdgeOn(TString name)
1127{
1139
1140 Int_t j=GetSlotIndex(name);
1141 if (j>0) SetEdgeOn(j);
1142}
1143
1145{
1155
1156 if (j<1)
1157 {
1158 cout << " *NcAttrib::SetEdgeOff* Invalid argument j = " << j << endl;
1159 return;
1160 }
1161
1162 if (!fCalflags || j>fCalflags->GetSize()) return;
1163
1164 SetEdgeValue(0,j);
1165}
1166
1167void NcAttrib::SetEdgeOff(TString name)
1168{
1180
1181 Int_t j=GetSlotIndex(name);
1182 if (j>0) SetEdgeOff(j);
1183}
1184
1185void NcAttrib::SetEdgeValue(Int_t val,Int_t j)
1186{
1197
1198 if (j<1)
1199 {
1200 cout << " *NcAttrib::SetEdgeValue* Invalid argument j = " << j << endl;
1201 return;
1202 }
1203
1204 if (!fCalflags)
1205 {
1206 fCalflags=new TArrayI(j);
1207 }
1208
1209 Int_t size=fCalflags->GetSize();
1210
1211 if (j>size)
1212 {
1213 fCalflags->Set(j);
1214 }
1215
1216 Int_t edge=val;
1217 Int_t lock=GetLockValue(j);
1218 Int_t dead=GetDeadValue(j);
1219 Int_t gflag=GetGainFlag(j);
1220 Int_t oflag=GetOffsetFlag(j);
1221
1222 Int_t word=10000*edge+1000*lock+100*dead+10*gflag+oflag;
1223
1224 fCalflags->AddAt(word,j-1);
1225}
1226
1227void NcAttrib::SetEdgeValue(Int_t val,TString name)
1228{
1240
1241 Int_t j=GetSlotIndex(name);
1242 if (j>0) SetEdgeValue(val,j);
1243}
1244
1246{
1257
1258 if (j<1)
1259 {
1260 cout << " *NcAttrib::IncreaseEdgeValue* Invalid argument j = " << j << endl;
1261 return;
1262 }
1263
1264 Int_t edge=GetEdgeValue();
1265 SetEdgeValue(edge+1,j);
1266}
1267
1269{
1281
1282 Int_t j=GetSlotIndex(name);
1283 if (j>0) IncreaseEdgeValue(j);
1284}
1285
1287{
1298
1299 if (j<1)
1300 {
1301 cout << " *NcAttrib::DecreaseEdgeValue* Invalid argument j = " << j << endl;
1302 return;
1303 }
1304
1305 Int_t edge=GetEdgeValue();
1306 SetEdgeValue(edge-1,j);
1307}
1308
1310{
1322
1323 Int_t j=GetSlotIndex(name);
1324 if (j>0) DecreaseEdgeValue(j);
1325}
1326
1327Int_t NcAttrib::GetEdgeValue(Int_t j) const
1328{
1336
1337 if (j<1)
1338 {
1339 cout << " *NcAttrib::GetEdgeValue* Invalid argument j = " << j << endl;
1340 return 0;
1341 }
1342
1343 Int_t edge=0;
1344 if (fCalflags)
1345 {
1346 if (j>0 && j<=(fCalflags->GetSize()))
1347 {
1348 Int_t word=fCalflags->At(j-1);
1349 edge=word/10000;
1350 }
1351 }
1352 return edge;
1353}
1354
1355Int_t NcAttrib::GetEdgeValue(TString name) const
1356{
1368
1369 Int_t j=GetSlotIndex(name);
1370 Int_t val=0;
1371 if (j>0) val=GetEdgeValue(j);
1372 return val;
1373}
1374
1375Int_t NcAttrib::GetDeadValue(Int_t j) const
1376{
1384
1385 if (j<1)
1386 {
1387 cout << " *NcAttrib::GetDeadValue* Invalid argument j = " << j << endl;
1388 return 0;
1389 }
1390
1391 Int_t dead=0;
1392 if (fCalflags)
1393 {
1394 if (j>0 && j<=(fCalflags->GetSize()))
1395 {
1396 Int_t word=fCalflags->At(j-1);
1397 word=word%1000;
1398 dead=word/100;
1399 }
1400 }
1401 return dead;
1402}
1403
1404Int_t NcAttrib::GetDeadValue(TString name) const
1405{
1417
1418 Int_t j=GetSlotIndex(name);
1419 Int_t val=0;
1420 if (j>0) val=GetDeadValue(j);
1421 return val;
1422}
1423
1424Int_t NcAttrib::GetLockValue(Int_t j) const
1425{
1433
1434 if (j<1)
1435 {
1436 cout << " *NcAttrib::GetLockValue* Invalid argument j = " << j << endl;
1437 return 0;
1438 }
1439
1440 Int_t lock=0;
1441 if (fCalflags)
1442 {
1443 if (j>0 && j<=(fCalflags->GetSize()))
1444 {
1445 Int_t word=fCalflags->At(j-1);
1446 word=word%10000;
1447 lock=word/1000;
1448 }
1449 }
1450 return lock;
1451}
1452
1453Int_t NcAttrib::GetLockValue(TString name) const
1454{
1466
1467 Int_t j=GetSlotIndex(name);
1468 Int_t val=0;
1469 if (j>0) val=GetLockValue(j);
1470 return val;
1471}
1472
1474{
1480
1481 Int_t n=GetNcalflags();
1482 Int_t nn=GetNnames();
1483 Int_t ncalf=GetNcalfuncs();
1484 Int_t ndecalf=GetNdecalfuncs();
1485 if (n<nn) n=nn;
1486 if (n<ncalf) n=ncalf;
1487 if (n<ndecalf) n=ndecalf;
1488
1489 return n;
1490}
1491
1493{
1500
1501 if (GetSlotIndex(s)) return;
1502
1503 Int_t n=GetNslots();
1504 SetSlotName(s,n+1);
1505}
1506
1507void NcAttrib::SetSlotName(TString s,Int_t j)
1508{
1518
1519 if (j<1)
1520 {
1521 cout << " *NcAttrib::SetSlotName* Invalid argument j = " << j << endl;
1522 return;
1523 }
1524
1525 if (!fNames)
1526 {
1527 fNames=new TObjArray(j);
1528 fNames->SetOwner();
1529 }
1530
1531 if (j>fNames->GetSize()) fNames->Expand(j);
1532
1533 TObjString* so=(TObjString*)fNames->At(j-1);
1534 if (!so)
1535 {
1536 so=new TObjString(s.Data());
1537 fNames->AddAt(so,j-1);
1538 }
1539 else
1540 {
1541 so->SetString(s);
1542 }
1543}
1544
1545TString NcAttrib::GetSlotName(Int_t j) const
1546{
1553
1554 TString s="";
1555 if (j<1)
1556 {
1557 cout << " *NcAttrib::GetSlotName* Invalid argument j = " << j << endl;
1558 return s;
1559 }
1560
1561 if (fNames)
1562 {
1563 if (j<=fNames->GetSize())
1564 {
1565 TObjString* so=(TObjString*)fNames->At(j-1);
1566 if (so) s=so->GetString();
1567 }
1568 }
1569 return s;
1570}
1571
1572Int_t NcAttrib::GetSlotIndex(TString name,Int_t opt) const
1573{
1587
1588 Int_t index=0;
1589
1590 if (fNames)
1591 {
1592 TString s;
1593 Int_t size=fNames->GetSize();
1594 for (Int_t i=0; i<size; i++)
1595 {
1596 TObjString* so=(TObjString*)fNames->At(i);
1597 if (so) s=so->GetString();
1598 if ((!opt && s==name) || (opt && s.Contains(name.Data())))
1599 {
1600 index=i+1;
1601 break;
1602 }
1603 }
1604 }
1605 return index;
1606}
1607
1608void NcAttrib::List(Int_t j) const
1609{
1617
1618 if (j<0)
1619 {
1620 cout << " *NcAttrib::Data* Invalid argument j = " << j << endl;
1621 return;
1622 }
1623
1624 if (j>0)
1625 {
1626 if (GetGainFlag(j)) cout << " gain : " << GetGain(j);
1627 if (GetOffsetFlag(j)) cout << " offset : " << GetOffset(j);
1628 if (GetEdgeValue(j)) cout << " edge : " << GetEdgeValue(j);
1629 if (GetDeadValue(j)) cout << " dead : " << GetDeadValue(j);
1630 if (GetLockValue(j)) cout << " lock : " << GetLockValue(j);
1631 if (GetCalFunction(j)) cout << " *Fcalib*";
1632 if (GetDecalFunction(j)) cout << " *Fdecalib*";
1633 TString s=GetSlotName(j);
1634 if (s!="") cout << " name : " << s.Data();
1635 }
1636 else
1637 {
1638 Int_t ng=GetNgains();
1639 Int_t no=GetNoffsets();
1640 Int_t nf=0;
1641 if (fCalflags) nf=fCalflags->GetSize();
1642 Int_t nn=GetNnames();
1643 Int_t n=ng;
1644 if (n<no) n=no;
1645 if (n<nn) n=nn;
1646 if (n<nf) n=nf;
1647 Int_t printf=0;
1648 TString s;
1649 for (Int_t i=1; i<=n; i++)
1650 {
1651 printf=0;
1652 if (GetGainFlag(i)) {cout << " gain : " << GetGain(i); printf=1;}
1653 if (GetOffsetFlag(i)) {cout << " offset : " << GetOffset(i); printf=1;}
1654 if (GetEdgeValue(i)) {cout << " edge : " << GetEdgeValue(i); printf=1;}
1655 if (GetDeadValue(i)) {cout << " dead : " << GetDeadValue(i); printf=1;}
1656 if (GetLockValue(i)) {cout << " lock : " << GetLockValue(i); printf=1;}
1657 if (GetCalFunction(i)) {cout << " *Fcalib*"; printf=1;}
1658 if (GetDecalFunction(i)) {cout << " *Fdecalib*"; printf=1;}
1659 s=GetSlotName(i);
1660 if (s!="") {cout << " name : " << s.Data(); printf=1;}
1661 if (printf) cout << endl;
1662 }
1663 }
1664}
1665
1666void NcAttrib::List(TString name) const
1667{
1679
1680 Int_t j=GetSlotIndex(name);
1681 if (j>0) List(j);
1682}
1683
1684void NcAttrib::Load(NcAttrib& a,Int_t j)
1685{
1695
1696 if (j<0)
1697 {
1698 cout << " *NcAttrib::Load* Invalid argument j = " << j << endl;
1699 return;
1700 }
1701
1702 Int_t n=0;
1703
1704 if (j==0) // load attributes for all slots
1705 {
1706 n=a.GetNgains();
1707 for (Int_t ig=1; ig<=n; ig++)
1708 {
1709 if (a.GetGainFlag(ig))
1710 {
1711 SetGain(a.GetGain(ig),ig);
1712 }
1713 else
1714 {
1715 ResetGain(ig);
1716 }
1717 }
1718 n=a.GetNoffsets();
1719 for (Int_t io=1; io<=n; io++)
1720 {
1721 if (a.GetOffsetFlag(io))
1722 {
1723 SetOffset(a.GetOffset(io),io);
1724 }
1725 else
1726 {
1727 ResetOffset(io);
1728 }
1729 }
1730 n=a.GetNcalflags();
1731 for (Int_t ic=1; ic<=n; ic++)
1732 {
1733 SetEdgeValue(a.GetEdgeValue(ic),ic);
1734 if (a.GetLockValue(ic))
1735 {
1736 Lock(ic);
1737 }
1738 else
1739 {
1740 Unlock(ic);
1741 }
1742 if (a.GetDeadValue(ic))
1743 {
1744 SetDead(ic);
1745 }
1746 else
1747 {
1748 SetAlive(ic);
1749 }
1750 }
1751 n=a.GetNnames();
1752 TString s;
1753 for (Int_t in=1; in<=n; in++)
1754 {
1755 s=a.GetSlotName(in);
1756 SetSlotName(s,in);
1757 }
1758 n=a.GetNcalfuncs();
1759 for (Int_t icalf=1; icalf<=n; icalf++)
1760 {
1761 TF1* f=a.GetCalFunction(icalf);
1762 SetCalFunction(f,icalf);
1763 }
1764 n=a.GetNdecalfuncs();
1765 for (Int_t idecalf=1; idecalf<=n; idecalf++)
1766 {
1767 TF1* f=a.GetDecalFunction(idecalf);
1768 SetDecalFunction(f,idecalf);
1769 }
1770 }
1771 else // load attributes for specified j-th slot only
1772 {
1773 n=a.GetNgains();
1774 if (j<=n)
1775 {
1776 if (a.GetGainFlag(j))
1777 {
1778 SetGain(a.GetGain(j),j);
1779 }
1780 else
1781 {
1782 ResetGain(j);
1783 }
1784 }
1785 n=a.GetNoffsets();
1786 if (j<=n)
1787 {
1788 if (a.GetOffsetFlag(j))
1789 {
1790 SetOffset(a.GetOffset(j),j);
1791 }
1792 else
1793 {
1794 ResetOffset(j);
1795 }
1796 }
1797 n=a.GetNcalflags();
1798 if (j<=n)
1799 {
1800 SetEdgeValue(a.GetEdgeValue(j),j);
1801 if (a.GetLockValue(j))
1802 {
1803 Lock(j);
1804 }
1805 else
1806 {
1807 Unlock(j);
1808 }
1809 if (a.GetDeadValue(j))
1810 {
1811 SetDead(j);
1812 }
1813 else
1814 {
1815 SetAlive(j);
1816 }
1817 }
1818 n=a.GetNnames();
1819 TString s;
1820 if (j<=n)
1821 {
1822 s=a.GetSlotName(j);
1823 SetSlotName(s,j);
1824 }
1825 n=a.GetNcalfuncs();
1826 if (j<=n)
1827 {
1828 TF1* f=a.GetCalFunction(j);
1829 SetCalFunction(f,j);
1830 }
1831 n=a.GetNdecalfuncs();
1832 if (j<=n)
1833 {
1834 TF1* f=a.GetDecalFunction(j);
1835 SetDecalFunction(f,j);
1836 }
1837 }
1838}
1839
1840void NcAttrib::Load(NcAttrib& a,TString name)
1841{
1854
1855 Int_t j=GetSlotIndex(name);
1856 if (j>0) Load(a,j);
1857}
1858
1860{
1866
1867 if (!fCalfuncs) return 0;
1868
1869 Int_t n=0;
1870 for (Int_t i=1; i<=fCalfuncs->GetSize(); i++)
1871 {
1872 if (fCalfuncs->At(i-1)) n=i;
1873 }
1874 return n;
1875}
1876
1878{
1884
1885 if (!fDecalfuncs) return 0;
1886
1887 Int_t n=0;
1888 for (Int_t i=1; i<=fDecalfuncs->GetSize(); i++)
1889 {
1890 if (fDecalfuncs->At(i-1)) n=i;
1891 }
1892 return n;
1893}
1894
1895TF1* NcAttrib::GetCalFunction(Int_t j) const
1896{
1903
1904 TF1* f=0;
1905 if (j>0 && j<=GetNcalfuncs()) f=(TF1*)fCalfuncs->At(j-1);
1906 return f;
1907}
1908
1909TF1* NcAttrib::GetCalFunction(TString name) const
1910{
1917
1918 TF1* f=0;
1919 Int_t j=GetSlotIndex(name);
1920 if (j>0) f=GetCalFunction(j);
1921 return f;
1922}
1923
1924void NcAttrib::SetCalFunction(TF1* f,Int_t j)
1925{
1946
1947 if (j<1) return;
1948
1949 if (!fCalfuncs)
1950 {
1951 fCalfuncs=new TObjArray(j);
1952 fCalfuncs->SetOwner();
1953 }
1954
1955 if (j > fCalfuncs->GetSize()) fCalfuncs->Expand(j);
1956
1957 TF1* fcur=(TF1*)fCalfuncs->At(j-1);
1958 if (f != fcur)
1959 {
1960 if (fcur)
1961 {
1962 fCalfuncs->Remove(fcur);
1963 delete fcur;
1964 fcur=0;
1965 }
1966 if (f)
1967 {
1968 fcur=new TF1(*f);
1969 fCalfuncs->AddAt(fcur,j-1);
1970 }
1971 }
1972}
1973
1974void NcAttrib::SetCalFunction(TF1* f,TString name)
1975{
1991
1992 Int_t j=GetSlotIndex(name);
1993 if (j>0) SetCalFunction(f,j);
1994}
1995
1997{
2004
2005 TF1* f=0;
2006 if (j>0 && j<=GetNdecalfuncs()) f=(TF1*)fDecalfuncs->At(j-1);
2007 return f;
2008}
2009
2010TF1* NcAttrib::GetDecalFunction(TString name) const
2011{
2018
2019 TF1* f=0;
2020 Int_t j=GetSlotIndex(name);
2021 if (j>0) f=GetDecalFunction(j);
2022 return f;
2023}
2024
2025void NcAttrib::SetDecalFunction(TF1* f,Int_t j)
2026{
2047
2048 if (j<1) return;
2049
2050 if (!fDecalfuncs)
2051 {
2052 fDecalfuncs=new TObjArray(j);
2053 fDecalfuncs->SetOwner();
2054 }
2055
2056 if (j > fDecalfuncs->GetSize()) fDecalfuncs->Expand(j);
2057
2058 TF1* fcur=(TF1*)fDecalfuncs->At(j-1);
2059 if (f != fcur)
2060 {
2061 if (fcur)
2062 {
2063 fDecalfuncs->Remove(fcur);
2064 delete fcur;
2065 fcur=0;
2066 }
2067 if (f)
2068 {
2069 fcur=new TF1(*f);
2070 fDecalfuncs->AddAt(fcur,j-1);
2071 }
2072 }
2073}
2074
2075void NcAttrib::SetDecalFunction(TF1* f,TString name)
2076{
2092
2093 Int_t j=GetSlotIndex(name);
2094 if (j>0) SetDecalFunction(f,j);
2095}
2096
ClassImp(NcAttrib)
Generic handling of detector signal (calibration) attributes.
Definition NcAttrib.h:16
Int_t GetNdecalfuncs() const
TString GetSlotName(Int_t j=1) const
Float_t GetGain(Int_t j=1) const
Definition NcAttrib.cxx:576
Int_t GetNcalflags() const
Definition NcAttrib.cxx:229
void SetCalFunction(TF1 *f, Int_t j=1)
void DecreaseEdgeValue(Int_t j=1)
TArrayF * fOffsets
Definition NcAttrib.h:91
void SetCalFlags(Int_t gf, Int_t of, Int_t j)
Definition NcAttrib.cxx:377
Int_t GetNgains() const
Definition NcAttrib.cxx:191
void SetAlive(Int_t j=1)
Definition NcAttrib.cxx:946
TObjArray * fDecalfuncs
Definition NcAttrib.h:95
void SetEdgeOn(Int_t j=1)
TObjArray * fCalfuncs
Definition NcAttrib.h:94
void AddNamedSlot(TString s)
void Lock(Int_t j=1)
Definition NcAttrib.cxx:995
virtual Int_t GetNslots() const
Int_t GetGainFlag(Int_t j=1) const
Definition NcAttrib.cxx:417
void SetDecalFunction(TF1 *f, Int_t j=1)
virtual ~NcAttrib()
Definition NcAttrib.cxx:88
Int_t GetDeadValue(Int_t j=1) const
void SetOffset(Double_t off, Int_t j=1)
Definition NcAttrib.cxx:322
Int_t GetCalWord(Int_t j=1) const
Definition NcAttrib.cxx:529
Int_t GetSlotIndex(TString name, Int_t opt=0) const
Float_t GetOffset(Int_t j=1) const
Definition NcAttrib.cxx:624
void SetEdgeOff(Int_t j=1)
void SetSlotName(TString s, Int_t j=1)
void SetEdgeValue(Int_t val, Int_t j=1)
void DeleteCalibrations(Int_t mode=0)
Definition NcAttrib.cxx:786
void ResetGain(Int_t j=1)
Definition NcAttrib.cxx:672
TF1 * GetCalFunction(Int_t j=1) const
Int_t GetOffsetFlag(Int_t j=1) const
Definition NcAttrib.cxx:473
Int_t GetLockValue(Int_t j=1) const
virtual void Load(NcAttrib &a, Int_t j=0)
Int_t GetNcalfuncs() const
void IncreaseEdgeValue(Int_t j=1)
TArrayF * fGains
Definition NcAttrib.h:90
virtual void List(Int_t j=0) const
void SetGain(Double_t gain, Int_t j=1)
Definition NcAttrib.cxx:267
void SetDead(Int_t j=1)
Definition NcAttrib.cxx:886
TObjArray * fNames
Definition NcAttrib.h:93
Int_t GetEdgeValue(Int_t j=1) const
Int_t GetNoffsets() const
Definition NcAttrib.cxx:210
TArrayI * fCalflags
Definition NcAttrib.h:92
TF1 * GetDecalFunction(Int_t j=1) const
void Unlock(Int_t j=1)
void ResetOffset(Int_t j=1)
Definition NcAttrib.cxx:729
Int_t GetNnames() const
Definition NcAttrib.cxx:248