1 |
/** |
2 |
* ArrDumpToXML |
3 |
* author Nagni |
4 |
* version 2.0 - 03 February 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 - 03 March 2005 |
14 |
* First implementation |
15 |
* |
16 |
* version 2.0 - 03 February 2006 |
17 |
* Modified for new Yoda unpacking structure (one single file) |
18 |
*/ |
19 |
#include <arrDump/ArrDumpRecord.h> |
20 |
#include <arrDump/ArrDumpEvent.h> |
21 |
#include <PscuHeader.h> |
22 |
#include <EventHeader.h> |
23 |
#include <fstream> |
24 |
|
25 |
#include <TFile.h> |
26 |
#include <TObjString.h> |
27 |
#include <TString.h> |
28 |
#include <TTree.h> |
29 |
|
30 |
|
31 |
void ArrDumpToXML(TString base, TString outDirectory = "", TString xslPath = ""){ |
32 |
|
33 |
Int_t tmpSize; |
34 |
ofstream outputFile; |
35 |
stringstream oss; |
36 |
|
37 |
pamela::ArrDumpEvent *ade = 0; |
38 |
pamela::ArrDumpRecord *adr = 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() << "ArrDump.xml"; |
53 |
} else { |
54 |
oss << outDirectory.Data() << fileName.Data() << "ArrDump.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("ArrDump"); |
66 |
Long64_t nevents = tr->GetEntries(); |
67 |
tr->SetBranchAddress("ArrDump", &ade); |
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 = ade->Records->GetEntries(); |
76 |
ph = eh->GetPscuHeader(); |
77 |
outputFile << "<ARRDUMP_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>" << ade->PARAMETER_STAMP << "</COMPILATION_TS>\n"; |
81 |
outputFile << "\t<ARRDUMP_RECORDS>\n"; |
82 |
for (int j = 0; j < tmpSize; j++){ |
83 |
adr = (pamela::ArrDumpRecord*)ade->Records->At(j); |
84 |
outputFile << "\t\t<ARRDUMP_RECORD>\n"; |
85 |
outputFile << "\t\t\t<ARR_ID>" << (short)adr->Arr_ID << "</ARR_ID>\n"; |
86 |
TArrayI *Data = (TArrayI*)adr->Data; |
87 |
for (int k = 0; k < adr->Arr_len; k++){ |
88 |
outputFile << "\t\t\t<ARR_VALUE>" << (unsigned int)Data->At(k) << "</ARR_VALUE>\n"; |
89 |
} |
90 |
outputFile << "\t\t</ARRDUMP_RECORD>\n"; |
91 |
} |
92 |
outputFile << "\t</ARRDUMP_RECORDS>\n"; |
93 |
outputFile << "</ARRDUMP_EVENT>\n"; |
94 |
} |
95 |
outputFile << "</ROOT_SOURCE>\n"; |
96 |
outputFile.close(); |
97 |
} |
98 |
|
99 |
int main(int argc, char* argv[]){ |
100 |
TString outDir = ""; |
101 |
TString xslPath = ""; |
102 |
|
103 |
if (argc < 2){ |
104 |
printf("You have to insert at least the file to analyze \n"); |
105 |
printf("Try '--help' for more information. \n"); |
106 |
exit(1); |
107 |
} |
108 |
|
109 |
if (!strcmp(argv[1], "--help")){ |
110 |
printf( "Usage: ArrDumpToXML FILE [OPTION] \n"); |
111 |
printf( "\t --help Print this help and exit \n"); |
112 |
printf( "\t -outDir[path] Path where to put the output [default ~/tmp] \n"); |
113 |
printf( "\t -xslPath[path] Set the path to a XSL file for formatting [default '']\n"); |
114 |
exit(1); |
115 |
} |
116 |
|
117 |
for (int i = 2; i < argc; i++){ |
118 |
if (!strcmp(argv[i], "-outDir")){ |
119 |
if (++i >= argc){ |
120 |
printf( "-outDir needs arguments. \n"); |
121 |
printf( "Try '--help' for more information. \n"); |
122 |
exit(1); |
123 |
} else { |
124 |
outDir = argv[i]; |
125 |
continue; |
126 |
} |
127 |
} |
128 |
|
129 |
if (!strcmp(argv[i], "-xslPath")) |
130 |
if (++i >= argc){ |
131 |
printf( "-xslPath needs arguments. \n"); |
132 |
printf( "Try '--help' for more information. \n"); |
133 |
exit(1); |
134 |
} else { |
135 |
xslPath = argv[i]; |
136 |
continue; |
137 |
} |
138 |
} |
139 |
ArrDumpToXML(argv[1], outDir, xslPath); |
140 |
} |