//----------------------------------------------------------- // File and Version Information: // $Id$ // // Description: // Implementation of class TpcPadShapePool // see TpcPadShapePool.h for details // // Environment: // Software developed for the PANDA Detector at FAIR. // // Author List: // Cristoforo Simonetto TUM (original author) // // //----------------------------------------------------------- // This Class' Header ------------------ #include "TpcPadShapePool.h" // C/C++ Headers ---------------------- #include #include // Collaborating Class Headers -------- #include "TpcAbsPadShape.h" #include "TpcPadShapeSquare.h" #include "TpcPadShapePolygon.h" #include "TpcPRLookupTable.h" #include "TError.h" // Class Member definitions ----------- TpcPadShapePool::TpcPadShapePool() {;} TpcPadShapePool::TpcPadShapePool(const char* const filename, const TpcGem& gem, const double _range, const double _step, const double _intStep) { ReadFromFile(filename); BuildLookupTable(gem, _range, _step, _intStep); } TpcPadShapePool::~TpcPadShapePool() { for(int i=0; i= references.size() || references[_ID] == 0) { Warning("TpcPadShapePool::RemovePadShape","There is no TpcAbsPadShape with the ID=%i",_ID); return; } delete references[_ID]; references[_ID] = 0; if (_ID == references.size()-1) { int i=_ID; while (i>=0 && references[i] == 0) i--; references.resize(i+1,0); } } void TpcPadShapePool::ReadFromFile(const char* const filename) { //Reading the file bool noproblem = true; std::ifstream infile(filename, std::fstream::in); Warning("TpcPadShapePool::ReadFromFile","Reading file %s",filename); if (!infile.good()) Fatal("TpcPadShapePool::ReadFromFile","The file %s can not be found.",filename); while(infile.good() && noproblem) noproblem = ReadLine(infile); if (!infile.eof()) Fatal("TpcPadShapePool::ReadFromFile","The file %s can not be read.",filename); infile.close(); if (noproblem == false) Fatal("TpcPadShapePool::ReadFromFile","The file %s does not correspond to the required format.",filename); } void TpcPadShapePool::BuildLookupTable(const TpcGem& gem, const double _range, const double _step, const double _intStep){ for (int i=0; iGetLookupTable()->IsBuilt()) references[i]->GetLookupTable()->BuildTable(gem, *references[i], _range, _step, _intStep); } bool TpcPadShapePool::TryAddingPadShape(TpcAbsPadShape* padshape) { unsigned int id = padshape->GetID(); if (references.size() > id && references[id] != 0) return(false); else if (references.size() <= id) references.resize(id+1, 0); references[id]=padshape; return(true); } bool TpcPadShapePool::ReadLine(std::ifstream& infile) { TpcAbsPadShape* padshape=0; char line[256]; int begin=0; infile.getline(line, 256); //remove blanks at begin of line while (isspace((int) line[begin])) { if (line[begin] == '\0') return(true); begin++; } //remove comments at end of line char* com=strchr(line, '*');//comment if (com != 0) *com = '\0'; //decide which PadShape if (line[begin] == 's') padshape = ReadShape(&line[++begin]); else if (line[begin] == 'p') padshape = ReadPolygon(&line[++begin]); else if (line[begin] == '\0') return(true); else { Warning("TpcPadShapePool::ReadLine","In line: %i \nFirst character in line has no meaning.",line); return(false); } //if it was not possible to create a padshape with th data if (padshape==0) { Warning("TpcPadShapePool::ReadLine","In line: %i\nIt was not possible to create a TpcPadShape.",line); return(false); } if (TryAddingPadShape(padshape)== true) return(true); //if the ID is already used Warning("TpcPadShapePool::ReadLine","In line: %i\nThe padshape could not be added, because the ID %i is already occupied.",line,padshape->GetID()); delete padshape; return(false); } TpcAbsPadShape* TpcPadShapePool::ReadShape(const char* const line) { char* rest; unsigned int id; double d; id = (unsigned int) strtoul(line,&rest,10); d = strtod(rest,&rest); if (d==0) Warning("TpcPadShapePool::ReadShape","The size of the padshape wit ID=%i is 0.",id); TpcPadShapeSquare* pads = new TpcPadShapeSquare(d, id); return(pads); } TpcAbsPadShape* TpcPadShapePool::ReadPolygon(const char* const line) { char* rest; unsigned int id; std::vector xCoord(0); std::vector yCoord(0); id = (unsigned int) strtoul(line,&rest,10); for (int i=0; ;i++) { char* end; xCoord.push_back(strtod(rest,&rest)); yCoord.push_back(strtod(rest,&end)); if (rest == end) { xCoord.pop_back(); yCoord.pop_back(); break; } rest = end; } TpcPadShapePolygon* padp = new TpcPadShapePolygon(xCoord, yCoord, id); return(padp); } std::ostream& operator<< (std::ostream& s, const TpcPadShapePool& me) { return s <<"TpcPadShapePool:\n" <<"max. ID of a PadShape="<