EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimFlag.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SimFlag.cxx
1 #include "SimFlag.h"
2 #include "TMath.h"
3 #include "TString.h"
4 
5 //_____________________________________________________________________________
6 
8 {
10 }
11 
12 //_____________________________________________________________________________
13 
14 const Char_t* SimFlag::AsString(SimFlag_t simFlag)
15 {
16  // static function to return mapping enum --> string
17 
18  switch (simFlag) {
19  case kUnknown:
20  return "Unknown";
21  break;
22  case kData:
23  return "Data";
24  break;
25  case kDaqSimData:
26  return "DaqSimData";
27  break;
28  case kMC:
29  return "MC";
30  break;
31  case kReroot:
32  return "Reroot";
33  break;
34  default:
35  return "?Data?";
36  break;
37  }
38 }
39 
40 //_____________________________________________________________________________
41 
42 const Char_t* SimFlag::MaskToString(Int_t mask)
43 {
44  // Return a mask of SimFlags as a string
45  //
46  // Result is a pointer to a statically allocated string.
47  // User should copy this into their own buffer before calling
48  // this method again.
49 
50  static Char_t newstring[255] = "";
51 
52  Char_t* ptr = newstring; // start at the beginning
53 
54  *ptr = 0; // start with nothing
55  Int_t fullmask = SimFlag::FullMask();
56 
57  for (Int_t i=0; i<32; i++) {
59  if (mask & flag & fullmask) {
60  const Char_t* toadd = SimFlag::AsString(flag);
61  if (ptr != newstring) { *ptr++ = ','; }
62  strcpy(ptr,toadd);
63  ptr += strlen(toadd);
64  }
65  }
66  *ptr++ = 0; // ensure trailing 0
67 
68  return newstring;
69 }
70 
71 //_____________________________________________________________________________
72 
73 SimFlag::SimFlag_t SimFlag::StringToEnum(const Char_t* chars, Int_t maxChar)
74 {
75  // convert a set of chars to a valid enum
76 
77  Int_t mask = SimFlag::StringToMask(chars,maxChar);
78 
79  switch (mask) {
80  case kUnknown:
81  return kUnknown;
82  break;
83  case kData:
84  return kData;
85  break;
86  case kDaqSimData:
87  return kDaqSimData;
88  break;
89  case kMC:
90  return kMC;
91  break;
92  case kReroot:
93  return kReroot;
94  break;
95  default:
96  return kUnknown;
97  break;
98  }
99 
100 }
101 
102 //_____________________________________________________________________________
103 
104 Int_t SimFlag::StringToMask(const Char_t* chars, Int_t maxChar)
105 {
106  // convert a set of chars to a mask of enum's
107  // simple tests for unique characters: {d,s,m,r}
108 
109  Int_t mask = 0;
110 
111  TString thestring(chars);
112  if (maxChar>0 && maxChar<thestring.Length()) { thestring.Resize(maxChar); }
113 
114  thestring.ToLower();
115  if (thestring.Contains("d")) { mask |= kData; }
116  if (thestring.Contains("s")) { mask |= kDaqSimData; }
117  if (thestring.Contains("m")) { mask |= kMC; }
118  if (thestring.Contains("r")) { mask |= kReroot; }
119 
120  return mask;
121 }
122 
123 //_____________________________________________________________________________
124 
126 {
127  // turn mask-like enum value into sequential int
128 
129  switch (simFlag) {
130  case kUnknown:
131  return -1;
132  break;
133  case kData:
134  return 0;
135  break;
136  case kDaqSimData:
137  return 1;
138  break;
139  case kMC:
140  return 2;
141  break;
142  case kReroot:
143  return 3;
144  break;
145  default:
146  return -1;
147  break;
148  }
149 
150 }
151 
152 //_____________________________________________________________________________
153 
154 SimFlag::SimFlag_t SimFlag::Expand(Int_t compactSimFlag)
155 {
156  // turn sequential int into mask-like enum value
157 
158  switch (compactSimFlag) {
159  case 0:
160  return kData;
161  break;
162  case 1:
163  return kDaqSimData;
164  break;
165  case 2:
166  return kMC;
167  break;
168  case 3:
169  return kReroot;
170  break;
171  default:
172  return kUnknown;
173  break;
174  }
175 }
176 
177 //_____________________________________________________________________________