| 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 |
outputFile << "\t<PACKET_OBT>" << dec << ph->GetOrbitalTime() << "</PACKET_OBT>\n"; |
| 82 |
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<BOARD_ID_REG>" << (int)cer.CALO_BOARD_ID_REG << "</BOARD_ID_REG>\n"; |
| 100 |
outputFile << "\t\t\t<BOARD_ST_REG>" << (int)cer.CALO_BOARD_STATUS_REG << "</BOARD_ST_REG>\n"; |
| 101 |
outputFile << "\t\t\t<CALO_REG>\n"; |
| 102 |
for (int k = 0; k < 7; k++){ |
| 103 |
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 |
outputFile << "\t\t<ALARM_MASK>" << (int)ter.TB_ALARM_MASK << "</ALARM_MASK>\n"; |
| 113 |
outputFile << "\t\t<PMT_MASK_S3>" << (int)ter.TB_PMT_MASK_S3 << "</PMT_MASK_S3>\n"; |
| 114 |
outputFile << "\t\t<PMT_MASK_S2>" << (int)ter.TB_PMT_MASK_S2 << "</PMT_MASK_S2>\n"; |
| 115 |
outputFile << "\t\t<PMT_MASK_S12>" << (int)ter.TB_PMT_MASK_S12 << "</PMT_MASK_S12>\n"; |
| 116 |
outputFile << "\t\t<PMT_MASK_S11>" << (int)ter.TB_PMT_MASK_S11 << "</PMT_MASK_S11>\n"; |
| 117 |
outputFile << "\t\t<S4_MASK>" << (int)ter.TB_S4_MASK << "</S4_MASK>\n"; |
| 118 |
outputFile << "\t\t<CALO_MASK>" << (int)ter.TB_CALO_MASK << "</CALO_MASK>\n"; |
| 119 |
outputFile << "\t\t<BUSY_MASK>" << (int)ter.TB_BUSY_MASK << "</BUSY_MASK>\n"; |
| 120 |
outputFile << "\t\t<CALIB_FLAG>" << (int)ter.TB_CALIB_FLAG << "</CALIB_FLAG>\n"; |
| 121 |
outputFile << "\t\t<S4_TRIG>" << (int)ter.TB_S4_TRIG << "</S4_TRIG>\n"; |
| 122 |
outputFile << "\t\t<CALO_TRIG>" << (int)ter.TB_CALO_TRIG << "</CALO_TRIG>\n"; |
| 123 |
outputFile << "\t\t<TOF_TRIG>" << (int)ter.TB_TOF_TRIG << "</TOF_TRIG>\n"; |
| 124 |
outputFile << "\t</TBENDRUN>\n"; |
| 125 |
|
| 126 |
outputFile << "</PHYSER_EVENT>\n"; |
| 127 |
} |
| 128 |
outputFile << "</ROOT_SOURCE>\n"; |
| 129 |
outputFile.close(); |
| 130 |
} |
| 131 |
|
| 132 |
int main(int argc, char* argv[]){ |
| 133 |
TString outDir = ""; |
| 134 |
TString xslPath = ""; |
| 135 |
|
| 136 |
if (argc < 2){ |
| 137 |
printf("You have to insert at least the file to analyze \n"); |
| 138 |
printf("Try '--help' for more information. \n"); |
| 139 |
exit(1); |
| 140 |
} |
| 141 |
|
| 142 |
if (!strcmp(argv[1], "--help")){ |
| 143 |
printf( "Usage: PhysEndRunToXML FILE [OPTION] \n"); |
| 144 |
printf( "\t --help Print this help and exit \n"); |
| 145 |
printf( "\t -outDir[path] Path where to put the output [default ~/tmp] \n"); |
| 146 |
printf( "\t -xslPath[path] Set the path to a XSL file for formatting [default '']\n"); |
| 147 |
exit(1); |
| 148 |
} |
| 149 |
|
| 150 |
for (int i = 2; i < argc; i++){ |
| 151 |
if (!strcmp(argv[i], "-outDir")){ |
| 152 |
if (++i >= argc){ |
| 153 |
printf( "-outDir needs arguments. \n"); |
| 154 |
printf( "Try '--help' for more information. \n"); |
| 155 |
exit(1); |
| 156 |
} else { |
| 157 |
outDir = argv[i]; |
| 158 |
continue; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
if (!strcmp(argv[i], "-xslPath")) |
| 163 |
if (++i >= argc){ |
| 164 |
printf( "-xslPath needs arguments. \n"); |
| 165 |
printf( "Try '--help' for more information. \n"); |
| 166 |
exit(1); |
| 167 |
} else { |
| 168 |
xslPath = argv[i]; |
| 169 |
continue; |
| 170 |
} |
| 171 |
} |
| 172 |
PhysEndRunToXML(argv[1], outDir, xslPath); |
| 173 |
} |
| 174 |
|