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

Annotation of /quicklook/dataToXML/ArrDumpToXML.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed Jun 14 07:25:24 2006 UTC (18 years, 6 months ago) by kusanagi
Branch: MAIN
CVS Tags: dataToXML1_02/01, dataToXML1_02/00, dataToXML1_03/00, dataToXML1_03/01, dataToXML1_03_02, HEAD
Changes since 1.1: +5 -1 lines
Bugfix: Elena reported a wrong representation of the values, related to the little-endian/big-endian representation.

1 kusanagi 1.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 kusanagi 1.2 #include <yodaUtility.h>
24 kusanagi 1.1 #include <fstream>
25    
26     #include <TFile.h>
27     #include <TObjString.h>
28     #include <TString.h>
29     #include <TTree.h>
30    
31    
32     void ArrDumpToXML(TString base, TString outDirectory = "", TString xslPath = ""){
33    
34     Int_t tmpSize;
35     ofstream outputFile;
36     stringstream oss;
37    
38     pamela::ArrDumpEvent *ade = 0;
39     pamela::ArrDumpRecord *adr = 0;
40     pamela::EventHeader *eh = 0;
41     pamela::PscuHeader *ph = 0;
42     TFile *rootFile = new TFile(base);
43    
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() << "ArrDump.xml";
54     } else {
55     oss << outDirectory.Data() << fileName.Data() << "ArrDump.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    
66     TTree *tr = (TTree*)rootFile->Get("ArrDump");
67     Long64_t nevents = tr->GetEntries();
68 kusanagi 1.2 UInt_t k_data = 0;
69 kusanagi 1.1 tr->SetBranchAddress("ArrDump", &ade);
70     tr->SetBranchAddress("Header", &eh);
71     outputFile << "<?xml version='1.0' encoding='ISO-8859-1'?>\n";
72     outputFile << "<!-- Prologo XML -->\n";
73     outputFile << "<?xml-stylesheet type='text/xsl' href='" << xslPath.Data() << "'?>\n";
74     outputFile << "<ROOT_SOURCE>\n";
75     for (int i = 0; i < nevents; i++){
76     tr->GetEntry(i);
77     tmpSize = ade->Records->GetEntries();
78     ph = eh->GetPscuHeader();
79     outputFile << "<ARRDUMP_EVENT>\n";
80     outputFile << "\t<PACKET_OBT>" << ph->GetOrbitalTime() << "</PACKET_OBT>\n";
81     outputFile << "\t<PACKET_NUM>" << ph->GetCounter() << "</PACKET_NUM>\n";
82     outputFile << "\t<COMPILATION_TS>" << ade->PARAMETER_STAMP << "</COMPILATION_TS>\n";
83     outputFile << "\t<ARRDUMP_RECORDS>\n";
84     for (int j = 0; j < tmpSize; j++){
85     adr = (pamela::ArrDumpRecord*)ade->Records->At(j);
86     outputFile << "\t\t<ARRDUMP_RECORD>\n";
87     outputFile << "\t\t\t<ARR_ID>" << (short)adr->Arr_ID << "</ARR_ID>\n";
88     TArrayI *Data = (TArrayI*)adr->Data;
89     for (int k = 0; k < adr->Arr_len; k++){
90 kusanagi 1.2 k_data = (UInt_t)Data->At(k);
91     Utility::endian_swap(k_data);
92     outputFile << "\t\t\t<ARR_VALUE>" << k_data << "</ARR_VALUE>\n";
93 kusanagi 1.1 }
94     outputFile << "\t\t</ARRDUMP_RECORD>\n";
95     }
96     outputFile << "\t</ARRDUMP_RECORDS>\n";
97     outputFile << "</ARRDUMP_EVENT>\n";
98     }
99     outputFile << "</ROOT_SOURCE>\n";
100     outputFile.close();
101     }
102    
103     int main(int argc, char* argv[]){
104     TString outDir = "";
105     TString xslPath = "";
106    
107     if (argc < 2){
108     printf("You have to insert at least the file to analyze \n");
109     printf("Try '--help' for more information. \n");
110     exit(1);
111     }
112    
113     if (!strcmp(argv[1], "--help")){
114     printf( "Usage: ArrDumpToXML FILE [OPTION] \n");
115     printf( "\t --help Print this help and exit \n");
116     printf( "\t -outDir[path] Path where to put the output [default ~/tmp] \n");
117     printf( "\t -xslPath[path] Set the path to a XSL file for formatting [default '']\n");
118     exit(1);
119     }
120    
121     for (int i = 2; i < argc; i++){
122     if (!strcmp(argv[i], "-outDir")){
123     if (++i >= argc){
124     printf( "-outDir needs arguments. \n");
125     printf( "Try '--help' for more information. \n");
126     exit(1);
127     } else {
128     outDir = argv[i];
129     continue;
130     }
131     }
132    
133     if (!strcmp(argv[i], "-xslPath"))
134     if (++i >= argc){
135     printf( "-xslPath needs arguments. \n");
136     printf( "Try '--help' for more information. \n");
137     exit(1);
138     } else {
139     xslPath = argv[i];
140     continue;
141     }
142     }
143     ArrDumpToXML(argv[1], outDir, xslPath);
144     }

  ViewVC Help
Powered by ViewVC 1.1.23