]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliModule.cxx
Change Float_t to Double32_t
[u/mrichter/AliRoot.git] / STEER / AliModule.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // Base class for ALICE modules. Both sensitive modules (Modules) and      //
21 // non-sensitive ones are described by this base class. This class           //
22 // supports the hit and digit trees produced by the simulation and also      //
23 // the objects produced by the reconstruction.                               //
24 //                                                                           //
25 // This class is also responsible for building the geometry of the           //
26 // Modules.                                                                //
27 //                                                                           //
28 //Begin_Html
29 /*
30 <img src="picts/AliModuleClass.gif">
31 */
32 //End_Html
33 //                                                                           //
34 ///////////////////////////////////////////////////////////////////////////////
35
36 #include <TNode.h>
37 #include <TObjArray.h>
38 #include <TClonesArray.h>
39 #include <TTree.h>
40 #include <TSystem.h>
41 #include <TDirectory.h>
42 #include <TVirtualMC.h>
43 #include <TGeoManager.h>
44 #include <TString.h>
45
46 #include "AliLog.h"
47 #include "AliConfig.h"
48 #include "AliLoader.h"
49 #include "AliMagF.h"
50 #include "AliModule.h"
51 #include "AliRun.h"
52 #include "AliTrackReference.h"
53 #include "AliMC.h"
54 #include "AliRawDataHeader.h"
55
56 #include "AliDAQ.h"
57
58 ClassImp(AliModule)
59  
60 //_______________________________________________________________________
61 AliModule::AliModule():
62   fEuclidMaterial(""),
63   fEuclidGeometry(""),
64   fIdtmed(0),
65   fIdmate(0),
66   fLoMedium(0),
67   fHiMedium(0),
68   fActive(0),
69   fHistograms(0),
70   fNodes(0),
71   fEnable(1),
72   fTrackReferences(0),
73   fMaxIterTrackRef(0),
74   fCurrentIterTrackRef(0),
75   fRunLoader(0)
76 {
77   //
78   // Default constructor for the AliModule class
79   //
80 }
81  
82 //_______________________________________________________________________
83 AliModule::AliModule(const char* name,const char *title):
84   TNamed(name,title),
85   fEuclidMaterial(""),
86   fEuclidGeometry(""),
87   fIdtmed(new TArrayI(100)),
88   fIdmate(new TArrayI(100)),
89   fLoMedium(65536),
90   fHiMedium(0),
91   fActive(0),
92   fHistograms(new TList()),
93   fNodes(new TList()),
94   fEnable(1),
95   fTrackReferences(new TClonesArray("AliTrackReference", 100)),
96   fMaxIterTrackRef(0),
97   fCurrentIterTrackRef(0),
98   fRunLoader(0)
99 {
100   //
101   // Normal constructor invoked by all Modules.
102   // Create the list for Module specific histograms
103   // Add this Module to the global list of Modules in Run.
104   //
105   // Get the Module numeric ID
106   Int_t id = gAlice->GetModuleID(name);
107   if (id>=0) {
108     // Module already added !
109      AliWarning(Form("Module: %s already present at %d",name,id));
110      return;
111   }
112   //
113   // Add this Module to the list of Modules
114
115   gAlice->AddModule(this);
116
117   //PH  SetMarkerColor(3);
118   //
119   // Clear space for tracking media and material indexes
120
121   for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
122 }
123  
124 //_______________________________________________________________________
125 AliModule::~AliModule()
126 {
127   //
128   // Destructor
129   //
130
131   // Remove this Module from the list of Modules
132   if (gAlice) {
133     TObjArray * modules = gAlice->Modules();
134     if (modules) modules->Remove(this);
135   }
136   // Delete ROOT geometry
137   if(fNodes) {
138     fNodes->Clear();
139     delete fNodes;
140     fNodes = 0;
141   }
142   // Delete histograms
143   if(fHistograms) {
144     fHistograms->Clear();
145     delete fHistograms;
146     fHistograms = 0;
147   }
148   // Delete track references
149   if (fTrackReferences) {
150     fTrackReferences->Delete();
151     delete fTrackReferences;
152     fTrackReferences     = 0;
153   }
154   // Delete TArray objects
155   delete fIdtmed;
156   delete fIdmate;
157
158 }
159  
160 //_______________________________________________________________________
161 void AliModule::Disable()
162 {
163   //
164   // Disable Module on viewer
165   //
166   fActive = kFALSE;
167   TIter next(fNodes);
168   TNode *node;
169   //
170   // Loop through geometry to disable all
171   // nodes for this Module
172   while((node = dynamic_cast<TNode*>(next()))) {
173     node->SetVisibility(-1);
174   }   
175 }
176
177 //_______________________________________________________________________
178 void AliModule::Enable()
179 {
180   //
181   // Enable Module on the viewver
182   //
183   fActive = kTRUE;
184   TIter next(fNodes);
185   TNode *node;
186   //
187   // Loop through geometry to enable all
188   // nodes for this Module
189   while((node = dynamic_cast<TNode*>(next()))) {
190     node->SetVisibility(3);
191   }   
192 }
193
194 //_______________________________________________________________________
195 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a, 
196                             Float_t z, Float_t dens, Float_t radl,
197                             Float_t absl, Float_t *buf, Int_t nwbuf) const
198 {
199   //
200   // Store the parameters for a material
201   //
202   // imat        the material index will be stored in (*fIdmate)[imat]
203   // name        material name
204   // a           atomic mass
205   // z           atomic number
206   // dens        density
207   // radl        radiation length
208   // absl        absorbtion length
209   // buf         adress of an array user words
210   // nwbuf       number of user words
211   //
212   Int_t kmat;
213   //Build the string uniquename as "DET_materialname"
214   TString uniquename = GetName();
215   uniquename.Append("_");
216   uniquename.Append(name);
217   //if geometry loaded from file only fill fIdmate, else create material too
218   if(gAlice->IsRootGeometry()){
219     TGeoMaterial *mat = gGeoManager->GetMaterial(uniquename.Data());
220     kmat = mat->GetUniqueID();
221     (*fIdmate)[imat]=kmat;
222   }else{
223     gMC->Material(kmat, uniquename.Data(), a, z, dens, radl, absl, buf, nwbuf);
224     (*fIdmate)[imat]=kmat;
225   }
226 }
227   
228 //_______________________________________________________________________
229 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a, 
230                                Float_t &z, Float_t &dens, Float_t &radl,
231                                Float_t &absl) const
232 {
233   //
234   // Store the parameters for a material
235   //
236   // imat        the material index will be stored in (*fIdmate)[imat]
237   // name        material name
238   // a           atomic mass
239   // z           atomic number
240   // dens        density
241   // radl        radiation length
242   // absl        absorbtion length
243   // buf         adress of an array user words
244   // nwbuf       number of user words
245   //
246
247   Float_t buf[10];
248   Int_t nwbuf, kmat;
249   kmat=(*fIdmate)[imat];
250   gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
251 }
252   
253
254 //_______________________________________________________________________
255 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
256                            Float_t *z, Float_t dens, Int_t nlmat,
257                            Float_t *wmat) const
258
259   //
260   // Defines mixture or compound imat as composed by 
261   // nlmat materials defined by arrays a, z and wmat
262   // 
263   // If nlmat > 0 wmat contains the proportion by
264   // weights of each basic material in the mixture  
265   // 
266   // If nlmat < 0 wmat contains the number of atoms 
267   // of eack kind in the molecule of the compound
268   // In this case, wmat is changed on output to the relative weigths.
269   //
270   // imat        the material index will be stored in (*fIdmate)[imat]
271   // name        material name
272   // a           array of atomic masses
273   // z           array of atomic numbers
274   // dens        density
275   // nlmat       number of components
276   // wmat        array of concentrations
277   //
278   Int_t kmat;
279   //Build the string uniquename as "DET_mixturename"
280   TString uniquename = GetName();
281   uniquename.Append("_");
282   uniquename.Append(name);
283   //if geometry loaded from file only fill fIdmate, else create mixture too
284   if(gAlice->IsRootGeometry()){
285     TGeoMaterial *mat = gGeoManager->GetMaterial(uniquename.Data());
286     kmat = mat->GetUniqueID();
287     (*fIdmate)[imat]=kmat;
288   }else{
289     gMC->Mixture(kmat, uniquename.Data(), a, z, dens, nlmat, wmat);
290     (*fIdmate)[imat]=kmat;
291   }
292
293  
294 //_______________________________________________________________________
295 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
296                           Int_t isvol, Int_t ifield, Float_t fieldm,
297                           Float_t tmaxfd, Float_t stemax, Float_t deemax,
298                           Float_t epsil, Float_t stmin, Float_t *ubuf,
299                           Int_t nbuf) const
300
301   //
302   // Store the parameters of a tracking medium
303   //
304   // numed       the medium number is stored into (*fIdtmed)[numed]
305   // name        medium name
306   // nmat        the material number is stored into (*fIdmate)[nmat]
307   // isvol       sensitive volume if isvol!=0
308   // ifield      magnetic field flag (see below)
309   // fieldm      maximum magnetic field
310   // tmaxfd      maximum deflection angle due to magnetic field
311   // stemax      maximum step allowed
312   // deemax      maximum fractional energy loss in one step
313   // epsil       tracking precision in cm
314   // stmin       minimum step due to continuous processes
315   //
316   // ifield =  0       no magnetic field
317   //        = -1       user decision in guswim
318   //        =  1       tracking performed with Runge Kutta
319   //        =  2       tracking performed with helix
320   //        =  3       constant magnetic field along z
321   //  
322   Int_t kmed;
323   //Build the string uniquename as "DET_mediumname"
324   TString uniquename = GetName();
325   uniquename.Append("_");
326   uniquename.Append(name);
327   //if geometry loaded from file only fill fIdtmed, else create medium too
328   if(gAlice->IsRootGeometry()){
329     TGeoMedium *med = gGeoManager->GetMedium(uniquename.Data());
330     kmed = med->GetId();
331     (*fIdtmed)[numed]=kmed;
332   }else{
333     gMC->Medium(kmed, uniquename.Data(), (*fIdmate)[nmat], isvol, ifield,
334                 fieldm, tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
335     (*fIdtmed)[numed]=kmed;
336   }
337
338  
339 //_______________________________________________________________________
340 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
341                           Float_t theta2, Float_t phi2, Float_t theta3,
342                           Float_t phi3) const
343 {
344   // 
345   // Define a rotation matrix. Angles are in degrees.
346   //
347   // nmat        on output contains the number assigned to the rotation matrix
348   // theta1      polar angle for axis I
349   // phi1        azimuthal angle for axis I
350   // theta2      polar angle for axis II
351   // phi2        azimuthal angle for axis II
352   // theta3      polar angle for axis III
353   // phi3        azimuthal angle for axis III
354   //
355   gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3); 
356
357
358 //_______________________________________________________________________
359 Float_t AliModule::ZMin() const
360 {
361   return -500;
362 }
363
364 //_______________________________________________________________________
365 Float_t AliModule::ZMax() const
366 {
367   return 500;
368 }
369
370 //_______________________________________________________________________
371 void AliModule::SetEuclidFile(char* material, char* geometry)
372 {
373   //
374   // Sets the name of the Euclid file
375   //
376   fEuclidMaterial=material;
377   if(geometry) {
378     fEuclidGeometry=geometry;
379   } else {
380     char* name = new char[strlen(material)];
381     strcpy(name,material);
382     strcpy(&name[strlen(name)-4],".euc");
383     fEuclidGeometry=name;
384     delete [] name;
385   }
386 }
387  
388 //_______________________________________________________________________
389 void AliModule::ReadEuclid(const char* filnam, char* topvol)
390 {
391   //                                                                     
392   //       read in the geometry of the detector in euclid file format    
393   //                                                                     
394   //        id_det : the detector identification (2=its,...)            
395   //        topvol : return parameter describing the name of the top    
396   //        volume of geometry.                                          
397   //                                                                     
398   //            author : m. maire                                        
399   //                                                                     
400   //     28.07.98
401   //     several changes have been made by miroslav helbich
402   //     subroutine is rewrited to follow the new established way of memory
403   //     booking for tracking medias and rotation matrices.
404   //     all used tracking media have to be defined first, for this you can use
405   //     subroutine  greutmed.
406   //     top volume is searched as only volume not positioned into another 
407   //
408
409   Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
410   Int_t ndvmx, nr, flag;
411   char key[5], card[77], natmed[21];
412   char name[5], mother[5], shape[5], konly[5], volst[7000][5];
413   char *filtmp;
414   Float_t par[100];
415   Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
416   Float_t xo, yo, zo;
417   const Int_t kMaxRot=5000;
418   Int_t idrot[kMaxRot],istop[7000];
419   FILE *lun;
420   //
421   // *** The input filnam name will be with extension '.euc'
422   filtmp=gSystem->ExpandPathName(filnam);
423   lun=fopen(filtmp,"r");
424   delete [] filtmp;
425   if(!lun) {
426     AliError(Form("Could not open file %s",filnam));
427     return;
428   }
429   //* --- definition of rotation matrix 0 ---  
430   TArrayI &idtmed = *fIdtmed;
431   for(i=1; i<kMaxRot; ++i) idrot[i]=-99;
432   idrot[0]=0;
433   nvol=0;
434  L10:
435   for(i=0;i<77;i++) card[i]=0;
436   iret=fscanf(lun,"%77[^\n]",card);
437   if(iret<=0) goto L20;
438   fscanf(lun,"%*c");
439   //*
440   strncpy(key,card,4);
441   key[4]='\0';
442   if (!strcmp(key,"TMED")) {
443     sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
444     if( itmed<0 || itmed>=100 ) {
445       AliError(Form("TMED illegal medium number %d for %s",itmed,natmed));
446       exit(1);
447     }
448     //Pad the string with blanks
449     i=-1;
450     while(natmed[++i]);
451     while(i<20) natmed[i++]=' ';
452     natmed[i]='\0';
453     //
454     if( idtmed[itmed]<=0 ) {
455       AliError(Form("TMED undefined medium number %d for %s",itmed,natmed));
456       exit(1);
457     }
458     gMC->Gckmat(idtmed[itmed],natmed);
459     //*
460   } else if (!strcmp(key,"ROTM")) {
461     sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
462     if( irot<=0 || irot>=kMaxRot ) {
463       AliError(Form("ROTM rotation matrix number %d illegal",irot));
464       exit(1);
465     }
466     AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
467     //*
468   } else if (!strcmp(key,"VOLU")) {
469     sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
470     if (npar>0) {
471       for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
472       fscanf(lun,"%*c");
473     }
474     gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
475     //*     save the defined volumes
476     strcpy(volst[++nvol],name);
477     istop[nvol]=1;
478     //*
479   } else if (!strcmp(key,"DIVN")) {
480     sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
481     gMC->Gsdvn  ( name, mother, ndiv, iaxe );
482     //*
483   } else if (!strcmp(key,"DVN2")) {
484     sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
485     gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
486     //*
487   } else if (!strcmp(key,"DIVT")) {
488     sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
489     gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
490     //*
491   } else if (!strcmp(key,"DVT2")) {
492     sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
493     gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
494     //*
495   } else if (!strcmp(key,"POSI")) {
496     sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
497     if( irot<0 || irot>=kMaxRot ) {
498       Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot);
499       exit(1);
500     }
501     if( idrot[irot] == -99) {
502       Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot);
503       exit(1);
504     }
505     //*** volume name cannot be the top volume
506     for(i=1;i<=nvol;i++) {
507       if (!strcmp(volst[i],name)) istop[i]=0;
508     }
509     //*
510     gMC->Gspos  ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
511     //*
512   } else if (!strcmp(key,"POSP")) {
513     sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
514     if( irot<0 || irot>=kMaxRot ) {
515       Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot);
516       exit(1);
517     }
518     if( idrot[irot] == -99) {
519       Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot);
520       exit(1);
521     }
522     if (npar > 0) {
523       for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
524       fscanf(lun,"%*c");
525     }
526     //*** volume name cannot be the top volume
527     for(i=1;i<=nvol;i++) {
528       if (!strcmp(volst[i],name)) istop[i]=0;
529     }
530     //*
531     gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
532   }
533   //*
534   if (strcmp(key,"END")) goto L10;
535   //* find top volume in the geometry
536   flag=0;
537   for(i=1;i<=nvol;i++) {
538     if (istop[i] && flag) {
539       AliWarning(Form(" %s is another possible top volume",volst[i]));
540     }
541     if (istop[i] && !flag) {
542       strcpy(topvol,volst[i]);
543       AliDebug(2, Form("volume %s taken as a top volume",topvol));
544       flag=1;
545     }
546   }
547   if (!flag) {
548     AliWarning("top volume not found");
549   }
550   fclose (lun);
551   //*
552   //*     commented out only for the not cernlib version
553   AliDebug(1, Form("file: %s is now read in",filnam));
554   //
555   return;
556   //*
557   L20:
558   AliError("reading error or premature end of file");
559 }
560
561 //_______________________________________________________________________
562 void AliModule::ReadEuclidMedia(const char* filnam)
563 {
564   //                                                                     
565   //       read in the materials and tracking media for the detector     
566   //                   in euclid file format                             
567   //                                                                     
568   //       filnam: name of the input file                                
569   //       id_det: id_det is the detector identification (2=its,...)     
570   //                                                                     
571   //            author : miroslav helbich                                
572   //
573   Float_t sxmgmx = gAlice->Field()->Max();
574   Int_t   isxfld = gAlice->Field()->Integ();
575   Int_t end, i, iret, itmed;
576   char key[5], card[130], natmed[21], namate[21];
577   Float_t ubuf[50];
578   char* filtmp;
579   FILE *lun;
580   Int_t imate;
581   Int_t nwbuf, isvol, ifield, nmat;
582   Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
583   //
584   end=strlen(filnam);
585   for(i=0;i<end;i++) if(filnam[i]=='.') {
586     end=i;
587     break;
588   }
589   //
590   // *** The input filnam name will be with extension '.euc'
591   AliDebug(1, Form("The file name is %s",filnam)); //Debug
592   filtmp=gSystem->ExpandPathName(filnam);
593   lun=fopen(filtmp,"r");
594   delete [] filtmp;
595   if(!lun) {
596     AliWarning(Form("Could not open file %s",filnam));
597     return;
598   }
599   //
600   // Retrieve Mag Field parameters
601   Int_t globField=gAlice->Field()->Integ();
602   Float_t globMaxField=gAlice->Field()->Max();
603   //  TArrayI &idtmed = *fIdtmed;
604   //
605  L10:
606   for(i=0;i<130;i++) card[i]=0;
607   iret=fscanf(lun,"%4s %[^\n]",key,card);
608   if(iret<=0) goto L20;
609   fscanf(lun,"%*c");
610   //*
611   //* read material
612   if (!strcmp(key,"MATE")) {
613     sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
614     if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
615     //Pad the string with blanks
616     i=-1;
617     while(namate[++i]);
618     while(i<20) namate[i++]=' ';
619     namate[i]='\0';
620     //
621     AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
622     //* read tracking medium
623   } else if (!strcmp(key,"TMED")) {
624     sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
625            &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
626            &stemax,&deemax,&epsil,&stmin,&nwbuf);
627     if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
628     if (ifield<0) ifield=isxfld;
629     if (fieldm<0) fieldm=sxmgmx;
630     //Pad the string with blanks
631     i=-1;
632     while(natmed[++i]);
633     while(i<20) natmed[i++]=' ';
634     natmed[i]='\0';
635     //
636     AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd,
637                    stemax,deemax,epsil,stmin,ubuf,nwbuf);
638     //    (*fImedia)[idtmed[itmed]-1]=id_det;
639     //*
640   }
641   //*
642   if (strcmp(key,"END")) goto L10;
643   fclose (lun);
644   //*
645   //*     commented out only for the not cernlib version
646   AliDebug(1, Form("file %s is now read in",filnam));
647   //*
648   return;
649   //*
650  L20:
651   AliWarning("reading error or premature end of file");
652
653
654 //_______________________________________________________________________
655 void AliModule::AddAlignableVolumes() const
656 {
657   // 
658   if (IsActive())
659     AliWarning(Form(" %s still has to implement the AddAlignableVolumes method!",GetName()));
660 }
661
662 //_______________________________________________________________________
663
664 AliLoader*  AliModule::MakeLoader(const char* /*topfoldername*/)
665 {
666   return 0x0;
667 }
668  
669
670 //_____________________________________________________________________________
671 AliTrackReference*  AliModule::AddTrackReference(Int_t label, Int_t id){
672   //
673   // add a trackrefernce to the list
674     return (gAlice->GetMCApp()->AddTrackReference(label, id));
675 }
676
677  //_______________________________________________________________________
678 AliTrackReference* AliModule::FirstTrackReference(Int_t track)
679 {
680     //
681     // Initialise the hit iterator
682     // Return the address of the first hit for track
683     // If track>=0 the track is read from disk
684     // while if track0 the first hit of the current
685     // track is returned
686     //
687     if(track>=0)
688     {
689         if (fRunLoader == 0x0)
690             AliFatal("AliRunLoader not initialized. Can not proceed");
691         fRunLoader->GetAliRun()->GetMCApp()->ResetTrackReferences();
692         fRunLoader->TreeTR()->GetEvent(track);
693     }
694     //
695     fMaxIterTrackRef     = fTrackReferences->GetEntriesFast();
696     fCurrentIterTrackRef = 0;
697     if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
698     else            return 0;
699 }
700
701  //_______________________________________________________________________
702 AliTrackReference* AliModule::NextTrackReference()
703 {
704     //
705     // Return the next hit for the current track
706     //
707     if(fMaxIterTrackRef) {
708         if(++fCurrentIterTrackRef < fMaxIterTrackRef)
709             return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
710         else
711             return 0;
712     } else {
713         AliWarning("Iterator called without calling FistTrackReference before");
714         return 0;
715     }
716 }
717
718
719
720
721 //_____________________________________________________________________________
722 TTree* AliModule::TreeTR()
723 {
724   //
725   // Return TR tree pointer
726   //
727   if ( fRunLoader == 0x0)
728    {
729      AliError("Can not get the run loader");
730      return 0x0;
731    }
732
733   TTree* tree = fRunLoader->TreeTR();
734   return tree;
735 }
736
737
738 //_____________________________________________________________________________
739 void AliModule::Digits2Raw()
740 {
741 // This is a dummy version that just copies the digits file contents
742 // to a raw data file.
743
744   AliWarning(Form("Dummy version called for %s", GetName()));
745
746   Int_t nDDLs = AliDAQ::NumberOfDdls(GetName());
747
748   if (!GetLoader()) return;
749   fstream digitsFile(GetLoader()->GetDigitsFileName(), ios::in);
750   if (!digitsFile) return;
751
752   digitsFile.seekg(0, ios::end);
753   UInt_t size = digitsFile.tellg();
754   UInt_t ddlSize = 4 * (size / (4*nDDLs));
755   Char_t* buffer = new Char_t[ddlSize+1];
756
757   for (Int_t iDDL = 0; iDDL < nDDLs; iDDL++) {
758     char fileName[20];
759     strcpy(fileName,AliDAQ::DdlFileName(GetName(),iDDL));
760     fstream rawFile(fileName, ios::out);
761     if (!rawFile) return;
762
763     AliRawDataHeader header;
764     header.fSize = ddlSize + sizeof(header);
765     rawFile.write((char*) &header, sizeof(header));
766
767     digitsFile.read(buffer, ddlSize);
768     rawFile.write(buffer, ddlSize);
769     rawFile.close();
770   }
771
772   digitsFile.close();
773   delete[] buffer;
774 }