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