- added new task for pi0 reconstruction using purely calorimeter clusters
[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 using std::ofstream;
11
12 int Root2Date(AliRawVEvent *gdcRootEvent, unsigned char *gdcDateEvent, char *ddlDir) {
13
14  unsigned char *p=gdcDateEvent;
15  int ldcCounter, equipmentCounter, chunkSize;
16  AliRawVEquipment *aliEquipment=NULL;
17  AliRawEquipmentHeader *aliEquipmentHeader=NULL;
18  AliRawEventHeaderBase *aliHeader=NULL;
19  AliRawVEvent *ldcRootEvent=NULL;
20  
21  aliHeader=gdcRootEvent->GetHeader();
22
23  char runNbFileName[256];
24  snprintf(runNbFileName,sizeof(runNbFileName),"%s/run%u",ddlDir,aliHeader->Get("RunNb"));
25  ofstream runNbFile(runNbFileName);
26  runNbFile.close();
27
28  memcpy(p, aliHeader->HeaderBaseBegin(), chunkSize=aliHeader->HeaderBaseSize());
29  p+=chunkSize;
30  memcpy(p, aliHeader->HeaderBegin(), chunkSize=aliHeader->HeaderSize()); // Write DATE GDC header
31  p+=chunkSize;
32  memcpy(p, aliHeader->GetExtendedData(), chunkSize=aliHeader->GetExtendedDataSize());
33  p+=chunkSize;
34  for(ldcCounter=0; ldcCounter<gdcRootEvent->GetNSubEvents(); ldcCounter++) {
35   ldcRootEvent=gdcRootEvent->GetSubEvent(ldcCounter);
36   aliHeader=ldcRootEvent->GetHeader();
37   memcpy(p, aliHeader->HeaderBaseBegin(), chunkSize=aliHeader->HeaderBaseSize());
38   p+=chunkSize;
39   memcpy(p, aliHeader->HeaderBegin(), chunkSize=aliHeader->HeaderSize()); // Write DATE LDC header
40   p+=chunkSize;
41   memcpy(p, aliHeader->GetExtendedData(), chunkSize=aliHeader->GetExtendedDataSize());
42   p+=chunkSize;
43   for(equipmentCounter=0; equipmentCounter<ldcRootEvent->GetNEquipments(); equipmentCounter++) {
44    aliEquipment=ldcRootEvent->GetEquipment(equipmentCounter);
45    aliEquipmentHeader=aliEquipment->GetEquipmentHeader();
46    if(aliEquipmentHeader->GetEquipmentSize()) {
47     memcpy(p, aliEquipmentHeader->HeaderBegin(), chunkSize=aliEquipmentHeader->HeaderSize()); // Write DATE Equipment header
48     p+=chunkSize;
49    }
50    memcpy(p, aliEquipment->GetRawData()->GetBuffer(), chunkSize=aliEquipment->GetRawData()->GetSize()); // Write Equipment payload (including CDH)
51    // Write ddl files if requested by the user
52    if (ddlDir && aliEquipmentHeader->GetEquipmentSize()) {
53      Int_t ddlIndex;
54      Int_t detId = AliDAQ::DetectorIDFromDdlID(aliEquipmentHeader->GetId(),ddlIndex);
55      char ddlFileName[256];
56      snprintf(ddlFileName,sizeof(ddlFileName),"%s/%s",ddlDir,AliDAQ::DdlFileName(detId,ddlIndex));
57      FILE *ddlFile;
58      if((ddlFile=fopen(ddlFileName, "wb"))) {
59        fwrite(p, chunkSize, 1, ddlFile);
60        fclose(ddlFile);
61      }
62    }
63    p+=chunkSize;
64   }
65  }
66  
67  return(p-gdcDateEvent);
68  
69 }