StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
detectorId.C
1 // this is auxiliary macro used in StEvent/StEnumerations
2 // It is invoked once to provide relations between detector id & detector name
3 // Author V.Perev
4 
5 
6 
7 void detectorId(int *ids=0, char** cds=0)
8 {
9 
10  std::cout << "------------------------------" << std::endl;
11  std::cout << "detectorId has been deprecated" << std::endl;
12  std::cout << "------------------------------" << std::endl;
13 
14  int myIds[100];
15  char *myCds[100];
16  if (!ids) { ids = myIds; cds = myCds; }
17 
18 
19  memset(ids,0,sizeof(ids[0])*100);
20  memset(cds,0,sizeof(cds[0])*100);
21 
22  TString myPath("$STAR/StRoot/StEvent/StEnumerations.h");
23  gSystem->ExpandPathName(myPath);
24 // printf ("=%s\n",myPath.Data());
25  int notExi = gSystem->AccessPathName(myPath.Data(),kFileExists);
26  if (notExi) { ids[0]=-1; return;}
27  FILE *fp = fopen(myPath.Data(),"r");
28  if (!fp) { ids[0]=-1; return;}
29  char buf[400];
30 
31  int kase = 0;
32  while (2015) {
33  fgets(buf,200,fp);
34  int eof = feof(fp);
35  if (eof) break;
36  TString tb(buf);
37 
38  if(!kase) {
39 // enum StDetectorId {kUnknownId = kUnknownIdentifier,
40  if (tb.Index("enum")<0) continue;
41  if (tb.Index("StDetectorId")<0) continue;
42  if (tb.Index("=")<0) continue;
43  if (tb.Index("kUnknownId")<0) continue;
44  kase = 1;
45  }
46  tb.ReplaceAll(" ","");
47  if (tb.Index("//")==0) continue;
48  int myK = tb.Index("k"); if (myK <0) break;
49  int myEq= tb.Index("="); if (myEq<0) break;
50  int myE = tb.Index(",");
51  if (myE<0) myE = tb.Index("}");
52  if (myE<0) break;
53 // printf("%s",buf);
54  TString com(tb.Data()+myK,myEq-myK);
55  int id = gROOT->ProcessLineFast(com);
56  ids[0]++;
57  ids[ids[0]] = id;
58  cds[ids[0]] = new char[com.Length()+1];
59  strcpy(cds[ids[0]],com.Data());
60 // printf("%d = %s\n",ids[ids[0]],cds[ids[0]]);
61  if (tb[myE]=='}') break;
62  }
63  fclose(fp);
64  for (int i=1;i<=ids[0];i++) {
65  printf("%d = %s\n",ids[i],cds[i]);
66 }
67 
68 
69 
70 
71 
72 #if 0
73 
74  const char *res =0;
75  int nG=0, nGtot=0, nGmax=0;
76  int nG15=0, nG15tot=0, nG15max=0;
77  int nP=0, nPtot=0, nPmax=0;
78  int nP15=0, nP15tot=0, nP15max=0;
79  int nFile=0, nEv=0;
80  double times[4] = {0};
81  const char* file=0;
82  int num=0;
83 
84 
85 
86 
87  FILE *fp = fopen(file,"r");
88 
89 
90 
91 
92 
93 
94  while ((file = it.NextFile())) {
95  nFile++;
96  num++;
97  if ((num%100)==1) printf("%5d - InputFile = %s\n",num,file);
98  FILE *fp = fopen(file,"r");
99  if (!fp) { printf("Wrong file %s\n",file); continue;}
100  char buf[400];
101 
102  while (2007) {
103  fgets(buf,200,fp);
104  int eof = feof(fp);
105  if (eof) break;
106  res = strstr(buf,"StvStEventFiller::fillEvent");
107  if (!res) res = strstr(buf,"StiStEventFiller::fillEvent");
108  if (res) { //it is EventFiller
109  res = strstr(buf,"global(2):");
110  if (res) { //count globals
111  if (nEv == nEvt) break;
112  nEv++;
113  sscanf(res,"global(2):%d",&nG);
114  nGtot+=nG; if (nGmax<nG) nGmax=nG;
115  }
116  res = strstr(buf,"GOOD globals:");
117  if (res) { //count globals
118  sscanf(res,"GOOD globals:%d",&nG15);
119  nG15tot+=nG15;if (nG15max<nG15) nG15max=nG15;
120  }
121  res = strstr(buf,"fillEventPrimaries");
122  if (res) {
123  res = strstr(buf,"(2):");
124  if (res) {
125  sscanf(res,"(2):%d",&nP);
126  nPtot+=nP;if (nPmax<nP) nPmax=nP;
127  }
128  res = strstr(buf,"GOOD:");
129  if (res) {
130  sscanf(res,"GOOD:%d",&nP15);
131  nP15tot+=nP15;if (nP15max<nP15) nP15max=nP15;
132  }
133  }
134 
135  }
136  const char *cpu = strstr(buf,"Ast =");
137  if (cpu) { //Cpu count
138  int kase=0;
139  if (strstr(buf,"StBFChain::bfc")) kase = 1;
140  if (strstr(buf,"StiMaker::Sti" )) kase = 2;
141  if (strstr(buf,"StvMaker::Stv" )) kase = 3;
142  double cpuTime = 0;
143  if (kase) { // It is our case
144  cpuTime = atof(cpu+5);
145  times[kase]+=cpuTime;
146  } }
147  }
148 
149  fclose(fp);
150  }//end file iter
151  printf("In File(s) %s\n",myfile);
152  printf("nFiles =%g nEvents = %d <nEvents>=%d\n",nFile,nEv,nEv/nFile);
153  printf("nGlob = %10d <nGlob> = %5d nGlobMax=%5d\n" ,nGtot ,nGtot /nEv,nGmax );
154  printf("nGgoo = %10d <nGgoo> = %5d nGgooMax=%5d Ggoo/Gtot=%5.3f\n",nG15tot,nG15tot/nEv,nG15max,double(nG15tot)/nGtot );
155  printf("nPrim = %10d <nPrim> = %5d nPrimMax=%5d Ptot/Gtot=%5.3f\n",nPtot ,nPtot /nEv,nPmax ,double(nPtot )/nGtot );
156  printf("nPgoo = %10d <nPgoo> = %5d nPgooMax=%5d Pgoo/Ggoo=%5.3f\n",nP15tot,nP15tot/nEv,nP15max,double(nP15tot)/nG15tot);
157 
158 
159  printf("CpuTot/Event = %g CpuTot/tracks = %g\n",times[1]/nEv,times[1]/nGtot);
160  if (times[1]>0) {
161  if (times[2]) {
162  printf("StiTot/Event = %g StiTot/tracks = %g StiPct=%g%%\n"
163  ,times[2]/nEv,times[2]/nGtot,times[2]/(times[1]-times[2])*100+1e-10);}
164  else {
165  printf("StvTot/Event = %g StvTot/tracks = %g StvPct=%g%%\n"
166  ,times[3]/nEv,times[3]/nGtot,times[3]/(times[1]-times[3])*100+1e-10);}
167  }
168 
169 
170 #endif
171 }
172