1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#include <Riostream.h>
#include <TDirectory.h>
#include <TFile.h>
#include <TKey.h>
#include <TH1.h>
#include <TXMLEngine.h>
#include <string>
#include <vector>
#include <map>
bool goToDir(TDirectory* top_dir, string dname);
void findHistoParameters(TDirectory* top_dir, vector<string>& names, string& tag,
TXMLEngine* xml_engine,XMLNodePointer_t& mainnode);
void sistrip_extract_dataquality(string fname) {
TFile* file = new TFile(fname.c_str());
if (!file || !file->IsOpen()) return;
TDirectory* topDir = dynamic_cast<TDirectory*>( file->Get("DQMData"));
goToDir(topDir, "SiStrip");
TDirectory* stripDir = gDirectory;
TIter next(stripDir->GetListOfKeys());
TKey *key;
while ( (key = dynamic_cast<TKey*>(next())) ) {
string clName(key->GetClassName());
if (clName == "TDirectoryFile") {
TDirectory *curr_dir = dynamic_cast<TDirectory*>(key->ReadObj());
string name = curr_dir->GetName();
if (name == "Run summary"){
curr_dir->cd();
break;
}
}
}
TDirectory* rsDir = gDirectory;
// First create engine
TXMLEngine* xml = new TXMLEngine;
// Create main node of document tree
XMLNodePointer_t mainnode = xml->NewChild(0, 0, "main");
vector<string> hnames;
string tag;
tag = "Tracks";
hnames.push_back("Tracks/NumberOfTracks_CKFTk");
hnames.push_back("Tracks/NumberOfRecHitsPerTrack_CKFTk");
findHistoParameters(rsDir, hnames, tag, xml, mainnode);
hnames.clear();
tag = "TEC";
hnames.push_back("MechanicalView/TEC/Summary_TotalNumberOfClusters_OnTrack_in_TEC");
hnames.push_back("MechanicalView/TEC/Summary_TotalNumberOfClusters_OffTrack_in_TEC");
hnames.push_back("MechanicalView/TEC/Summary_ClusterStoNCorr_OnTrack_in_TEC");
hnames.push_back("MechanicalView/TEC/Summary_ClusterCharge_OffTrack_in_TEC");
findHistoParameters(rsDir, hnames, tag, xml, mainnode);
hnames.clear();
tag = "TIB";
hnames.push_back("MechanicalView/TIB/Summary_TotalNumberOfClusters_OnTrack_in_TIB");
hnames.push_back("MechanicalView/TIB/Summary_TotalNumberOfClusters_OffTrack_in_TIB");
hnames.push_back("MechanicalView/TIB/Summary_ClusterCharge_OffTrack_in_TIB");
hnames.push_back("MechanicalView/TIB/Summary_ClusterStoNCorr_OnTrack_in_TIB");
findHistoParameters(rsDir, hnames, tag, xml, mainnode);
hnames.clear();
tag = "TOB";
hnames.push_back("MechanicalView/TOB/Summary_TotalNumberOfClusters_OnTrack_in_TOB");
hnames.push_back("MechanicalView/TOB/Summary_TotalNumberOfClusters_OffTrack_in_TOB");
hnames.push_back("MechanicalView/TOB/Summary_ClusterStoNCorr_OnTrack_in_TOB");
hnames.push_back("MechanicalView/TOB/Summary_ClusterCharge_OffTrack_in_TOB");
findHistoParameters(rsDir, hnames, tag, xml, mainnode);
hnames.clear();
tag = "TID";
hnames.push_back("MechanicalView/TID/Summary_TotalNumberOfClusters_OffTrack_in_TID");
hnames.push_back("MechanicalView/TID/Summary_TotalNumberOfClusters_OnTrack_in_TID");
hnames.push_back("MechanicalView/TID/Summary_ClusterStoNCorr_OnTrack_in_TID");
hnames.push_back("MechanicalView/TID/Summary_ClusterCharge_OffTrack_in_TID");
findHistoParameters(rsDir, hnames, tag, xml, mainnode);
file->Close();
// now create doccumnt and assign main node of document
XMLDocPointer_t xmldoc = xml->NewDoc();
xml->DocSetRootElement(xmldoc, mainnode);
// Save document to file
xml->SaveDoc(xmldoc, "sistrip_report.xml");
// Release memory before exit
xml->FreeDoc(xmldoc);
delete xml;
}
void findHistoParameters(TDirectory* top_dir,vector<string>& hnames, string& tag,
TXMLEngine* xml_engine, XMLNodePointer_t& mainnode){
char mval[10];
char rval[10];
string dir_name = top_dir->GetTitle();
cout << " ======================= " << tag << " ======================= " << endl;
for (vector<string>::iterator it = hnames.begin(); it != hnames.end(); it++) {
TH1* th1 = dynamic_cast<TH1*>(gDirectory->Get((*it).c_str()));
if (th1) {
sprintf(mval,"%.2f",th1->GetMean());
sprintf(rval,"%.2f",th1->GetRMS());
XMLNodePointer_t child = xml_engine->NewChild(mainnode, 0, tag.c_str());
xml_engine->NewAttr(child, 0, "Name", th1->GetName());
xml_engine->NewAttr(child, 0, "Mean", mval);
xml_engine->NewAttr(child, 0, "RMS", rval);
cout << th1->GetName() << " Mean " << mval << " RMS " << rval << endl;
}
}
cout << endl;
}
bool goToDir(TDirectory* top_dir, string dname){
string dir_name = top_dir->GetTitle();
if (dir_name == dname) {
return true;
} else {
TIter next(top_dir->GetListOfKeys());
TKey *key;
while ( (key = dynamic_cast<TKey*>(next())) ) {
string clName(key->GetClassName());
if (clName == "TDirectoryFile") {
TDirectory *curr_dir = dynamic_cast<TDirectory*>(key->ReadObj());
string name = curr_dir->GetName();
if (name == "Reference") continue;
curr_dir->cd();
if (goToDir(curr_dir, dname)) return true;
curr_dir->cd("..");
}
}
}
return false;
}
|