1. Removal of huge hard-coded memory allocation. The memory is now allocated dynamica...
authorcvetan <cvetan@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 28 Jan 2008 12:38:18 +0000 (12:38 +0000)
committercvetan <cvetan@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 28 Jan 2008 12:38:18 +0000 (12:38 +0000)
MONITOR/deroot.cxx
MONITOR/root2date.cxx
MONITOR/root2date.h

index 00ee57f..d42fbdd 100644 (file)
@@ -5,17 +5,14 @@
 ******************************************************************************/
 
 #include <TError.h>
+#include <TSystem.h>
 #include <TSysEvtHandler.h>
 #include "deroot.h"
 
-int deroot(const char *rootFileName, const char *dateFileName);
+int deroot(const char *rootFileName, const char *dateFileName, const char *ddlFilesFolder);
 
-int deroot(const char *rootFileName, const char *dateFileName) {
+int deroot(const char *rootFileName, const char *dateFileName, const char *ddlFilesFolder) {
 
- unsigned char *dateEvent=new unsigned char [1000000000];
-
- FILE *dateFile;
- size_t gdcCounter, gdcSize;
  TFile rootFile(rootFileName);
  TTree *t=(TTree *)rootFile.Get("RAW");
  if(!t) {
@@ -26,15 +23,38 @@ int deroot(const char *rootFileName, const char *dateFileName) {
  
  t->SetBranchAddress("rawevent", &rootEvent);
 
+ FILE *dateFile;
  if(!(dateFile=fopen(dateFileName, "wb"))) {
   cerr << "Error opening DATE file" << endl;
   return(1);
  }
  
- for(gdcCounter=0; gdcCounter<t->GetEntries(); gdcCounter++) {
+ UInt_t eventSize = 10000000; // 10MB by default
+ unsigned char *dateEvent = new unsigned char[eventSize];
+ for(size_t gdcCounter=0; gdcCounter<t->GetEntries(); gdcCounter++) {
   rootEvent=new AliRawEvent;
   t->GetEntry(gdcCounter);
-  gdcSize=Root2Date(rootEvent, dateEvent);
+  if (rootEvent->GetHeader()->GetEventSize() > eventSize) {
+    delete [] dateEvent;
+    eventSize = (UInt_t)(1.05*rootEvent->GetHeader()->GetEventSize());
+    dateEvent = new unsigned char[eventSize];
+  }
+
+  size_t gdcSize;
+  if (ddlFilesFolder) {
+    char command[256];
+    sprintf(command, "rm -r %s/raw%d", ddlFilesFolder, gdcCounter);
+    gSystem->Exec(command);
+    sprintf(command, "%s/raw%d", ddlFilesFolder, gdcCounter);
+    if (gSystem->MakeDirectory(command) < 0) {
+      cerr << "Can not create directory " << command << endl;
+      return(1);
+    }
+    gdcSize=Root2Date(rootEvent, dateEvent, command);
+  }
+  else
+    gdcSize=Root2Date(rootEvent, dateEvent, NULL);
+
   delete rootEvent;
   cerr << "\r     \r" << setprecision(3) << 100*(float)(gdcCounter+1)/t->GetEntries() << "% ";
   fwrite(dateEvent, gdcSize, 1, dateFile);
@@ -55,12 +75,15 @@ int deroot(const char *rootFileName, const char *dateFileName) {
 
 int main(int argc, char **argv) {
 
-  if (argc != 3) {
-    cerr << "Usage: deroot <input_root_file> <output_date_file>" << endl;
+  if (argc != 3 && argc != 4) {
+    cerr << "Usage: deroot <input_root_file> <output_date_file> [<optional_folder_for_ddl_files>]" << endl;
     return 1;
   }
 
- deroot(argv[1], argv[2]);
+  if (argc ==3)
+    deroot(argv[1], argv[2], NULL);
+  else
+    deroot(argv[1], argv[2], argv[3]);
 
  return(0);
 
index 093c0be..e5eff02 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "root2date.h"
 
-int Root2Date(AliRawEvent *gdcRootEvent, unsigned char *gdcDateEvent) {
+int Root2Date(AliRawEvent *gdcRootEvent, unsigned char *gdcDateEvent, char *ddlDir) {
 
  unsigned char *p=gdcDateEvent;
  int ldcCounter, equipmentCounter, chunkSize;
@@ -36,6 +36,18 @@ int Root2Date(AliRawEvent *gdcRootEvent, unsigned char *gdcDateEvent) {
     p+=chunkSize;
    }
    memcpy(p, aliEquipment->GetRawData()->GetBuffer(), chunkSize=aliEquipment->GetRawData()->GetSize()); // Write Equipment payload (including CDH)
+   // Write ddl files if requested by the user
+   if (ddlDir) {
+     Int_t ddlIndex;
+     Int_t detId = AliDAQ::DetectorIDFromDdlID(aliEquipmentHeader->GetId(),ddlIndex);
+     char ddlFileName[256];
+     sprintf(ddlFileName,"%s/%s",ddlDir,AliDAQ::DdlFileName(detId,ddlIndex));
+     FILE *ddlFile;
+     if(ddlFile=fopen(ddlFileName, "wb")) {
+       fwrite(p, chunkSize, 1, ddlFile);
+     }
+     fclose(ddlFile);
+   }
    p+=chunkSize;
   }
  }
index c71a414..4227130 100644 (file)
 #include "AliRawEventHeaderBase.h"
 #include "AliRawEquipment.h"
 #include "AliRawEquipmentHeader.h"
-#include "AliRawReaderRoot.h"
+#include "AliRawData.h"
+#include "AliDAQ.h"
 
 #include <Riostream.h>
 
-int Root2Date(AliRawEvent *gdcRootEvent, unsigned char *gdcDateEvent);
+int Root2Date(AliRawEvent *gdcRootEvent, unsigned char *gdcDateEvent, char *ddlDir);
 
 #endif