7 #include "St_base/StMessMgr.h"
11 static void detectorIdInit();
13 void detectorId(
int *ids=0,
char** cds=0)
17 if (!ids) { ids = myIds; cds = myCds; }
19 memset(ids,0,
sizeof(ids[0])*100);
20 memset(cds,0,
sizeof(cds[0])*100);
23 TString myPath(
"./StRoot/StEvent/StEnumerations.h");
24 int notExi = gSystem->AccessPathName(myPath.Data(),kFileExists);
26 myPath =
"$STAR/StRoot/StEvent/StEnumerations.h";
27 gSystem->ExpandPathName(myPath);
28 notExi = gSystem->AccessPathName(myPath.Data(),kFileExists);
29 if (notExi) { ids[0]=-1;
return;}
31 FILE *fp = fopen(myPath.Data(),
"r");
32 if (!fp) { ids[0]=-1;
return;}
50 if (tb.Index(
"enum")<0)
continue;
51 if (tb.Index(
"StDetectorId")<0)
continue;
52 if (tb.Index(
"=")<0)
continue;
53 if (tb.Index(
"kUnknownId")<0)
continue;
56 tb.ReplaceAll(
" ",
"");
57 if (tb.Index(
"//")==0)
continue;
58 int myK = tb.Index(
"k");
if (myK <0)
break;
59 int myEq= tb.Index(
"=");
if (myEq<0)
break;
60 int myE = tb.Index(
",");
61 if (myE<0) myE = tb.Index(
"}");
63 TString com(tb.Data()+myK,myEq-myK);
64 int id = gROOT->ProcessLineFast(com);
67 cds[ids[0]] =
new char[com.Length()+1];
68 strcpy(cds[ids[0]],com.Data());
70 if (tb[myE]==
'}')
break;
73 for (
int i=1;i<=ids[0];i++) {
74 printf(
"%d = %s\n",ids[i],cds[i]);
78 const char *detectorNameById(StDetectorId
id)
80 if (ids[0]<0)
return "Unknown";
81 if (!ids[0] ) detectorIdInit();
83 for (
int i=1;i<=ids[0];i++) {
if (ids[i]==
id)
return cds[i]+1;}
87 StDetectorId detectorIdByName(
const char *name)
89 if (ids[0]<0)
return kUnknownId;
90 if (!ids[0] ) detectorIdInit();
91 TString tName(name); tName.ReplaceAll(
"Id",
"");
92 for (
int i=1;i<=ids[0];i++){
93 TString tds(cds[i]+1); tds.ReplaceAll(
"Id",
"");
94 if (tName.Contains(tds,TString::kIgnoreCase))
return (StDetectorId)ids[i];
101 detectorId( ids, cds );
103 LOG_FATAL <<
"Failed to parse StEnumerations.h / StDetectorId enumeration. Kaboom." << endm;