7 void transformBackupHistoToDBTable(Char_t *hist_filename =
"./backup.emconline_ped/bemcPed.20060302.084014.root", Char_t *tables_path =
"./tables.emconline_ped/") {
8 gROOT->LoadMacro(
"$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
10 gSystem->Load(
"StDbLib");
11 gSystem->Load(
"StEmcUtil");
13 TString inputFilename(hist_filename);
14 cout <<
"Input filename is " << inputFilename.Data() << endl;
16 TString outputFilename;
19 TObjArray *dirNames = inputFilename.Tokenize(TString(
"/"));
22 cout <<
"Input filename tokenized" << endl;
23 TObjString *lastFileName = (TObjString*)dirNames->Last();
25 outputFilename = lastFileName->GetString();
26 cout <<
"File is " << outputFilename.Data() << endl;
27 TObjArray *pieces = outputFilename.Tokenize(
".");
29 cout <<
"File name tokenized" << endl;
30 TObjString *firstPiece = (TObjString*)pieces->First();
32 tableName = firstPiece->GetString();
33 cout <<
"Table name is " << tableName.Data() << endl;
41 if (outputFilename.Length() != 0) outputFilename.Prepend(
"/");
44 if (tableName ==
"bemcPed") {
46 if (outputFilename.Length() != 0) outputFilename.Prepend(
"/y3bemc");
48 if (tableName ==
"bsmdePed") {
50 if (outputFilename.Length() != 0) outputFilename.Prepend(
"/y3bsmde");
52 if (tableName ==
"bsmdpPed") {
54 if (outputFilename.Length() != 0) outputFilename.Prepend(
"/y3bsmdp");
56 if (tableName ==
"bprsPed") {
58 if (outputFilename.Length() != 0) outputFilename.Prepend(
"/y3bprs");
61 if (outputFilename.Length() != 0) outputFilename.Prepend(tables_path);
63 cout <<
"Output filename is " << outputFilename.Data() << endl;
64 cout <<
"Output table name is " << tableName.Data() << endl;
67 cout <<
"Unknown detector!" << endl;
71 TFile *hist_file =
new TFile(hist_filename,
"READ");
76 if (hist_file && hist_file->IsOpen()) {
77 cout <<
"Input file is open" << endl;
78 ped =
dynamic_cast<TH1F*
>(hist_file->Get(
"mPed"));
79 cout <<
"Read ped = " << ped << endl;
80 rms =
dynamic_cast<TH1F*
>(hist_file->Get(
"mRms"));
81 cout <<
"Read rms = " << rms << endl;
82 chi =
dynamic_cast<TH1F*
>(hist_file->Get(
"mChi"));
83 cout <<
"Read chi = " << chi << endl;
84 status =
dynamic_cast<TH1F*
>(hist_file->Get(
"mStatus"));
85 cout <<
"Read status = " << status << endl;
88 TFile *table_file = 0;
89 if (ped && rms && chi && status) table_file =
new TFile(outputFilename.Data(),
"RECREATE");
91 if (table_file && table_file->IsOpen()) {
92 cout <<
"Output file open" << endl;
94 if ((detector == 1) || (detector == 4)) {
95 St_emcPed *st =
new St_emcPed(tableName.Data(), 1);
96 emcPed_st *rec = st->GetTable();
97 for (Int_t i = 0;i < 4800;i++) {
98 Float_t pedestal = (i < ped->GetXaxis()->GetNbins()) ? ped->GetBinContent(i + 1) : 0;
99 Float_t pedestalRms = (i < rms->GetXaxis()->GetNbins()) ? rms->GetBinContent(i + 1) : 0;
100 Float_t pedestalChi = (i < chi->GetXaxis()->GetNbins()) ? chi->GetBinContent(i + 1) : 0;
101 Float_t pedestalStatus = (i < status->GetXaxis()->GetNbins()) ? status->GetBinContent(i + 1) : 1;
102 cout << i <<
": ped = " << pedestal <<
", rms = " << pedestalRms <<
", chi = " << pedestalChi <<
", status = " << pedestalStatus << endl;
103 rec->AdcPedestal[i] = pedestal * 100;
104 rec->AdcPedestalRMS[i] = pedestalRms * 100;
105 rec->Status[i] = pedestalStatus;
111 if ((detector == 2) || (detector == 3)) {
112 St_smdPed *st =
new St_smdPed(tableName.Data(), 1);
113 smdPed_st *rec = st->GetTable();
114 for (Int_t i = 0;i < 18000;i++) {
115 Float_t pedestal = (i < ped->GetXaxis()->GetNbins()) ? ped->GetBinContent(i + 1) : 0;
116 Float_t pedestalRms = (i < rms->GetXaxis()->GetNbins()) ? rms->GetBinContent(i + 1) : 0;
117 Float_t pedestalChi = (i < chi->GetXaxis()->GetNbins()) ? chi->GetBinContent(i + 1) : 0;
118 Float_t pedestalStatus = (i < status->GetXaxis()->GetNbins()) ? status->GetBinContent(i + 1) : 1;
119 cout << i <<
": ped = " << pedestal <<
", rms = " << pedestalRms <<
", chi = " << pedestalChi <<
", status = " << pedestalStatus << endl;
120 rec->AdcPedestal[i][0] = pedestal * 100;
121 rec->AdcPedestalRMS[i][0] = pedestalRms * 100;
122 rec->Status[i] = pedestalStatus;
129 cout <<
"Output file written" << endl;
135 cout <<
"Output file closed" << endl;
138 if (hist_file)
delete hist_file;
139 cout <<
"Finished." << endl;