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

Annotation of /quicklook/dataToXML/TabDumpToXML.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (download) (vendor branch)
Tue Apr 25 09:00:20 2006 UTC (18 years, 7 months ago) by kusanagi
CVS Tags: dataToXML1_00/00, firstRelease, dataToXML1_01/00
Changes since 1.1: +0 -0 lines
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 kusanagi 1.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 <fstream>
22    
23     #include <TFile.h>
24     #include <TObjString.h>
25     #include <TString.h>
26     #include <TTree.h>
27    
28    
29     void TabDumpToXML(TString base, TString outDirectory = "", TString xslPath = ""){
30    
31     Int_t tmpSize, nrow, ncol;
32     ofstream outputFile;
33     stringstream oss;
34    
35     pamela::TabDumpEvent *tde = 0;
36     pamela::TabDumpRecord *tdr = 0;
37     pamela::EventHeader *eh = 0;
38     pamela::PscuHeader *ph = 0;
39     TFile *rootFile = new TFile(base);
40    
41    
42     if (rootFile->IsZombie()) printf("The %s file does not exist", base.Data());
43     TString fileName = ((TObjString*)base.Tokenize('\/')->Last())->GetString();
44     TString filePath = base;
45     filePath.ReplaceAll(fileName, "");
46     fileName.ReplaceAll(".root", "");
47    
48     oss.str("");
49     if (outDirectory == "") {
50     oss << fileName.Data() << "TabDump.xml";
51     } else {
52     oss << outDirectory.Data() << fileName.Data() << "TabDump.xml";
53     }
54     const char* xmlFilePath = oss.str().c_str();
55    
56     outputFile.open(xmlFilePath, ios::trunc);
57     if (!outputFile.is_open()){
58     printf("Cannot open the file %s for the output", xmlFilePath);
59     exit(0);
60     }
61    
62    
63     TTree *tr = (TTree*)rootFile->Get("TabDump");
64     Long64_t nevents = tr->GetEntries();
65     tr->SetBranchAddress("TabDump", &tde);
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     for (int i = 0; i < nevents; i++){
72     tr->GetEntry(i);
73     tmpSize = tde->Records->GetEntries();
74     ph = eh->GetPscuHeader();
75     outputFile << "<TABDUMP_EVENT>\n";
76     outputFile << "\t<PACKET_OBT>" << ph->GetOrbitalTime() << "</PACKET_OBT>\n";
77     outputFile << "\t<PACKET_NUM>" << ph->GetCounter() << "</PACKET_NUM>\n";
78     outputFile << "\t<COMPILATION_TS>" << tde->PARAMETER_STAMP << "</COMPILATION_TS>\n";
79     outputFile << "\t<TABDUMP_RECORDS>\n";
80     for (int j = 0; j < tmpSize; j++){
81     tdr = (pamela::TabDumpRecord*)tde->Records->At(j);
82     nrow = (short)tdr->Nrow;
83     ncol = (short)tdr->Ncol;
84     outputFile << "\t\t<TABDUMP_RECORD>\n";
85     outputFile << "\t\t\t<TAB_ID>" << (short)tdr->Tab_ID << "</TAB_ID>\n";
86    
87     TArrayI *Data = (TArrayI*)tdr->Data;
88     for (int k = 0; k < nrow; k++){
89     outputFile << "\t\t\t<ROW> \n";
90     for (int z = 0; z < ncol; z++){
91     outputFile << "\t\t\t<COL>" << (unsigned int)Data->At((k*ncol) + z) << "</COL>\n";
92     }
93     outputFile << "\t\t\t</ROW> \n";
94     }
95    
96     outputFile << "\t\t</TABDUMP_RECORD>\n";
97     }
98     outputFile << "\t</TABDUMP_RECORDS>\n";
99     outputFile << "</TABDUMP_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: TabDumpToXML 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     TabDumpToXML(argv[1], outDir, xslPath);
146     }

  ViewVC Help
Powered by ViewVC 1.1.23