Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CellUniqueId.cxx

Go to the documentation of this file.
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     // Experience has shown that only depths below this "depth0"
00043     // contribute to a cell's 'uniqueness'.
00044     static const unsigned int depth0 = 3;
00045     
00046     // Now construct the id
00047     CellUniqueId id = 0ULL;
00048     for (unsigned int i=depth0; i<ids.size(); ++i) {
00049       // The following check is useful, although not really
00050       // required. The code in Geometry.cxx checks that the ID's are
00051       // unique which is all that really matters. Even if we happen to
00052       // overflow the storage limits of the CellUniqueId, the result
00053       // will always be the same for the same cell. So, as long as the
00054       // overflow is unique, all is OK. BTW, I've checked that as of
00055       // at least v1.6 2008/08/17 the CellUniqueID's do not overflow
00056       //
00057       // if (id>0 && ULLONG_MAX/id < 1000) abort();
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 }

Generated on Mon Dec 1 02:35:17 2008 for NOvA Offline by  doxygen 1.3.9.1