RPD.cpp 3.07 KB
Newer Older
clantz's avatar
clantz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
/** @file RPD.cpp
 *  @brief Implementation of RPD.
 *
 *  Function definitions for RPD are provided. 
 *  This is a daughter class of Detector.
 *  Methods specific to RPDs are implemented here.
 *
 *  @author Chad Lantz
 *  @bug No known bugs.
 */

#include "RPD.h"

14
15
#include <string>
#include <stdio.h>
clantz's avatar
clantz committed
16
17
18
19

/** @brief Default Constructor for RPD.
 */
RPD::RPD( ){
20

clantz's avatar
clantz committed
21
22
}

23
24
25
26
27
/** @brief Constructor that takes the whole vector of channels readout and selects and stores only the RPD ones
*/

RPD::RPD( std::vector < Channel* > _readOut){

28
    ResizeSortedElements();
29
30
31
    for(int row=0; row<nRows; row++){
        for(int column; column<nColumns; column++){
            m_SortedElements[row][column]=GetElement(row,column);
32
33
        }
    }
34
35

    std::cout << "RPD object created with " << nRows << " rows and " << nColumns << " columns" << std::endl;
36
37
}

clantz's avatar
clantz committed
38
39
40
41
42
43
/** @brief Destructor for RPD.
 */
RPD::~RPD( ){

}

44
45
46
47
48
49
50
51
52
/** @brief Get the properties of a detector element
 *
 * If m_SortedElements is populated, return the element in 
 * m_SortedElements[row][column].
 * Otherwise returns a pointer to the Channel stored in m_Element 
 * with the requested row and column.
 * If the requested element is not found, return a warning message and a NULL pointer.
 * 
 */
53
Channel* RPD::GetElement(int row, int column){
54
55
56
    
    if((int)m_SortedElements.size()==nElements){ return m_SortedElements[row][column];
    }else{
57
58
59
        for(int i=0; i < (int)GetChannelsVector().size(); i++){
            if(row == GetChannelsVector().at(i)->mapping_row && column == GetChannelsVector().at(i)->mapping_column){
            return GetChannelsVector().at(i);
60
61
62
63
64
65
66
67
            }
        }
     }
  std::cerr << " WARNING: Element (" << row << "," << column << ") not found! " << std::endl;
  return nullptr;
    
}

clantz's avatar
clantz committed
68
69
70
71
72
73
74
75
/** @brief Prints a map of the RPD to the terminal
 *
 * Prints the map of a 4x4 RPD.
 * Displays a grid of elements with row,column on the top line, DRS4
 * Channel on the second line, and if the element is functioning on the
 * third line.
 * 
 */
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
void RPD::PrintMap(){
  std::cout << " ___________________________________ " << std::endl;
  //RPD has 4 rows and 4 columns
  for(int row = 1; row <= 4; row++){
      Channel* c[4];
      std::string status, name;
      for(int cln = 1; cln <= 4; cln++){
          
          c[cln] = GetElement(row,cln);
          if(c[cln]->is_on) status = "ON";
              else status = "OFF";
          if (cln == 1) std::cout << "|  " << row << "," << cln << " --> " << c[cln]->name << " , " << status;
          else std::cout << "  |  " << row << "," << cln << " --> " << c[cln]->name << " , " << status;
          
        }//End of the loop over columns
      }//End of the loop over rows
clantz's avatar
clantz committed
92
}
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

/** @brief Resizes m_SortedElements
 *
 * Uses nRows and nColumns to resize m_SortedElements
 * 2D vectors must have columns sized individually.
 * 
 */
void RPD::ResizeSortedElements(){
    m_SortedElements.resize(nRows);
    for(int row=0; row < nRows; row++){
        m_SortedElements.resize(nColumns);
    }
}