+ const Int_t kMaxHcWords = (fGeo->TBmax()/3)
+ * fGeo->ADCmax()
+ * fGeo->MCMmax()
+ * fGeo->ROBmaxC1()/2
+ + 100 + 20;
+
+ // Buffer to temporary store half chamber data
+ UInt_t *hcBuffer = new UInt_t[kMaxHcWords];
+
+ // sect is same as iDDL, so I use only sect here.
+ for (Int_t sect = 0; sect < fGeo->Nsect(); sect++) {
+
+ char name[1024];
+ sprintf(name,"TRD_%d.ddl",sect + AliTRDRawStream::kDDLOffset);
+
+ AliFstream* of = new AliFstream(name);
+
+ // Write a dummy data header
+ AliRawDataHeaderSim header; // the event header
+ UInt_t hpos = of->Tellp();
+ of->WriteBuffer((char *) (& header), sizeof(header));
+
+ // Reset payload byte size (payload does not include header).
+ Int_t npayloadbyte = 0;
+
+ // GTU common data header (5x4 bytes per super module, shows link mask)
+ for( Int_t cham = 0; cham < fGeo->Ncham(); cham++ ) {
+ UInt_t gtuCdh = (UInt_t)(0xe << 28);
+ for( Int_t plan = 0; plan < fGeo->Nplan(); plan++) {
+ Int_t iDet = fGeo->GetDetector(plan, cham, sect);
+ // If chamber status is ok, we assume that the optical link is also OK.
+ // This is shown in the GTU link mask.
+ if ( AliTRDcalibDB::Instance()->GetChamberStatus(iDet) )
+ gtuCdh = gtuCdh | (3 << (2*plan));
+ }
+ of->WriteBuffer((char *) (& gtuCdh), sizeof(gtuCdh));
+ npayloadbyte += 4;
+ }
+
+ // Prepare chamber data
+ for( Int_t cham = 0; cham < fGeo->Ncham(); cham++) {
+ for( Int_t plan = 0; plan < fGeo->Nplan(); plan++) {
+
+ Int_t iDet = fGeo->GetDetector(plan,cham,sect);
+
+ // Get the digits array
+ AliTRDdataArrayS *digits = (AliTRDdataArrayS *) digitsManager->GetDigits(iDet);
+ if (digits->HasData()) {
+
+ digits->Expand();
+
+ Int_t hcwords = 0;
+ Int_t rv = fFee->GetRAWversion();
+
+ // Process A side of the chamber
+ if ( rv >= 1 && rv <= 2 ) {
+ hcwords = ProduceHcDataV1andV2(digits,0,iDet,hcBuffer,kMaxHcWords);
+ }
+ if ( rv == 3 ) {
+ hcwords = ProduceHcDataV3 (digits,0,iDet,hcBuffer,kMaxHcWords);
+ }
+
+ of->WriteBuffer((char *) hcBuffer, hcwords*4);
+ npayloadbyte += hcwords*4;
+
+ // Process B side of the chamber
+ if ( rv >= 1 && rv <= 2 ) {
+ hcwords = ProduceHcDataV1andV2(digits,1,iDet,hcBuffer,kMaxHcWords);
+ }
+ if ( rv >= 3 ) {
+ hcwords = ProduceHcDataV3 (digits,1,iDet,hcBuffer,kMaxHcWords);
+ }
+
+ of->WriteBuffer((char *) hcBuffer, hcwords*4);
+ npayloadbyte += hcwords*4;
+
+ }
+
+ }
+ }
+
+ // Complete header
+ header.fSize = UInt_t(of->Tellp()) - hpos;
+ header.SetAttribute(0); // Valid data
+ of->Seekp(hpos); // Rewind to header position
+ of->WriteBuffer((char *) (& header), sizeof(header));
+ delete of;
+ }
+
+ delete [] hcBuffer;
+
+ return kTRUE;