]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/deroot.cxx
STORAGE module added, new macro for Event Display, minor changes in MONITOR
[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 <RConfig.h>
8 #include <TError.h>
9 #include <TSystem.h>
10 #include <TSysEvtHandler.h>
11 #include <TGrid.h>
12 #include "deroot.h"
13
14 using std::cerr;
15 using std::endl;
16
17 int deroot(const char *rootFileName, const char *dateFileName, const char *ddlFilesFolder);
18
19 int deroot(const char *rootFileName, const char *dateFileName, const char *ddlFilesFolder) {
20
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");
32  if(!t) {
33   cerr << "Error getting RAW tree" << endl;
34   return(1);
35  }
36  AliRawVEvent *rootEvent=NULL;
37  
38  t->SetBranchAddress("rawevent", &rootEvent);
39
40  FILE *dateFile;
41 #if defined(R__SEEK64)
42  if(!(dateFile=fopen64(dateFileName, "wb"))) {
43 #else
44  if(!(dateFile=fopen(dateFileName, "wb"))) {
45 #endif
46   cerr << "Error opening DATE file" << endl;
47   return(1);
48  }
49  
50  UInt_t eventSize = 10000000; // 10MB by default
51  unsigned char *dateEvent = new unsigned char[eventSize];
52  for(Long_t gdcCounter=0; gdcCounter<t->GetEntries(); gdcCounter++) {
53   rootEvent=NULL;
54   t->GetEntry(gdcCounter);
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];
64     snprintf(command, sizeof(command), "rm -rf %s/raw%ld", ddlFilesFolder, gdcCounter);
65     gSystem->Exec(command);
66     snprintf(command, sizeof(command), "%s/raw%ld", ddlFilesFolder, gdcCounter);
67     if (gSystem->MakeDirectory(command) < 0) {
68       cerr << "Can not create directory " << command << endl;
69       fclose(dateFile);
70       delete [] dateEvent;
71       return(1);
72     }
73     gdcSize=Root2Date(rootEvent, dateEvent, command);
74   }
75   else
76     gdcSize=Root2Date(rootEvent, dateEvent, NULL);
77
78   delete rootEvent;
79   cerr << "\r     \r" << int(100*(float)(gdcCounter+1)/t->GetEntries()) << "% ";
80   fwrite(dateEvent, gdcSize, 1, dateFile);
81  }
82
83  // Cleanup resources
84  
85  cerr << "\r     \r";
86  cerr.flush();
87  delete t;
88  rootFile->Close();
89  fclose(dateFile);
90  delete [] dateEvent;
91  
92  return(0);
93
94 }
95
96 int main(int argc, char **argv) {
97
98   if (argc != 3 && argc != 4) {
99     cerr << "Usage: deroot <input_root_file> <output_date_file> [<optional_folder_for_ddl_files>]" << endl;
100     return 1;
101   }
102
103   if (argc ==3)
104     deroot(argv[1], argv[2], NULL);
105   else
106     deroot(argv[1], argv[2], argv[3]);
107
108  return(0);
109
110 }
111