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

Contents of /quicklook/dataToXML/RunHeaderToXML.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Fri Jan 17 15:10:33 2014 UTC (10 years, 10 months ago) by mocchiut
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +12 -10 lines
Compilation warnings using GCC4.7 fixed

1 /**
2 * RunHeaderToXML
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 <RunHeaderEvent.h>
20 #include <PscuHeader.h>
21 #include <EventHeader.h>
22 #include <fstream>
23 #include <cstdlib>
24 #include <sys/stat.h>
25 #include <TFile.h>
26 #include <TObjString.h>
27 #include <TString.h>
28 #include <TTree.h>
29
30 void RunHeaderToXML(TString base, TString outDirectory = "", TString xslPath = ""){
31
32 // Int_t tmpSize;
33 ofstream outputFile;
34 stringstream oss;
35
36 pamela::RunHeaderEvent *rhe = 0;
37 pamela::EventHeader *eh = 0;
38 pamela::PscuHeader *ph = 0;
39 TFile *rootFile = new TFile(base);
40
41 if (rootFile->IsZombie()) printf("The %s file does not exist", base.Data());
42 TString fileName = ((TObjString*)base.Tokenize('\/')->Last())->GetString();
43 TString filePath = base;
44 filePath.ReplaceAll(fileName, "");
45 fileName.ReplaceAll(".root", "");
46
47 oss.str("");
48 if (outDirectory == "") {
49 oss << fileName.Data() << "RunHeader.xml";
50 } else {
51 oss << outDirectory.Data() << fileName.Data() << "RunHeader.xml";
52 }
53 const char* xmlFilePath = oss.str().c_str();
54
55 outputFile.open(xmlFilePath, ios::trunc);
56 if (!outputFile.is_open()){
57 printf("Cannot open the file %s for the output", xmlFilePath);
58 exit(0);
59 }
60
61 //Takes the tree of the header file
62 TTree *tr = (TTree*)rootFile->Get("RunHeader");
63 Long64_t nevents = tr->GetEntries();
64 tr->SetBranchAddress("RunHeader", &rhe);
65 tr->SetBranchAddress("Header", &eh);
66 outputFile << "<?xml version='1.0' encoding='ISO-8859-1'?>\n";
67 outputFile << "<!-- Prologo XML -->\n";
68 outputFile << "<?xml-stylesheet type='text/xsl' href='" << xslPath.Data() << "'?>\n";
69 outputFile << "<ROOT_SOURCE>\n";
70 for (int i = 0; i < nevents; i++){
71 tr->GetEntry(i);
72 ph = eh->GetPscuHeader();
73 outputFile << "<RUN_HEADER_EVENT>\n";
74 outputFile << "\t<PACKET_OBT>" << ph->GetOrbitalTime() << "</PACKET_OBT>\n";
75 outputFile << "\t<PACKET_NUM>" << ph->GetCounter() << "</PACKET_NUM>\n";
76 outputFile << "\t<COMPILATION_TS>" << rhe->COMPILATIONTIMESTAMP << "</COMPILATION_TS>\n";
77 outputFile << "\t<RM_SETT_MODE>" << (int)rhe->RM_ACQ_SETTING_MODE << "</RM_SETT_MODE>\n";
78 outputFile << "\t<OBT_TM_SYNC>" << rhe->OBT_TIME_SYNC << "</OBT_TM_SYNC>\n";
79 outputFile << "\t<LAST_TM_SYNC_INFO>" << rhe->LAST_TIME_SYNC_INFO << "</LAST_TM_SYNC_INFO>\n";
80 outputFile << "\t<FAV_WRK_SCHEDULE>" << (int)rhe->FAVOURITE_WORKING_SCHEDULE << "</FAV_WRK_SCHEDULE>\n";
81 outputFile << "\t<EFF_WRK_SCHEDULE>" << (int)rhe->EFFECTIVE_WORKING_SCHEDULE << "</EFF_WRK_SCHEDULE>\n";
82 outputFile << "\t<PRH_VAR_TRIG_A>" << rhe->PRH_VAR_TRIGGER_MODE_A << "</PRH_VAR_TRIG_A>\n";
83 outputFile << "\t<PRH_VAR_TRIG_B>" << rhe->PRH_VAR_TRIGGER_MODE_B << "</PRH_VAR_TRIG_B>\n";
84 outputFile << "\t<RM_ACQ_AFTER_CALIB>" << (int)rhe->RM_ACQ_AFTER_CALIB << "</RM_ACQ_AFTER_CALIB>\n";
85 outputFile << "\t<TRK_CALIB_USED>" << rhe->TRK_CALIB_USED << "</TRK_CALIB_USED>\n";
86 outputFile << "\t<ACQ_BUILD_INFO>" << rhe->ACQ_BUILD_INFO << "</ACQ_BUILD_INFO>\n";
87 outputFile << "\t<ACQ_VAR_INFO>" << rhe->ACQ_VAR_INFO << "</ACQ_VAR_INFO>\n";
88 outputFile << "\t<CAL_DSP_MASK>" << (int)rhe->CAL_DSP_MASK << "</CAL_DSP_MASK>\n";
89 outputFile << "</RUN_HEADER_EVENT>\n";
90 }
91 outputFile << "</ROOT_SOURCE>\n";
92 outputFile.close();
93 }
94
95 int main(int argc, char* argv[]){
96 TString outDir = "";
97 TString xslPath = "";
98
99 if (argc < 2){
100 printf("You have to insert at least the file to analyze \n");
101 printf("Try '--help' for more information. \n");
102 exit(1);
103 }
104
105 if (!strcmp(argv[1], "--help")){
106 printf( "Usage: RunHeaderToXML FILE [OPTION] \n");
107 printf( "\t --help Print this help and exit \n");
108 printf( "\t -outDir[path] Path where to put the output [default ./] \n");
109 printf( "\t -xslPath[path] Set the path to a XSL file for formatting [default '']\n");
110 exit(1);
111 }
112
113 for (int i = 2; i < argc; i++){
114 if (!strcmp(argv[i], "-outDir")){
115 if (++i >= argc){
116 printf( "-outDir needs arguments. \n");
117 printf( "Try '--help' for more information. \n");
118 exit(1);
119 } else {
120 outDir = argv[i];
121 continue;
122 }
123 }
124
125 if (!strcmp(argv[i], "-xslPath")){
126 if (++i >= argc){
127 printf( "-xslPath needs arguments. \n");
128 printf( "Try '--help' for more information. \n");
129 exit(1);
130 } else {
131 xslPath = argv[i];
132 continue;
133 }
134 }
135 }
136 RunHeaderToXML(argv[1], outDir, xslPath);
137 }
138
139
140

  ViewVC Help
Powered by ViewVC 1.1.23