Skip to content

Developer's guide

nsoblath edited this page Oct 17, 2012 · 9 revisions

Concepts

Event

Data

Processor

Configuring a KTConfigurable

All classes that are able to be configured via the configuration system should inherit from KTConfigurable. KTConfigurables have a member function Configure(const KTPStoreNode*) that is used to perform the configuration of the KTConfigurable instance. The KTPStoreNode pointer that is passed to the instance should be the branch of the configuration tree that is relevant to that instance. It can then process that branch in any way it sees fit.

Patterns for configuring a KTConfigurable

Here are some examples of code that has been used to configure different KTConfigurable classes in Katydid. This is an incomplete list, and if new ways are developed, they should be added here.

  • Basic method for getting information from the tree, for the available data types (an exception is thrown if the data cannot be cast to the requested type, or if the data doesn't exist):

      std::string stringData = node->GetData< std::string >("string-data")
      Int_t intData = node->GetData< Int_t >("int-data")
      Double_t floatData = node->GetData< Double_t >("float-data")
      Bool_t boolData = node->GetData< Bool_t >("bool-data")
    
  • Data can be accessed with a default to make setting optional (from KTEggProcessor):

      SetNEvents(node->GetData< UInt_t >("number-of-events", fNEvents));
    
  • Optional setting with limited possibilities (from KTEggProcessor)

      string eggReaderTypeString = node->GetData< string >("egg-reader", "monarch");
      if (eggReaderTypeString == "monarch") SetEggReaderType(kMonarchEggReader);
      else if (eggReaderTypeString == "2011") SetEggReaderType(k2011EggReader);
      else
      {
          KTERROR(egglog, "Illegal string for egg reader type: <" << eggReaderTypeString << ">");
          return false;
      }
    
  • Require that a setting is present (from KTProcessorToolbox)

      if (! subNode.HasData("type"))
      {
          KTERROR(proclog, "Unable to create processor: no processor type given");
          return false;
      }
      string procType = subNode.GetData("type");
    
  • Iterate over all settings in a child tree (from KTProcessorToolbox)

      for (KTPStoreNode::const_iterator iter = subNodePtr->Begin(); iter != subNodePtr->End(); iter++)
      {
          string procName = iter->second.get_value< string >("processor");
          KTProcessor* procForRunQueue = GetProcessor(procName);
          /* . . . */
      }
    
  • Iterate over multiple settings with the same name (from KTProcessorToolbox)

      KTPStoreNode::csi_pair itPair = node->EqualRange("processor");
      for (KTPStoreNode::const_sorted_iterator it = itPair.first; it != itPair.second; it++)
      {
          KTPStoreNode subNode = KTPStoreNode(&(it->second));
    
          /* extract information from subNode */
      }
    
  • Nested configuration option 1: process the child tree (from KTProcessorToolbox)

      const KTPStoreNode* subNodePtr = node->GetChild("run-queue");
      if (subNodePtr != NULL)
      {
          /* extract configuration information from subNodePtr */
      }
    
  • Nested configuration option 2: to get a child tree and use it to configure a member (from KTFFTEHunt)

      const KTPStoreNode* clusterNode = node->GetChild("simple-clustering");
      if (clusterNode != NULL)
      {
          if (! fClustering.Configure(clusterNode)) return false;
      }
    
Clone this wiki locally