StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SplitSvtWafer.C
1 void SplitSvtWafer(const Char_t *name = "StarDb/Geometry/svt/svtWafersPosition.20050101.000100.C") {
2  TString Top(name);
3  Top.ReplaceAll("$STAR/","");
4  Top = gSystem->DirName(Top.Data());
5  static const Char_t *Barrels[4] = {"InnerBarrel","MiddleBarrel","OuterBarrel","Ssd"};
6  static const Char_t *Ladder = "Ladder_";
7  static const Char_t *Wafer = "Wafer_";
8  TString Name(name);
9  gSystem->ExpandPathName(Name);
10  gSystem->Load("libStDb_Tables.so");
11  TString cmd(".L ");
12  cmd += Name;
13  gInterpreter->ProcessLine(cmd);
14  St_svtWafersPosition *table = CreateTable();
15  cmd.ReplaceAll(".L ",".U ");
16  gInterpreter->ProcessLine(cmd);
17  table->Print(0,10);
18  TString tname = gSystem->BaseName(Name);
19  Int_t N = table->GetNRows();
20  svtWafersPosition_st *row = table->GetTable();
21  TString separator("/");
22  for (Int_t i = 0; i < N; i++, row++) {
23  // Int_t Id = ladder + 100*(wafer + 10*layer);
24  Int_t Id = row->ID;
25  Int_t layer = Id/1000; if (layer > 7) layer = 7;
26  Id = Id - 1000*layer;
27  Int_t wafer = Id/100;
28  Int_t ladder = Id%100;
29  Int_t barrel = (layer-1)/2;
30  TString dir(Top);
31  dir += Form("/%s/%s%02i/%s%02i",Barrels[barrel],Ladder,ladder,Wafer,wafer);
32  if (gSystem->AccessPathName(dir)) {
33  Int_t iok = gSystem->mkdir(dir,kTRUE);
34  if (iok > -1) cout << "Make directory " << dir << " done " << endl;
35  else {cout << "Make directory " << dir << " failed with " << iok << endl;}
36  }
37  TString ts(dir);
38  ts += "/";
39  ts += tname;
40  ofstream out;
41  St_svtWafersPosition *newtable = new St_svtWafersPosition(table->GetName(),1);
42  newtable->AddAt(row);
43  out.open(ts.Data()); cout << "Create " << ts << endl;
44  newtable->SavePrimitive(out,"");
45  out.close();
46  delete newtable;
47  }
48 }