]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/deroot.cxx
Fixed compilation warning (Mikolaj)
[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  AliRawEvent *rootEvent=NULL;
33  
34  t->SetBranchAddress("rawevent", &rootEvent);
35
36  FILE *dateFile;
37  if(!(dateFile=fopen(dateFileName, "wb"))) {
38   cerr << "Error opening DATE file" << endl;
39   return(1);
40  }
41  
42  UInt_t eventSize = 10000000; // 10MB by default
43  unsigned char *dateEvent = new unsigned char[eventSize];
44  for(Long_t gdcCounter=0; gdcCounter<t->GetEntries(); gdcCounter++) {
45   rootEvent=new AliRawEvent;
46   t->GetEntry(gdcCounter);
47   if (rootEvent->GetHeader()->GetEventSize() > eventSize) {
48     delete [] dateEvent;
49     eventSize = (UInt_t)(1.05*rootEvent->GetHeader()->GetEventSize());
50     dateEvent = new unsigned char[eventSize];
51   }
52
53   size_t gdcSize;
54   if (ddlFilesFolder) {
55     char command[256];
56     sprintf(command, "rm -rf %s/raw%ld", ddlFilesFolder, gdcCounter);
57     gSystem->Exec(command);
58     sprintf(command, "%s/raw%ld", ddlFilesFolder, gdcCounter);
59     if (gSystem->MakeDirectory(command) < 0) {
60       cerr << "Can not create directory " << command << endl;
61       return(1);
62     }
63     gdcSize=Root2Date(rootEvent, dateEvent, command);
64   }
65   else
66     gdcSize=Root2Date(rootEvent, dateEvent, NULL);
67
68   delete rootEvent;
69   cerr << "\r     \r" << setprecision(3) << 100*(float)(gdcCounter+1)/t->GetEntries() << "% ";
70   fwrite(dateEvent, gdcSize, 1, dateFile);
71  }
72
73  // Cleanup resources
74  
75  cerr << "\r     \r";
76  cerr.flush();
77  delete t;
78  rootFile->Close();
79  fclose(dateFile);
80  delete [] dateEvent;
81  
82  return(0);
83
84 }
85
86 int main(int argc, char **argv) {
87
88   if (argc != 3 && argc != 4) {
89     cerr << "Usage: deroot <input_root_file> <output_date_file> [<optional_folder_for_ddl_files>]" << endl;
90     return 1;
91   }
92
93   if (argc ==3)
94     deroot(argv[1], argv[2], NULL);
95   else
96     deroot(argv[1], argv[2], argv[3]);
97
98  return(0);
99
100 }
101