1 |
/** |
2 |
* McmdToXML |
3 |
* author Nagni |
4 |
* version 2.0 - 14 February 2006 |
5 |
* |
6 |
* Exctract info from the Mcmd packets into the ROOT file generated by YODA |
7 |
* Note that the libutils.so and the utils/*.h are needed to compile this code. |
8 |
* |
9 |
* Parameters: |
10 |
* base - the path where to find the PAMELA unpacked root file. |
11 |
* outDirectory - the path where to put the output file. |
12 |
* xslPath - the path where to find an XSL format for the output. |
13 |
* |
14 |
* version 1.0 - 03 March 2005 |
15 |
* First implementation |
16 |
* |
17 |
* version 2.0 - 14 February 2006 |
18 |
* Modified for new Yoda unpacking structure (one single file) |
19 |
* |
20 |
*/ |
21 |
#include <mcmd/McmdEvent.h> |
22 |
#include <mcmd/McmdRecord.h> |
23 |
#include <PscuHeader.h> |
24 |
#include <EventHeader.h> |
25 |
#include <sstream> |
26 |
#include <fstream> |
27 |
#include <YMcmd.h> |
28 |
|
29 |
using namespace std; |
30 |
void McmdToXML(TString base, TString outDirectory = "", TString xslPath = ""){ |
31 |
|
32 |
Int_t tmpSize; |
33 |
Int_t tmpSize2; |
34 |
ofstream outputFile; |
35 |
stringstream oss; |
36 |
|
37 |
McmdScan *mcmdReader = new McmdScan(); |
38 |
TArrayC *data; |
39 |
pamela::McmdEvent *mcmde = 0; |
40 |
pamela::McmdRecord *mcmdr = 0; |
41 |
pamela::EventHeader *eh = 0; |
42 |
pamela::PscuHeader *ph = 0; |
43 |
TFile *rootFile = new TFile(base); |
44 |
|
45 |
if (rootFile->IsZombie()) printf("The %s file does not exist", base.Data()); |
46 |
TString fileName = ((TObjString*)base.Tokenize('\/')->Last())->GetString(); |
47 |
TString filePath = base; |
48 |
filePath.ReplaceAll(fileName, ""); |
49 |
fileName.ReplaceAll(".root", ""); |
50 |
|
51 |
oss.str(""); |
52 |
if (outDirectory == "") { |
53 |
oss << fileName.Data() << "Mcmd.xml"; |
54 |
} else { |
55 |
oss << outDirectory.Data() << fileName.Data() << "Mcmd.xml"; |
56 |
} |
57 |
const char* xmlFilePath = oss.str().c_str(); |
58 |
|
59 |
outputFile.open(xmlFilePath, ios::trunc); |
60 |
if (!outputFile.is_open()){ |
61 |
printf("Cannot open the file %s for the output", xmlFilePath); |
62 |
exit(0); |
63 |
} |
64 |
|
65 |
//Takes the tree of the header file |
66 |
TTree *tr = (TTree*)rootFile->Get("Mcmd"); |
67 |
Long64_t nevents = tr->GetEntries(); |
68 |
tr->SetBranchAddress("Mcmd", &mcmde); |
69 |
tr->SetBranchAddress("Header", &eh); |
70 |
outputFile << "<?xml version='1.0' encoding='ISO-8859-1'?>\n"; |
71 |
outputFile << "<!-- Prologo XML -->\n"; |
72 |
outputFile << "<?xml-stylesheet type='text/xsl' href='" << xslPath.Data() << "'?>\n"; |
73 |
outputFile << "<McmdFile fileName = '" << fileName.Data() << "'>\n"; |
74 |
|
75 |
//<!-- Istruzione che indica il documento XSLT da associare --> |
76 |
for (int i = 0; i < nevents; i++){ |
77 |
tr->GetEntry(i); |
78 |
tmpSize = mcmde->Records->GetEntries(); |
79 |
ph = eh->GetPscuHeader(); |
80 |
outputFile << "\t<McmdEvent PacketOBT = '" << ph->GetOrbitalTime() |
81 |
<< "' PacketNum = '" << ph->GetCounter() << "'>\n"; |
82 |
for (int j = 0; j < tmpSize; j++){ |
83 |
mcmdr = (pamela::McmdRecord*)mcmde->Records->At(j); |
84 |
outputFile << "\t\t<McmdRecord McmdOBT = '" << mcmdr->MCMD_RECORD_OBT |
85 |
<< "' SeqID = '" << (int)mcmdr->SeqID |
86 |
<< "' ID1 = '" << hex << (int)mcmdr->ID1 << "'>\n"; |
87 |
//printf("mcmd Code: %x \n", mcmdr->ID1); |
88 |
outputFile << mcmdReader->extract(mcmdr->McmdData, mcmdr->ID1, "\t\t\t"); |
89 |
|
90 |
outputFile << "\t\t</McmdRecord>\n"; |
91 |
} |
92 |
outputFile << "\t</McmdEvent>\n"; |
93 |
} |
94 |
outputFile << "</McmdFile>\n"; |
95 |
outputFile.close(); |
96 |
} |
97 |
|
98 |
int main(int argc, char* argv[]){ |
99 |
TString outDir = ""; |
100 |
TString xslPath = ""; |
101 |
|
102 |
if (argc < 2){ |
103 |
printf("You have to insert at least the file to analyze \n"); |
104 |
printf("Try '--help' for more information. \n"); |
105 |
exit(1); |
106 |
} |
107 |
|
108 |
if (!strcmp(argv[1], "--help")){ |
109 |
printf( "Usage: McmdToXML FILE [OPTION] \n"); |
110 |
printf( "\t --help Print this help and exit \n"); |
111 |
printf( "\t -outDir[path] Path where to put the output [default ./] \n"); |
112 |
printf( "\t -xslPath[path] Set the path to a XSL file for formatting [default '']\n"); |
113 |
exit(1); |
114 |
} |
115 |
|
116 |
for (int i = 2; i < argc; i++){ |
117 |
if (!strcmp(argv[i], "-outDir")){ |
118 |
if (++i >= argc){ |
119 |
printf( "-outDir needs arguments. \n"); |
120 |
printf( "Try '--help' for more information. \n"); |
121 |
exit(1); |
122 |
} else { |
123 |
outDir = argv[i]; |
124 |
continue; |
125 |
} |
126 |
} |
127 |
|
128 |
if (!strcmp(argv[i], "-xslPath")) |
129 |
if (++i >= argc){ |
130 |
printf( "-xslPath needs arguments. \n"); |
131 |
printf( "Try '--help' for more information. \n"); |
132 |
exit(1); |
133 |
} else { |
134 |
xslPath = argv[i]; |
135 |
continue; |
136 |
} |
137 |
} |
138 |
McmdToXML(argv[1], outDir, xslPath); |
139 |
} |
140 |
|
141 |
|
142 |
|