- Macro to create the "raw" data file with selected events
authormarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 14 Apr 2011 09:21:26 +0000 (09:21 +0000)
committermarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 14 Apr 2011 09:21:26 +0000 (09:21 +0000)
Magnus

-This line, and those below, will be ignored--

A    rawmerge.C

PWG1/macros/rawmerge.C [new file with mode: 0644]

diff --git a/PWG1/macros/rawmerge.C b/PWG1/macros/rawmerge.C
new file mode 100644 (file)
index 0000000..21efd6d
--- /dev/null
@@ -0,0 +1,76 @@
+//\r
+// Macro to create the "raw" data file with selected events\r
+// Paramaters:\r
+//  eventListFileName - input ascii file with list of chunks and event numbers - two collumns\r
+//  osplit            - split the file after given threhshold value\r
+//\r
+void rawmerge(const char *eventListFileName,\r
+              const char *outputDirectoryURI,\r
+              Long64_t osplit=-1)\r
+{\r
+  Int_t eventNumber;\r
+  FILE *files=fopen(eventListFileName,"r");\r
+  if (!files) {\r
+    fprintf(stderr,"error: could not read event list file \"%s\". Exiting.\n",eventListFileName);\r
+    return;\r
+  }\r
+  char iURI[1000];\r
+  char oURI[1000];\r
+  TFile *ifile=0;\r
+  TFile *ofile=0;\r
+  TTree *itree=0;\r
+  TTree *otree=0;\r
+  Long64_t ievent;\r
+  Long64_t oevent;\r
+  Int_t ofilenumber=0;\r
+  Int_t line=0;\r
+  while (!feof(files)) {\r
+    delete ifile;ifile=0;\r
+    ++line;\r
+    if (fscanf(files,"%s %d\n",iURI,&ievent)!=2) {\r
+      fprintf(stderr,"warning: corrupted event line (%d) in input file, skipping it...\n",line);\r
+      continue;\r
+    }\r
+    printf("> processing \"%s\" event %d...\n",iURI,ievent);\r
+    TFile *ifile=TFile::Open(iURI);\r
+    if (!ifile) {\r
+      fprintf(stderr,"warning: could not open file for event \"%s\", skipping it...\n",iURI);\r
+      continue;\r
+    }\r
+    TTree *itree=dynamic_cast<TTree*>(ifile->Get("RAW"));\r
+    if (!itree) {\r
+      fprintf(stderr,"warning: could not find RAW tree for event \"%s\", skipping it...\n",iURI);\r
+      continue;\r
+    }\r
+\r
+    // create (new) output file and tree\r
+    if (!ofile || (osplit>0 && oevent%osplit==0)) {\r
+      delete ofile;\r
+      ++ofilenumber;\r
+      sprintf(oURI,"%s/merged_%d.root",outputDirectoryURI,ofilenumber);\r
+      printf("< creating output file \"%s\"\n",oURI);\r
+      ofile=TFile::Open(oURI,"RECREATE");\r
+      if (!ofile) {\r
+        fprintf(stderr,"error: could not create output file: \"%s\" Exiting.\n",oURI);\r
+        break;\r
+      }\r
+      otree=itree->CloneTree(0);\r
+    }\r
+\r
+    // copy event and write to file\r
+    otree->CopyAddresses(itree);\r
+    itree->GetEntry(ievent);\r
+    otree->Fill();\r
+//    otree->CopyEntries(itree,Form("Entry$==%d",ievent),1);\r
+    ofile->Write();\r
+    ++oevent;\r
+\r
+    // reset input\r
+    itree->ResetBranchAddresses();\r
+  }\r
+\r
+  printf("Merged %d events.\n",oevent);\r
+  delete ifile;\r
+  delete ofile;\r
+}\r
+\r