]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/deroot.cxx
Better starting value for estimate of covariance matrix (Maksym, Silvia)
[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     snprintf(command, sizeof(command), "rm -rf %s/raw%ld", ddlFilesFolder, gdcCounter);
62     gSystem->Exec(command);
63     snprintf(command, sizeof(command), "%s/raw%ld", ddlFilesFolder, gdcCounter);
64     if (gSystem->MakeDirectory(command) < 0) {
65       cerr << "Can not create directory " << command << endl;
66       fclose(dateFile);
67       delete [] dateEvent;
68       return(1);
69     }
70     gdcSize=Root2Date(rootEvent, dateEvent, command);
71   }
72   else
73     gdcSize=Root2Date(rootEvent, dateEvent, NULL);
74
75   delete rootEvent;
76   cerr << "\r     \r" << int(100*(float)(gdcCounter+1)/t->GetEntries()) << "% ";
77   fwrite(dateEvent, gdcSize, 1, dateFile);
78  }
79
80  // Cleanup resources
81  
82  cerr << "\r     \r";
83  cerr.flush();
84  delete t;
85  rootFile->Close();
86  fclose(dateFile);
87  delete [] dateEvent;
88  
89  return(0);
90
91 }
92
93 int main(int argc, char **argv) {
94
95   if (argc != 3 && argc != 4) {
96     cerr << "Usage: deroot <input_root_file> <output_date_file> [<optional_folder_for_ddl_files>]" << endl;
97     return 1;
98   }
99
100   if (argc ==3)
101     deroot(argv[1], argv[2], NULL);
102   else
103     deroot(argv[1], argv[2], argv[3]);
104
105  return(0);
106
107 }
108