otsdaq  v2_03_00
DetectorConfiguration_configuration.cc
1 #include <iostream>
2 #include "otsdaq-core/ConfigurationPluginDataFormats/DetectorTable.h"
3 #include "otsdaq-coreMacros/TablePluginMacros.h"
4 
5 using namespace ots;
6 
7 //==============================================================================
8 DetectorConfiguration::DetectorConfiguration(void) : TableBase("DetectorConfiguration")
9 {
11  // WARNING: the names and the order MUST match the ones in the enum //
13  // DetectorConfigurationInfo.xml
14  //<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
15  //<ROOT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
16  // xsi:noNamespaceSchemaLocation="TableInfo.xsd">
17  // <CONFIGURATION Name="DetectorConfiguration">
18  // <VIEW Name="DETECTOR_CONFIGURATION" Type="File,Database,DatabaseTest">
19  // <COLUMN Name="DetectorID" StorageName="DETECTOR_ID" DataType="VARCHAR2"/>
20  // <COLUMN Name="DetectorType" StorageName="DETECTOR_TYPE"
21  // DataType="VARCHAR2"/> <COLUMN Name="DetectorStatus"
22  // StorageName="DETECTOR_STATUS" DataType="VARCHAR2"/>
23  // </VIEW>
24  // </CONFIGURATION>
25  //</ROOT>
26 }
27 
28 //==============================================================================
29 DetectorConfiguration::~DetectorConfiguration(void) {}
30 
31 //==============================================================================
32 void DetectorConfiguration::init(ConfigurationManager* configManager)
33 {
34  nameToRow_.clear();
35  detectorIDs_.clear();
36  detectorTypes_.clear();
37  std::string tmpDetectorID;
38  std::map<std::string, bool> detectorTypes;
39  for(unsigned int row = 0; row < TableBase::activeTableView_->getNumberOfRows(); row++)
40  {
41  TableBase::activeTableView_->getValue(tmpDetectorID, row, DetectorID);
42  nameToRow_[tmpDetectorID] = row;
43  detectorTypes[TableBase::getView().getDataView()[row][DetectorType]] = true;
44  detectorIDs_.push_back(tmpDetectorID);
45  }
46  for(auto& it : detectorTypes)
47  detectorTypes_.push_back(it.first);
48 }
49 
50 //==============================================================================
51 const std::vector<std::string>& DetectorConfiguration::getDetectorIDs() const
52 {
53  return detectorIDs_;
54 }
55 
56 //==============================================================================
57 const std::vector<std::string>& DetectorConfiguration::getDetectorTypes() const
58 {
59  return detectorTypes_;
60 }
61 
62 //==============================================================================
63 const std::string& DetectorConfiguration::getDetectorType(
64  const std::string& detectorID) const
65 {
66  return TableBase::getView()
67  .getDataView()[nameToRow_.find(detectorID)->second][DetectorType];
68 }
69 
70 //==============================================================================
71 const std::string& DetectorConfiguration::getDetectorStatus(
72  const std::string& detectorID) const
73 {
74  return TableBase::getView()
75  .getDataView()[nameToRow_.find(detectorID)->second][DetectorStatus];
76 }
77 
78 DEFINE_OTS_CONFIGURATION(DetectorConfiguration)