fix for bug #66294
[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
8e8e0e3e 14int deroot(const char *rootFileName, const char *dateFileName, const char *ddlFilesFolder);
36470d8d 15
8e8e0e3e 16int deroot(const char *rootFileName, const char *dateFileName, const char *ddlFilesFolder) {
36470d8d 17
a0d9ff9d 18 TString str = rootFileName;
19 if (str.BeginsWith("alien://"))
20 TGrid::Connect("alien://");
21
22 TFile *rootFile = TFile::Open(rootFileName,"READ");
23 if (!rootFile) {
24 cerr << "Raw data file can not be opened" << endl;
25 return(1);
26 }
27
28 TTree *t=(TTree *)rootFile->Get("RAW");
36470d8d 29 if(!t) {
30 cerr << "Error getting RAW tree" << endl;
31 return(1);
32 }
33314186 33 AliRawVEvent *rootEvent=NULL;
36470d8d 34
35 t->SetBranchAddress("rawevent", &rootEvent);
36
8e8e0e3e 37 FILE *dateFile;
3b3d947a 38#if defined(R__SEEK64)
87862561 39 if(!(dateFile=fopen64(dateFileName, "wb"))) {
3b3d947a 40#else
41 if(!(dateFile=fopen(dateFileName, "wb"))) {
82bdd0b2 42#endif
36470d8d 43 cerr << "Error opening DATE file" << endl;
44 return(1);
45 }
46
8e8e0e3e 47 UInt_t eventSize = 10000000; // 10MB by default
48 unsigned char *dateEvent = new unsigned char[eventSize];
f8e4a10a 49 for(Long_t gdcCounter=0; gdcCounter<t->GetEntries(); gdcCounter++) {
33314186 50 rootEvent=NULL;
36470d8d 51 t->GetEntry(gdcCounter);
8e8e0e3e 52 if (rootEvent->GetHeader()->GetEventSize() > eventSize) {
53 delete [] dateEvent;
54 eventSize = (UInt_t)(1.05*rootEvent->GetHeader()->GetEventSize());
55 dateEvent = new unsigned char[eventSize];
56 }
57
58 size_t gdcSize;
59 if (ddlFilesFolder) {
60 char command[256];
db001056 61 sprintf(command, "rm -rf %s/raw%ld", ddlFilesFolder, gdcCounter);
8e8e0e3e 62 gSystem->Exec(command);
e41f1e44 63 sprintf(command, "%s/raw%ld", ddlFilesFolder, gdcCounter);
8e8e0e3e 64 if (gSystem->MakeDirectory(command) < 0) {
65 cerr << "Can not create directory " << command << endl;
66 return(1);
67 }
68 gdcSize=Root2Date(rootEvent, dateEvent, command);
69 }
70 else
71 gdcSize=Root2Date(rootEvent, dateEvent, NULL);
72
36470d8d 73 delete rootEvent;
74 cerr << "\r \r" << setprecision(3) << 100*(float)(gdcCounter+1)/t->GetEntries() << "% ";
75 fwrite(dateEvent, gdcSize, 1, dateFile);
76 }
77
78 // Cleanup resources
79
80 cerr << "\r \r";
81 cerr.flush();
82 delete t;
a0d9ff9d 83 rootFile->Close();
36470d8d 84 fclose(dateFile);
85 delete [] dateEvent;
86
87 return(0);
88
89}
90
91int main(int argc, char **argv) {
92
8e8e0e3e 93 if (argc != 3 && argc != 4) {
94 cerr << "Usage: deroot <input_root_file> <output_date_file> [<optional_folder_for_ddl_files>]" << endl;
36470d8d 95 return 1;
96 }
97
8e8e0e3e 98 if (argc ==3)
99 deroot(argv[1], argv[2], NULL);
100 else
101 deroot(argv[1], argv[2], argv[3]);
36470d8d 102
103 return(0);
104
105}
106