/[PAMELA software]/quicklook/dataToXML/VarDumpToXML.cpp
ViewVC logotype

Contents of /quicklook/dataToXML/VarDumpToXML.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Tue Apr 25 09:00:20 2006 UTC (18 years, 7 months ago) by kusanagi
Branch: MAIN
CVS Tags: dataToXML1_02/01, dataToXML1_02/00, dataToXML1_03/00, dataToXML1_03/01, dataToXML1_00/00, firstRelease, dataToXML1_01/00, dataToXML1_03_02, HEAD
Changes since 1.1: +0 -0 lines
Error occurred while calculating annotation data.
These program extract in an XML format the info contained into the ROOT files generated by YODA from the PAMELA data. To visualize the XML files in a more human readable format a collection of XSL files are given in the Data subfolder.

1 /**
2 * VarDumpToXML
3 * author Nagni
4 * version 2.0 - 06 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 - 06 February 2006
17 * Modified for new Yoda unpacking structure (one single file)
18 */
19 #include <varDump/VarDumpRecord.h>
20 #include <varDump/VarDumpEvent.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 void VarDumpToXML(TString base, TString outDirectory = "", TString xslPath = ""){
31
32 Int_t tmpSize;
33 ofstream outputFile;
34 stringstream oss;
35
36 pamela::VarDumpEvent *vde = 0;
37 pamela::VarDumpRecord *vdr = 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() << "VarDump.xml";
52 } else {
53 oss << outDirectory.Data() << fileName.Data() << "VarDump.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("VarDump");
64 Long64_t nevents = tr->GetEntries();
65 tr->SetBranchAddress("VarDump", &vde);
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'>ID - Name</COL>\n";
73 outputFile << "<COL id='seconda'>Value</COL>\n";
74 outputFile << "<COL id='terza'>Description</COL>\n";
75 outputFile << "</TABLE_HEAD>\n";
76
77 for (int i = 0; i < nevents; i++){
78 tr->GetEntry(i);
79 tmpSize = vde->Records->GetEntries();
80 ph = eh->GetPscuHeader();
81 outputFile << "<VARDUMP_EVENT>\n";
82 outputFile << "\t<PACKET_OBT>" << ph->GetOrbitalTime() << "</PACKET_OBT>\n";
83 outputFile << "\t<PACKET_NUM>" << ph->GetCounter() << "</PACKET_NUM>\n";
84 outputFile << "\t<COMPILATION_TS>" << vde->PARAMETER_STAMP << "</COMPILATION_TS>\n";
85 outputFile << "\t<VARDUMP_RECORDS>\n";
86 for (Int_t j = 0; j < tmpSize; j++){
87 vdr = (pamela::VarDumpRecord*)vde->Records->At(j);
88 outputFile << "\t\t<VARDUMP_RECORD>\n";
89 outputFile << "\t\t\t<VAR_ID>" << (short)vdr->VAR_ID << "</VAR_ID>\n";
90 outputFile << "\t\t\t<VAR_VALUE>" << vdr->VAR_VALUE << "</VAR_VALUE>\n";
91 outputFile << "\t\t</VARDUMP_RECORD>\n";
92 }
93 outputFile << "\t</VARDUMP_RECORDS>\n";
94 outputFile << "</VARDUMP_EVENT>\n";
95 }
96 outputFile << "</ROOT_SOURCE>\n";
97 outputFile.close();
98 }
99
100 int main(int argc, char* argv[]){
101 TString outDir = "";
102 TString xslPath = "";
103
104 if (argc < 2){
105 printf("You have to insert at least the file to analyze \n");
106 printf("Try '--help' for more information. \n");
107 exit(1);
108 }
109
110 if (!strcmp(argv[1], "--help")){
111 printf( "Usage: VarDumpToXML FILE [OPTION] \n");
112 printf( "\t --help Print this help and exit \n");
113 printf( "\t -outDir[path] Path where to put the output [default ~/tmp] \n");
114 printf( "\t -xslPath[path] Set the path to a XSL file for formatting [default '']\n");
115 exit(1);
116 }
117
118 for (int i = 2; i < argc; i++){
119 if (!strcmp(argv[i], "-outDir")){
120 if (++i >= argc){
121 printf( "-outDir needs arguments. \n");
122 printf( "Try '--help' for more information. \n");
123 exit(1);
124 } else {
125 outDir = argv[i];
126 continue;
127 }
128 }
129
130 if (!strcmp(argv[i], "-xslPath"))
131 if (++i >= argc){
132 printf( "-xslPath needs arguments. \n");
133 printf( "Try '--help' for more information. \n");
134 exit(1);
135 } else {
136 xslPath = argv[i];
137 continue;
138 }
139 }
140 VarDumpToXML(argv[1], outDir, xslPath);
141 }

  ViewVC Help
Powered by ViewVC 1.1.23