#include "PixelMap.h" #include #include #include #include #include const unsigned int PixelMap::PM_ERROR_CODE; PixelMap::PixelMap(std::string data, bool verbose) { pixelmap.clear(); ReadPixelMap(pixelmap, data, verbose); } PixelMap::~PixelMap() { for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { delete ((*iter).second); } } void PixelMap::ReadPixelMap(std::map& pixelmap, std::string data, bool verbose) { if (verbose) { std::cout<<"Creating pixelmap table"< 0) && (count1 < 5) ) { unsigned int pixelID = (unsigned int)atoi(name2); std::map::iterator found = pixelmap.find(pixelID); if( found == pixelmap.end() ) {//pixelID already existing? rest = strtok(NULL, delim); if(rest != NULL) { unsigned int FPAcrate = (unsigned int)strtod(rest, &rest); unsigned int FPAboard = (unsigned int)strtod(rest, &rest); unsigned int FPApatch = (unsigned int)strtod(rest, &rest); unsigned int FPApixel = (unsigned int)strtod(rest, &rest); unsigned int HVcrate = (unsigned int)strtod(rest, &rest); unsigned int HVboard = (unsigned int)strtod(rest, &rest); unsigned int HVchannel = (unsigned int)strtod(rest, &rest); int POSx = (int)strtod(rest, &rest); int POSy = (int)strtod(rest, &rest); pixelmap[pixelID] = new Pixel(FPAcrate, FPAboard, FPApatch, FPApixel, HVcrate, HVboard, HVchannel, POSx, POSy); } else { pixelmap[pixelID] = new Pixel(); } } else { if (verbose) { std::cout << "ERROR in PixelMap::ReadPixelMap: pixel ID already existing: " << pixelID << " -> pixel not initialized again" << std::endl; } } } else { if (verbose) { std::cout << "ERROR in PixelMap::ReadPixelMap: wrong pixel ID: " << name2 << " -> pixel not initialized" << std::endl; } } delete[] ctokens; } else { if(verbose){ std::cout << "ERROR in PixelMap::ReadPixelMap: entry without pixel ID: " << tokens << " -> pixel not initialized" << std::endl; } } } if (verbose) { std::cout << std::endl << pixelmap.size() << " pixels found" << std::endl << std::endl; } } void PixelMap::Print() { std::cout << "Printing entries of pixelmap:" << std::endl << std::endl; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { std::cout << (*iter).first << std::endl << "------------" << std::endl << *((*iter).second) << std::endl; } } unsigned int PixelMap::FPA_to_Pixel(unsigned int FPAcrate, unsigned int FPAboard, unsigned int FPApatch, unsigned int FPApixel, bool verbose) { unsigned int pixelID = PM_ERROR_CODE; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ( ((*iter).second)->GetPixelFPAcrate() == FPAcrate ) && ( ((*iter).second)->GetPixelFPAboard() == FPAboard ) && ( ((*iter).second)->GetPixelFPApatch() == FPApatch ) && ( ((*iter).second)->GetPixelFPApixel() == FPApixel ) ) { pixelID = (*iter).first; } } if(pixelID == PM_ERROR_CODE){ if (verbose) { std::cout << "ERROR in PixelMap::FPA_to_Pixel: No pixel with FPA crate, board, patch, pixel = " << FPAcrate << ", " << FPAboard << ", " << FPApatch << ", " << FPApixel << " found in pixelmap" << std::endl; } } return pixelID; } std::vector PixelMap::HV_to_Pixel(unsigned int HVcrate, unsigned int HVboard, unsigned int HVchannel, bool verbose) { unsigned int last_pixelID = PM_ERROR_CODE; std::vector PixelIDs; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ( ((*iter).second)->GetPixelHVcrate() == HVcrate ) && ( ((*iter).second)->GetPixelHVboard() == HVboard ) && ( ((*iter).second)->GetPixelHVchannel() == HVchannel ) ) { last_pixelID = (*iter).first; PixelIDs.push_back(last_pixelID); } } if(last_pixelID == PM_ERROR_CODE){ if (verbose) { std::cout << "ERROR in PixelMap::HV_to_Pixel: No pixel with HV crate, board, channel = " << HVcrate << ", " << HVboard << ", " << HVchannel << " found in pixelmap" << std::endl; } } return PixelIDs; } unsigned int PixelMap::POS_to_Pixel(int POSx, int POSy, bool verbose) { unsigned int pixelID = PM_ERROR_CODE; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ( ((*iter).second)->GetPixelPOSx() == POSx ) && ( ((*iter).second)->GetPixelPOSy() == POSy ) ) { pixelID = (*iter).first; } } if(pixelID == PM_ERROR_CODE){ if (verbose) { std::cout << "ERROR in PixelMap::POS_to_Pixel: No pixel with position x, y = " << POSx << ", " << POSy << " found in pixelmap" << std::endl; } } return pixelID; } unsigned int PixelMap::Pixel_to_FPAcrate(unsigned int pixelID, bool verbose) { unsigned int FPAcrate = PM_ERROR_CODE; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ((*iter).first) == pixelID ){ FPAcrate = ((*iter).second)->GetPixelFPAcrate(); } } if (FPAcrate == PM_ERROR_CODE) { if (verbose) { std::cout << "ERROR in PixelMap::Pixel_to_FPAcrate: No pixel with ID = " << pixelID << " found in pixelmap" << std::endl; } } return FPAcrate; } unsigned int PixelMap::Pixel_to_FPAboard(unsigned int pixelID, bool verbose) { unsigned int FPAboard = PM_ERROR_CODE; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ((*iter).first) == pixelID ){ FPAboard = ((*iter).second)->GetPixelFPAboard(); } } if (FPAboard == PM_ERROR_CODE) { if (verbose) { std::cout << "ERROR in PixelMap::Pixel_to_FPAboard: No pixel with ID = " << pixelID << " found in pixelmap" << std::endl; } } return FPAboard; } unsigned int PixelMap::Pixel_to_FPApatch(unsigned int pixelID, bool verbose) { unsigned int FPApatch = PM_ERROR_CODE; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ((*iter).first) == pixelID ){ FPApatch = ((*iter).second)->GetPixelFPApatch(); } } if (FPApatch == PM_ERROR_CODE) { if (verbose) { std::cout << "ERROR in PixelMap::Pixel_to_FPApatch: No pixel with ID = " << pixelID << " found in pixelmap" << std::endl; } } return FPApatch; } unsigned int PixelMap::Pixel_to_FPApixel(unsigned int pixelID, bool verbose) { unsigned int FPApixel = PM_ERROR_CODE; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ((*iter).first) == pixelID ){ FPApixel = ((*iter).second)->GetPixelFPApixel(); } } if (FPApixel == PM_ERROR_CODE) { if (verbose) { std::cout << "ERROR in PixelMap::Pixel_to_FPApixel: No pixel with ID = " << pixelID << " found in pixelmap" << std::endl; } } return FPApixel; } unsigned int PixelMap::Pixel_to_HVcrate(unsigned int pixelID, bool verbose) { unsigned int HVcrate = PM_ERROR_CODE; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ((*iter).first) == pixelID ){ HVcrate = ((*iter).second)->GetPixelHVcrate(); } } if (HVcrate == PM_ERROR_CODE) { if (verbose) { std::cout << "ERROR in PixelMap::Pixel_to_HVcrate: No pixel with ID = " << pixelID << " found in pixelmap" << std::endl; } } return HVcrate; } unsigned int PixelMap::Pixel_to_HVboard(unsigned int pixelID, bool verbose) { unsigned int HVboard = PM_ERROR_CODE; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ((*iter).first) == pixelID ){ HVboard = ((*iter).second)->GetPixelHVboard(); } } if (HVboard == PM_ERROR_CODE) { if (verbose) { std::cout << "ERROR in PixelMap::Pixel_to_HVboard: No pixel with ID = " << pixelID << " found in pixelmap" << std::endl; } } return HVboard; } unsigned int PixelMap::Pixel_to_HVchannel(unsigned int pixelID, bool verbose) { unsigned int HVchannel = PM_ERROR_CODE; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ((*iter).first) == pixelID ){ HVchannel = ((*iter).second)->GetPixelHVchannel(); } } if (HVchannel == PM_ERROR_CODE) { if (verbose) { std::cout << "ERROR in PixelMap::Pixel_to_HVchannel: No pixel with ID = " << pixelID << " found in pixelmap" << std::endl; } } return HVchannel; } int PixelMap::Pixel_to_POSx(unsigned int pixelID, bool verbose) { int POSx = PM_ERROR_CODE; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ((*iter).first) == pixelID ){ POSx = ((*iter).second)->GetPixelPOSx(); } } if (POSx == (int)PM_ERROR_CODE) { if (verbose) { std::cout << "ERROR in PixelMap::Pixel_to_POSx: No pixel with ID = " << pixelID << " found in pixelmap" << std::endl; } } return POSx; } int PixelMap::Pixel_to_POSy(unsigned int pixelID, bool verbose) { int POSy = PM_ERROR_CODE; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ((*iter).first) == pixelID ){ POSy = ((*iter).second)->GetPixelPOSy(); } } if (POSy == (int)PM_ERROR_CODE) { if (verbose) { std::cout << "ERROR in PixelMap::Pixel_to_POSy: No pixel with ID = " << pixelID << " found in pixelmap" << std::endl; } } return POSy; }