EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Experiment.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Experiment.cxx
1 //
2 // Body for Experiment namespace so that CINT recognizes its existence
3 //
4 #include "Experiment.h"
5 #include "TString.h"
6 
7 //_____________________________________________________________________________
9 {
11 }
12 //_____________________________________________________________________________
14 {
15  switch (exp) {
16  case kS001:
17  return "S001";
18  break;
19  case kS002:
20  return "S002";
21  break;
22  case kS003:
23  return "S003";
24  break;
25  case kS004:
26  return "S004";
27  break;
28  case kS005:
29  return "S005";
30  break;
31  case kS006:
32  return "S006";
33  break;
34  default:
35  return "?Unknown?";
36  break;
37  }
38 }
39 
40 //_____________________________________________________________________________
42 {
43  switch(c) {
44  case 'N':
45  case 'n':
46  case '1':
47  case 0x01:
48  return kS001;
49  case 'F':
50  case 'f':
51  case '2':
52  case 0x02:
53  return kS002;
54  case 'C':
55  case 'c':
56  case '4':
57  case 0x04:
58  return kS003;
59  case 'T':
60  case 't':
61  case '8':
62  case 0x08:
63  return kS004;
64  case 'M':
65  case 'm':
66  case 0x10:
67  return kS005;
68  default:
69  return kUnknown;
70  }
71 }
72 
73 //_____________________________________________________________________________
74 Char_t* Experiment::MaskToString(Int_t mask)
75 {
76  // Return a mask of Experiment as a string
77  //
78  // Result is a pointer to a statically allocated string.
79  // User should copy this into their own buffer before calling
80  // this method again.
81 
82  static Char_t newstring[255] = "";
83 
84  Char_t* ptr = newstring; // start at the beginning
85 
86  *ptr = 0; // start with nothing
87  Int_t fullmask = Experiment::FullMask();
88 
89  for (Int_t i=0; i<32; i++) {
91  if (mask & adet & fullmask) {
92  const Char_t* toadd = Experiment::AsString(adet);
93  if (ptr != newstring) { *ptr++ = ','; }
94  strcpy(ptr,toadd);
95  ptr += strlen(toadd);
96  }
97  }
98  *ptr++ = 0; // ensure trailing 0
99 
100  return newstring;
101 }
102 
103 //_____________________________________________________________________________
104 Experiment::Experiment_t Experiment::StringToEnum(const Char_t* chars, Int_t maxChar)
105 {
106  // convert a set of chars to a valid enum
107 
108  Int_t mask = Experiment::StringToMask(chars,maxChar);
109 
110  switch (mask) {
111  case kS001:
112  return kS001;
113  break;
114  case kS002:
115  return kS002;
116  break;
117  case kS003:
118  return kS003;
119  break;
120  case kS004:
121  return kS004;
122  break;
123  case kS005:
124  return kS005;
125  break;
126  case kS006:
127  return kS006;
128  break;
129  default:
130  return kUnknown;
131  break;
132  }
133 
134 }
135 
136 //_____________________________________________________________________________
137 Int_t Experiment::StringToMask(const Char_t* chars, Int_t maxChar)
138 {
139  // convert a set of chars to a mask of enum's
140  // simple tests for unique characters: {n,f,c,t,m}
141 
142  Int_t mask = 0;
143 
144  TString thestring(chars);
145  if (maxChar>0 && maxChar<thestring.Length()) { thestring.Resize(maxChar); }
146 
147  thestring.ToLower();
148  if (thestring.Contains("S1")) { mask |= kS001; }
149  if (thestring.Contains("S2")) { mask |= kS002; }
150  if (thestring.Contains("S3")) { mask |= kS003; }
151  if (thestring.Contains("S4")) { mask |= kS004; }
152  if (thestring.Contains("S5")) { mask |= kS005; }
153 
154 
155 
156  return mask;
157 }
158 
159 //_____________________________________________________________________________
160