Changeset 15214 for trunk


Ignore:
Timestamp:
03/31/13 12:07:46 (12 years ago)
Author:
tbretz
Message:
Moved a lot of code to the header file, removed dependencies from FACT++ and the need of a source file.
Location:
trunk/Mars/mcore
Files:
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mcore/PixelMap.cc

    r15212 r15214  
    1 #include "PixelMap.h"
    2 
    3 #ifdef __EXCEPTIONS
    4 #include <stdexcept>
    5 #endif
    6 
    7 #ifdef __MARS__
    8 #include "MLog.h"
    9 #include "MLogManip.h"
    10 #endif
     1#include "externals/PixelMap.h"
    112
    123using namespace std;
    134
    14 const PixelMapEntry PixelMap::empty = { -1, 0, 0, 0, 0 };
    15 const BiasMapEntry  BiasMap::empty  = { -1, 0, 0, 0 };
    16 
    17 bool BiasMap::Read(const std::string &fname)
    18 {
    19     std::ifstream fin(fname);
    20 
    21     int l = 0;
    22 
    23     std::string buf;
    24     while (getline(fin, buf, '\n'))
    25     {
    26         if (l>416)
    27             break;
    28 
    29         buf = Tools::Trim(buf);
    30         if (buf[0]=='#')
    31             continue;
    32 
    33         std::stringstream str(buf);
    34 
    35         BiasMapEntry entry;
    36 
    37         str >> entry.hv_board;
    38         str >> entry.hv_channel;
    39         str >> entry.Vnom;
    40         str >> entry.Voff;
    41 
    42 #ifdef __EXCEPTIONS
    43         if (entry.hv_channel+32*entry.hv_board>=416)
    44             throw runtime_error("Invalid board/channel read from "+fname+".");
    45 #endif
    46 #ifdef __MARS__
    47         if (entry.hv_channel+32*entry.hv_board>=416)
    48         {
    49             gLog << err << "Invalid board/channel read from " << fname << "." << endl;
    50             return false;
    51         }
    52 #endif
    53 
    54         (*this)[entry.hv()] = entry;
    55 
    56         l++;
    57     }
    58 
    59 #ifdef __EXCEPTIONS
    60     if (l!=416)
    61         throw runtime_error("Number of lines read from "+fname+" does not match 416.");
    62 
    63     if (size()!=416)
    64         throw runtime_error("Number of entries read from "+fname+" does not match 416.");
    65 #endif
    66 
    67 #ifdef __MARS__
    68     if (l!=416)
    69     {
    70         gLog << err  << "Number of lines read from " << fname << " does not match 416." << endl;
    71         return false;
    72     }
    73 
    74     if (size()!=416)
    75     {
    76         gLog << "Number of entries read from " << fname << " does not match 416." << endl;
    77         return false;
    78     }
    79 #endif
    80 
    81     return true;
    82 }
    83 
    84 #ifndef __MARS__
    855#include <boost/regex.hpp>
    866#include <mysql++/mysql++.h>
     
    14868        throw runtime_error("Number of entries retrived from database does not match 416.");
    14969}
    150 #endif
  • trunk/Mars/mcore/PixelMap.h

    r15212 r15214  
    77#include <sstream>
    88
    9 #include "tools.h"
    10 
    119#ifdef DEBUG
    1210#include <iostream>  // cerr -- to be removed?
     11#endif
     12
     13#ifdef __EXCEPTIONS
     14#include <stdexcept>
     15#endif
     16
     17#ifdef __MARS__
     18#include "MLog.h"
     19#include "MLogManip.h"
    1320#endif
    1421
     
    2229//    float Vgapd;               /// gAPD Bias voltage
    2330    int   hv_board;            /// Bias suppply board
    24     int   hv_channel;          /// Bias supply channel
     31    int   hv_channel;
     32
     33    PixelMapEntry() : index(-1) { } /// Bias supply channel
    2534
    2635    int crate() const { return cbpx/1000; }
     
    3342
    3443    operator bool() const { return index>=0; }
     44
     45    static const PixelMapEntry &empty() { const static PixelMapEntry e; return e; }
    3546};
    3647
     
    3849{
    3950public:
    40     static const PixelMapEntry empty;
    41 
    4251    PixelMap() : std::vector<PixelMapEntry>(1440)
    4352    {
     
    5665                break;
    5766
    58             buf = Tools::Trim(buf);
    59             if (buf[0]=='#')
     67            buf.erase(buf.find_last_not_of(' ')+1);         //surfixing spaces
     68            buf.erase(0, buf.find_first_not_of(' '));       //prefixing spaces
     69 
     70            if (buf.empty() || buf[0]=='#')
    6071                continue;
    6172
     
    101112        std::cerr << "PixelMap: index " << idx << " not found" << std::endl;
    102113#endif
    103         return empty;
     114        return PixelMapEntry::empty();
    104115    }
    105116
     
    112123        std::cerr << "PixelMap: cbpx " << c << " not found" << std::endl;
    113124#endif
    114         return empty;
     125        return PixelMapEntry::empty();
    115126    }
    116127
     
    133144        std::cerr << "PixelMap: hv " << board << "/" << channel << " not found" << std::endl;
    134145#endif
    135         return empty;
     146        return PixelMapEntry::empty();
    136147    }
    137148
     
    192203    float Voff;                /// Channel bias voltage offset
    193204
     205    BiasMapEntry() : hv_board(-1) { }
     206
    194207    int hv() const { return hv_channel+hv_board*32; }
     208
     209    operator bool() const { return hv_board>=0; }
     210
     211    static const BiasMapEntry &empty() { const static BiasMapEntry e; return e; }
    195212};
    196213
     
    198215{
    199216public:
    200     static const BiasMapEntry empty;
    201 
    202217    BiasMap() : std::vector<BiasMapEntry>(416)
    203218    {
     
    207222    void Retrieve(const std::string &database);
    208223#endif
    209     bool Read(const std::string &fname);
     224    bool Read(const std::string &fname)
     225    {
     226        std::ifstream fin(fname);
     227
     228        int l = 0;
     229
     230        std::string buf;
     231        while (getline(fin, buf, '\n'))
     232        {
     233            if (l>416)
     234                break;
     235
     236            buf.erase(buf.find_last_not_of(' ')+1);         //surfixing spaces
     237            buf.erase(0, buf.find_first_not_of(' '));       //prefixing spaces
     238
     239            if (buf.empty() || buf[0]=='#')
     240                continue;
     241
     242            std::stringstream str(buf);
     243
     244            BiasMapEntry entry;
     245
     246            str >> entry.hv_board;
     247            str >> entry.hv_channel;
     248            str >> entry.Vnom;
     249            str >> entry.Voff;
     250
     251#ifdef __EXCEPTIONS
     252            if (entry.hv_channel+32*entry.hv_board>=416)
     253                throw std::runtime_error("Invalid board/channel read from "+fname+".");
     254#endif
     255#ifdef __MARS__
     256            if (entry.hv_channel+32*entry.hv_board>=416)
     257            {
     258                gLog << err << "Invalid board/channel read from " << fname << "." << endl;
     259                return false;
     260            }
     261#endif
     262
     263            (*this)[entry.hv()] = entry;
     264
     265            l++;
     266        }
     267
     268#ifdef __EXCEPTIONS
     269        if (l!=416)
     270            throw std::runtime_error("Number of lines read from "+fname+" does not match 416.");
     271
     272        if (size()!=416)
     273            throw std::runtime_error("Number of entries read from "+fname+" does not match 416.");
     274#endif
     275
     276#ifdef __MARS__
     277        if (l!=416)
     278        {
     279            gLog << err  << "Number of lines read from " << fname << " does not match 416." << endl;
     280            return false;
     281        }
     282
     283        if (size()!=416)
     284        {
     285            gLog << "Number of entries read from " << fname << " does not match 416." << endl;
     286            return false;
     287        }
     288#endif
     289
     290        return true;
     291    }
    210292
    211293    const BiasMapEntry &hv(int board, int channel) const
     
    217299        std::cerr << "PixelMap: hv " << board << "/" << channel << " not found" << std::endl;
    218300#endif
    219         return empty;
     301        return BiasMapEntry::empty();
    220302    }
    221303
Note: See TracChangeset for help on using the changeset viewer.