1 |
kusanagi |
1.1 |
/** |
2 |
|
|
* LogToXML |
3 |
|
|
* author Nagni |
4 |
|
|
* version 2.0 - 13 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 - 13 February 2006 |
17 |
|
|
* Modified for new Yoda unpacking structure (one single file) |
18 |
|
|
*/ |
19 |
|
|
|
20 |
|
|
#include <log/LogRecord.h> |
21 |
|
|
#include <log/LogEvent.h> |
22 |
|
|
#include <PscuHeader.h> |
23 |
|
|
#include <EventHeader.h> |
24 |
|
|
#include <fstream> |
25 |
|
|
|
26 |
|
|
#include <TFile.h> |
27 |
|
|
#include <TObjString.h> |
28 |
|
|
#include <TString.h> |
29 |
|
|
#include <TTree.h> |
30 |
|
|
|
31 |
|
|
void LogToXML(TString base, TString outDirectory = "", TString xslPath = ""){ |
32 |
|
|
Int_t tmpSize; |
33 |
|
|
ofstream outputFile; |
34 |
|
|
stringstream oss; |
35 |
|
|
|
36 |
|
|
pamela::LogEvent *logev = 0; |
37 |
|
|
pamela::LogRecord *logrec = 0; |
38 |
|
|
pamela::EventHeader *eh = 0; |
39 |
|
|
pamela::PscuHeader *ph = 0; |
40 |
|
|
TFile *rootFile = new TFile(base); |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
if (rootFile->IsZombie()) printf("The %s file does not exist", base.Data()); |
44 |
|
|
TString fileName = ((TObjString*)base.Tokenize('\/')->Last())->GetString(); |
45 |
|
|
TString filePath = base; |
46 |
|
|
filePath.ReplaceAll(fileName, ""); |
47 |
|
|
fileName.ReplaceAll(".root", ""); |
48 |
|
|
|
49 |
|
|
oss.str(""); |
50 |
|
|
if (outDirectory == "") { |
51 |
|
|
oss << fileName.Data() << "Log.xml"; |
52 |
|
|
} else { |
53 |
|
|
oss << outDirectory.Data() << fileName.Data() << "Log.xml"; |
54 |
|
|
} |
55 |
|
|
const char* xmlFilePath = oss.str().c_str(); |
56 |
|
|
|
57 |
|
|
outputFile.open(xmlFilePath, ios::trunc); |
58 |
|
|
if (!outputFile.is_open()){ |
59 |
|
|
printf("Cannot open the file %s for the output", xmlFilePath); |
60 |
|
|
exit(0); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
TTree *tr = (TTree*)rootFile->Get("Log"); |
64 |
|
|
Long64_t nevents = tr->GetEntries(); |
65 |
|
|
tr->SetBranchAddress("Log", &logev); |
66 |
|
|
tr->SetBranchAddress("Header", &eh); |
67 |
|
|
outputFile << "<?xml version='1.0' encoding='ISO-8859-1'?>\n"; |
68 |
|
|
outputFile << "<!-- Prologo XML -->\n"; |
69 |
|
|
outputFile << "<?xml-stylesheet type='text/xsl' href='" << xslPath.Data() << "'?>\n"; |
70 |
|
|
outputFile << "<ROOT_SOURCE>\n"; |
71 |
|
|
outputFile << "<TABLE_HEAD>\n"; |
72 |
|
|
outputFile << "<COL id='prima'>Record OBT</COL>\n"; |
73 |
|
|
outputFile << "<COL id='seconda'>Mask Type</COL>\n"; |
74 |
|
|
outputFile << "<COL id='terza'>File Name</COL>\n"; |
75 |
|
|
outputFile << "<COL id='quinta'>Info1</COL>\n"; |
76 |
|
|
outputFile << "</TABLE_HEAD>\n"; |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
//<!-- Istruzione che indica il documento XSLT da associare --> |
80 |
|
|
for (int i = 0; i < nevents; i++){ |
81 |
|
|
tr->GetEntry(i); |
82 |
|
|
tmpSize = logev->Records->GetEntries(); |
83 |
|
|
ph = eh->GetPscuHeader(); |
84 |
|
|
outputFile << "<LOG_EVENT>\n"; |
85 |
|
|
outputFile << "\t<PACKET_OBT>" << ph->GetOrbitalTime() << "</PACKET_OBT>\n"; |
86 |
|
|
outputFile << "\t<PACKET_NUM>" << ph->GetCounter() << "</PACKET_NUM>\n"; |
87 |
|
|
outputFile << "\t<LOG_RECORDS>\n"; |
88 |
|
|
for (Int_t j = 0; j < tmpSize; j++){ |
89 |
|
|
logrec = (pamela::LogRecord*)logev->Records->At(j); |
90 |
|
|
outputFile << "\t\t<LOG_RECORD>\n"; |
91 |
|
|
outputFile << "\t\t\t<RECORD_OBT>" << logrec->RECORD_OBT << "</RECORD_OBT>\n"; |
92 |
|
|
outputFile << "\t\t\t<MASKTYPE>" << (short)logrec->MASKTYPE << "</MASKTYPE>\n"; |
93 |
|
|
outputFile << "\t\t\t<FILE_ID>" << (int)logrec->FILE_ID << "</FILE_ID>\n"; |
94 |
|
|
outputFile << "\t\t\t<LINE_NO>" << logrec->LINE_NO << "</LINE_NO>\n"; |
95 |
|
|
outputFile << "\t\t\t<INFO1>" << logrec->INFO1 << "</INFO1>\n"; |
96 |
|
|
outputFile << "\t\t</LOG_RECORD>\n"; |
97 |
|
|
} |
98 |
|
|
outputFile << "\t</LOG_RECORDS>\n"; |
99 |
|
|
outputFile << "</LOG_EVENT>\n"; |
100 |
|
|
} |
101 |
|
|
outputFile << "</ROOT_SOURCE>\n"; |
102 |
|
|
outputFile.close(); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
int main(int argc, char* argv[]){ |
106 |
|
|
TString outDir = ""; |
107 |
|
|
TString xslPath = ""; |
108 |
|
|
|
109 |
|
|
if (argc < 2){ |
110 |
|
|
printf("You have to insert at least the file to analyze \n"); |
111 |
|
|
printf("Try '--help' for more information. \n"); |
112 |
|
|
exit(1); |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
if (!strcmp(argv[1], "--help")){ |
116 |
|
|
printf( "Usage: LogToXML FILE [OPTION] \n"); |
117 |
|
|
printf( "\t --help Print this help and exit \n"); |
118 |
|
|
printf( "\t -outDir[path] Path where to put the output [default ~/tmp] \n"); |
119 |
|
|
printf( "\t -xslPath[path] Set the path to a XSL file for formatting [default '']\n"); |
120 |
|
|
exit(1); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
for (int i = 2; i < argc; i++){ |
124 |
|
|
if (!strcmp(argv[i], "-outDir")){ |
125 |
|
|
if (++i >= argc){ |
126 |
|
|
printf( "-outDir needs arguments. \n"); |
127 |
|
|
printf( "Try '--help' for more information. \n"); |
128 |
|
|
exit(1); |
129 |
|
|
} else { |
130 |
|
|
outDir = argv[i]; |
131 |
|
|
continue; |
132 |
|
|
} |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
if (!strcmp(argv[i], "-xslPath")) |
136 |
|
|
if (++i >= argc){ |
137 |
|
|
printf( "-xslPath needs arguments. \n"); |
138 |
|
|
printf( "Try '--help' for more information. \n"); |
139 |
|
|
exit(1); |
140 |
|
|
} else { |
141 |
|
|
xslPath = argv[i]; |
142 |
|
|
continue; |
143 |
|
|
} |
144 |
|
|
} |
145 |
|
|
LogToXML(argv[1], outDir, xslPath); |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|