#include "PixelMap.h" #include #include #include #include PixelMap::PixelMap() { pixelmap.clear(); ReadPixelMap(pixelmap, false); } PixelMap::~PixelMap() { for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { delete ((*iter).second); } } void PixelMap::ReadPixelMap(std::map& pixelmap, bool verbose) { std::string filename("PixelMap.txt"); std::ifstream infile(filename.c_str(), std::fstream::in); std::cout<<"Reading mapping file: "< 4){ rest = strtok(NULL, delim); if(rest != NULL) { unsigned int DRSboard = (unsigned int)strtod(rest, &rest); unsigned int DRSchip = (unsigned int)strtod(rest, &rest); unsigned int DRSchannel = (unsigned int)strtod(rest, &rest); unsigned int HVboard = (unsigned int)strtod(rest, &rest); unsigned int HVchain = (unsigned int)strtod(rest, &rest); unsigned int HVchannel = (unsigned int)strtod(rest, &rest); pixelmap[name] = new Pixel(DRSboard, DRSchip, DRSchannel, HVboard, HVchain, HVchannel); } } else { std::cout << "ERROR in PixelMap::ReadPixelMap: Wrong pixel name: " << name << "-> pixel not initialized" << std::endl; } } } } if(verbose){ for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { std::cout << std::endl << (*iter).first << std::endl << "-----------" << std::endl << *((*iter).second); } } std::cout << pixelmap.size() << " pixels found" << std::endl << std::endl; infile.close(); } 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; } } std::string PixelMap::DRS_to_Pixel(unsigned int DRSboard, unsigned int DRSchip, unsigned int DRSchannel) { std::string pixelname = ""; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ( ((*iter).second)->GetPixelDRSboard() == DRSboard ) && ( ((*iter).second)->GetPixelDRSchip() == DRSchip ) && ( ((*iter).second)->GetPixelDRSchannel() == DRSchannel ) ) { pixelname = (*iter).first; } } if(pixelname == ""){ std::cout << "ERROR in PixelMap::DRS_to_Pixel: No pixel with DRS board, chip, channel = " << DRSboard << ", " << DRSchip << ", " << DRSchannel << " found in pixelmap" << std::endl; } return pixelname; } std::string PixelMap::HV_to_Pixel(unsigned int HVboard, unsigned int HVchain, unsigned int HVchannel) { std::string pixelname = ""; for( std::map::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) { if( ( ((*iter).second)->GetPixelHVboard() == HVboard ) && ( ((*iter).second)->GetPixelHVchain() == HVchain ) && ( ((*iter).second)->GetPixelHVchannel() == HVchannel ) ) { pixelname = (*iter).first; } } if(pixelname == ""){ std::cout << "ERROR in PixelMap::HV_to_Pixel: No pixel with HV board, chain, channel = " << HVboard << ", " << HVchain << ", " << HVchannel << " found in pixelmap" << std::endl; } return pixelname; } unsigned int PixelMap::Pixel_to_DRSboard(std::string pixelname) { unsigned int DRSboard = 999999999; if(pixelmap[pixelname] != NULL) { DRSboard = pixelmap[pixelname]->GetPixelDRSboard(); } else { std::cout << "ERROR in PixelMap::Pixel_to_DRSboard: No pixel with name = " << pixelname << " found in pixelmap" << std::endl; } return DRSboard; } unsigned int PixelMap::Pixel_to_DRSchip(std::string pixelname) { unsigned int DRSchip = 999999999; if(pixelmap[pixelname] != NULL) { DRSchip = pixelmap[pixelname]->GetPixelDRSchip(); } else { std::cout << "ERROR in PixelMap::Pixel_to_DRSchip: No pixel with name = " << pixelname << " found in pixelmap" << std::endl; } return DRSchip; } unsigned int PixelMap::Pixel_to_DRSchannel(std::string pixelname) { unsigned int DRSchannel = 999999999; if(pixelmap[pixelname] != NULL) { DRSchannel = pixelmap[pixelname]->GetPixelDRSchannel(); } else { std::cout << "ERROR in PixelMap::Pixel_to_DRSchannel: No pixel with name = " << pixelname << " found in pixelmap" << std::endl; } return DRSchannel; } unsigned int PixelMap::Pixel_to_HVboard(std::string pixelname) { unsigned int HVboard = 999999999; if(pixelmap[pixelname] != NULL) { HVboard = pixelmap[pixelname]->GetPixelHVboard(); } else { std::cout << "ERROR in PixelMap::Pixel_to_HVboard: No pixel with name = " << pixelname << " found in pixelmap" << std::endl; } return HVboard; } unsigned int PixelMap::Pixel_to_HVchain(std::string pixelname) { unsigned int HVchain = 999999999; if(pixelmap[pixelname] != NULL) { HVchain = pixelmap[pixelname]->GetPixelHVchain(); } else { std::cout << "ERROR in PixelMap::Pixel_to_HVchain: No pixel with name = " << pixelname << " found in pixelmap" << std::endl; } return HVchain; } unsigned int PixelMap::Pixel_to_HVchannel(std::string pixelname) { unsigned int HVchannel = 999999999; if(pixelmap[pixelname] != NULL) { HVchannel = pixelmap[pixelname]->GetPixelHVchannel(); } else { std::cout << "ERROR in PixelMap::Pixel_to_HVchannel: No pixel with name = " << pixelname << " found in pixelmap" << std::endl; } return HVchannel; }