AliPhysics  vAN-20151012 (2287573)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliEMCALConfigHandler.cxx
Go to the documentation of this file.
1 /*
2  * AliEMCALConfigHandler.cxx
3  *
4  * Created on: 06.11.2014
5  * Author: markusfasel
6  */
7 
8 #include <sstream>
9 #include <TList.h>
10 
11 #include "AliEMCALConfigHandler.h"
12 #include "AliEMCALConfiguration.h"
13 #include "AliJSONData.h"
14 
16 
18  TObject(),
19  fConfiguration(NULL)
20 {
21  fConfiguration = new TList;
22  fConfiguration->SetOwner();
23 }
24 
26  delete fConfiguration;
27 }
28 
31  if(config)
32  this->Error("AliEMCALConfigHandler::CreateConfiguration", "Configuration with name %s already exists, not duplicating", name);
33  else{
34  config = new AliEMCALConfiguration(name);
35  fConfiguration->Add(config);
36  }
37  return config;
38 }
39 
40 void AliEMCALConfigHandler::AddParam(const char* configName, const char* key,
41  AliJSONValue* value) {
42  AliEMCALConfiguration *config = FindConfiguration(configName);
43  if(!config){
44  this->Warning("AliEMCALConfigHandler", "Configuration with name %s does not exist, creating it", configName);
45  config = CreateConfiguration(configName);
46  }
47  config->AddParam(key, value);
48 }
49 
51  std::stringstream jsonbuilder;
52  jsonbuilder << "{";
53  TIter confentries(fConfiguration);
54  bool isFirst = true;
55  for(TIter it = confentries.Begin(); it != confentries.End(); ++it){
56  AliEMCALConfiguration *conf = static_cast<AliEMCALConfiguration *>(*it);
57  if(!isFirst) jsonbuilder << ",";
58  jsonbuilder << "\"" << conf->GetName() << "\":" << conf->CreateJSONString();
59  if(isFirst) isFirst = false;
60  }
61  jsonbuilder << "}";
62  return jsonbuilder.str();
63 }
64 
65 std::string AliEMCALConfigHandler::GetConfigurationString(const char* configname) const {
66  AliEMCALConfiguration *conf = FindConfiguration(configname);
67  if(!conf) return "";
68  return conf->CreateJSONString();
69 }
70 
72  return dynamic_cast<AliEMCALConfiguration *>(fConfiguration->FindObject(configName));
73 }
std::string CreateJSONString() const
AliEMCALConfiguration * CreateConfiguration(const char *name)
ClassImp(AliEMCALConfigHandler) AliEMCALConfigHandler
void AddParam(const char *configName, const char *key, AliJSONValue *value)
std::string GetConfigurationString() const
AliEMCALConfiguration * FindConfiguration(const char *configName) const
void AddParam(const char *name, AliJSONValue *value)