1 |
/** |
2 |
* TabDumpToXML |
3 |
* author Nagni |
4 |
* version 1.0 - 01 March 2006 |
5 |
* |
6 |
* Description: Generate an XML file starting from a PAMELA unpacked file. |
7 |
* |
8 |
* Parameters: |
9 |
* base - the path where to find the PAMELA unpacked root file. |
10 |
* outDirectory - the path where to put the output file. |
11 |
* xslPath - the path where to find an XSL format for the output. |
12 |
* |
13 |
* version 1.0 - 01 March 2006 |
14 |
* First implementation |
15 |
* |
16 |
*/ |
17 |
#include <tabDump/TabDumpRecord.h> |
18 |
#include <tabDump/TabDumpEvent.h> |
19 |
#include <PscuHeader.h> |
20 |
#include <EventHeader.h> |
21 |
#include <yodaUtility.h> |
22 |
#include <fstream> |
23 |
|
24 |
#include <TFile.h> |
25 |
#include <TObjString.h> |
26 |
#include <TString.h> |
27 |
#include <TTree.h> |
28 |
|
29 |
|
30 |
void TabDumpToXML(TString base, TString outDirectory = "", TString xslPath = ""){ |
31 |
|
32 |
Int_t tmpSize, nrow, ncol; |
33 |
ofstream outputFile; |
34 |
stringstream oss; |
35 |
UInt_t k_data = 0; |
36 |
|
37 |
pamela::TabDumpEvent *tde = 0; |
38 |
pamela::TabDumpRecord *tdr = 0; |
39 |
pamela::EventHeader *eh = 0; |
40 |
pamela::PscuHeader *ph = 0; |
41 |
TFile *rootFile = new TFile(base); |
42 |
|
43 |
|
44 |
if (rootFile->IsZombie()) printf("The %s file does not exist", base.Data()); |
45 |
TString fileName = ((TObjString*)base.Tokenize('\/')->Last())->GetString(); |
46 |
TString filePath = base; |
47 |
filePath.ReplaceAll(fileName, ""); |
48 |
fileName.ReplaceAll(".root", ""); |
49 |
|
50 |
oss.str(""); |
51 |
if (outDirectory == "") { |
52 |
oss << fileName.Data() << "TabDump.xml"; |
53 |
} else { |
54 |
oss << outDirectory.Data() << fileName.Data() << "TabDump.xml"; |
55 |
} |
56 |
const char* xmlFilePath = oss.str().c_str(); |
57 |
|
58 |
outputFile.open(xmlFilePath, ios::trunc); |
59 |
if (!outputFile.is_open()){ |
60 |
printf("Cannot open the file %s for the output", xmlFilePath); |
61 |
exit(0); |
62 |
} |
63 |
|
64 |
|
65 |
TTree *tr = (TTree*)rootFile->Get("TabDump"); |
66 |
Long64_t nevents = tr->GetEntries(); |
67 |
tr->SetBranchAddress("TabDump", &tde); |
68 |
tr->SetBranchAddress("Header", &eh); |
69 |
outputFile << "<?xml version='1.0' encoding='ISO-8859-1'?>\n"; |
70 |
outputFile << "<!-- Prologo XML -->\n"; |
71 |
outputFile << "<?xml-stylesheet type='text/xsl' href='" << xslPath.Data() << "'?>\n"; |
72 |
outputFile << "<ROOT_SOURCE>\n"; |
73 |
for (int i = 0; i < nevents; i++){ |
74 |
tr->GetEntry(i); |
75 |
tmpSize = tde->Records->GetEntries(); |
76 |
ph = eh->GetPscuHeader(); |
77 |
outputFile << "<TABDUMP_EVENT>\n"; |
78 |
outputFile << "\t<PACKET_OBT>" << ph->GetOrbitalTime() << "</PACKET_OBT>\n"; |
79 |
outputFile << "\t<PACKET_NUM>" << ph->GetCounter() << "</PACKET_NUM>\n"; |
80 |
outputFile << "\t<COMPILATION_TS>" << tde->PARAMETER_STAMP << "</COMPILATION_TS>\n"; |
81 |
outputFile << "\t<TABDUMP_RECORDS>\n"; |
82 |
for (int j = 0; j < tmpSize; j++){ |
83 |
tdr = (pamela::TabDumpRecord*)tde->Records->At(j); |
84 |
nrow = (short)tdr->Nrow; |
85 |
ncol = (short)tdr->Ncol; |
86 |
outputFile << "\t\t<TABDUMP_RECORD>\n"; |
87 |
outputFile << "\t\t\t<TAB_ID>" << (short)tdr->Tab_ID << "</TAB_ID>\n"; |
88 |
|
89 |
TArrayI *Data = (TArrayI*)tdr->Data; |
90 |
for (int k = 0; k < nrow; k++){ |
91 |
outputFile << "\t\t\t<ROW> \n"; |
92 |
for (int z = 0; z < ncol; z++){ |
93 |
k_data = (UInt_t)Data->At((k*ncol) + z); |
94 |
Utility::endian_swap(k_data); |
95 |
outputFile << "\t\t\t<COL>" << k_data << "</COL>\n"; |
96 |
} |
97 |
outputFile << "\t\t\t</ROW> \n"; |
98 |
} |
99 |
|
100 |
outputFile << "\t\t</TABDUMP_RECORD>\n"; |
101 |
} |
102 |
outputFile << "\t</TABDUMP_RECORDS>\n"; |
103 |
outputFile << "</TABDUMP_EVENT>\n"; |
104 |
} |
105 |
outputFile << "</ROOT_SOURCE>\n"; |
106 |
outputFile.close(); |
107 |
} |
108 |
|
109 |
int main(int argc, char* argv[]){ |
110 |
TString outDir = ""; |
111 |
TString xslPath = ""; |
112 |
|
113 |
if (argc < 2){ |
114 |
printf("You have to insert at least the file to analyze \n"); |
115 |
printf("Try '--help' for more information. \n"); |
116 |
exit(1); |
117 |
} |
118 |
|
119 |
if (!strcmp(argv[1], "--help")){ |
120 |
printf( "Usage: TabDumpToXML FILE [OPTION] \n"); |
121 |
printf( "\t --help Print this help and exit \n"); |
122 |
printf( "\t -outDir[path] Path where to put the output [default ~/tmp] \n"); |
123 |
printf( "\t -xslPath[path] Set the path to a XSL file for formatting [default '']\n"); |
124 |
exit(1); |
125 |
} |
126 |
|
127 |
for (int i = 2; i < argc; i++){ |
128 |
if (!strcmp(argv[i], "-outDir")){ |
129 |
if (++i >= argc){ |
130 |
printf( "-outDir needs arguments. \n"); |
131 |
printf( "Try '--help' for more information. \n"); |
132 |
exit(1); |
133 |
} else { |
134 |
outDir = argv[i]; |
135 |
continue; |
136 |
} |
137 |
} |
138 |
|
139 |
if (!strcmp(argv[i], "-xslPath")) |
140 |
if (++i >= argc){ |
141 |
printf( "-xslPath needs arguments. \n"); |
142 |
printf( "Try '--help' for more information. \n"); |
143 |
exit(1); |
144 |
} else { |
145 |
xslPath = argv[i]; |
146 |
continue; |
147 |
} |
148 |
} |
149 |
TabDumpToXML(argv[1], outDir, xslPath); |
150 |
} |