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