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

Annotation of /quicklook/dataToXML/PhysEndRunToXML.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Tue Oct 14 07:42:48 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: MAIN
Changes since 1.2: +8 -14 lines
New PhysEndRun class (chewbacca) needs new PhysEndRunToXML

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    
26     #include <TFile.h>
27     #include <TObjString.h>
28     #include <TString.h>
29     #include <TTree.h>
30    
31     void PhysEndRunToXML(TString base, TString outDirectory = "", TString xslPath = ""){
32    
33     Int_t tmpSize;
34     ofstream outputFile;
35     stringstream oss;
36    
37     pamela::PhysEndRunEvent *pere = 0;
38     pamela::CaloEndRun cer;
39     pamela::TBEndRun ter;
40    
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() << "PhysEndRun.xml";
54     } else {
55     oss << outDirectory.Data() << fileName.Data() << "PhysEndRun.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     //Takes the tree of the header file
67     TTree *tr = (TTree*)rootFile->Get("PhysEndRun");
68     Long64_t nevents = tr->GetEntries();
69     tr->SetBranchAddress("PhysEndRun", &pere);
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    
76     //<!-- Istruzione che indica il documento XSLT da associare -->
77     for (int i = 0; i < nevents; i++){
78     tr->GetEntry(i);
79     ph = eh->GetPscuHeader();
80     outputFile << "<PHYSER_EVENT>\n";
81 kusanagi 1.2 outputFile << "\t<PACKET_OBT>" << dec << ph->GetOrbitalTime() << "</PACKET_OBT>\n";
82 kusanagi 1.1 outputFile << "\t<PACKET_NUM>" << ph->GetCounter() << "</PACKET_NUM>\n";
83     outputFile << "\t<CALOENDRUN_RECORDS>\n";
84     for (int j = 0; j < 4; j++){
85     cer = pere->CALO_ENDRUN[j];
86     outputFile << "\t\t<CALOENDRUN_RECORD>\n";
87     outputFile << "\t\t\t<BOARD_ID_HK>" << (int)cer.CALO_BOARD_ID_HK << "</BOARD_ID_HK>\n";
88     outputFile << "\t\t\t<BOARD_ST_HK>" << (int)cer.CALO_BOARD_STATUS_HK << "</BOARD_ST_HK>\n";
89     outputFile << "\t\t\t<HK0>\n";
90     for (int k = 0; k < 11; k++){
91     outputFile << "\t\t\t\t<HK0_ITEM>" << (int)cer.CALO_HK0[k] << "</HK0_ITEM>\n";
92     }
93     outputFile << "\t\t\t</HK0>\n";
94     outputFile << "\t\t\t<HK1>\n";
95     for (int k = 0; k < 11; k++){
96     outputFile << "\t\t\t\t<HK1_ITEM>" << (int)cer.CALO_HK1[k] << "</HK1_ITEM>\n";
97     }
98     outputFile << "\t\t\t</HK1>\n";
99     outputFile << "\t\t\t<CALO_REG>\n";
100     for (int k = 0; k < 7; k++){
101 mocchiut 1.3 outputFile << "\t\t\t\t<CALO_REG_ITEM>" << (short)cer.CALO_BOARD_ID_REG[k] << "</CALO_REG_ITEM>\n";
102     outputFile << "\t\t\t\t<CALO_REG_ITEM>" << (short)cer.CALO_BOARD_STATUS_REG[k] << "</CALO_REG_ITEM>\n";
103 kusanagi 1.1 outputFile << "\t\t\t\t<CALO_REG_ITEM>" << (int)cer.CALO_REG[k] << "</CALO_REG_ITEM>\n";
104     }
105     outputFile << "\t\t\t</CALO_REG>\n";
106     outputFile << "\t\t</CALOENDRUN_RECORD>\n";
107     }
108     outputFile << "\t</CALOENDRUN_RECORDS>\n";
109    
110     outputFile << "\t<TBENDRUN>\n";
111     ter = pere->TB_ENDRUN;
112 mocchiut 1.3 outputFile << "\t\t<ALARM_MASK>" << (UInt_t)ter.TB_ALARM_MASK << "</ALARM_MASK>\n";
113     outputFile << "\t\t<PMT_MASK_S3S2S12>" << (UInt_t)ter.TB_PMT_MASK_S3S2S12 << "</PMT_MASK_S3S2S12>\n";
114     outputFile << "\t\t<PMT_MASK_S11CRC>" << (UInt_t)ter.TB_PMT_MASK_S11CRC << "</PMT_MASK_S11CRC>\n";
115     outputFile << "\t\t<PMT_MASK_S4CAL>" << (UInt_t)ter.TB_S4_CAL_MASK << "</PMT_MASK_S4CAL>\n";
116     outputFile << "\t\t<BUSY_MASK>" << (UInt_t)ter.TB_BUSY_MASK << "</BUSY_MASK>\n";
117     outputFile << "\t\t<TRIG_CONF>" << (UInt_t)ter.TB_TRIG_CONF << "</TRIG_CONF>\n";
118 kusanagi 1.1 outputFile << "\t</TBENDRUN>\n";
119    
120     outputFile << "</PHYSER_EVENT>\n";
121     }
122     outputFile << "</ROOT_SOURCE>\n";
123     outputFile.close();
124     }
125    
126     int main(int argc, char* argv[]){
127     TString outDir = "";
128     TString xslPath = "";
129    
130     if (argc < 2){
131     printf("You have to insert at least the file to analyze \n");
132     printf("Try '--help' for more information. \n");
133     exit(1);
134     }
135    
136     if (!strcmp(argv[1], "--help")){
137     printf( "Usage: PhysEndRunToXML FILE [OPTION] \n");
138     printf( "\t --help Print this help and exit \n");
139     printf( "\t -outDir[path] Path where to put the output [default ~/tmp] \n");
140     printf( "\t -xslPath[path] Set the path to a XSL file for formatting [default '']\n");
141     exit(1);
142     }
143    
144     for (int i = 2; i < argc; i++){
145     if (!strcmp(argv[i], "-outDir")){
146     if (++i >= argc){
147     printf( "-outDir needs arguments. \n");
148     printf( "Try '--help' for more information. \n");
149     exit(1);
150     } else {
151     outDir = argv[i];
152     continue;
153     }
154     }
155    
156     if (!strcmp(argv[i], "-xslPath"))
157     if (++i >= argc){
158     printf( "-xslPath needs arguments. \n");
159     printf( "Try '--help' for more information. \n");
160     exit(1);
161     } else {
162     xslPath = argv[i];
163     continue;
164     }
165     }
166     PhysEndRunToXML(argv[1], outDir, xslPath);
167     }
168    

  ViewVC Help
Powered by ViewVC 1.1.23