otsdaq  v1_01_03
 All Classes Namespaces Functions
RegisterBase.cpp
1 /*
2  * RegisterBase.cpp
3  *
4  * Created on: Jul 29, 2015
5  * Author: parilla
6  */
7 
8 #include "otsdaq-core/ConfigurationDataFormats/RegisterBase.h"
9 #include "otsdaq-core/ConfigurationDataFormats/RegisterConfigurationInfoReader.h"
10 #include "otsdaq-core/ConfigurationDataFormats/RegisterSequencerInfoReader.h"
11 
12 #include <algorithm>
13 
14 using namespace ots;
15 
16 RegisterBase::RegisterBase(std::string configurationName, std::string componentType) :
17  ConfigurationBase(configurationName)
18  ,componentTypeName_ (componentType)
19 {
20 
21  RegisterConfigurationInfoReader configurationInfoReader;
22  configurationInfoReader.read(this);
23 
24  RegisterSequencerInfoReader sequencerInfoReader;
25  sequencerInfoReader.read(this);
26 
27  init();
28 }
29 
30 RegisterBase::~RegisterBase() {
31  // TODO Auto-generated destructor stub
32 }
33 //==============================================================================
34 void RegisterBase::init(void)
35 {
36  theComponentList_.clear();
37 
38  //Loop through each component via the sequencer and add them to theComponentList_
39  for(auto it : *mockupRegisterView_.getRegistersSequencerInfoPointer())
40  {
41  // if(theComponentList_.find(it->getComponentName()) != theComponentList_.end())
42  //the insert function will have no effect if it already finds the key (component name) in theComponentList_; otherwise, let's add it
43  theComponentList_.insert(std::make_pair(it.getComponentName(), Component(it.getComponentName())));
44  //theComponentList_ now atleast contains the component, now lets set the state that we are looking at
45  auto regs = theComponentList_.find(it.getComponentName())->second.getRegistersPointer();
46  std::find_if(regs->begin(), regs->end(),[it](auto r){return r.getName() == it.getRegisterName();})->setState(it.getState(), it.getValueSequencePair());
47 
48  }
49  //Iterate through our newly-filled theComponentList_
50  for(auto aComponent : theComponentList_) {
51  //Iterate through each register of the component
52  for(auto registerFromConfiguration : *aComponent.second.getRegistersPointer())
53  {
54  //Iterate through MockupView of the xxxRegisterConfiguration.xml
55  for(auto aRegister : *mockupRegisterView_.getRegistersInfoPointer())
56  {
57  //If the Register names match
58  if(aRegister.getRegisterName() == registerFromConfiguration.getName()
59  //&& aRegister.getComponentName() == registerFromConfiguration.getComponentName()
60  ){
61  registerFromConfiguration.fillRegisterInfo(aRegister.getBaseAddress(), aRegister.getSize(), aRegister.getAccess());
62  }
63  }
64  }
65  }
66 
67 //Print for Debugging
68  for(auto aComponent : theComponentList_) {
69  aComponent.second.printInfo();
70  }
71 
72 
73  //create new instance of "Component" and add to "theComponentList_; set Name according to XML
74  //tempComponent = new Component(FROM_XML);
75  //mockupRegisterView_.getRegistersInfoPointer();
76  //theComponent_ = new Component(componentNameType_);
77 
78  //Add component based on sequencer XML
79 
80  /*
81  for(std::vector<ViewRegisterInfo>::iterator it = mockupRegisterView_.getRegistersInfoPointer().begin(); it != mockupRegisterView_.getRegistersInfoPointer().end(); ++it){
82 
83  if(it->getTypeName == componentNameType_)
84  {
85  //Check the Component's "type_name"
86  //Accordingly create instances of "Register" based on Configuration XML and add to Component
87  theComponent_.addRegister(it->getregisterName(), it->getBaseAddress, it->getSize(), it->getAccess);
88 
89  }
90  }*/
91 
92 
93  //Fill the Registers based on the Sequencer XML File
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 /*
104  std::string tmpDetectorID;
105  std::string tmpDACName;
106  unsigned int tmpDACValue;
107  for(unsigned int row=0; row<activeRegisterView_->getNumberOfRows(); row++)
108  {
109  activeRegisterView_->getValue(tmpDetectorID,row,rocNameColumn_);
110  nameToROCDACsMap_[tmpDetectorID] = ROCDACs();
111  ROCDACs& aROCDACs = nameToROCDACsMap_[tmpDetectorID];
112  for(unsigned int col=firstDAC_; col<=lastDAC_; col++)*/
113 /*
114  theComponentList_.pushback()
115  {
116  activeRegisterView_->getValue(tmpDACValue,row,col);
117  tmpDACName = activeRegisterView_->getColumnInfo(col).getName();
118  aROCDACs.setDAC(tmpDACName,dacNameToDACAddress_[tmpDACName],tmpDACValue);
119  //std::cout << __COUT_HDR_FL__ << "DAC. Name: " << tmpDACName << " addr: " << dacNameToDACAddress_[tmpDACName] << " val: " << tmpDACValue << std::endl;
120  }
121  }*/
122 }
123 //==============================================================================
124 const RegisterView& RegisterBase::getRegisterView() const
125 {
126  return *activeRegisterView_;
127 }
128 
129 //==============================================================================
130 RegisterView* RegisterBase::getRegisterViewPointer()
131 {
132  return activeRegisterView_;
133 }
134 
135 //==============================================================================
136 RegisterView* RegisterBase::getMockupRegisterViewPointer()
137 {
138  return &mockupRegisterView_;
139 }
140 //==============================================================================
141 std::string RegisterBase::getTypeName()
142 {
143  return componentTypeName_;
144 }