otsdaq  v2_05_02_indev
FESlowControlsTable_table.cc
1 #include "otsdaq/Macros/TablePluginMacros.h"
2 #include "otsdaq/TablePlugins/FESlowControlsTable.h"
3 
4 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
5 
6 #include <iostream>
7 
8 using namespace ots;
9 
10 //==============================================================================
11 FESlowControlsTable::FESlowControlsTable(void) : TableBase("FESlowControlsTable") {}
12 
13 //==============================================================================
14 FESlowControlsTable::~FESlowControlsTable(void) {}
15 
16 //==============================================================================
17 // init
18 // Validates user inputs for data type.
19 void FESlowControlsTable::init(ConfigurationManager* configManager)
20 {
21  // use isFirstAppInContext to only run once per context, for example to avoie
22  // generating files on local disk multiple times.
23  bool isFirstAppInContext = configManager->isOwnerFirstAppInContext();
24 
25  __COUTV__(isFirstAppInContext);
26  if(!isFirstAppInContext)
27  return;
28 
29  // check for valid data types
30  __COUT__ << "*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl;
31  __COUT__ << configManager->__SELF_NODE__ << std::endl;
32 
33  // __COUT__ << configManager->getNode(this->getTableName()).getValueAsString()
34  // << std::endl;
35 
36  std::string childType;
37  std::vector<std::pair<std::string, ConfigurationTree>> childrenMap = configManager->__SELF_NODE__.getChildren();
38  for(auto& childPair : childrenMap)
39  {
40  // check each row in table
41  __COUT__ << childPair.first << std::endl;
42  childPair.second.getNode(colNames_.colDataType_).getValue(childType);
43  __COUT__ << "childType=" << childType << std::endl;
44 
45  if(childType[childType.size() - 1] == 'b') // if ends in 'b' then take that many bits
46  {
47  unsigned int sz;
48  sscanf(&childType[0], "%u", &sz);
49  if(sz < 1 || sz > 64)
50  {
51  __SS__ << "Data type '" << childType << "' for UID=" << childPair.first << " is invalid. "
52  << " The bit size given was " << sz << " and it must be between 1 and 64." << std::endl;
53  __COUT_ERR__ << "\n" << ss.str();
54  __SS_THROW__;
55  }
56  }
57  else if(childType != TableViewColumnInfo::DATATYPE_STRING_DEFAULT && childType != "char" && childType != "unsigned char" && childType != "short" &&
58  childType != "unsigned short" && childType != "int" && childType != "unsigned int" && childType != "long long " &&
59  childType != "unsigned long long" && childType != "float" && childType != "double")
60  {
61  __SS__ << "Data type '" << childType << "' for UID=" << childPair.first << " is invalid. "
62  << "Valid data types (w/size in bytes) are as follows: "
63  << "#b (# bits)"
64  << ", char (" << sizeof(char) << "B), unsigned char (" << sizeof(unsigned char) << "B), short (" << sizeof(short) << "B), unsigned short ("
65  << sizeof(unsigned short) << "B), int (" << sizeof(int) << "B), unsigned int (" << sizeof(unsigned int) << "B), long long ("
66  << sizeof(long long) << "B), unsigned long long (" << sizeof(unsigned long long) << "B), float (" << sizeof(float) << "B), double ("
67  << sizeof(double) << "B)." << std::endl;
68  __COUT_ERR__ << "\n" << ss.str();
69  __SS_THROW__;
70  }
71  }
72 } // end init()
73 
74 DEFINE_OTS_TABLE(FESlowControlsTable)