Changeset 10116 for fact


Ignore:
Timestamp:
01/24/11 12:04:23 (14 years ago)
Author:
weitzel
Message:
new version of pixelmap class
Location:
fact
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • fact/pixelmap/Pixel.cc

    r16 r10116  
    1 #include "PixelMap.h"
     1#include "Pixel.h"
    22#include <iostream>
    33
    4 Pixel::Pixel() : _DRSboard(999999999), _DRSchip(999999999), _DRSchannel(999999999),
    5                  _HVboard(999999999), _HVchain(999999999), _HVchannel(999999999) { }
     4Pixel::Pixel() : _FPAcrate(0), _FPAboard(0), _FPApatch(0), _FPApixel(0),
     5                 _HVcrate(0), _HVboard(0), _HVchannel(0),
     6                 _POSx(0), _POSy(0) {
    67
    7 Pixel::Pixel(unsigned int DRSboard, unsigned int DRSchip, unsigned int DRSchannel,
    8              unsigned int HVboard, unsigned int HVchain, unsigned int HVchannel)
    9     : _DRSboard(DRSboard), _DRSchip(DRSchip), _DRSchannel(DRSchannel),
    10       _HVboard(HVboard), _HVchain(HVchain), _HVchannel(HVchannel) {
     8}
    119
    12     //???check here whether values make sense and eventually give error messages???
     10Pixel::Pixel(unsigned int FPAcrate, unsigned int FPAboard, unsigned int FPApatch, unsigned int FPApixel,
     11             unsigned int HVcrate, unsigned int HVboard, unsigned int HVchannel,
     12             int POSx, int POSy)
     13    : _FPAcrate(FPAcrate), _FPAboard(FPAboard), _FPApatch(FPApatch), _FPApixel(FPApixel),
     14      _HVcrate(HVcrate), _HVboard(HVboard), _HVchannel(HVchannel),
     15      _POSx(POSx), _POSy(POSy) {
    1316
    1417}
     
    1619std::ostream& operator << (std::ostream& s, const Pixel& pixel) {
    1720 
    18     return s << "DRSboard="<<pixel._DRSboard<<"\n"
    19              << "DRSchip="<<pixel._DRSchip<<"\n"
    20              << "DRSchannel="<<pixel._DRSchannel<<"\n"
     21    return s << "FPAcrate="<<pixel._FPAcrate<<"\n"
     22             << "FPAboard="<<pixel._FPAboard<<"\n"
     23             << "FPApatch="<<pixel._FPApatch<<"\n"
     24             << "FPApixel="<<pixel._FPApixel<<"\n"
     25             << "HVcrate="<<pixel._HVcrate<<"\n"
    2126             << "HVboard="<<pixel._HVboard<<"\n"
    22              << "HVchain="<<pixel._HVchain<<"\n"
    23              << "HVchannel="<<pixel._HVchannel<<"\n";
     27             << "HVchannel="<<pixel._HVchannel<<"\n"
     28             << "POSx="<<pixel._POSx<<"\n"
     29             << "POSy="<<pixel._POSy<<"\n";
    2430
    2531}
  • fact/pixelmap/Pixel.h

    r9 r10116  
    88private:
    99
    10     unsigned int _DRSboard;
    11     unsigned int _DRSchip;
    12     unsigned int _DRSchannel;
     10    unsigned int _FPAcrate;
     11    unsigned int _FPAboard;
     12    unsigned int _FPApatch;
     13    unsigned int _FPApixel;
    1314
     15    unsigned int _HVcrate;
    1416    unsigned int _HVboard;
    15     unsigned int _HVchain;
    1617    unsigned int _HVchannel;
     18
     19    int _POSx;
     20    int _POSy;
    1721
    1822public:
    1923   
    2024    Pixel();
    21     Pixel(unsigned int DRSboard, unsigned int DRSchip, unsigned int DRSchannel,
    22           unsigned int HVboard, unsigned int HVchain, unsigned int HVchannel);
     25    Pixel(unsigned int FPAcrate, unsigned int FPAboard, unsigned int FPApatch, unsigned int FPApixel,
     26          unsigned int HVcrate, unsigned int HVboard, unsigned int HVchannel,
     27          int POSx, int POSy);
    2328
    2429    ~Pixel() { }
    2530
    26     //void SetPixelDRSboard(unsigned int DRSboard);
    27     //void SetPixelDRSchip(unsigned int DRSchip);
    28     //void SetPixelDRSchannel(unsigned int DRSchannel);
     31    unsigned int GetPixelFPAcrate() const {return _FPAcrate;}
     32    unsigned int GetPixelFPAboard() const {return _FPAboard;}
     33    unsigned int GetPixelFPApatch() const {return _FPApatch;}
     34    unsigned int GetPixelFPApixel() const {return _FPApixel;}
    2935
    30     //void SetPixelHVboard(unsigned int HVboard);
    31     //void SetPixelHVchain(unsigned int HVchain);
    32     //void SetPixelHVchannel(unsigned int HVchannel);
     36    unsigned int GetPixelHVcrate() const {return _HVcrate;}
     37    unsigned int GetPixelHVboard() const {return _HVboard;}
     38    unsigned int GetPixelHVchannel() const {return _HVchannel;}
    3339
    34     unsigned int GetPixelDRSboard() const {return _DRSboard;}
    35     unsigned int GetPixelDRSchip() const {return _DRSchip;}
    36     unsigned int GetPixelDRSchannel() const {return _DRSchannel;}
    37 
    38     unsigned int GetPixelHVboard() const {return _HVboard;}
    39     unsigned int GetPixelHVchain() const {return _HVchain;}
    40     unsigned int GetPixelHVchannel() const {return _HVchannel;}
     40    int GetPixelPOSx() const {return _POSx;}
     41    int GetPixelPOSy() const {return _POSy;}
    4142
    4243    friend std::ostream& operator << (std::ostream& s, const Pixel& pixel);
  • fact/pixelmap/PixelMap.cc

    r18 r10116  
    66#include <cctype>
    77
    8 PixelMap::PixelMap(std::string file, bool verbose) {
     8const unsigned int PixelMap::PM_ERROR_CODE;
     9
     10PixelMap::PixelMap(std::string data, bool verbose) {
    911
    1012    pixelmap.clear();
    11     ReadPixelMap(pixelmap, file, verbose);
     13    ReadPixelMap(pixelmap, data, verbose);
    1214
    1315}
     
    1517PixelMap::~PixelMap() {
    1618
    17     for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     19    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
    1820        delete ((*iter).second);
    1921    }
     
    2123}
    2224
    23 void PixelMap::ReadPixelMap(std::map<std::string, Pixel*>& pixelmap, std::string file, bool verbose) {
    24 
    25     //std::string filename("PixelMap.txt");
    26     std::ifstream infile(file.c_str(), std::fstream::in);
     25void PixelMap::ReadPixelMap(std::map<unsigned int, Pixel*>& pixelmap, std::string data, bool verbose) {
    2726
    2827    if (verbose) {
    29         std::cout<<"Reading mapping file: "<<file<<std::endl<<std::endl;   
    30         if (!infile.good()) {
    31             std::cerr<<"ERROR in PixelMap::ReadPixelMap: File "<<file<<" cannot be found."<<std::endl;
    32         }
    33     }
    34 
    35     while (infile.good()) {
     28        std::cout<<"Creating pixelmap table"<<std::endl;   
     29        if (strlen(data.c_str()) == 0) {
     30            std::cerr<<"WARNING in PixelMap::ReadPixelMap: input table is empty"<<std::endl;
     31        }
     32    }
     33
     34    std::string::size_type Next, EndNext = 0;
     35
     36    while (EndNext != std::string::npos) {
    3637       
    37         char line[1024];
    38 
    39         infile.getline(line, 1024);
    40 
    41         if (line[0] == '#') {
    42             if (verbose) {
    43                 std::cout << "Ignoring comment: " << line << std::endl;
     38        Next = data.find_first_not_of(";", EndNext);
     39        EndNext = data.find_first_of(";", Next);
     40
     41        // Stop if end of string reached
     42        if (Next == std::string::npos) break;
     43   
     44        std::string tokens = data.substr(Next, EndNext - Next);
     45
     46        if (tokens.find(":") != std::string::npos) {
     47
     48            char* ctokens = new char[tokens.size()+1];
     49            strcpy (ctokens, tokens.c_str());
     50               
     51            char delim[] = ":";
     52            char *name = NULL; //unformated name before : tokens
     53            char name2[256] = ""; //formated name without whitespaces
     54            char *rest = NULL;
     55               
     56            name = strtok(ctokens, delim);
     57
     58            unsigned int count1 = 0; //count non-whitespace characters in name
     59
     60            for (unsigned int i = 0; i < strlen(name); i++) {
     61
     62                if ( !(isspace(name[i])) ) {               
     63                    name2[count1] = name[i];
     64                    count1+=1;
     65                }
     66
    4467            }
    45         }
    46 
    47         else {
    48            
    49             if (strlen(line)!=0) {
     68
     69            if( (count1 > 0) && (count1 < 5) ) {
     70
     71                unsigned int pixelID = (unsigned int)atoi(name2);
     72                std::map<const unsigned int, Pixel*>::iterator found = pixelmap.find(pixelID);
    5073               
    51                 char delim[] = ":";
    52                 char *name = NULL; //unformated name before : tokens
    53                 char name2[256] = ""; //formated name without whitespaces
    54                 char *rest = NULL;
    55                
    56                 name = strtok(line, delim);
    57 
    58                 unsigned int count1 = 0; //count non-whitespace characters in name
    59                 unsigned int count2 = 0; //count number of - in name
    60 
    61                 for (unsigned int i = 0; i < strlen(name); i++) {
    62 
    63                     if ( !(isspace(name[i])) ) {
    64 
    65                         name2[count1] = name[i];
    66                         count1+=1;
    67 
    68                         if ( (name[i] == 45) ) {
    69                             count2+=1;
    70                         }
    71 
    72                     }
    73 
    74                 }
    75 
    76                 //if (verbose) {
    77                 //  std::cout << "Formated pixel name: " << name2 << std::endl;
    78                 //}
    79 
    80                 if( (count1 > 4) && (count1 < 7) && (count2 == 2) ) {
     74                if( found == pixelmap.end() ) {//pixelID already existing?
    8175
    8276                    rest = strtok(NULL, delim);
     
    8478                    if(rest != NULL) {
    8579                       
    86                         unsigned int DRSboard = (unsigned int)strtod(rest, &rest);                                         
    87                         unsigned int DRSchip = (unsigned int)strtod(rest, &rest);           
    88                         unsigned int DRSchannel = (unsigned int)strtod(rest, &rest);
     80                        unsigned int FPAcrate = (unsigned int)strtod(rest, &rest);
     81                        unsigned int FPAboard = (unsigned int)strtod(rest, &rest);                                         
     82                        unsigned int FPApatch = (unsigned int)strtod(rest, &rest);         
     83                        unsigned int FPApixel = (unsigned int)strtod(rest, &rest);
     84                        unsigned int HVcrate = (unsigned int)strtod(rest, &rest);
    8985                        unsigned int HVboard = (unsigned int)strtod(rest, &rest);
    90                         unsigned int HVchain = (unsigned int)strtod(rest, &rest);
    9186                        unsigned int HVchannel = (unsigned int)strtod(rest, &rest);
    92 
    93                         pixelmap[name2] = new Pixel(DRSboard, DRSchip, DRSchannel,
    94                                                     HVboard, HVchain, HVchannel);
    95 
     87                        int POSx = (int)strtod(rest, &rest);
     88                        int POSy = (int)strtod(rest, &rest);
     89
     90                        pixelmap[pixelID] = new Pixel(FPAcrate, FPAboard, FPApatch, FPApixel,
     91                                                      HVcrate, HVboard, HVchannel,
     92                                                      POSx, POSy);
    9693                    }
    9794
     95                    else {
     96                       
     97                        pixelmap[pixelID] = new Pixel();
     98
     99                    }
     100
    98101                }
    99102
     
    101104
    102105                    if (verbose) {
    103                         std::cout << "ERROR in PixelMap::ReadPixelMap: Wrong pixel name: " << name2 << " -> pixel not initialized" << std::endl;
     106                        std::cout << "ERROR in PixelMap::ReadPixelMap: pixel ID already existing: " << pixelID << " -> pixel not initialized again" << std::endl;
    104107                    }
    105108
    106109                }
    107110
    108             } 
     111            }
    109112
    110113            else {
    111114
    112                 if(verbose){
    113                     std::cout << "Skipping empty line" << std::endl;
     115                if (verbose) {
     116                    std::cout << "ERROR in PixelMap::ReadPixelMap: wrong pixel ID: " << name2 << " -> pixel not initialized" << std::endl;
    114117                }
    115118
    116119            }
    117120
    118         }
    119        
     121            delete[] ctokens;
     122
     123        }
     124
     125        else {
     126
     127            if(verbose){
     128                std::cout << "ERROR in PixelMap::ReadPixelMap: entry without pixel ID: " << tokens << " -> pixel not initialized" << std::endl;
     129            }
     130
     131        }
     132
    120133    }
    121134
     
    123136        std::cout << std::endl << pixelmap.size() << " pixels found" << std::endl << std::endl;
    124137    }
    125 
    126     infile.close();
    127138                                                               
    128139}
     
    132143    std::cout << "Printing entries of pixelmap:" << std::endl << std::endl;
    133144
    134     for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     145    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
    135146        std::cout << (*iter).first << std::endl << "------------" << std::endl << *((*iter).second) << std::endl;
    136147    }
     
    138149}
    139150
    140 std::string PixelMap::DRS_to_Pixel(unsigned int DRSboard, unsigned int DRSchip, unsigned int DRSchannel, bool verbose) {
    141 
    142     std::string pixelname = "";
    143 
    144     for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
    145 
    146         if( ( ((*iter).second)->GetPixelDRSboard() == DRSboard ) &&
    147             ( ((*iter).second)->GetPixelDRSchip() == DRSchip ) &&
    148             ( ((*iter).second)->GetPixelDRSchannel() == DRSchannel ) ) {
    149 
    150             pixelname = (*iter).first;
    151 
    152         }
    153 
    154     }
    155 
    156     if(pixelname == ""){
     151unsigned int PixelMap::FPA_to_Pixel(unsigned int FPAcrate, unsigned int FPAboard, unsigned int FPApatch, unsigned int FPApixel, bool verbose) {
     152
     153    unsigned int pixelID = PM_ERROR_CODE;
     154
     155    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     156
     157        if( ( ((*iter).second)->GetPixelFPAcrate() == FPAcrate ) &&
     158            ( ((*iter).second)->GetPixelFPAboard() == FPAboard ) &&
     159            ( ((*iter).second)->GetPixelFPApatch() == FPApatch ) &&
     160            ( ((*iter).second)->GetPixelFPApixel() == FPApixel ) ) {
     161
     162            pixelID = (*iter).first;
     163
     164        }
     165
     166    }
     167
     168    if(pixelID == PM_ERROR_CODE){
    157169       
    158170        if (verbose) {
    159             std::cout << "ERROR in PixelMap::DRS_to_Pixel: No pixel with DRS board, chip, channel = "
    160                       << DRSboard << ", "
    161                       << DRSchip << ", "
    162                       << DRSchannel << " found in pixelmap" << std::endl;
     171            std::cout << "ERROR in PixelMap::FPA_to_Pixel: No pixel with FPA crate, board, patch, pixel = "
     172                      << FPAcrate << ", "
     173                      << FPAboard << ", "
     174                      << FPApatch << ", "
     175                      << FPApixel << " found in pixelmap" << std::endl;
    163176        }       
    164177
    165178    }
    166179
    167     return pixelname;
    168 
    169 }
    170 
    171 std::string PixelMap::HV_to_Pixel(unsigned int HVboard, unsigned int HVchain, unsigned int HVchannel, bool verbose) {
    172 
    173     std::string pixelname = "";
    174 
    175     for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
    176 
    177         if( ( ((*iter).second)->GetPixelHVboard() == HVboard ) &&
    178             ( ((*iter).second)->GetPixelHVchain() == HVchain ) &&
     180    return pixelID;
     181
     182}
     183
     184std::vector<unsigned int> PixelMap::HV_to_Pixel(unsigned int HVcrate, unsigned int HVboard, unsigned int HVchannel, bool verbose) {
     185
     186    unsigned int last_pixelID = PM_ERROR_CODE;
     187
     188    std::vector<unsigned int> PixelIDs;
     189
     190    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     191
     192        if( ( ((*iter).second)->GetPixelHVcrate() == HVcrate ) &&
     193            ( ((*iter).second)->GetPixelHVboard() == HVboard ) &&
    179194            ( ((*iter).second)->GetPixelHVchannel() == HVchannel ) ) {
    180195
    181             pixelname = (*iter).first;
    182 
    183         }
    184 
    185     }
    186 
    187     if(pixelname == ""){
    188 
    189         if (verbose) {
    190             std::cout << "ERROR in PixelMap::HV_to_Pixel: No pixel with HV board, chain, channel = "
     196            last_pixelID = (*iter).first;
     197            PixelIDs.push_back(last_pixelID);
     198
     199        }
     200
     201    }
     202
     203    if(last_pixelID == PM_ERROR_CODE){
     204
     205        if (verbose) {
     206            std::cout << "ERROR in PixelMap::HV_to_Pixel: No pixel with HV crate, board, channel = "
     207                      << HVcrate << ", "
    191208                      << HVboard << ", "
    192                       << HVchain << ", "
    193209                      << HVchannel << " found in pixelmap" << std::endl;
    194210        }       
     
    196212    }
    197213
    198     return pixelname;
    199 
    200 }
    201 
    202 unsigned int PixelMap::Pixel_to_DRSboard(std::string pixelname, bool verbose) {
    203 
    204     unsigned int DRSboard = 999999999;
    205 
    206     for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
    207 
    208         if( ((*iter).first) == pixelname ){
    209             DRSboard = ((*iter).second)->GetPixelDRSboard();
    210         }
    211 
    212     }
    213 
    214     if (DRSboard == 999999999) {
    215 
    216         if (verbose) {
    217             std::cout << "ERROR in PixelMap::Pixel_to_DRSboard: No pixel with name = "
    218                       << pixelname << " found in pixelmap" << std::endl;
    219         }
    220 
    221     }
    222 
    223     return DRSboard;
    224 
    225 }
    226 
    227 unsigned int PixelMap::Pixel_to_DRSchip(std::string pixelname, bool verbose) {
    228 
    229     unsigned int DRSchip = 999999999;
    230 
    231     for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
    232 
    233         if( ((*iter).first) == pixelname ){
    234             DRSchip = ((*iter).second)->GetPixelDRSchip();
    235         }
    236 
    237     }
    238 
    239     if (DRSchip == 999999999) {
    240 
    241         if (verbose) {
    242             std::cout << "ERROR in PixelMap::Pixel_to_DRSchip: No pixel with name = "
    243                       << pixelname << " found in pixelmap" << std::endl;
    244         }
    245 
    246     }
    247 
    248     return DRSchip;
    249 
    250 }
    251 
    252 unsigned int PixelMap::Pixel_to_DRSchannel(std::string pixelname, bool verbose) {
    253 
    254     unsigned int DRSchannel = 999999999;
    255 
    256     for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
    257 
    258         if( ((*iter).first) == pixelname ){
    259             DRSchannel = ((*iter).second)->GetPixelDRSchannel();
     214    return PixelIDs;
     215
     216}
     217
     218unsigned int PixelMap::POS_to_Pixel(int POSx, int POSy, bool verbose) {
     219
     220    unsigned int pixelID = PM_ERROR_CODE;
     221
     222    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     223
     224        if( ( ((*iter).second)->GetPixelPOSx() == POSx ) &&
     225            ( ((*iter).second)->GetPixelPOSy() == POSy ) ) {
     226
     227            pixelID = (*iter).first;
     228
     229        }
     230
     231    }
     232
     233    if(pixelID == PM_ERROR_CODE){
     234       
     235        if (verbose) {
     236            std::cout << "ERROR in PixelMap::POS_to_Pixel: No pixel with position x, y = "
     237                      << POSx << ", "
     238                      << POSy << " found in pixelmap" << std::endl;
     239        }       
     240
     241    }
     242
     243    return pixelID;
     244
     245}
     246
     247unsigned int PixelMap::Pixel_to_FPAcrate(unsigned int pixelID, bool verbose) {
     248
     249    unsigned int FPAcrate = PM_ERROR_CODE;
     250
     251    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     252
     253        if( ((*iter).first) == pixelID ){
     254            FPAcrate = ((*iter).second)->GetPixelFPAcrate();
     255        }
     256
     257    }
     258
     259    if (FPAcrate == PM_ERROR_CODE) {
     260
     261        if (verbose) {
     262            std::cout << "ERROR in PixelMap::Pixel_to_FPAcrate: No pixel with ID = "
     263                      << pixelID << " found in pixelmap" << std::endl;
     264        }
     265
     266    }
     267
     268    return FPAcrate;
     269
     270}
     271
     272unsigned int PixelMap::Pixel_to_FPAboard(unsigned int pixelID, bool verbose) {
     273
     274    unsigned int FPAboard = PM_ERROR_CODE;
     275
     276    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     277
     278        if( ((*iter).first) == pixelID ){
     279            FPAboard = ((*iter).second)->GetPixelFPAboard();
     280        }
     281
     282    }
     283
     284    if (FPAboard == PM_ERROR_CODE) {
     285
     286        if (verbose) {
     287            std::cout << "ERROR in PixelMap::Pixel_to_FPAboard: No pixel with ID = "
     288                      << pixelID << " found in pixelmap" << std::endl;
     289        }
     290
     291    }
     292
     293    return FPAboard;
     294
     295}
     296
     297unsigned int PixelMap::Pixel_to_FPApatch(unsigned int pixelID, bool verbose) {
     298
     299    unsigned int FPApatch = PM_ERROR_CODE;
     300
     301    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     302
     303        if( ((*iter).first) == pixelID ){
     304            FPApatch = ((*iter).second)->GetPixelFPApatch();
     305        }
     306
     307    }
     308
     309    if (FPApatch == PM_ERROR_CODE) {
     310
     311        if (verbose) {
     312            std::cout << "ERROR in PixelMap::Pixel_to_FPApatch: No pixel with ID = "
     313                      << pixelID << " found in pixelmap" << std::endl;
     314        }
     315
     316    }
     317
     318    return FPApatch;
     319
     320}
     321
     322unsigned int PixelMap::Pixel_to_FPApixel(unsigned int pixelID, bool verbose) {
     323
     324    unsigned int FPApixel = PM_ERROR_CODE;
     325
     326    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     327
     328        if( ((*iter).first) == pixelID ){
     329            FPApixel = ((*iter).second)->GetPixelFPApixel();
    260330        }
    261331
    262332    }
    263333   
    264     if (DRSchannel == 999999999) {
    265 
    266         if (verbose) {
    267             std::cout << "ERROR in PixelMap::Pixel_to_DRSchannel: No pixel with name = "
    268                       << pixelname << " found in pixelmap" << std::endl;
    269         }
    270 
    271     }
    272 
    273     return DRSchannel;
    274 
    275 }
    276 
    277 unsigned int PixelMap::Pixel_to_HVboard(std::string pixelname, bool verbose) {
    278 
    279     unsigned int HVboard = 999999999;
    280 
    281     for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
    282 
    283         if( ((*iter).first) == pixelname ){
     334    if (FPApixel == PM_ERROR_CODE) {
     335
     336        if (verbose) {
     337            std::cout << "ERROR in PixelMap::Pixel_to_FPApixel: No pixel with ID = "
     338                      << pixelID << " found in pixelmap" << std::endl;
     339        }
     340
     341    }
     342
     343    return FPApixel;
     344
     345}
     346
     347unsigned int PixelMap::Pixel_to_HVcrate(unsigned int pixelID, bool verbose) {
     348
     349    unsigned int HVcrate = PM_ERROR_CODE;
     350
     351    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     352
     353        if( ((*iter).first) == pixelID ){
     354            HVcrate = ((*iter).second)->GetPixelHVcrate();
     355        }
     356
     357    }
     358
     359    if (HVcrate == PM_ERROR_CODE) {
     360
     361        if (verbose) {
     362            std::cout << "ERROR in PixelMap::Pixel_to_HVcrate: No pixel with ID = "
     363                      << pixelID << " found in pixelmap" << std::endl;
     364        }
     365
     366    }
     367
     368    return HVcrate;
     369
     370}
     371
     372unsigned int PixelMap::Pixel_to_HVboard(unsigned int pixelID, bool verbose) {
     373
     374    unsigned int HVboard = PM_ERROR_CODE;
     375
     376    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     377
     378        if( ((*iter).first) == pixelID ){
    284379            HVboard = ((*iter).second)->GetPixelHVboard();
    285380        }
     
    287382    }
    288383
    289     if (HVboard == 999999999) {
    290 
    291         if (verbose) {
    292             std::cout << "ERROR in PixelMap::Pixel_to_HVboard: No pixel with name = "
    293                       << pixelname << " found in pixelmap" << std::endl;
     384    if (HVboard == PM_ERROR_CODE) {
     385
     386        if (verbose) {
     387            std::cout << "ERROR in PixelMap::Pixel_to_HVboard: No pixel with ID = "
     388                      << pixelID << " found in pixelmap" << std::endl;
    294389        }
    295390
     
    300395}
    301396
    302 unsigned int PixelMap::Pixel_to_HVchain(std::string pixelname, bool verbose) {
    303 
    304     unsigned int HVchain = 999999999;
    305 
    306     for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
    307 
    308         if( ((*iter).first) == pixelname ){
    309             HVchain = ((*iter).second)->GetPixelHVchain();
    310         }
    311 
    312     }
    313 
    314     if (HVchain == 999999999) {
    315 
    316         if (verbose) {
    317             std::cout << "ERROR in PixelMap::Pixel_to_HVchain: No pixel with name = "
    318                       << pixelname << " found in pixelmap" << std::endl;
    319         }
    320 
    321     }
    322 
    323     return HVchain;
    324 
    325 }
    326 
    327 unsigned int PixelMap::Pixel_to_HVchannel(std::string pixelname, bool verbose) {
    328 
    329     unsigned int HVchannel = 999999999;
    330 
    331     for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
    332 
    333         if( ((*iter).first) == pixelname ){
     397unsigned int PixelMap::Pixel_to_HVchannel(unsigned int pixelID, bool verbose) {
     398
     399    unsigned int HVchannel = PM_ERROR_CODE;
     400
     401    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     402
     403        if( ((*iter).first) == pixelID ){
    334404            HVchannel = ((*iter).second)->GetPixelHVchannel();
    335405        }
     
    337407    }
    338408
    339     if (HVchannel == 999999999) {
    340 
    341         if (verbose) {
    342             std::cout << "ERROR in PixelMap::Pixel_to_HVchannel: No pixel with name = "
    343                       << pixelname << " found in pixelmap" << std::endl;
     409    if (HVchannel == PM_ERROR_CODE) {
     410
     411        if (verbose) {
     412            std::cout << "ERROR in PixelMap::Pixel_to_HVchannel: No pixel with ID = "
     413                      << pixelID << " found in pixelmap" << std::endl;
    344414        }
    345415
     
    349419
    350420}
     421
     422int PixelMap::Pixel_to_POSx(unsigned int pixelID, bool verbose) {
     423
     424    int POSx = PM_ERROR_CODE;
     425
     426    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     427
     428        if( ((*iter).first) == pixelID ){
     429            POSx = ((*iter).second)->GetPixelPOSx();
     430        }
     431
     432    }
     433
     434    if (POSx == (int)PM_ERROR_CODE) {
     435
     436        if (verbose) {
     437            std::cout << "ERROR in PixelMap::Pixel_to_POSx: No pixel with ID = "
     438                      << pixelID << " found in pixelmap" << std::endl;
     439        }
     440
     441   }
     442
     443    return POSx;
     444
     445}
     446
     447int PixelMap::Pixel_to_POSy(unsigned int pixelID, bool verbose) {
     448
     449    int POSy = PM_ERROR_CODE;
     450
     451    for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
     452
     453        if( ((*iter).first) == pixelID ){
     454            POSy = ((*iter).second)->GetPixelPOSy();
     455        }
     456
     457    }
     458
     459    if (POSy == (int)PM_ERROR_CODE) {
     460
     461        if (verbose) {
     462            std::cout << "ERROR in PixelMap::Pixel_to_POSy: No pixel with ID = "
     463                      << pixelID << " found in pixelmap" << std::endl;
     464        }
     465
     466   }
     467
     468    return POSy;
     469
     470}
  • fact/pixelmap/PixelMap.h

    r18 r10116  
    33
    44#include "Pixel.h"
     5#include <vector>
    56#include <map>
    67#include <string>
    7 #include <map>
    88
    99class PixelMap {
     
    1313public:
    1414   
    15     PixelMap(std::string file, bool verbose=false);
     15    static const unsigned int PM_ERROR_CODE = 999999999;
     16   
     17    PixelMap(std::string data, bool verbose=false);
    1618    ~PixelMap();
    1719   
    18     std::map<std::string, Pixel*> pixelmap;
     20    std::map<unsigned int, Pixel*> pixelmap;
    1921
    20     void ReadPixelMap(std::map<std::string, Pixel*>& pixelmap, std::string file, bool verbose=false);
     22    void ReadPixelMap(std::map<unsigned int, Pixel*>& pixelmap, std::string data, bool verbose=false);
    2123    void Print();
    2224
    23     std::string DRS_to_Pixel(unsigned int DRSboard, unsigned int DRSchip, unsigned int DRSchannel, bool verbose=false);
    24     std::string HV_to_Pixel(unsigned int HVboard, unsigned int HVchain, unsigned int HVchannel, bool verbose=false);
     25    unsigned int FPA_to_Pixel(unsigned int FPAcrate, unsigned int FPAboard, unsigned int FPApatch, unsigned int FPApixel, bool verbose=false);
     26    std::vector<unsigned int> HV_to_Pixel(unsigned int HVcrate, unsigned int HVboard, unsigned int HVchannel, bool verbose=false);
     27    unsigned int POS_to_Pixel(int POSx, int POSy, bool verbose=false);
    2528   
    26     unsigned int Pixel_to_DRSboard(std::string pixelname, bool verbose=false);
    27     unsigned int Pixel_to_DRSchip(std::string pixelname, bool verbose=false);
    28     unsigned int Pixel_to_DRSchannel(std::string pixelname, bool verbose=false);
     29    unsigned int Pixel_to_FPAcrate(unsigned int PixelID, bool verbose=false);
     30    unsigned int Pixel_to_FPAboard(unsigned int PixelID, bool verbose=false);
     31    unsigned int Pixel_to_FPApatch(unsigned int PixelID, bool verbose=false);
     32    unsigned int Pixel_to_FPApixel(unsigned int PixelID, bool verbose=false);
    2933
    30     unsigned int Pixel_to_HVboard(std::string pixelname, bool verbose=false);
    31     unsigned int Pixel_to_HVchain(std::string pixelname, bool verbose=false);
    32     unsigned int Pixel_to_HVchannel(std::string pixelname, bool verbose=false);
     34    unsigned int Pixel_to_HVcrate(unsigned int PixelID, bool verbose=false);
     35    unsigned int Pixel_to_HVboard(unsigned int PixelID, bool verbose=false);
     36    unsigned int Pixel_to_HVchannel(unsigned int PixelID, bool verbose=false);
     37
     38    int Pixel_to_POSx(unsigned int PixelID, bool verbose=false);
     39    int Pixel_to_POSy(unsigned int PixelID, bool verbose=false);
    3340
    3441};
  • fact/tools/pixelmap_test/PixelMapTest.cc

    r18 r10116  
    11//simple test program to check the PixelMap class
     2//Q. Weitzel, ETH Zurich, December 14, 2010
    23
    34#include "../../pixelmap/PixelMap.h"
    45#include <iostream>
    56
     7using namespace std;
     8
    69int main(){
    710
    8     std::cout << std::endl;
    9     std::cout << "==============================" << std::endl;
    10     std::cout << "PixelMap Test Program" << std::endl;
    11     std::cout << "==============================" << std::endl;
    12     std::cout << std::endl;
     11    cout << endl;
     12    cout << "==============================" << endl;
     13    cout << "PixelMap Test Program" << endl;
     14    cout << "==============================" << endl;
     15    cout << endl;
    1316
    14     PixelMap* pm = new PixelMap("Test_PixelMap.txt", true);
     17    cout << "Return value when asking for a non-existing pixel: " << PixelMap::PM_ERROR_CODE << endl;
     18    cout << endl;
    1519
     20    //PixelMap* pm = new PixelMap("", true);
     21    PixelMap* pm = new PixelMap("0:   0 0 0 0   0 2 0   0 0;   1:   0 0 0 1   0 0 1   -1 -1;   237:   0 0 0 2   0 0 1   0 -1;", true);
     22   
    1623    pm->Print();
    1724
    18     std::string drs1 = pm->DRS_to_Pixel(0,0,0,true);
    19     std::cout << "Name: " << drs1 << std::endl;
     25    unsigned int fpa;
     26    fpa = pm->FPA_to_Pixel(0,0,0,0,true);
     27    cout << "PixelID: " << fpa << endl;
     28    fpa = pm->FPA_to_Pixel(0,1,0,0,true);
     29    cout << "PixelID: " << fpa << endl;
     30    fpa = pm->FPA_to_Pixel(0,0,0,0,true);
     31    cout << "PixelID: " << fpa << endl;
    2032
    21     std::string drs2 = pm->DRS_to_Pixel(1,0,0,true);
    22     std::cout << "Name: " << drs2 << std::endl;
     33    vector<unsigned int> hv;
     34    hv = pm->HV_to_Pixel(6,1,8,true);
     35    cout << hv.size() << " PixelIDs found: ";
     36    for (unsigned int i=0; i < hv.size(); i++){cout << hv[i] << " ";}
     37    cout << endl;
     38    hv = pm->HV_to_Pixel(6,9,1,true);
     39    cout << hv.size() << " PixelIDs found: ";
     40    for (unsigned int i=0; i < hv.size(); i++){cout << hv[i] << " ";}
     41    cout << endl;
     42    hv = pm->HV_to_Pixel(0,0,1,true);
     43    cout << hv.size() << " PixelIDs found: ";
     44    for (unsigned int i=0; i < hv.size(); i++){cout << hv[i] << " ";}
     45    cout << endl;
     46    hv = pm->HV_to_Pixel(0,0,1,true);
     47    cout << hv.size() << " PixelIDs found: ";
     48    for (unsigned int i=0; i < hv.size(); i++){cout << hv[i] << " ";}
     49    cout << endl;
    2350
    24     std::string drs3 = pm->DRS_to_Pixel(0,0,0,true);
    25     std::cout << "Name: " << drs3 << std::endl;
     51    unsigned int pos;
     52    pos = pm->POS_to_Pixel(-1,-1,true);
     53    cout << "PixelID: " << pos << endl;
     54    pos = pm->POS_to_Pixel(-10,1,true);
     55    cout << "PixelID: " << pos << endl;
    2656
    27     std::string hv1 = pm->HV_to_Pixel(6,1,8,true);
    28     std::cout << "Name: " << hv1 << std::endl;
     57    unsigned int fpab;
     58    fpab = pm->Pixel_to_FPAboard(0,true);
     59    cout << "Board: " << fpab << endl;
     60    fpab = pm->Pixel_to_FPAboard(5,true);
     61    cout << "Board: " << fpab << endl;
    2962
    30     std::string hv2 = pm->HV_to_Pixel(6,9,1,true);
    31     std::cout << "Name: " << hv2 << std::endl;
     63    unsigned int hvboard;
     64    hvboard = pm->Pixel_to_HVboard(0,true);
     65    cout << "Board: " << hvboard << endl;
     66    hvboard = pm->Pixel_to_HVboard(5,true);
     67    cout << "Board: " << hvboard << endl;
    3268
    33     std::string hv3 = pm->HV_to_Pixel(1,0,0,true);
    34     std::cout << "Name: " << hv3 << std::endl;
    35 
    36     unsigned int drsb1 = pm->Pixel_to_DRSboard("0-1-1",true);
    37     std::cout << "Board: " << drsb1 << std::endl;
    38 
    39     unsigned int drsb2 = pm->Pixel_to_DRSboard("1-0-0",true);
    40     std::cout << "Board: " << drsb2 << std::endl;
    41 
    42     pm->Print();
    43 
    44     std::string drs4 = pm->DRS_to_Pixel(0,0,1,true);
    45     std::cout << "Name: " << drs4 << std::endl;
    46 
    47     unsigned int hvchain1 = pm->Pixel_to_HVchain("0-1-1",true);
    48     std::cout << "Chain: " << hvchain1 << std::endl;
    49 
    50     unsigned int hvchain2 = pm->Pixel_to_HVchain("1-0-0",true);
    51     std::cout << "Chain: " << hvchain2 << std::endl;
     69    int posy;
     70    posy = pm->Pixel_to_POSy(1,true);
     71    cout << "POSy: " << posy << endl;
     72    posy = pm->Pixel_to_POSy(15,true);
     73    cout << "POSy: " << posy << endl;
    5274
    5375    delete pm;
  • fact/tools/pixelmap_test/Test_PixelMap.txt

    r18 r10116  
    2525# pixel numbering: module-superpixel-pixel
    2626#
    27 ######################################################################
     27#######################################################################
    2828
    2929
    30 #Pixel:  DRS-board DRS-chip DRS-channel   HV board HV-chain HV-channel
    31 #---------------------------------------------------------------------
     30#Pixel:  DRS-board DRS-chip DRS-channel    HV-crate HV-board HV-channel
     31#----------------------------------------------------------------------
    32320-1-1:          0       0       0               0       2       0
    33330-1-2:          0       0       1               0       0       1
    343410-2-3:         7       8       6               6       9       1       
    35 #---------------------------------------------------------------------
     35#----------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.