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