Merge branch 'master' into TPCdev
[u/mrichter/AliRoot.git] / MONITOR / deroot.cxx
CommitLineData
36470d8d 1// Author: Filimon Roukoutakis 02/08/2006
2
3/******************************************************************************
4 MOOD - Monitor Of On-line Data and Detector Debugger for ALICE Experiment
5******************************************************************************/
6
3b3d947a 7#include <RConfig.h>
36470d8d 8#include <TError.h>
8e8e0e3e 9#include <TSystem.h>
36470d8d 10#include <TSysEvtHandler.h>
a0d9ff9d 11#include <TGrid.h>
36470d8d 12#include "deroot.h"
13
3a7af7bd 14using std::cerr;
15using std::endl;
16
8e8e0e3e 17int deroot(const char *rootFileName, const char *dateFileName, const char *ddlFilesFolder);
36470d8d 18
8e8e0e3e 19int deroot(const char *rootFileName, const char *dateFileName, const char *ddlFilesFolder) {
36470d8d 20
a0d9ff9d 21 TString str = rootFileName;
22 if (str.BeginsWith("alien://"))
23 TGrid::Connect("alien://");
24
25 TFile *rootFile = TFile::Open(rootFileName,"READ");
26 if (!rootFile) {
27 cerr << "Raw data file can not be opened" << endl;
28 return(1);
29 }
30
31 TTree *t=(TTree *)rootFile->Get("RAW");
36470d8d 32 if(!t) {
33 cerr << "Error getting RAW tree" << endl;
34 return(1);
35 }
33314186 36 AliRawVEvent *rootEvent=NULL;
36470d8d 37
38 t->SetBranchAddress("rawevent", &rootEvent);
39
8e8e0e3e 40 FILE *dateFile;
3b3d947a 41#if defined(R__SEEK64)
87862561 42 if(!(dateFile=fopen64(dateFileName, "wb"))) {
3b3d947a 43#else
44 if(!(dateFile=fopen(dateFileName, "wb"))) {
82bdd0b2 45#endif
36470d8d 46 cerr << "Error opening DATE file" << endl;
47 return(1);
48 }
49
8e8e0e3e 50 UInt_t eventSize = 10000000; // 10MB by default
51 unsigned char *dateEvent = new unsigned char[eventSize];
f8e4a10a 52 for(Long_t gdcCounter=0; gdcCounter<t->GetEntries(); gdcCounter++) {
33314186 53 rootEvent=NULL;
36470d8d 54 t->GetEntry(gdcCounter);
8e8e0e3e 55 if (rootEvent->GetHeader()->GetEventSize() > eventSize) {
56 delete [] dateEvent;
57 eventSize = (UInt_t)(1.05*rootEvent->GetHeader()->GetEventSize());
58 dateEvent = new unsigned char[eventSize];
59 }
60
61 size_t gdcSize;
62 if (ddlFilesFolder) {
63 char command[256];
a696b49b 64 snprintf(command, sizeof(command), "rm -rf %s/raw%ld", ddlFilesFolder, gdcCounter);
8e8e0e3e 65 gSystem->Exec(command);
a696b49b 66 snprintf(command, sizeof(command), "%s/raw%ld", ddlFilesFolder, gdcCounter);
8e8e0e3e 67 if (gSystem->MakeDirectory(command) < 0) {
68 cerr << "Can not create directory " << command << endl;
b34206a8 69 fclose(dateFile);
70 delete [] dateEvent;
8e8e0e3e 71 return(1);
72 }
73 gdcSize=Root2Date(rootEvent, dateEvent, command);
74 }
75 else
76 gdcSize=Root2Date(rootEvent, dateEvent, NULL);
77
36470d8d 78 delete rootEvent;
8d94ddd3 79 cerr << "\r \r" << int(100*(float)(gdcCounter+1)/t->GetEntries()) << "% ";
36470d8d 80 fwrite(dateEvent, gdcSize, 1, dateFile);
81 }
82
83 // Cleanup resources
84
85 cerr << "\r \r";
86 cerr.flush();
87 delete t;
a0d9ff9d 88 rootFile->Close();
36470d8d 89 fclose(dateFile);
90 delete [] dateEvent;
91
92 return(0);
93
94}
95
96int main(int argc, char **argv) {
97
8e8e0e3e 98 if (argc != 3 && argc != 4) {
99 cerr << "Usage: deroot <input_root_file> <output_date_file> [<optional_folder_for_ddl_files>]" << endl;
36470d8d 100 return 1;
101 }
102
8e8e0e3e 103 if (argc ==3)
104 deroot(argv[1], argv[2], NULL);
105 else
106 deroot(argv[1], argv[2], argv[3]);
36470d8d 107
108 return(0);
109
110}
111