3 #include "cheprep/config.h"
12 #include "HEPREP/HepRepConstants.h"
14 #include "cheprep/DefaultHepRepAttValue.h"
25 std::string DefaultHepRepAttValue::labelStrings[LABELSTRINGS_LEN];
27 DefaultHepRepAttValue::DefaultHepRepAttValue(
string aName,
string aValue,
int aShowLabel)
29 , type(HepRepConstants::TYPE_STRING)
34 , showLabelValue(aShowLabel)
39 DefaultHepRepAttValue::DefaultHepRepAttValue(
string aName, int64 aValue,
int aShowLabel)
41 , type(HepRepConstants::TYPE_LONG)
45 , showLabelValue(aShowLabel)
50 DefaultHepRepAttValue::DefaultHepRepAttValue(
string aName,
int aValue,
int aShowLabel)
52 , type(HepRepConstants::TYPE_INT)
56 , showLabelValue(aShowLabel)
61 DefaultHepRepAttValue::DefaultHepRepAttValue(
string aName,
double aValue,
int aShowLabel)
63 , type(HepRepConstants::TYPE_DOUBLE)
67 , showLabelValue(aShowLabel)
72 DefaultHepRepAttValue::DefaultHepRepAttValue(
string aName,
bool aValue,
int aShowLabel)
74 , type(HepRepConstants::TYPE_BOOLEAN)
77 , booleanValue(aValue)
78 , showLabelValue(aShowLabel)
83 DefaultHepRepAttValue::DefaultHepRepAttValue(
string aName, vector<double> aValue,
int aShowLabel)
85 , type(HepRepConstants::TYPE_COLOR)
90 , showLabelValue(aShowLabel)
95 DefaultHepRepAttValue::~DefaultHepRepAttValue() {
98 void DefaultHepRepAttValue::init() {
99 labelStrings[0] =
"NAME";
100 labelStrings[1] =
"DESC";
101 labelStrings[2] =
"VALUE";
102 labelStrings[3] =
"EXTRA";
105 HepRepAttValue* DefaultHepRepAttValue::copy() {
115 case HepRepConstants::TYPE_COLOR:
return new DefaultHepRepAttValue(
name, colorValue, showLabelValue);
116 case HepRepConstants::TYPE_STRING:
return new DefaultHepRepAttValue(
name, stringValue, showLabelValue);
117 case HepRepConstants::TYPE_LONG:
return new DefaultHepRepAttValue(
name, longValue, showLabelValue);
118 case HepRepConstants::TYPE_INT:
return new DefaultHepRepAttValue(
name, (
int)longValue, showLabelValue);
119 case HepRepConstants::TYPE_DOUBLE:
return new DefaultHepRepAttValue(
name, doubleValue, showLabelValue);
120 case HepRepConstants::TYPE_BOOLEAN:
return new DefaultHepRepAttValue(
name, booleanValue, showLabelValue);
121 default:
return new DefaultHepRepAttValue(
name,
"Unknown type stored in HepRepAttDef", showLabelValue);
129 string DefaultHepRepAttValue::getLowerCaseName() {
131 transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
135 int DefaultHepRepAttValue::getType() {
139 string DefaultHepRepAttValue::getTypeName() {
141 case HepRepConstants::TYPE_COLOR:
return(
"Color");
142 case HepRepConstants::TYPE_STRING:
return(
"String");
143 case HepRepConstants::TYPE_LONG:
return(
"long");
144 case HepRepConstants::TYPE_INT:
return(
"int");
145 case HepRepConstants::TYPE_DOUBLE:
return(
"double");
146 case HepRepConstants::TYPE_BOOLEAN:
return(
"boolean");
147 default:
return "Unknown type stored in HepRepAttDef";
151 int DefaultHepRepAttValue::showLabel() {
152 return showLabelValue;
155 string DefaultHepRepAttValue::getString() {
156 if (type != HepRepConstants::TYPE_STRING) cerr <<
"Trying to access AttValue '" <<
getName() <<
"' as 'string'" << endl;
160 string DefaultHepRepAttValue::getLowerCaseString() {
161 if (type != HepRepConstants::TYPE_STRING) cerr <<
"Trying to access AttValue '" <<
getName() <<
"' as 'string'" << endl;
162 string s = stringValue;
163 transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
167 int64 DefaultHepRepAttValue::getLong() {
168 if (type != HepRepConstants::TYPE_LONG) cerr <<
"Trying to access AttValue '" <<
getName() <<
"' as 'long'" << endl;
172 int DefaultHepRepAttValue::getInteger() {
173 if (type != HepRepConstants::TYPE_INT) cerr <<
"Trying to access AttValue '" <<
getName() <<
"' as 'int'" << endl;
174 return (int64)longValue;
177 double DefaultHepRepAttValue::getDouble() {
178 if (type != HepRepConstants::TYPE_DOUBLE) cerr <<
"Trying to access AttValue '" <<
getName() <<
"' as 'double'" << endl;
182 bool DefaultHepRepAttValue::getBoolean() {
183 if (type != HepRepConstants::TYPE_BOOLEAN) cerr <<
"Trying to access AttValue '" <<
getName() <<
"' as 'boolean'" << endl;
187 vector<double> DefaultHepRepAttValue::getColor() {
188 if (type != HepRepConstants::TYPE_COLOR) cerr <<
"Trying to access AttValue '" <<
getName() <<
"' as 'color'" << endl;
193 string DefaultHepRepAttValue::getAsString() {
195 case HepRepConstants::TYPE_COLOR:
return getAsString(getColor());
196 case HepRepConstants::TYPE_STRING:
return getString();
197 case HepRepConstants::TYPE_LONG:
return getAsString(getLong());
198 case HepRepConstants::TYPE_INT:
return getAsString(getInteger());
199 case HepRepConstants::TYPE_DOUBLE:
return getAsString(getDouble());
200 case HepRepConstants::TYPE_BOOLEAN:
return getAsString(getBoolean());
201 default:
return "Unknown typecode";
205 string DefaultHepRepAttValue::getAsString(vector<double> c) {
207 sprintf(buffer,
"%4.2f, %4.2f, %4.2f, %4.2f",
211 (c.size() > 3) ? c[3] : 1.0);
215 string DefaultHepRepAttValue::getAsString(
int i) {
217 sprintf(buffer,
"%d", i);
221 string DefaultHepRepAttValue::getAsString(int64 i) {
223 sprintf(buffer, CHEPREP_INT64_FORMAT, i);
228 string DefaultHepRepAttValue::getAsString(
double d) {
230 sprintf(buffer,
"%g", d);
234 string DefaultHepRepAttValue::getAsString(
bool b) {
235 return b ?
"true" :
"false";
241 string DefaultHepRepAttValue::toShowLabel() {
242 return toShowLabel(showLabel());
246 string DefaultHepRepAttValue::toShowLabel(
int showLabel) {
249 if (showLabel == HepRepConstants::SHOW_NONE) {
252 for (
int i=0; i<16; i++) {
253 if (((showLabel >> i) & 0x0001) == 0x0001) {
259 if (i < LABELSTRINGS_LEN) {
260 label.append(labelStrings[i]);
263 sprintf(hex,
"%0x", 1 << i);
std::string getName(const ParticleType t)
Get the native INCL name of the particle.