//----------------------------------------------------------- // File and Version Information: // $Id$ // // Description: // Implementation of class PndTpcPadPlane // see PndTpcPadPlane.h for details // // Environment: // Software developed for the PANDA Detector at FAIR. // // Author List: // Sebastian Neubert TUM (original author) // // //----------------------------------------------------------- // This Class' Header ------------------ #include "PndTpcPadPlane.h" // C/C++ Headers ---------------------- #include #include #include #include "string.h" #include "stdlib.h" // Collaborating Class Headers -------- #include "TError.h" #include "TString.h" #include "PndTpcPadShapePool.h" #include "PndTpcAbsPadShape.h" // Class Member definitions ----------- PndTpcPadPlane::PndTpcPadPlane(int fnx, int fny, double fxbin, double fybin, double fx0, double fy0) : nx(fnx),ny(fny),xbin(fxbin),ybin(fybin),x0(fx0),y0(fy0), fnSectors(0), Indexer(fnx,fny,fxbin,fybin,fx0,fy0) { int nRegions=nx*ny; for(int iRegion=0; iRegion); } } PndTpcPadPlane::PndTpcPadPlane(const char* const filename, const PndTpcPadShapePool* const pspool) : fnSectors(0), Indexer(0,0,0.,0.,0.,0.) { if(pspool==NULL)std::cout<<"WARNING: no padshapes defined!" <<" PadPlane will not be usable!"<); infile.unget();//if it was the last line=>eof=>without this !infile.good() break; } if (!infile.good())//e.g. eof Fatal("PndTpcPadPlane::PndTpcPadPlane","Error searching a line of the form:\n PadPlaneSubDivision int int double double double double \n Pad Plane can't be build."); infile.close(); ReadFromFile(filename, pspool); } // PadPlane Takes Ownership over Pads! PndTpcPadPlane::~PndTpcPadPlane(){ int n=PadReferences.size(); for(int i=0;i& buffer) const { for(int iy=-1; iy<=1; ++iy){ for(int ix=-1; ix<=1; ++ix){ double xin = x+ix*xbin; double yin = y+iy*ybin; if (xinnx*xbin+x0 || yinny*ybin+y0) continue; //Get Regions int iRegion=Indexer(xin,yin); int nPads=Regions[iRegion]->size(); for(int iPad=0; iPadCircleIntersection(x,y,r))buffer.push_back(aPad); } } } } void PndTpcPadPlane::GetPadXY(const unsigned int PadID, double& x, double& y) const { PndTpcPad* pad=GetPad(PadID); x=pad->x(); y=pad->y(); } PndTpcPad* PndTpcPadPlane::GetPad(const unsigned int PadID) const { if (PadID >= PadReferences.size()) throw superior_unknown_padId(PadID); PndTpcPad* pad=PadReferences[PadID]; if(pad==NULL) throw superior_unknown_padId(PadID); return(pad); } unsigned int PndTpcPadPlane::GetNPads() const { unsigned int np=0; for (unsigned int i=0; ipush_back(pad); fSectors[pad->sectorId()].minx=std::min(fSectors[pad->sectorId()].minx,pad->x()); fSectors[pad->sectorId()].miny=std::min(fSectors[pad->sectorId()].miny,pad->y()); fSectors[pad->sectorId()].maxx=std::max(fSectors[pad->sectorId()].maxx,pad->x()); fSectors[pad->sectorId()].maxy=std::max(fSectors[pad->sectorId()].maxy,pad->y()); // this assumes continually nummbered sectors: if(pad->sectorId()>=fnSectors)fnSectors=pad->sectorId()+1; } catch (std::exception& e) { std::cerr<<"Index="<id(); try { GetPad(ID); } catch (unknown_padID& e)//the desired case { if(PadReferences.size()<=ID)PadReferences.resize(ID+1,0); PadReferences[ID]=pad; if(fSectorLists[pad->sectorId()]==0)fSectorLists[pad->sectorId()]=new std::map; (*fSectorLists[pad->sectorId()])[pad->padId()]=pad; return; } catch (superior_unknown_padId& e)//the desired case { if(PadReferences.size()<=ID)PadReferences.resize(ID+1,0); PadReferences[ID]=pad; if(fSectorLists[pad->sectorId()]==0)fSectorLists[pad->sectorId()]=new std::map; (*fSectorLists[pad->sectorId()])[pad->padId()]=pad; return; } //the padID is not unknown=> some other pad has this ID Regions.at(i)->pop_back(); throw used_padID(); } void PndTpcPadPlane::ReadFromFile(const char* const filename, const PndTpcPadShapePool* const pspool) { bool noproblem = true; std::ifstream infile(filename, std::fstream::in); Warning("PndTpcPadPlane::ReadFromFile","Reading file %s",filename); if (!infile.good()) Fatal("PndTpcPadPlane::ReadFromFile","The file %s can not be found.",filename); while (infile.good() && noproblem) { char line[256]; infile.getline(line, 256); noproblem = ReadLine(line, pspool); } // if (!infile.eof()) // Fatal("PndTpcPadPlane::ReadFromFile","The file %s can not be read.",filename); infile.close(); if (noproblem == false) Fatal("PndTpcPadPlane::ReadFromFile","The file %s does not correspond to the required format.",filename); } bool PndTpcPadPlane::ReadLine(char* const line, const PndTpcPadShapePool* const pspool) { //remove comments at end of line char* com=strchr(line, '*');//comment if (com != 0) *com = '\0'; if (line[0] == '\0') return(true); //Is either read by the right constructor or ignored if (strstr(line, "PadPlaneSubDivision") != 0) return(true); char* rest; unsigned int ID; unsigned int sectorID; unsigned int shapeID; double x; double y; double angle; ID = (unsigned int) strtoul(line, &rest, 10); sectorID = (unsigned int) strtoul(rest, &rest, 10); shapeID = (unsigned int) strtoul(rest, &rest, 10); x = strtod(rest,&rest); y = strtod(rest,&rest); char* end; angle = strtod(rest,&end); if (rest == line)//No reading happened (e.g. only blanks) return(true); if (rest == end)//It was impossible to read angle { Warning("PndTpcPadPlane::ReadLine","In line: %s \n Too less arguments.",line); return(false); } PndTpcAbsPadShape* shape=0; if(pspool!=NULL){ shape=pspool->GetPadShape(shapeID); if (shape == 0)//shapeId does not exist { Warning("PndTpcPadPlane::ReadLine","In line: %s \n There is no PndTpcPadShape with ID= %i",line,shapeID); return(false); } } PndTpcPad* pad = new PndTpcPad(x, y, angle, shape, sectorID, ID); // read in neighbour ids if available char* end2; unsigned int nid= (unsigned int) strtoul(end, &end2, 10); while(end!=end2){ pad->addNeighbour(nid); end=end2; nid= (unsigned int) strtoul(end, &end2, 10); } try { AddPad(pad); } catch (std::exception& e) { Warning("PndTpcPadPlane::ReadLine","The pad from line: %s \ncould not be added.Reason: \n %s",line,e.what()); return(false); } return(true); } std::vector PndTpcPadPlane::GetSectorIds()const { std::map*>::const_iterator sIt=fSectorLists.begin(); std::vector ids; while(sIt!=fSectorLists.end()){ ids.push_back(sIt->first); ++sIt; } return ids; } // Operators std::ostream& operator<< (std::ostream& s, const PndTpcPadPlane& me){ return s << "PndTpcPadPlane:\n" << " nx="<("<id() <<" " << pad->sectorId() <<" " << pad->shape()->GetID()<<" " << pad->x()<<" " << pad->y()<<" " << pad->angle()<<" "; unsigned int nn=pad->nNeighbours(); for(unsigned int in=0;ingetNeighbour(in) <<" "; } stream << std::endl; } stream.flush(); } ClassImp(PndTpcPadPlane)