Locked History Actions

attachment:TArtParameters.cc of ANAROOT/掲示板

Attachment 'TArtParameters.cc'

Download

#include "TArtParameters.hh"

#include "TArtCore.hh"
#include "TArtStoreManager.hh"

#include <TDOMParser.h>
#include <TXMLNode.h>

#include <stdlib.h>
#include <iostream>

using namespace std;
TArtParameters* TArtParameters::fParameters = 0;

//__________________________________________________________
TArtParameters::TArtParameters(const char* name, const char* title)
  : TNamed(name, title)
{
  TArtCore::Info(__FILE__,"Creating parameters...");
  fStoreManager = TArtStoreManager::Instance();
  fStoreManager->AddParameters(this);
}
//__________________________________________________________
TArtParameters::~TArtParameters() 
{
  fParameters = 0;
}
//__________________________________________________________
TArtParameters* TArtParameters::Instance(const char* name, const char* title)
{
  if(!fParameters) fParameters = new TArtParameters(name, title);
  return fParameters;
}    

//__________________________________________________________
void TArtParameters::Delete()
{
  delete fParameters;
  fParameters = 0;  
}
//__________________________________________________________
Bool_t TArtParameters::LoadParameter(const char *xmlfile)
{
  TArtCore::Info(__FILE__,"Load parameter from %s", xmlfile);
  TDOMParser domParser;
  domParser.SetValidate(false);
  Int_t parsecode = domParser.ParseFile(xmlfile);
  if(parsecode < 0){
    std::cerr << domParser.GetParseCodeMessage(parsecode) << std::endl;
    return false;
  }
  TXMLNode* node = domParser.GetXMLDocument()->GetRootNode();
  ParseParaList(node->GetChildren());
  return true;
}
//__________________________________________________________
void TArtParameters::ParseParaList(TXMLNode *node)
{
  for(; node; node = node->GetNextNode()){
    if(node->GetNodeType() != TXMLNode::kXMLElementNode) continue; // Element Node

    if(strcmp(node->GetNodeName(), "PARAMETER") == 0)
      ParsePara(node->GetChildren());
    else 
      TArtCore::Info(__FILE__,"Unknown Parameter %s.",node->GetNodeName());
  }
}
//__________________________________________________________
void TArtParameters::ParsePara(TXMLNode *node)
{
  TString name;
  TString type;
  TString svalue;

  for ( ; node; node = node->GetNextNode()) {
    if (node->GetNodeType() == TXMLNode::kXMLElementNode) { // Element Node

      if (strcmp(node->GetNodeName(), "name") == 0)
        name = node->GetText();
      else if (strcmp(node->GetNodeName(), "type") == 0)
        type = node->GetText();
      else if (strcmp(node->GetNodeName(), "value") == 0)
        svalue = node->GetText();
    }
  }

  if (type == "int" || type=="Int_t"){
    if (svalue.IsDigit())
      imap.insert(std::pair<TString,Int_t>(name,svalue.Atoi()) );
    else
      TArtCore::Info(__FILE__,"type %s is invalid for %s (value = %s).",type.Data(),name.Data(),svalue.Data());
  }

  else if (type == "double" || type=="Double_t"){
    if (svalue.IsFloat())
      dmap.insert(std::pair<TString,Double_t>(name,svalue.Atof()) );
    else
      TArtCore::Info(__FILE__,"type %s is invalid for %s (value = %s).",type.Data(),name.Data(),svalue.Data());
  }

  else if (type == "string" || type=="TString"){
    smap.insert(std::pair<TString,TString>(name,svalue) );
  }

  else
    TArtCore::Info(__FILE__,"Unknown parameter type %s for %s.",type.Data(),name.Data());

}
//_____________________________________________________________________
void TArtParameters::PrintPara(){

  std::map<TString, Int_t>::iterator i_itr;
  TArtCore::Info(__FILE__,"Parameters (Int_t)");
  for (i_itr=imap.begin();i_itr!=imap.end();i_itr++)
    std::cout<<i_itr->first<<" = "<<i_itr->second<<std::endl;

  std::map<TString, Double_t>::iterator d_itr;
  TArtCore::Info(__FILE__,"Parameters (Double_t)");
  for (d_itr=dmap.begin();d_itr!=dmap.end();d_itr++)
    std::cout<<d_itr->first<<" = "<<d_itr->second<<std::endl;

  std::map<TString, TString>::iterator s_itr;
  TArtCore::Info(__FILE__,"Parameters (TString)");
  for (s_itr=smap.begin();s_itr!=smap.end();s_itr++)
    std::cout<<s_itr->first<<" = "<<s_itr->second<<std::endl;
}
//_____________________________________________________________________
const Int_t TArtParameters::FindIntPara(const TString str) const
{
  std::map<TString, Int_t>::const_iterator itr = imap.find(str);
  if(itr != imap.end()) return itr->second;
  else return 0;
}
//_____________________________________________________________________
const Double_t TArtParameters::FindDoublePara(const TString str) const
{
  std::map<TString, Double_t>::const_iterator itr = dmap.find(str);
  if(itr != dmap.end()) return itr->second;
  else return 0;
}
//_____________________________________________________________________
const TString TArtParameters::FindStringPara(const TString str) const
{
  std::map<TString, TString>::const_iterator itr = smap.find(str);
  if(itr != smap.end()) return itr->second;
  else return "";
}
//_____________________________________________________________________

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2012-10-17 06:59:08, 278.1 KB) [[attachment:ANAROOT講習会資料.pdf]]
  • [get | view] (2013-06-25 06:26:53, 0.5 KB) [[attachment:CounterExample.cc]]
  • [get | view] (2012-10-17 06:53:24, 1.6 KB) [[attachment:MakePlaHist.C]]
  • [get | view] (2012-08-20 06:37:41, 6.2 KB) [[attachment:TArtCSVParameter.cc]]
  • [get | view] (2012-08-20 06:37:53, 1.0 KB) [[attachment:TArtCSVParameter.hh]]
  • [get | view] (2013-06-25 06:26:20, 5.3 KB) [[attachment:TArtCounter.cc]]
  • [get | view] (2013-06-25 06:26:40, 1.2 KB) [[attachment:TArtCounter.hh]]
  • [get | view] (2012-11-29 12:05:55, 4.8 KB) [[attachment:TArtParameters.cc]]
  • [get | view] (2012-11-29 12:05:35, 1.0 KB) [[attachment:TArtParameters.hh]]
  • [get | view] (2012-12-04 15:34:16, 6.3 KB) [[attachment:TArtUserParameters.cc]]
  • [get | view] (2012-12-04 15:34:00, 1.6 KB) [[attachment:TArtUserParameters.hh]]
  • [get | view] (2012-12-04 15:34:38, 1.6 KB) [[attachment:UserParameters.xml]]
  • [get | view] (2012-04-19 08:38:22, 3.0 KB) [[attachment:ana-mode.el]]
  • [get | view] (2012-04-20 03:38:36, 2.7 KB) [[attachment:anaroot_filter.ver1.00.jar]]
  • [get | view] (2012-06-04 04:07:52, 2.6 KB) [[attachment:anaroot_filter.ver1.01.jar]]
  • [get | view] (2012-06-01 17:27:17, 4.7 KB) [[attachment:calc2xml.v2.xsl]]
  • [get | view] (2012-04-20 03:33:51, 6.3 KB) [[attachment:calc2xml.xsl]]
  • [get | view] (2012-10-17 07:32:11, 1.0 KB) [[attachment:install-example.txt]]
  • [get | view] (2012-11-29 12:06:11, 1.0 KB) [[attachment:parameters.xml]]
  • [get | view] (2012-04-20 03:33:17, 3.1 KB) [[attachment:xml2calc.xsl]]

You are not allowed to attach a file to this page.