Optional scoring for background studies in HALL.
[u/mrichter/AliRoot.git] / MONITOR / root2date.cxx
1 // Author: Filimon Roukoutakis 02/08/2006
2 //         Cvetan Cheshkov
3
4 /******************************************************************************
5   MOOD - Monitor Of On-line Data and Detector Debugger for ALICE Experiment
6 ******************************************************************************/
7
8 #include "root2date.h"
9
10 int Root2Date(AliRawVEvent *gdcRootEvent, unsigned char *gdcDateEvent, char *ddlDir) {
11
12  unsigned char *p=gdcDateEvent;
13  int ldcCounter, equipmentCounter, chunkSize;
14  AliRawVEquipment *aliEquipment=NULL;
15  AliRawEquipmentHeader *aliEquipmentHeader=NULL;
16  AliRawEventHeaderBase *aliHeader=NULL;
17  AliRawVEvent *ldcRootEvent=NULL;
18  
19  aliHeader=gdcRootEvent->GetHeader();
20
21  char runNbFileName[256];
22  snprintf(runNbFileName,sizeof(runNbFileName),"%s/run%u",ddlDir,aliHeader->Get("RunNb"));
23  ofstream runNbFile(runNbFileName);
24  runNbFile.close();
25
26  memcpy(p, aliHeader->HeaderBaseBegin(), chunkSize=aliHeader->HeaderBaseSize());
27  p+=chunkSize;
28  memcpy(p, aliHeader->HeaderBegin(), chunkSize=aliHeader->HeaderSize()); // Write DATE GDC header
29  p+=chunkSize;
30  memcpy(p, aliHeader->GetExtendedData(), chunkSize=aliHeader->GetExtendedDataSize());
31  p+=chunkSize;
32  for(ldcCounter=0; ldcCounter<gdcRootEvent->GetNSubEvents(); ldcCounter++) {
33   ldcRootEvent=gdcRootEvent->GetSubEvent(ldcCounter);
34   aliHeader=ldcRootEvent->GetHeader();
35   memcpy(p, aliHeader->HeaderBaseBegin(), chunkSize=aliHeader->HeaderBaseSize());
36   p+=chunkSize;
37   memcpy(p, aliHeader->HeaderBegin(), chunkSize=aliHeader->HeaderSize()); // Write DATE LDC header
38   p+=chunkSize;
39   memcpy(p, aliHeader->GetExtendedData(), chunkSize=aliHeader->GetExtendedDataSize());
40   p+=chunkSize;
41   for(equipmentCounter=0; equipmentCounter<ldcRootEvent->GetNEquipments(); equipmentCounter++) {
42    aliEquipment=ldcRootEvent->GetEquipment(equipmentCounter);
43    aliEquipmentHeader=aliEquipment->GetEquipmentHeader();
44    if(aliEquipmentHeader->GetEquipmentSize()) {
45     memcpy(p, aliEquipmentHeader->HeaderBegin(), chunkSize=aliEquipmentHeader->HeaderSize()); // Write DATE Equipment header
46     p+=chunkSize;
47    }
48    memcpy(p, aliEquipment->GetRawData()->GetBuffer(), chunkSize=aliEquipment->GetRawData()->GetSize()); // Write Equipment payload (including CDH)
49    // Write ddl files if requested by the user
50    if (ddlDir && aliEquipmentHeader->GetEquipmentSize()) {
51      Int_t ddlIndex;
52      Int_t detId = AliDAQ::DetectorIDFromDdlID(aliEquipmentHeader->GetId(),ddlIndex);
53      char ddlFileName[256];
54      snprintf(ddlFileName,sizeof(ddlFileName),"%s/%s",ddlDir,AliDAQ::DdlFileName(detId,ddlIndex));
55      FILE *ddlFile;
56      if((ddlFile=fopen(ddlFileName, "wb"))) {
57        fwrite(p, chunkSize, 1, ddlFile);
58        fclose(ddlFile);
59      }
60    }
61    p+=chunkSize;
62   }
63  }
64  
65  return(p-gdcDateEvent);
66  
67 }