NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcDetectorUnit.cxx
Go to the documentation of this file.
1
31
33
95
96#include "NcDetectorUnit.h"
97#include "Riostream.h"
98
99ClassImp(NcDetectorUnit); // Class implementation to enable ROOT I/O
100
102NcDetectorUnit::NcDetectorUnit(const char* name,const char* title) : NcDevice(name,title)
103{
112
113 fDevices=0;
114 fDevCopy=1;
115 fDevs=0;
116 fThits=0;
117 fOrdered=0;
118 fDisplay=0;
119}
120
122{
128
129 if (fDevices)
130 {
131 delete fDevices;
132 fDevices=0;
133 }
134 if (fDevs)
135 {
136 delete fDevs;
137 fDevs=0;
138 }
139 if (fThits)
140 {
141 delete fThits;
142 fThits=0;
143 }
144 if (fOrdered)
145 {
146 delete fOrdered;
147 fOrdered=0;
148 }
149 if (fDisplay)
150 {
151 delete fDisplay;
152 fDisplay=0;
153 }
154}
155
157{
163
165
166 fDevs=0;
167 fThits=0;
168 fOrdered=0;
169 fDisplay=0;
170
171 fDevices=0;
172 Int_t ndevs=0;
173 if (q.fDevices) ndevs=q.fDevices->GetEntries();
174 if (ndevs)
175 {
176 fDevices=new TObjArray(ndevs);
177 if (fDevCopy) fDevices->SetOwner();
178 for (Int_t i=1; i<=ndevs; i++)
179 {
180 NcDevice* dev=q.GetDevice(i);
181 if (dev)
182 {
183 if (fDevCopy)
184 {
185 fDevices->Add(dev->Clone());
186 }
187 else
188 {
189 fDevices->Add(dev);
190 }
191 }
192 }
193 }
194}
195
197{
222
223 if (!fDevices)
224 {
225 if (j==0 || j==1)
226 {
227 fDevCopy=j;
228 }
229 else
230 {
231 cout << " *" << ClassName() << "::SetDevCopy* Invalid argument : " << j << endl;
232 }
233 }
234 else
235 {
236 cout << " *" << ClassName() << "::SetDevCopy* Storage already contained devices."
237 << " ==> DevCopy mode not changed." << endl;
238 }
239}
240
242{
260
261 return fDevCopy;
262}
263
265{
288
289 Int_t mode=1;
290 if (!own) mode=0;
291 if (fDevices) fDevices->SetOwner(own);
292 fDevCopy=mode;
293
295}
296
297void NcDetectorUnit::Reset(Int_t mode)
298{
307
308 NcDevice::Reset(mode);
309
310 if (fDevices)
311 {
312 delete fDevices;
313 fDevices=0;
314 }
315 if (fThits)
316 {
317 delete fThits;
318 fThits=0;
319 }
320 if (fOrdered)
321 {
322 delete fOrdered;
323 fOrdered=0;
324 }
325 if (fDevs)
326 {
327 delete fDevs;
328 fDevs=0;
329 }
330 if (fDisplay)
331 {
332 delete fDisplay;
333 fDisplay=0;
334 }
335}
336
338{
354
355 if (!fDevices)
356 {
357 fDevices=new TObjArray();
358 if (fDevCopy) fDevices->SetOwner();
359 }
360
361 // Add the device to this detector unit
362 if (fDevCopy)
363 {
364 fDevices->Add(d.Clone());
365 }
366 else
367 {
368 fDevices->Add(&d);
369 }
370}
371
373{
379
380 if (!fDevices || !d) return;
381
382 TObject* obj=fDevices->Remove(d);
383 if (obj)
384 {
385 if (fDevCopy) delete obj;
386 fDevices->Compress();
387 }
388}
389
390Int_t NcDetectorUnit::GetNdevices(Bool_t follow)
391{
400
401 Int_t ndevs=0;
402
403 if (!follow)
404 {
405 if (fDevices) ndevs=fDevices->GetEntries();
406 }
407 else
408 {
409 TObjArray devs;
410 LoadDevices("*",follow,&devs);
411 ndevs=devs.GetEntries();
412 }
413
414 return ndevs;
415}
416
417Int_t NcDetectorUnit::GetNdevices(TString classname,Bool_t follow,TObjArray* hits)
418{
438
439 if (classname=="*") classname="NcDevice";
440
441 Int_t ndevs=0;
442
443 if (!hits) // Investigate the stored devices
444 {
445 TObjArray devs;
446 LoadDevices(classname,follow,&devs);
447 ndevs=devs.GetEntries();
448 }
449 else // Investigate the provided hit array
450 {
451 Int_t nh=hits->GetEntries();
452 if (!nh) return 0;
453
454 // Check for the encountered unique device identifiers of the specified class
455 TArrayI devids(nh);
456 Int_t idxmax=0;
457 Int_t jdev=0;
458 Int_t match=0;
459 for (Int_t ih=0; ih<nh; ih++)
460 {
461 TObject* obj=hits->At(ih);
462 if (!obj) continue;
463
464 NcSignal* sx=0;
465 if (obj->InheritsFrom("NcSignal")) sx=(NcSignal*)obj;
466 if (!sx) continue;
467
468 NcDevice* dev=sx->GetDevice();
469 if (!dev) continue;
470 if (!(dev->InheritsFrom(classname))) continue;
471
472 // Update the number of devices
473 jdev=dev->GetUniqueID();
474 match=0;
475 idxmax=ndevs;
476 for (Int_t idx=0; idx<idxmax; idx++)
477 {
478 if (jdev==devids.At(idx))
479 {
480 match=1;
481 break;
482 }
483 }
484 if (!match) // Device number was not present in array
485 {
486 ndevs++;
487 devids.AddAt(jdev,ndevs-1);
488 }
489 }
490 }
491
492 return ndevs;
493}
494
496{
503
504 if (!fDevices)
505 {
506 return 0;
507 }
508 else
509 {
510 Int_t ndevs=fDevices->GetEntries();
511 if (i<=0 || i>ndevs)
512 {
513 cout << " *" << ClassName() << "::GetDevice* Invalid argument i : " << i
514 << " ndevs = " << ndevs << endl;
515 return 0;
516 }
517 else
518 {
519 return (NcDevice*)fDevices->At(i-1);
520 }
521 }
522}
523
524NcDevice* NcDetectorUnit::GetDevice(TString name,Bool_t follow)
525{
534
535 if (!fDevices)
536 {
537 return 0;
538 }
539 else
540 {
541 TString s;
542 TObjArray devs;
543 LoadDevices("NcDevice",follow,&devs);
544 Int_t ndevs=devs.GetEntries();
545 for (Int_t i=0; i<ndevs; i++)
546 {
547 NcDevice* dev=(NcDevice*)devs.At(i);
548 if (dev)
549 {
550 s=dev->GetName();
551 if (s==name) return dev;
552 }
553 }
554
555 return 0; // No matching name found
556 }
557}
558
559NcDevice* NcDetectorUnit::GetIdDevice(Int_t id,Bool_t follow,TObjArray* devs)
560{
574
575 TObjArray temp;
576
577 TObjArray* arr=devs;
578 if (!arr)
579 {
580 if (!follow)
581 {
582 arr=fDevices;
583 }
584 else
585 {
586 arr=&temp;
587 LoadDevices("NcDevice",follow,arr);
588 }
589 }
590
591 if (!arr || id<0) return 0;
592
593 Int_t idx=0;
594 for (Int_t i=0; i<arr->GetSize(); i++)
595 {
596 TObject* obj=arr->At(i);
597
598 if (!obj) continue;
599
600 NcDevice* dev=0;
601 if (obj->InheritsFrom("NcDevice")) dev=(NcDevice*)obj;
602 if (dev)
603 {
604 idx=dev->GetUniqueID();
605 if (idx==id) return dev;
606 }
607 }
608 return 0; // No matching id found
609}
610
611NcDevice* NcDetectorUnit::GetIdDevice(Int_t id,TString classname,Bool_t follow)
612{
625
626 if (!fDevices || id<0) return 0;
627
628 if (classname=="*") classname="NcDevice";
629
630 TObjArray temp;
631
632 TObjArray* arr=fDevices;
633 if (follow)
634 {
635 arr=&temp;
636 LoadDevices(classname,follow,arr);
637 }
638
639 Int_t idx=0;
640 for (Int_t i=0; i<arr->GetEntries(); i++)
641 {
642 NcDevice* dev=(NcDevice*)arr->At(i);
643 if (dev)
644 {
645 idx=dev->GetUniqueID();
646 if (idx==id && dev->InheritsFrom(classname)) return dev;
647 }
648 }
649 return 0; // No matching id found for the specified class
650}
651
652TObjArray* NcDetectorUnit::GetDevices(TString classname,Bool_t follow,TObjArray* devices)
653{
675
676 if (classname=="*") classname="NcDevice";
677
678 TObjArray* arr=0;
679
680 if (devices)
681 {
682 devices->Clear();
683 arr=devices;
684 }
685 else
686 {
687 if (fDevs)
688 {
689 fDevs->Clear();
690 }
691 else
692 {
693 fDevs=new TObjArray();
694 }
695 arr=fDevs;
696 }
697
698 LoadDevices(classname,follow,arr);
699
700 if (devices)
701 {
702 return 0;
703 }
704 else
705 {
706 return fDevs;
707 }
708}
709
711{
720
721 if (!fDevices)
722 {
723 return 0;
724 }
725 else
726 {
727 TString s;
728 TObjArray devs;
729 LoadDevices("NcDetectorUnit",follow,&devs);
730 Int_t ndevs=devs.GetEntries();
731 for (Int_t i=0; i<ndevs; i++)
732 {
733 NcDevice* dev=(NcDevice*)devs.At(i);
734 if (dev)
735 {
736 if (!(dev->InheritsFrom("NcDetectorUnit"))) continue;
737 s=dev->GetName();
738 if (s==name) return (NcDetectorUnit*)dev;
739 }
740 }
741
742 return 0; // No matching name found
743 }
744}
745
746NcDetectorUnit* NcDetectorUnit::GetIdDetectorUnit(Int_t id,Bool_t follow,TObjArray* devs)
747{
761
762 TObjArray temp;
763
764 TObjArray* arr=devs;
765 if (!arr)
766 {
767 if (!follow)
768 {
769 arr=fDevices;
770 }
771 else
772 {
773 arr=&temp;
774 LoadDevices("NcDetectorUnit",follow,arr);
775 }
776 }
777
778 if (!arr || id<0) return 0;
779
780 Int_t idx=0;
781 for (Int_t i=0; i<arr->GetSize(); i++)
782 {
783 TObject* obj=arr->At(i);
784
785 if (!obj) continue;
786
787 NcDetectorUnit* dev=0;
788 if (obj->InheritsFrom("NcDetectorUnit")) dev=(NcDetectorUnit*)obj;
789 if (dev)
790 {
791 idx=dev->GetUniqueID();
792 if (idx==id) return dev;
793 }
794 }
795 return 0; // No matching id found
796}
797
798NcDetectorUnit* NcDetectorUnit::GetIdDetectorUnit(Int_t id,TString classname,Bool_t follow)
799{
812
813 if (!fDevices || id<0) return 0;
814
815 if (classname=="*") classname="NcDetectorUnit";
816
817 TObjArray temp;
818
819 TObjArray* arr=fDevices;
820 if (follow)
821 {
822 arr=&temp;
823 LoadDevices(classname,follow,arr);
824 }
825
826 Int_t idx=0;
827 for (Int_t i=0; i<arr->GetEntries(); i++)
828 {
829 NcDevice* dev=(NcDevice*)arr->At(i);
830 if (dev)
831 {
832 if (!(dev->InheritsFrom("NcDetectorUnit"))) continue;
833 idx=dev->GetUniqueID();
834 if (idx==id && dev->InheritsFrom(classname)) return (NcDetectorUnit*)dev;
835 }
836 }
837 return 0; // No matching id found for the specified class
838}
839
840void NcDetectorUnit::Data(TString f,TString u)
841{
854
855 const char* name=GetName();
856 const char* title=GetTitle();
857 cout << " *" << ClassName() << "::Data* Id : " << GetUniqueID();
858 if (strlen(name)) cout << " Name : " << GetName();
859 if (strlen(title)) cout << " Title : " << GetTitle();
860 cout << endl;
861
862 // Provide an overview of the stored devices
863 ShowDevices(0);
864 if (GetNdevices(kFALSE))
865 {
866 cout << " More detailed info may be obtained by invokation of ShowDevices()." << endl;
867 cout << " For the data of these contained devices, please use the corresponding investigation tools." << endl;
868 }
869
870 cout << " === Data of the current detector unit object ===" << endl;
871
872 if (fNv)
873 {
874 cout << " Position";
875 NcPosition::Data(f,u);
876 }
877
878 if (fDevice)
879 {
880 const char* devname=fDevice->GetName();
881 const char* devtitle=fDevice->GetTitle();
882 cout << " Owned by device : " << fDevice->ClassName() << " Id : " << fDevice->GetUniqueID();
883 if (strlen(devname)) cout << " Name : " << devname;
884 if (strlen(devtitle)) cout << " Title : " << devtitle;
885 cout << endl;
886 }
887
888 // Provide an overview of the stored waveforms
889 ListWaveform(-1);
890
891 // Provide an overview of the stored samples
892 ListSample(-1);
893
894 // Provide an overview of the associated tracks
895 ListTrack(-1);
896
897 // Provide an overview of all the data and attribute slots
898 List(-1);
899
900 // Provide an overview of the stored hits
901 Int_t nhits=GetNhits();
902 if (nhits)
903 {
904 cout << " The following " << nhits << " hits are registered for this object : " << endl;
905 ShowHit(0,f,u);
906 }
907 else
908 {
909 cout << " No hits have been registered for this object." << endl;
910 }
911}
912
913void NcDetectorUnit::ShowDevices(Int_t mode,Bool_t header)
914{
928
929 ShowDevices("*",mode,header);
930}
931
932void NcDetectorUnit::ShowDevices(TString classname,Int_t mode,Bool_t header)
933{
948
949 Bool_t follow=kFALSE;
950 if (mode==2) follow=kTRUE;
951
952 Int_t ndevs=GetNdevices(classname,follow);
953
954 if (header)
955 {
956 cout << " *" << ClassName() <<"::ShowDevices* For mode=" << mode << " there are in total " << ndevs;
957 if (classname!="*") cout << " " << classname << " (derived)";
958 cout << " devices found." << endl;
959 }
960
961 if (classname=="*") classname="NcDevice";
962
963 ShowDevicesTree(classname,mode);
964}
965
966void NcDetectorUnit::ShowDevicesTree(TString classname,Int_t mode,NcDetectorUnit* unit)
967{
983
984 if (classname=="*") classname="NcDevice";
985
986 if (!unit) unit=this;
987
988 TObjArray units;
989
990 TString name=unit->GetName();
991
992 TString type="NcDetectorUnit";
993 if (unit->InheritsFrom("NcDetector")) type="NcDetector";
994
995 Int_t ndevs=unit->GetNdevices(kFALSE);
996 if (!ndevs)
997 {
998 cout << " No devices present for " << type << " : " << name << endl;
999 return;
1000 }
1001
1002 Int_t ndevs2=unit->GetNdevices(classname,kFALSE);
1003
1004 if (mode<2)
1005 {
1006 cout << " There are " << ndevs2;
1007 if (classname!="NcDevice") cout << " " << classname << " (derived)";
1008 cout << " devices available for the " << type << " : " << name << endl;
1009 if (!mode) return;
1010 }
1011
1012 if (ndevs2)
1013 {
1014 cout << " === The following " << ndevs2;
1015 if (classname!="NcDevice") cout << " " << classname << " (derived)";
1016 cout << " devices are available for the " << type << " : " << name << endl;
1017 }
1018
1019 Int_t nd=0;
1020 Int_t nh=0;
1021 Int_t nw=0;
1022 Int_t ns=0;
1023 NcDevice* dev=0;
1024 NcDetectorUnit* du=0;
1025 for (Int_t i=1; i<=ndevs; i++)
1026 {
1027 dev=unit->GetDevice(i);
1028
1029 if (!dev) continue;
1030
1031 if (dev->InheritsFrom(classname))
1032 {
1033 type="NcDevice";
1034 if (dev->InheritsFrom("NcDetectorUnit")) type="NcDetectorUnit";
1035 if (dev->InheritsFrom("NcDetector")) type="NcDetector";
1036 name=dev->GetName();
1037 cout << " Device number : " << i;
1038 cout << " Class : " << dev->ClassName();
1039 if (type!=(dev->ClassName())) cout << " (" << type << ")";
1040 cout << " Id : " << dev->GetUniqueID();
1041 if (name!="") cout << " Name : " << name;
1042 du=0;
1043 if (dev->InheritsFrom("NcDetectorUnit"))
1044 {
1045 du=(NcDetectorUnit*)dev;
1046 nd=du->GetNdevices(kFALSE);
1047 if (nd) cout << " Ndevices : " << nd;
1048 }
1049 nh=dev->GetNhits();
1050 if (nh) cout << " Nhits : " << nh;
1051 nw=dev->GetNwaveforms();
1052 if (nw) cout << " Nwaveforms : " << nw;
1053 ns=dev->GetNsamples();
1054 if (ns) cout << " Nsamples : " << ns;
1055 cout << endl;
1056 }
1057
1058 if (mode==2 && dev->InheritsFrom("NcDetectorUnit")) units.Add(dev);
1059 }
1060
1061 // Recursive invokation of the encountered detector units
1062 for (Int_t i=0; i<units.GetEntries(); i++)
1063 {
1064 du=(NcDetectorUnit*)units.At(i);
1065 if (du) ShowDevicesTree(classname,mode,du);
1066 }
1067}
1068
1069Int_t NcDetectorUnit::GetNhitsDevices(TString classname,Bool_t follow,Bool_t inc)
1070{
1089
1090 if (classname=="*") classname="NcDevice";
1091
1092 TObjArray hits;
1093 GetHitsDevices(classname,follow,inc,&hits);
1094 Int_t nhits=hits.GetEntries();
1095 return nhits;
1096}
1097
1098TObjArray* NcDetectorUnit::GetHitsDevices(TString classname,Bool_t follow,Bool_t inc,TObjArray* hits,TString name,Int_t mode,Int_t opt)
1099{
1144
1145 if (classname=="*") classname="NcDevice";
1146
1147 LoadHits(classname,follow,inc,hits);
1148
1149 // Check for further hit selection criteria
1150 if (name!="none")
1151 {
1152 TObjArray* selected=hits;
1153 if (!selected) selected=fThits;
1154 TObjArray ahits(*selected);
1155 GetHits(*selected,name,mode,opt,&ahits);
1156 }
1157
1158 if (hits)
1159 {
1160 return 0;
1161 }
1162 else
1163 {
1164 return fThits;
1165 }
1166}
1167
1168NcSignal* NcDetectorUnit::GetIdHit(Int_t id,TString classname,Bool_t follow,Bool_t inc)
1169{
1183
1184 if (id<0) return 0;
1185
1186 if (classname=="*") classname="NcDevice";
1187
1188 TObjArray hits;
1189 LoadHits(classname,follow,inc,&hits);
1190
1191 Int_t nhits=hits.GetEntries();
1192
1193 if (!nhits) return 0;
1194
1195 NcSignal* sx=0;
1196 Int_t sid=0;
1197 for (Int_t i=0; i<nhits; i++)
1198 {
1199 sx=(NcSignal*)hits.At(i);
1200 if (sx)
1201 {
1202 sid=sx->GetUniqueID();
1203 if (id==sid) return sx;
1204 }
1205 }
1206 return 0; // No matching id found
1207}
1208
1209void NcDetectorUnit::ShowHits(TString classname,Bool_t follow,Bool_t inc,Int_t mode,TString f,TString u)
1210{
1235
1236 if (classname=="*") classname="NcDevice";
1237
1238 TObjArray hits;
1239 LoadHits(classname,follow,inc,&hits);
1240
1241 Int_t nhits=hits.GetEntries();
1242
1243 cout << " *" << ClassName() << "::ShowHits* There are " << nhits
1244 << " hits recorded for device class " << classname << endl;
1245
1246 if (!nhits || !mode) return;
1247
1248 NcPosition r;
1249 for (Int_t i=0; i<hits.GetEntries(); i++)
1250 {
1251 NcSignal* sx=(NcSignal*)hits.At(i);
1252 if (sx) sx->Data(f,u);
1253 if (mode==2)
1254 {
1255 NcDevice* dev=(NcDevice*)sx->GetDevice();
1256 if (!dev) continue;
1257 r=dev->GetPosition();
1258 cout << " Device Position";
1259 r.Data(f,u);
1260 }
1261 }
1262}
1263
1264TObjArray* NcDetectorUnit::SortHits(TString classname,Bool_t follow,Bool_t inc,Int_t idx,Int_t mode,Int_t mcal,Int_t deadcheck,TObjArray* ordered)
1265{
1313
1314 if (classname=="*") classname="NcDevice";
1315
1316 if (ordered) ordered->Clear();
1317
1318 if (idx<=0 || abs(mode)!=1) return 0;
1319
1320 TObjArray hits;
1321 LoadHits(classname,follow,inc,&hits);
1322
1323 TObjArray* arr=SortHits(idx,mode,&hits,mcal,deadcheck,ordered);
1324
1325 if (ordered) return 0;
1326
1327 if (fThits)
1328 {
1329 delete fThits;
1330 fThits=0;
1331 }
1332 if (arr) fThits=new TObjArray(*arr);
1333 return fThits;
1334}
1335
1336TObjArray* NcDetectorUnit::SortHits(TString classname,Bool_t follow,Bool_t inc,TString name,Int_t mode,Int_t mcal,Int_t deadcheck,TObjArray* ordered)
1337{
1385
1386 if (classname=="*") classname="NcDevice";
1387
1388 if (ordered) ordered->Clear();
1389
1390 if (abs(mode)!=1) return 0;
1391
1392 TObjArray hits;
1393 LoadHits(classname,follow,inc,&hits);
1394
1395 TObjArray* arr=SortHits(name,mode,&hits,mcal,deadcheck,ordered);
1396
1397 if (ordered) return 0;
1398
1399 if (fThits)
1400 {
1401 delete fThits;
1402 fThits=0;
1403 }
1404 if (arr) fThits=new TObjArray(*arr);
1405 return fThits;
1406}
1407
1408void NcDetectorUnit::DisplayHits(TString classname,Bool_t follow,Bool_t inc,Int_t idx,Float_t scale,Int_t dp,Int_t mode,Int_t mcol)
1409{
1451
1452 if (idx<=0) return;
1453
1454 if (classname=="*") classname="NcDevice";
1455
1456 TObjArray hits;
1457 GetHitsDevices(classname,follow,inc,&hits);
1458
1459 NcDevice* dev=new NcDevice();
1460 dev->DisplayHits(idx,scale,&hits,dp,mode,mcol);
1461
1462 if (fDisplay)
1463 {
1464 delete fDisplay;
1465 fDisplay=0;
1466 }
1467 fDisplay=dev;
1468}
1469
1470void NcDetectorUnit::DisplayHits(TString classname,Bool_t follow,Bool_t inc,TString name,Float_t scale,Int_t dp,Int_t mode,Int_t mcol)
1471{
1515
1516 if (classname=="*") classname="NcDevice";
1517
1518 TObjArray hits;
1519 GetHitsDevices(classname,follow,inc,&hits,name,1);
1520
1521 NcDevice* dev=new NcDevice();
1522 dev->DisplayHits(name,scale,&hits,dp,mode,mcol);
1523
1524 if (fDisplay)
1525 {
1526 delete fDisplay;
1527 fDisplay=0;
1528 }
1529 fDisplay=dev;
1530}
1531
1532TObjArray* NcDetectorUnit::SortDevices(TString classname,Bool_t follow,Bool_t inc,TString name,Int_t mode,Int_t mcal,Int_t deadcheck,TObjArray* ordered)
1533{
1579
1580 if (classname=="*") classname="NcDevice";
1581
1582 if (ordered) ordered->Clear();
1583
1584 TObjArray hits;
1585 SortHits(classname,follow,inc,name,mode,mcal,deadcheck,&hits);
1586
1587 TObjArray* devs=SortDevices(&hits,"*",0,mcal,deadcheck,ordered);
1588
1589 if (ordered)
1590 {
1591 return 0;
1592 }
1593 else
1594 {
1595 return devs;
1596 }
1597}
1598
1599TObjArray* NcDetectorUnit::SortDevices(TString classname,Bool_t follow,Bool_t inc,Int_t idx,Int_t mode,Int_t mcal,Int_t deadcheck,TObjArray* ordered)
1600{
1646
1647 if (ordered) ordered->Clear();
1648
1649 if (classname=="*") classname="NcDevice";
1650
1651 TObjArray hits;
1652 SortHits(classname,follow,inc,idx,mode,mcal,deadcheck,&hits);
1653
1654 TObjArray* devs=SortDevices(&hits,0,0,mcal,deadcheck,ordered);
1655
1656 if (ordered)
1657 {
1658 return 0;
1659 }
1660 else
1661 {
1662 return devs;
1663 }
1664}
1665
1666TObjArray* NcDetectorUnit::SortDevices(TObjArray* hits,TString name,Int_t mode,Int_t mcal,Int_t deadcheck,TObjArray* ordered)
1667{
1707
1708 if (ordered)
1709 {
1710 ordered->Clear();
1711 }
1712 else
1713 {
1714 if (fOrdered)
1715 {
1716 fOrdered->Clear();
1717 }
1718 else
1719 {
1720 fOrdered=new TObjArray();
1721 }
1722 }
1723
1724 if (!hits) return 0;
1725
1726 TObjArray* sorthits=new TObjArray(*hits);
1727 if (mode) SortHits(name,mode,hits,mcal,deadcheck,sorthits);
1728
1729 TObjArray* arr=0; // Generic array pointer to be used in the logic below
1730
1731 if (ordered)
1732 {
1733 arr=ordered;
1734 }
1735 else
1736 {
1737 arr=fOrdered;
1738 }
1739
1740 Int_t nhits=sorthits->GetEntries();
1741 Int_t exist=0;
1742 for (Int_t ih=0; ih<nhits; ih++)
1743 {
1744 NcSignal* sx=(NcSignal*)sorthits->At(ih);
1745 if (!sx) continue;
1746 NcDevice* dx=sx->GetDevice();
1747 exist=0;
1748 for (Int_t id=0; id<arr->GetEntries(); id++)
1749 {
1750 NcDevice* odx=(NcDevice*)arr->At(id);
1751 if (dx==odx)
1752 {
1753 exist=1;
1754 break;
1755 }
1756 }
1757 if (!exist) arr->Add(dx);
1758 }
1759
1760 delete sorthits;
1761
1762 if (ordered)
1763 {
1764 return 0;
1765 }
1766 else
1767 {
1768 return fOrdered;
1769 }
1770}
1771
1772TObjArray* NcDetectorUnit::SortDevices(TObjArray* hits,Int_t idx,Int_t mode,Int_t mcal,Int_t deadcheck,TObjArray* ordered)
1773{
1813
1814 if (ordered)
1815 {
1816 ordered->Clear();
1817 }
1818 else
1819 {
1820 if (fOrdered)
1821 {
1822 fOrdered->Clear();
1823 }
1824 else
1825 {
1826 fOrdered=new TObjArray();
1827 }
1828 }
1829
1830 if (!hits) return 0;
1831
1832 TObjArray* sorthits=new TObjArray(*hits);
1833 if (mode) SortHits(idx,mode,hits,mcal,deadcheck,sorthits);
1834
1835 TObjArray* arr=0; // Generic array pointer to be used in the logic below
1836
1837 if (ordered)
1838 {
1839 arr=ordered;
1840 }
1841 else
1842 {
1843 arr=fOrdered;
1844 }
1845
1846 Int_t nhits=sorthits->GetEntries();
1847 Int_t exist=0;
1848 for (Int_t ih=0; ih<nhits; ih++)
1849 {
1850 NcSignal* sx=(NcSignal*)sorthits->At(ih);
1851 if (!sx) continue;
1852 NcDevice* dx=sx->GetDevice();
1853 exist=0;
1854 for (Int_t id=0; id<arr->GetEntries(); id++)
1855 {
1856 NcDevice* odx=(NcDevice*)arr->At(id);
1857 if (dx==odx)
1858 {
1859 exist=1;
1860 break;
1861 }
1862 }
1863 if (!exist) arr->Add(dx);
1864 }
1865
1866 delete sorthits;
1867
1868 if (ordered)
1869 {
1870 return 0;
1871 }
1872 else
1873 {
1874 return fOrdered;
1875 }
1876}
1877
1878void NcDetectorUnit::LoadHits(TString classname,Bool_t follow,Bool_t inc,TObjArray* hits,NcDetectorUnit* unit)
1879{
1906
1907 if (classname=="*") classname="NcDevice";
1908
1909 if (!unit) // Direct invokation, not recursive
1910 {
1911 unit=this;
1912
1913 if (hits)
1914 {
1915 hits->Clear();
1916 }
1917 else
1918 {
1919 if (fThits)
1920 {
1921 fThits->Clear();
1922 }
1923 else
1924 {
1925 fThits=new TObjArray();
1926 }
1927 }
1928 }
1929
1930 NcSignal* sx=0;
1931 if (inc && unit->InheritsFrom(classname))
1932 {
1933 for (Int_t ih=1; ih<=unit->GetNhits(); ih++)
1934 {
1935 sx=unit->GetHit(ih);
1936 if (!sx) continue;
1937 if (hits)
1938 {
1939 hits->Add(sx);
1940 }
1941 else
1942 {
1943 fThits->Add(sx);
1944 }
1945 }
1946 }
1947
1948 TObjArray units;
1949
1950 NcDevice* dev=0;
1951 NcDetectorUnit* du=0;
1952 for (Int_t idev=1; idev<=unit->GetNdevices(kFALSE); idev++)
1953 {
1954 dev=unit->GetDevice(idev);
1955 if (!dev) continue;
1956
1957 if (follow && dev->InheritsFrom("NcDetectorUnit")) units.Add(dev);
1958
1959 if (!(unit->InheritsFrom(classname)) && !(dev->InheritsFrom(classname))) continue;
1960
1961 for (Int_t ih=1; ih<=dev->GetNhits(); ih++)
1962 {
1963 sx=dev->GetHit(ih);
1964 if (!sx) continue;
1965 if (hits)
1966 {
1967 hits->Add(sx);
1968 }
1969 else
1970 {
1971 fThits->Add(sx);
1972 }
1973 }
1974 }
1975
1976 // Recursive invokation of the encountered detector units
1977 for (Int_t i=0; i<units.GetEntries(); i++)
1978 {
1979 du=(NcDetectorUnit*)units.At(i);
1980 if (du) LoadHits(classname,follow,inc,hits,du);
1981 }
1982}
1983
1984void NcDetectorUnit::LoadDevices(TString classname,Bool_t follow,TObjArray* devs,NcDetectorUnit* unit)
1985{
2008
2009 if (classname=="*") classname="NcDevice";
2010
2011 if (!unit) // Direct invokation, not recursive
2012 {
2013 unit=this;
2014
2015 if (devs)
2016 {
2017 devs->Clear();
2018 }
2019 else
2020 {
2021 if (fDevs)
2022 {
2023 fDevs->Clear();
2024 }
2025 else
2026 {
2027 fDevs=new TObjArray();
2028 }
2029 }
2030 }
2031
2032 TObjArray units;
2033
2034 Int_t ndevs=unit->GetNdevices(kFALSE);
2035
2036 if (!ndevs) return;
2037
2038 NcDevice* dev=0;
2039 NcDetectorUnit* du=0;
2040 for (Int_t i=1; i<=ndevs; i++)
2041 {
2042 dev=unit->GetDevice(i);
2043
2044 if (!dev) continue;
2045
2046 if (follow && dev->InheritsFrom("NcDetectorUnit")) units.Add(dev);
2047
2048 if (dev->InheritsFrom(classname))
2049 {
2050 if (devs)
2051 {
2052 devs->Add(dev);
2053 }
2054 else
2055 {
2056 fDevs->Add(dev);
2057 }
2058 }
2059 }
2060
2061 // Recursive invokation of the encountered detector units
2062 for (Int_t i=0; i<units.GetEntries(); i++)
2063 {
2064 du=(NcDetectorUnit*)units.At(i);
2065 if (du) LoadDevices(classname,follow,devs,du);
2066 }
2067}
2068
2069TObject* NcDetectorUnit::Clone(const char* name) const
2070{
2083
2084 NcDetectorUnit* q=new NcDetectorUnit(*this);
2085 if (name)
2086 {
2087 if (strlen(name)) q->SetName(name);
2088 }
2089 return q;
2090}
2091
ClassImp(NcDetectorUnit)
Int_t fNv
Definition Nc3Vector.h:59
Handling of a collection of generic devices.
TObject * fDisplay
! Temp. pointer to hold objects which serve event displays
NcDetectorUnit(const char *name="", const char *title="")
void DisplayHits(TString classname, Bool_t follow, Bool_t inc, TString name, Float_t scale=-1, Int_t dp=0, Int_t mode=1, Int_t mcol=4)
Int_t GetDevCopy() const
void ShowDevicesTree(TString classname, Int_t mode=1, NcDetectorUnit *unit=0)
Int_t GetNdevices(Bool_t follow)
void LoadHits(TString classname, Bool_t follow, Bool_t inc, TObjArray *hits=0, NcDetectorUnit *unit=0)
NcDevice * GetDevice(Int_t i) const
TObjArray * fThits
! Temp. array to hold references to the registered NcDevice hits
void AddDevice(NcDevice &d)
TObjArray * GetDevices(TString classname, Bool_t follow, TObjArray *devices=0)
Int_t GetNhitsDevices(TString classname, Bool_t follow, Bool_t inc)
virtual void Reset(Int_t mode=0)
void SetDevCopy(Int_t j)
NcDetectorUnit * GetIdDetectorUnit(Int_t id, Bool_t follow, TObjArray *devs=0)
void RemoveDevice(NcDevice *d)
TObjArray * SortDevices(TString classname, Bool_t follow, Bool_t inc, TString name, Int_t mode=-1, Int_t mcal=1, Int_t deadcheck=1, TObjArray *ordered=0)
virtual TObject * Clone(const char *name="") const
TObjArray * GetHitsDevices(TString classname, Bool_t follow, Bool_t inc, TObjArray *hits=0, TString name="none", Int_t mode=0, Int_t opt=0)
virtual void SetOwner(Bool_t own=kTRUE)
virtual void Data(TString f="car", TString u="rad")
NcSignal * GetIdHit(Int_t id, TString classname, Bool_t follow, Bool_t inc)
TObjArray * fDevs
! Temp. array to hold references to user selected devices
TObjArray * fOrdered
! Temp. array to hold references to various ordered objects
TObjArray * SortHits(TString classname, Bool_t follow, Bool_t inc, TString name, Int_t mode=-1, Int_t mcal=1, Int_t deadcheck=1, TObjArray *ordered=0)
void LoadDevices(TString classname, Bool_t follow, TObjArray *hits=0, NcDetectorUnit *unit=0)
void ShowHits(TString classname, Bool_t follow, Bool_t inc, Int_t mode=1, TString f="car", TString u="rad")
NcDetectorUnit * GetDetectorUnit(TString name, Bool_t follow)
NcDevice * GetIdDevice(Int_t id, Bool_t follow, TObjArray *devs=0)
TObjArray * fDevices
void ShowDevices(Int_t mode=1, Bool_t header=kTRUE)
virtual ~NcDetectorUnit()
TObjArray * GetHits()
Definition NcDevice.cxx:573
NcDevice(const char *name="", const char *title="")
Definition NcDevice.cxx:109
virtual TObject * Clone(const char *name="") const
void DisplayHits(TString name, Float_t scale=-1, TObjArray *hits=0, Int_t dp=0, Int_t mode=1, Int_t mcol=4)
virtual void SetOwner(Bool_t own=kTRUE)
Definition NcDevice.cxx:283
Int_t GetNhits() const
Definition NcDevice.cxx:437
NcSignal * GetHit(Int_t j) const
Definition NcDevice.cxx:489
void ShowHit(Int_t j=0, TString f="car", TString u="rad") const
Definition NcDevice.cxx:659
virtual void Reset(Int_t mode=0)
Definition NcDevice.cxx:222
void GetPosition(Double_t *r, TString f, TString u="rad", Float_t s=-1) const
virtual void Data(TString f="car", TString u="rad") const
Int_t GetNwaveforms() const
virtual void List(Int_t j=0) const
TObject * fDevice
Definition NcSignal.h:113
NcDevice * GetDevice() const
void ListWaveform(Int_t j=0) const
void ListSample(Int_t j=0) const
NcSignal(const char *name="", const char *title="")
Definition NcSignal.cxx:155
void ListTrack(Int_t j=0) const
Int_t GetNsamples() const
virtual void Data(TString f="car", TString u="rad") const
Definition NcSignal.cxx:959