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