00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "Geometry/CellUniqueId.h"
00010 #include <iostream>
00011 #include "TGeoNode.h"
00012
00013 namespace geo {
00014
00015
00016
00017 CellUniqueId NodesToUniqueId(const std::vector<const TGeoNode*>& n,
00018 unsigned int depth)
00019 {
00020 static std::vector<int> ids;
00021 ids.clear();
00022 for (unsigned int i=0; i<=depth; ++i) {
00023 GetNodeNumbers(n[i]->GetName(), ids);
00024 }
00025 return IdsToUniqueId(ids);
00026 }
00027
00028
00029
00030 CellUniqueId PathToUniqueId(const char* path)
00031 {
00032 static std::vector<int> ids;
00033 ids.clear();
00034 GetNodeNumbers(path, ids);
00035 return IdsToUniqueId(ids);
00036 }
00037
00038
00039
00040 CellUniqueId IdsToUniqueId(const std::vector<int>& ids)
00041 {
00042
00043
00044 static const unsigned int depth0 = 3;
00045
00046
00047 CellUniqueId id = 0ULL;
00048 for (unsigned int i=depth0; i<ids.size(); ++i) {
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 id = 1000*id + ids[i];
00059 }
00060 return id;
00061 }
00062
00063
00064
00065 void GetNodeNumbers(const char* nm, std::vector<int>& id)
00066 {
00067 char buff[8];
00068 const char* c;
00069 const char* start = nm;
00070 const char* end;
00071 int indx;
00072 while (1) {
00073 start = strchr(start, '_');
00074 if (start == NULL) break;
00075 ++start;
00076 end = strchr(start, '/');
00077 if (end==NULL) end = strchr(start, '\0');
00078 if (end==NULL) abort();
00079
00080 for (indx=0, c=start; c<end; ++indx, ++c) buff[indx] = *c;
00081 buff[indx] = '\0';
00082 id.push_back(atoi(buff));
00083 }
00084 }
00085 }