]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/deroot.cxx
Updating example reco macro for real data
[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 int deroot(const char *rootFileName, const char *dateFileName, const char *ddlFilesFolder);
15
16 int deroot(const char *rootFileName, const char *dateFileName, const char *ddlFilesFolder) {
17
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");
29  if(!t) {
30   cerr << "Error getting RAW tree" << endl;
31   return(1);
32  }
33  AliRawVEvent *rootEvent=NULL;
34  
35  t->SetBranchAddress("rawevent", &rootEvent);
36
37  FILE *dateFile;
38 #if defined(R__SEEK64)
39  if(!(dateFile=fopen64(dateFileName, "wb"))) {
40 #else
41  if(!(dateFile=fopen(dateFileName, "wb"))) {
42 #endif
43   cerr << "Error opening DATE file" << endl;
44   return(1);
45  }
46  
47  UInt_t eventSize = 10000000; // 10MB by default
48  unsigned char *dateEvent = new unsigned char[eventSize];
49  for(Long_t gdcCounter=0; gdcCounter<t->GetEntries(); gdcCounter++) {
50   rootEvent=NULL;
51   t->GetEntry(gdcCounter);
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];
61     sprintf(command, "rm -rf %s/raw%ld", ddlFilesFolder, gdcCounter);
62     gSystem->Exec(command);
63     sprintf(command, "%s/raw%ld", ddlFilesFolder, gdcCounter);
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
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;
83  rootFile->Close();
84  fclose(dateFile);
85  delete [] dateEvent;
86  
87  return(0);
88
89 }
90
91 int main(int argc, char **argv) {
92
93   if (argc != 3 && argc != 4) {
94     cerr << "Usage: deroot <input_root_file> <output_date_file> [<optional_folder_for_ddl_files>]" << endl;
95     return 1;
96   }
97
98   if (argc ==3)
99     deroot(argv[1], argv[2], NULL);
100   else
101     deroot(argv[1], argv[2], argv[3]);
102
103  return(0);
104
105 }
106