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