]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSAlignMille.cxx
updated for the photonic background tagging
[u/mrichter/AliRoot.git] / ITS / AliITSAlignMille.cxx
index b3348da335f9f88c1ec3da0d5ffdc0fff3df4fa6..5478e0559d5d468478549d461ece14c5659c9fda 100644 (file)
@@ -176,9 +176,12 @@ Int_t AliITSAlignMille::LoadConfig(const Char_t *cfile) {
     }
 
     if (strstr(st,"GEOMETRY_FILE")) {
-      sscanf(st,"%s %s",tmp,st2);
+      memset(tmp,0,100*sizeof(char));
+      memset(st2,0,200*sizeof(char));
+      sscanf(st,"%99s %199s",tmp,st2);
       if (gSystem->AccessPathName(st2)) {
        AliInfo("*** WARNING! *** geometry file not found! ");
+       fclose(pfc);
        return -1;
       }  
       fGeometryFileName=st2;
@@ -186,30 +189,38 @@ Int_t AliITSAlignMille::LoadConfig(const Char_t *cfile) {
     }
 
     if (strstr(st,"PREALIGNMENT_FILE")) {
-      sscanf(st,"%s %s",tmp,st2);
+      memset(tmp,0,100*sizeof(char));
+      memset(st2,0,200*sizeof(char));
+      sscanf(st,"%99s %199s",tmp,st2);
       if (gSystem->AccessPathName(st2)) {
        AliInfo("*** WARNING! *** prealignment file not found! ");
+       fclose(pfc);
        return -1;
       }  
       fPreAlignmentFileName=st2;
       itx=ApplyToGeometry();
       if (itx) {
        AliInfo(Form("*** WARNING! *** error %d reading prealignment file! ",itx));
+       fclose(pfc);
        return -6;
       }
     }
 
     if (strstr(st,"SUPERMODULE_FILE")) {
-      sscanf(st,"%s %s",tmp,st2);
+      memset(tmp,0,100*sizeof(char));
+      memset(st2,0,200*sizeof(char));
+      sscanf(st,"%99s %199s",tmp,st2);
       if (gSystem->AccessPathName(st2)) {
        AliInfo("*** WARNING! *** supermodule file not found! ");
+       fclose(pfc);
        return -1;
       }  
-      if (LoadSuperModuleFile(st2)) return -1;
+      if (LoadSuperModuleFile(st2)) {fclose(pfc); return -1;}
     }
 
     if (strstr(st,"SET_B_FIELD")) {
-      sscanf(st,"%s %f",tmp,&f1);
+      memset(tmp,0,100*sizeof(char));
+      sscanf(st,"%99s %f",tmp,&f1);
       if (f1>0) {
        fBField = f1;
        fBOn = kTRUE;
@@ -224,32 +235,38 @@ Int_t AliITSAlignMille::LoadConfig(const Char_t *cfile) {
     }
 
     if (strstr(st,"SET_PARSIG_TRA")) {
-      sscanf(st,"%s %f",tmp,&f1);
+      memset(tmp,0,100*sizeof(char));
+      sscanf(st,"%99s %f",tmp,&f1);
       fParSigTranslations=f1;
     }
 
     if (strstr(st,"SET_PARSIG_ROT")) {
-      sscanf(st,"%s %f",tmp,&f1);
+      memset(tmp,0,100*sizeof(char));
+      sscanf(st,"%99s %f",tmp,&f1);
       fParSigRotations=f1;
     }
 
     if (strstr(st,"SET_NSTDDEV")) {
-      sscanf(st,"%s %d",tmp,&idx);
+      memset(tmp,0,100*sizeof(char));
+      sscanf(st,"%99s %d",tmp,&idx);
       fNStdDev=idx;
     }
 
     if (strstr(st,"SET_RESCUT_INIT")) {
-      sscanf(st,"%s %f",tmp,&f1);
+      memset(tmp,0,100*sizeof(char));
+      sscanf(st,"%99s %f",tmp,&f1);
       fResCutInitial=f1;
     }
 
     if (strstr(st,"SET_RESCUT_OTHER")) {
-      sscanf(st,"%s %f",tmp,&f1);
+      memset(tmp,0,100*sizeof(char));
+      sscanf(st,"%99s %f",tmp,&f1);
       fResCut=f1;
     }
 
     if (strstr(st,"SET_LOCALSIGMAFACTOR")) {
-      sscanf(st,"%s %f %f",tmp,&f1,&f2);
+      memset(tmp,0,100*sizeof(char));
+      sscanf(st,"%99s %f %f",tmp,&f1,&f2);
       if (f1>0 && f2>0) {
        fSigmaXfactor=f1;
        fSigmaZfactor=f2;
@@ -257,7 +274,8 @@ Int_t AliITSAlignMille::LoadConfig(const Char_t *cfile) {
     }
 
     if (strstr(st,"SET_STARTFAC")) {
-      sscanf(st,"%s %f",tmp,&f1);
+      memset(tmp,0,100*sizeof(char));
+      sscanf(st,"%99s %f",tmp,&f1);
       fStartFac=f1;
     }
 
@@ -267,17 +285,19 @@ Int_t AliITSAlignMille::LoadConfig(const Char_t *cfile) {
       //    ndet = detector number: 1-6 for LAYER and 1-3 for DETECTOR (SPD=1, SDD=2, SSD=3)
       //    updw = 1 for Y>0, -1 for Y<0, 0 if not specified
       //    nreqpts = minimum number of points of that type
-      sscanf(st,"%s %s %d %d %d",tmp,st2,&itx,&ity,&itz);
+      memset(tmp,0,100*sizeof(char));
+      memset(st2,0,200*sizeof(char));
+      sscanf(st,"%99s %199s %d %d %d",tmp,st2,&itx,&ity,&itz);
       itx--;
       if (strstr(st2,"LAYER")) {
-       if (itx<0 || itx>5) return -7;
+       if (itx<0 || itx>5) {fclose(pfc); return -7;}
        if (ity>0) fNReqLayUp[itx]=itz;
        else if (ity<0) fNReqLayDown[itx]=itz;
        else fNReqLay[itx]=itz;
        fRequirePoints=kTRUE;
       }
       else if (strstr(st2,"DETECTOR")) { // DETECTOR
-       if (itx<0 || itx>2) return -7;
+       if (itx<0 || itx>2) {fclose(pfc); return -7;}
        if (ity>0) fNReqDetUp[itx]=itz;
        else if (ity<0) fNReqDetDown[itx]=itz;
        else fNReqDet[itx]=itz; 
@@ -292,10 +312,11 @@ Int_t AliITSAlignMille::LoadConfig(const Char_t *cfile) {
 
     if (strstr(st,"MODULE_INDEX")) { // works only for sensitive modules
       f1=0; f2=0;
-      sscanf(st,"%s %d %d %d %d %d %d %d %f %f",tmp,&idx,&itx,&ity,&itz,&iph,&ith,&ips,&f1,&f2);
-      if (idx<0 || idx>2197) return 1; // bad index
+      memset(tmp,0,100*sizeof(char));
+      sscanf(st,"%99s %d %d %d %d %d %d %d %f %f",tmp,&idx,&itx,&ity,&itz,&iph,&ith,&ips,&f1,&f2);
+      if (idx<0 || idx>2197) {fclose(pfc); return 1;} // bad index
       voluid=GetModuleVolumeID(idx);
-      if (!voluid || voluid>14300) return 1; // bad index
+      if (!voluid || voluid>14300) {fclose(pfc); return 1;} // bad index
       fModuleIndex[nmod]=idx;
       fModuleVolumeID[nmod]=voluid;
       fFreeParam[nmod][0]=itx;
@@ -312,14 +333,15 @@ Int_t AliITSAlignMille::LoadConfig(const Char_t *cfile) {
    
     if (strstr(st,"MODULE_VOLUID")) {
       f1=0; f2=0;
-      sscanf(st,"%s %d %d %d %d %d %d %d %f %f",tmp,&idx,&itx,&ity,&itz,&iph,&ith,&ips,&f1,&f2);
+      memset(tmp,0,100*sizeof(char));
+      sscanf(st,"%99s %d %d %d %d %d %d %d %f %f",tmp,&idx,&itx,&ity,&itz,&iph,&ith,&ips,&f1,&f2);
       voluid=UShort_t(idx);
       if (voluid>14335 && fUseSuperModules) { // custom supermodule
        int ism=-1;
        for (int j=0; j<fNSuperModules; j++) {
          if (voluid==fSuperModule[j]->GetVolumeID()) ism=j;
        }
-       if (ism<0) return -1; // bad volid
+       if (ism<0) {fclose(pfc); return -1;} // bad volid
        fModuleIndex[nmod]=fSuperModule[ism]->GetIndex();
        fModuleVolumeID[nmod]=voluid;
        fFreeParam[nmod][0]=itx;
@@ -344,7 +366,7 @@ Int_t AliITSAlignMille::LoadConfig(const Char_t *cfile) {
       }
       else { // sensitive volume
        idx=GetModuleIndex(voluid);
-       if (idx<0 || idx>2197) return 1; // bad index
+       if (idx<0 || idx>2197) {fclose(pfc); return 1;} // bad index
        fModuleIndex[nmod]=idx;
        fModuleVolumeID[nmod]=voluid;
        fFreeParam[nmod][0]=itx;
@@ -563,7 +585,7 @@ Int_t AliITSAlignMille::GetPreAlignmentQualityFactor(Int_t index) const {
   return fPreAlignQF[index];
 }
 
-AliTrackPointArray *AliITSAlignMille::PrepareTrack(AliTrackPointArray *atp) {
+AliTrackPointArray *AliITSAlignMille::PrepareTrack(const AliTrackPointArray *atp) {
   /// create a new AliTrackPointArray keeping only defined modules
   /// move points according to a given prealignment, if any
   /// sort alitrackpoints w.r.t. global Y direction, if selected
@@ -731,7 +753,7 @@ AliTrackPointArray *AliITSAlignMille::PrepareTrack(AliTrackPointArray *atp) {
 
 
 
-AliTrackPointArray *AliITSAlignMille::SortTrack(AliTrackPointArray *atp) {
+AliTrackPointArray *AliITSAlignMille::SortTrack(const AliTrackPointArray *atp) {
   /// sort alitrackpoints w.r.t. global Y direction
   AliTrackPointArray *atps=NULL;
   Int_t idx[20];
@@ -932,7 +954,7 @@ void AliITSAlignMille::Print(Option_t*) const
    
 }
 
-AliITSAlignMilleModule  *AliITSAlignMille::GetMilleModule(UShort_t voluid) 
+AliITSAlignMilleModule  *AliITSAlignMille::GetMilleModule(UShort_t voluid) const
 {
   // return pointer to a define supermodule
   // return NULL if error
@@ -1216,7 +1238,7 @@ Int_t AliITSAlignMille::ProcessTrack(AliTrackPointArray *track) {
   return 0;
 }
 
-Int_t AliITSAlignMille::CalcIntersectionPoint(Double_t *lpar, Double_t *gpar) {
+Int_t AliITSAlignMille::CalcIntersectionPoint(const Double_t *lpar, const Double_t *gpar) {
   /// calculate intersection point of track with current module in local coordinates
   /// according with a given set of parameters (local(4/5) and global(6))
   /// and fill fPintLoc/Glo
@@ -1460,25 +1482,25 @@ Int_t AliITSAlignMille::AddLocalEquation(AliITSAlignMilleData &m) {
   Double_t nonzero=0.0;
   for (Int_t i=0; i<fNLocal; i++) nonzero += TMath::Abs(dXdL[i]);
   if (nonzero==0.0) {
-    AliInfo("Aborting local equations for this point beacuse of zero local X derivatives!");
+    AliInfo("Discarding local equations for this point beacuse of zero local X derivatives!");
     return -2;
   }
   nonzero=0.0;
   for (Int_t i=0; i<ITSMILLENPARCH; i++) nonzero += TMath::Abs(dXdG[i]);
   if (nonzero==0.0) {
-    AliInfo("Aborting local equations for this point beacuse of zero global X derivatives!");
+    AliInfo("Discarding local equations for this point beacuse of zero global X derivatives!");
     return -2;
   }
   nonzero=0.0;
   for (Int_t i=0; i<fNLocal; i++) nonzero += TMath::Abs(dZdL[i]);
   if (nonzero==0.0) {
-    AliInfo("Aborting local equations for this point beacuse of zero local Z derivatives!");
+    AliInfo("Discarding local equations for this point beacuse of zero local Z derivatives!");
     return -2;
   }
   nonzero=0.0;
   for (Int_t i=0; i<ITSMILLENPARCH; i++) nonzero += TMath::Abs(dZdG[i]);
   if (nonzero==0.0) {
-    AliInfo("Aborting local equations for this point beacuse of zero global Z derivatives!");
+    AliInfo("Discarding local equations for this point beacuse of zero global Z derivatives!");
     return -2;
   }
 
@@ -1514,7 +1536,7 @@ Int_t AliITSAlignMille::AddLocalEquation(AliITSAlignMilleData &m) {
 }
 
 
-void AliITSAlignMille::SetLocalEquations(AliITSAlignMilleData *m, Int_t neq) {
+void AliITSAlignMille::SetLocalEquations(const AliITSAlignMilleData *m, Int_t neq) {
   /// Set local equations with data stored in m
   /// return 0 if success
   
@@ -1615,10 +1637,10 @@ Int_t AliITSAlignMille::LoadSuperModuleFile(const Char_t *sfile)
   for (Int_t i=0; i<nsma; i++) {
     AliAlignObjParams *a = (AliAlignObjParams*)sma->UncheckedAt(i);
     volid=a->GetVolUID();
-    strcpy(st,a->GetSymName());
+    strncpy(st,a->GetSymName(),TMath::Min(sizeof(st),strlen(a->GetSymName())+1));
     a->GetMatrix(m);
-
-    sscanf(st,"%s",symname);
+    memset(symname,0,250*sizeof(char));
+    sscanf(st,"%249s",symname);
     // decode module list
     char *stp=strstr(st,"ModuleList:");
     if (!stp) return -3;
@@ -1626,7 +1648,7 @@ Int_t AliITSAlignMille::LoadSuperModuleFile(const Char_t *sfile)
     int idx[2200];
     char spp[200]; int jp=0;
     char cl[20];
-    strcpy(st,stp);
+    strncpy(st,stp,TMath::Min(sizeof(st),strlen(stp)+1));
     int l=strlen(st);
     int j=0;
     int n=0;
@@ -1638,7 +1660,7 @@ Int_t AliITSAlignMille::LoadSuperModuleFile(const Char_t *sfile)
        if (strlen(spp)) {
          int k=strcspn(spp,"-");
          if (k<int(strlen(spp))) { // c'e' il -
-           strcpy(cl,&(spp[k+1]));
+           strncpy(cl,&(spp[k+1]), TMath::Min(sizeof(cl),strlen(&spp[k+1])+1));
            spp[k]=0;
            int ifrom=atoi(spp); int ito=atoi(cl);
            for (int b=ifrom; b<=ito; b++) {