1 |
kusanagi |
1.1 |
/** |
2 |
|
|
* PyhsEndRunToXML |
3 |
|
|
* author Nagni |
4 |
|
|
* version 2.0 - 14 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 - 14 February 2006 |
17 |
|
|
* Modified for new Yoda unpacking structure (one single file) |
18 |
|
|
*/ |
19 |
|
|
#include <endrun/PhysEndRunEvent.h> |
20 |
|
|
#include <endrun/CaloEndRun.h> |
21 |
|
|
#include <endrun/TBEndRun.h> |
22 |
|
|
#include <PscuHeader.h> |
23 |
|
|
#include <EventHeader.h> |
24 |
|
|
#include <fstream> |
25 |
mocchiut |
1.4 |
#include <cstdlib> |
26 |
|
|
#include <sys/stat.h> |
27 |
kusanagi |
1.1 |
#include <TFile.h> |
28 |
|
|
#include <TObjString.h> |
29 |
|
|
#include <TString.h> |
30 |
|
|
#include <TTree.h> |
31 |
|
|
|
32 |
|
|
void PhysEndRunToXML(TString base, TString outDirectory = "", TString xslPath = ""){ |
33 |
|
|
|
34 |
mocchiut |
1.4 |
// Int_t tmpSize; |
35 |
kusanagi |
1.1 |
ofstream outputFile; |
36 |
|
|
stringstream oss; |
37 |
|
|
|
38 |
|
|
pamela::PhysEndRunEvent *pere = 0; |
39 |
|
|
pamela::CaloEndRun cer; |
40 |
|
|
pamela::TBEndRun ter; |
41 |
|
|
|
42 |
|
|
pamela::EventHeader *eh = 0; |
43 |
|
|
pamela::PscuHeader *ph = 0; |
44 |
|
|
TFile *rootFile = new TFile(base); |
45 |
|
|
|
46 |
|
|
if (rootFile->IsZombie()) printf("The %s file does not exist", base.Data()); |
47 |
|
|
TString fileName = ((TObjString*)base.Tokenize('\/')->Last())->GetString(); |
48 |
|
|
TString filePath = base; |
49 |
|
|
filePath.ReplaceAll(fileName, ""); |
50 |
|
|
fileName.ReplaceAll(".root", ""); |
51 |
|
|
|
52 |
|
|
oss.str(""); |
53 |
|
|
if (outDirectory == "") { |
54 |
|
|
oss << fileName.Data() << "PhysEndRun.xml"; |
55 |
|
|
} else { |
56 |
|
|
oss << outDirectory.Data() << fileName.Data() << "PhysEndRun.xml"; |
57 |
|
|
} |
58 |
|
|
const char* xmlFilePath = oss.str().c_str(); |
59 |
|
|
|
60 |
|
|
outputFile.open(xmlFilePath, ios::trunc); |
61 |
|
|
if (!outputFile.is_open()){ |
62 |
|
|
printf("Cannot open the file %s for the output", xmlFilePath); |
63 |
|
|
exit(0); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
//Takes the tree of the header file |
68 |
|
|
TTree *tr = (TTree*)rootFile->Get("PhysEndRun"); |
69 |
|
|
Long64_t nevents = tr->GetEntries(); |
70 |
|
|
tr->SetBranchAddress("PhysEndRun", &pere); |
71 |
|
|
tr->SetBranchAddress("Header", &eh); |
72 |
|
|
outputFile << "<?xml version='1.0' encoding='ISO-8859-1'?>\n"; |
73 |
|
|
outputFile << "<!-- Prologo XML -->\n"; |
74 |
|
|
outputFile << "<?xml-stylesheet type='text/xsl' href='" << xslPath.Data() << "'?>\n"; |
75 |
|
|
outputFile << "<ROOT_SOURCE>\n"; |
76 |
|
|
|
77 |
|
|
//<!-- Istruzione che indica il documento XSLT da associare --> |
78 |
|
|
for (int i = 0; i < nevents; i++){ |
79 |
|
|
tr->GetEntry(i); |
80 |
|
|
ph = eh->GetPscuHeader(); |
81 |
|
|
outputFile << "<PHYSER_EVENT>\n"; |
82 |
kusanagi |
1.2 |
outputFile << "\t<PACKET_OBT>" << dec << ph->GetOrbitalTime() << "</PACKET_OBT>\n"; |
83 |
kusanagi |
1.1 |
outputFile << "\t<PACKET_NUM>" << ph->GetCounter() << "</PACKET_NUM>\n"; |
84 |
|
|
outputFile << "\t<CALOENDRUN_RECORDS>\n"; |
85 |
|
|
for (int j = 0; j < 4; j++){ |
86 |
|
|
cer = pere->CALO_ENDRUN[j]; |
87 |
|
|
outputFile << "\t\t<CALOENDRUN_RECORD>\n"; |
88 |
|
|
outputFile << "\t\t\t<BOARD_ID_HK>" << (int)cer.CALO_BOARD_ID_HK << "</BOARD_ID_HK>\n"; |
89 |
|
|
outputFile << "\t\t\t<BOARD_ST_HK>" << (int)cer.CALO_BOARD_STATUS_HK << "</BOARD_ST_HK>\n"; |
90 |
|
|
outputFile << "\t\t\t<HK0>\n"; |
91 |
|
|
for (int k = 0; k < 11; k++){ |
92 |
|
|
outputFile << "\t\t\t\t<HK0_ITEM>" << (int)cer.CALO_HK0[k] << "</HK0_ITEM>\n"; |
93 |
|
|
} |
94 |
|
|
outputFile << "\t\t\t</HK0>\n"; |
95 |
|
|
outputFile << "\t\t\t<HK1>\n"; |
96 |
|
|
for (int k = 0; k < 11; k++){ |
97 |
|
|
outputFile << "\t\t\t\t<HK1_ITEM>" << (int)cer.CALO_HK1[k] << "</HK1_ITEM>\n"; |
98 |
|
|
} |
99 |
|
|
outputFile << "\t\t\t</HK1>\n"; |
100 |
|
|
outputFile << "\t\t\t<CALO_REG>\n"; |
101 |
|
|
for (int k = 0; k < 7; k++){ |
102 |
mocchiut |
1.3 |
outputFile << "\t\t\t\t<CALO_REG_ITEM>" << (short)cer.CALO_BOARD_ID_REG[k] << "</CALO_REG_ITEM>\n"; |
103 |
|
|
outputFile << "\t\t\t\t<CALO_REG_ITEM>" << (short)cer.CALO_BOARD_STATUS_REG[k] << "</CALO_REG_ITEM>\n"; |
104 |
kusanagi |
1.1 |
outputFile << "\t\t\t\t<CALO_REG_ITEM>" << (int)cer.CALO_REG[k] << "</CALO_REG_ITEM>\n"; |
105 |
|
|
} |
106 |
|
|
outputFile << "\t\t\t</CALO_REG>\n"; |
107 |
|
|
outputFile << "\t\t</CALOENDRUN_RECORD>\n"; |
108 |
|
|
} |
109 |
|
|
outputFile << "\t</CALOENDRUN_RECORDS>\n"; |
110 |
|
|
|
111 |
|
|
outputFile << "\t<TBENDRUN>\n"; |
112 |
|
|
ter = pere->TB_ENDRUN; |
113 |
mocchiut |
1.3 |
outputFile << "\t\t<ALARM_MASK>" << (UInt_t)ter.TB_ALARM_MASK << "</ALARM_MASK>\n"; |
114 |
|
|
outputFile << "\t\t<PMT_MASK_S3S2S12>" << (UInt_t)ter.TB_PMT_MASK_S3S2S12 << "</PMT_MASK_S3S2S12>\n"; |
115 |
|
|
outputFile << "\t\t<PMT_MASK_S11CRC>" << (UInt_t)ter.TB_PMT_MASK_S11CRC << "</PMT_MASK_S11CRC>\n"; |
116 |
|
|
outputFile << "\t\t<PMT_MASK_S4CAL>" << (UInt_t)ter.TB_S4_CAL_MASK << "</PMT_MASK_S4CAL>\n"; |
117 |
|
|
outputFile << "\t\t<BUSY_MASK>" << (UInt_t)ter.TB_BUSY_MASK << "</BUSY_MASK>\n"; |
118 |
|
|
outputFile << "\t\t<TRIG_CONF>" << (UInt_t)ter.TB_TRIG_CONF << "</TRIG_CONF>\n"; |
119 |
kusanagi |
1.1 |
outputFile << "\t</TBENDRUN>\n"; |
120 |
|
|
|
121 |
|
|
outputFile << "</PHYSER_EVENT>\n"; |
122 |
|
|
} |
123 |
|
|
outputFile << "</ROOT_SOURCE>\n"; |
124 |
|
|
outputFile.close(); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
int main(int argc, char* argv[]){ |
128 |
|
|
TString outDir = ""; |
129 |
|
|
TString xslPath = ""; |
130 |
|
|
|
131 |
|
|
if (argc < 2){ |
132 |
|
|
printf("You have to insert at least the file to analyze \n"); |
133 |
|
|
printf("Try '--help' for more information. \n"); |
134 |
|
|
exit(1); |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
if (!strcmp(argv[1], "--help")){ |
138 |
|
|
printf( "Usage: PhysEndRunToXML FILE [OPTION] \n"); |
139 |
|
|
printf( "\t --help Print this help and exit \n"); |
140 |
|
|
printf( "\t -outDir[path] Path where to put the output [default ~/tmp] \n"); |
141 |
|
|
printf( "\t -xslPath[path] Set the path to a XSL file for formatting [default '']\n"); |
142 |
|
|
exit(1); |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
for (int i = 2; i < argc; i++){ |
146 |
|
|
if (!strcmp(argv[i], "-outDir")){ |
147 |
mocchiut |
1.4 |
if (++i >= argc){ |
148 |
|
|
printf( "-outDir needs arguments. \n"); |
149 |
|
|
printf( "Try '--help' for more information. \n"); |
150 |
|
|
exit(1); |
151 |
|
|
} else { |
152 |
|
|
outDir = argv[i]; |
153 |
|
|
continue; |
154 |
|
|
} |
155 |
kusanagi |
1.1 |
} |
156 |
mocchiut |
1.4 |
|
157 |
|
|
if (!strcmp(argv[i], "-xslPath")){ |
158 |
|
|
if (++i >= argc){ |
159 |
|
|
printf( "-xslPath needs arguments. \n"); |
160 |
|
|
printf( "Try '--help' for more information. \n"); |
161 |
|
|
exit(1); |
162 |
|
|
} else { |
163 |
|
|
xslPath = argv[i]; |
164 |
|
|
continue; |
165 |
|
|
} |
166 |
kusanagi |
1.1 |
} |
167 |
mocchiut |
1.4 |
} |
168 |
kusanagi |
1.1 |
PhysEndRunToXML(argv[1], outDir, xslPath); |
169 |
|
|
} |
170 |
|
|
|