]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpReader.cxx
STL=>ROOT for the mapping package. AliMpContainers.h for the compilation option WITH_...
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpReader.cxx
1 // $Id$
2 // Category: sector
3 //
4 // Class AliMpReader
5 // -------------------
6 // Class that takes care of reading the sector data.
7 //
8 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
9
10 #include <string>
11 #if !defined(__HP_aCC) && !defined(__alpha)
12   #include <sstream>
13 #endif
14
15 #include <Riostream.h>
16 #include <Rstrstream.h>
17 #include <TSystem.h>
18 #include <TError.h>
19 #include <TMath.h>
20
21 #include "AliMpReader.h"
22 #include "AliMpSector.h"
23 #include "AliMpFiles.h"
24 #include "AliMpZone.h"
25 #include "AliMpSubZone.h"
26 #include "AliMpRow.h"
27 #include "AliMpVRowSegment.h"
28 #include "AliMpRowSegment.h"
29 #include "AliMpRowSegmentLSpecial.h"
30 #include "AliMpRowSegmentRSpecial.h"
31 #include "AliMpPadRow.h"
32 #include "AliMpMotifMap.h"
33 #include "AliMpMotif.h"
34 #include "AliMpMotifSpecial.h"
35 #include "AliMpMotifType.h"
36 #include "AliMpConnection.h"
37 #include "AliMpIntPair.h"
38 #include "AliMpDirection.h"
39
40 ClassImp(AliMpReader)
41
42 #ifdef WITH_ROOT
43 const Int_t    AliMpReader::fgkSeparator = 100;
44 #endif
45
46 const TString  AliMpReader::fgkSectorKeyword  = "SECTOR_DATA";
47 const TString  AliMpReader::fgkZoneKeyword    = "ZONE";
48 const TString  AliMpReader::fgkSubZoneKeyword = "SUBZONE";
49 const TString  AliMpReader::fgkRowKeyword     = "ROW_SEGMENT";
50 const TString  AliMpReader::fgkEofKeyword     = "EOF";
51 const TString  AliMpReader::fgkSectorSpecialKeyword  = "SECTOR_SPECIAL_DATA";
52 const TString  AliMpReader::fgkMotifKeyword          = "MOTIF";
53 const TString  AliMpReader::fgkRowSpecialKeyword     = "ROW";
54 const TString  AliMpReader::fgkPadRowsKeyword        = "PAD_ROWS";
55 const TString  AliMpReader::fgkPadRowSegmentKeyword  = "PAD_ROW_SEGMENT";
56
57 //_____________________________________________________________________________
58 AliMpReader::AliMpReader(AliMpStationType station, AliMpPlaneType plane) 
59   : TObject(),
60     fStationType(station),
61     fPlaneType(plane),
62     fSector(0),
63     fVerboseLevel(0)
64 {
65 //
66 }
67
68 //_____________________________________________________________________________
69 AliMpReader::AliMpReader() 
70   : TObject(),
71     fStationType(kStation1),
72     fPlaneType(kBendingPlane),
73     fSector(0),
74     fVerboseLevel(0)
75 {
76 //
77 }
78
79 //_____________________________________________________________________________
80 AliMpReader::~AliMpReader() {
81 //  
82 }
83
84 //
85 // private methods
86 //
87
88 #ifdef WITH_ROOT
89 //_____________________________________________________________________________
90 Int_t  AliMpReader::GetIndex(const std::string& s) const 
91 {
92 // Converts the TString to integer.
93 // ---
94
95   if (s.length() > 5) {
96     Fatal("GetIndex", "String too long.");
97     return 0;
98   }  
99
100   Int_t index = 0;
101   for (Int_t i=s.length(); i>=0; --i)  index = index*100 + int(s[i]);
102   
103   return index;
104 }
105
106 //______________________________________________________________________________
107 Int_t  AliMpReader::GetIndex(const AliMpIntPair& pair) const
108 {
109 // Converts the pair of integers to integer.
110 // ---
111
112   if (pair.GetFirst() >= fgkSeparator || pair.GetSecond() >= fgkSeparator)
113     Fatal("GetIndex", "Index out of limit.");
114       
115   return pair.GetFirst()*fgkSeparator + pair.GetSecond() + 1;
116 }  
117
118 //_____________________________________________________________________________
119 std::string  AliMpReader::GetString(Int_t index) const
120 {
121 // Converts the integer index to the string.
122 // ---
123
124   string s;
125   while (index >0) {
126     Char_t c = index%100;
127     s += c;
128     index = index/100;
129   }
130   
131   return s;
132   
133 }
134
135 //______________________________________________________________________________
136 AliMpIntPair  AliMpReader::GetPair(Int_t index) const
137 {
138 // Converts the integer index to the pair of integers.
139 // ---
140
141   return AliMpIntPair((index-1)/fgkSeparator, (index-1)%fgkSeparator);
142 }  
143 #endif
144
145 //_____________________________________________________________________________
146 void  AliMpReader::ReadSectorData(ifstream& in)
147 {
148 // Reads sector input data;
149 // prepares zones and rows vectors to be filled in.
150 // ---
151
152   TString keyword;
153   in >> keyword;
154   
155   if (fVerboseLevel>0) 
156     cout << keyword << endl;
157
158   if (keyword != fgkSectorKeyword) {
159      Fatal("ReadSectorData", "Wrong file format.");
160      return;
161   }   
162     
163   Int_t nofZones, nofRows;
164   TString directionStr;
165   in >> nofZones;
166   in >> nofRows;
167   in >> directionStr;
168   
169   AliMpDirection direction;
170   direction = (directionStr == "Y") ? kY  :  kX;
171   if (fVerboseLevel>0) 
172      cout << nofZones << " " <<  nofRows << endl;
173
174   fSector = new AliMpSector("Not defined", nofZones, nofRows,direction);
175   
176   TString nextKeyword;
177   in >> nextKeyword;
178     
179   if (nextKeyword != fgkZoneKeyword) {
180      Fatal("ReadSectorData", "Wrong file format.");
181      return;
182   }      
183   
184   ReadZoneData(in);
185 }  
186
187 //_____________________________________________________________________________
188 void AliMpReader::ReadZoneData(ifstream& in)
189 {
190 // Reads zone input data;
191 // creates zone and adds it to zones vector.
192 // ---
193
194   Int_t zoneID;
195   Double_t  sizex, sizey; 
196   in >> zoneID;    
197   in >> sizex;
198   in >> sizey;
199   if (fVerboseLevel>0) 
200      cout << fgkZoneKeyword << " " <<  zoneID << "  "        
201           << sizex << " " << sizey << endl;
202   
203   AliMpZone* zone =  fSector->GetZone(zoneID);
204   zone->SetPadDimensions(TVector2(sizex/2.,sizey/2.)); 
205       
206   TString nextKeyword;
207   in >> nextKeyword;
208     
209   if (nextKeyword != fgkSubZoneKeyword) {
210      Fatal("ReadZoneData", "Wrong file format.");
211      return;
212   }  
213     
214   ReadSubZoneData(in, zone);
215 }
216
217 //_____________________________________________________________________________
218 void AliMpReader::ReadSubZoneData(ifstream& in, AliMpZone* zone)
219 {
220 // Reads subzone input data;
221 // creates subzone and its to the specified zone.
222 // ---
223
224   if (fVerboseLevel>0) 
225     cout << fgkSubZoneKeyword << " ";
226
227   AliMpVMotif* motif = ReadMotifData(in, zone);
228   AliMpSubZone* subZone = new AliMpSubZone(motif); 
229   zone->AddSubZone(subZone); 
230
231   TString nextKeyword;
232   in >> nextKeyword;
233     
234   if (nextKeyword != fgkRowKeyword) {
235      Fatal("ReadSubZoneData", "Wrong file format.");
236      return;
237   }  
238     
239   ReadRowSegmentsData(in, zone, subZone);
240 }   
241
242 //_____________________________________________________________________________
243 AliMpVMotif*  AliMpReader::ReadMotifData(ifstream& in, AliMpZone* zone)
244 {
245 // Reads the motif input data.
246 // ---
247
248   TString  motifID;
249   TString  motifTypeID;
250   in >> motifID;
251   in >> motifTypeID;
252   if (fVerboseLevel>0) {
253     cout << motifID << " " 
254          << motifTypeID << endl;
255   }      
256   
257   AliMpMotifMap* motifMap = fSector->GetMotifMap();
258
259   AliMpMotifType* motifType = 0;
260   AliMpVMotif* motif 
261     = motifMap->FindMotif(motifID, motifTypeID, zone->GetPadDimensions());
262   if (!motif) {    
263     motifType = motifMap->FindMotifType(motifTypeID);
264     if (!motifType) {
265       motifType = BuildMotifType(motifTypeID);     
266       motifMap->AddMotifType(motifType);
267     }
268     
269     if (zone->GetPadDimensions().X() != 0. && zone->GetPadDimensions().Y() != 0.) 
270       motif = new AliMpMotif(motifID, motifType, zone->GetPadDimensions());
271     else 
272       motif = BuildMotifSpecial(motifID, motifType);
273       
274     if (motif) 
275       motifMap->AddMotif(motif);
276
277   }  
278
279   return motif;   
280 }  
281
282 //_____________________________________________________________________________
283 void AliMpReader::ReadRowSegmentsData(ifstream& in, 
284                                       AliMpZone* zone, AliMpSubZone* subZone)
285 {
286 // Reads row segments input data of a specified zone and subzone;
287 // creates row segment and adds it to the specified subzone
288 // and a corresponding row in the rows vector.
289 // ---
290
291   TString nextKeyword;
292   do {
293     // 
294     // Read data from file
295     //
296     Int_t offX, offY, inRow, nofMotifs, firstMotifPositionId, firstMotifPositionDId;
297     in >> offX;
298     in >> offY;
299     in >> inRow;
300     in >> nofMotifs;
301     in >> firstMotifPositionId;
302     in >> firstMotifPositionDId;
303     if (fVerboseLevel>0) 
304        cout << fgkRowKeyword << " " 
305             << offX << " " << offY << " " << inRow << " " << nofMotifs << " " 
306             << firstMotifPositionId << " " << firstMotifPositionDId
307             << endl;
308
309     in >> nextKeyword;
310
311     //
312     // Process data
313     //
314     AliMpRow* row = fSector->GetRow(inRow);
315     AliMpVMotif* motif = subZone->GetMotif();
316     
317     // Create row segment and add it to its zone, row   
318     AliMpVRowSegment* rowSegment
319       = new AliMpRowSegment(row, motif, AliMpIntPair(offX, offY), nofMotifs, 
320                         firstMotifPositionId, firstMotifPositionDId);
321                         
322     subZone->AddRowSegment(rowSegment);
323     row->AddRowSegment(rowSegment);
324   }
325   while (!in.eof() && (nextKeyword == fgkRowKeyword));
326
327   if (in.eof()) return;
328
329   if (nextKeyword == fgkZoneKeyword) {
330     ReadZoneData(in);
331   }
332   else if (nextKeyword == fgkSubZoneKeyword) {
333     ReadSubZoneData(in, zone);
334   }   
335   else {
336     Fatal("ReadRowSegmentsData", "Wrong file format.");
337   } 
338 }   
339
340 //_____________________________________________________________________________
341 void AliMpReader::ReadSectorSpecialData(ifstream& in, AliMpXDirection direction)
342 {
343 // Reads sector input data
344 // with a special (irregular) motifs.
345 // ---
346
347   TString keyword;
348   in >> keyword;
349   if (fVerboseLevel>0) 
350     cout << keyword << endl;
351
352   if (keyword != fgkSectorSpecialKeyword) {
353      Fatal("ReadSectorSpecialData", "Wrong file format.");
354      return;
355   }   
356
357   TString nextKeyword;
358   in >> nextKeyword;
359   if (fVerboseLevel>0) 
360     cout << keyword << endl;
361     
362   if (nextKeyword != fgkMotifKeyword) {
363     Fatal("ReadSectorSpecialData", "Wrong file format.");
364     return;
365   }  
366
367   ReadMotifsSpecialData(in);     
368   ReadRowSpecialData(in, direction); 
369 }  
370
371 //_____________________________________________________________________________
372 void AliMpReader::ReadMotifsSpecialData(ifstream& in)
373 {
374 // Reads the special (irregular) motifs input data.
375 // ---
376
377   if (fVerboseLevel>0) 
378     cout << fgkMotifKeyword << " ";
379
380   TString nextKeyword;
381   do {
382     Int_t zone;
383     in >> zone;
384     AliMpVMotif* motif =  ReadMotifData(in, fSector->GetZone(zone));
385     AliMpSubZone* subZone = new AliMpSubZone(motif); 
386     fSector->GetZone(zone)->AddSubZone(subZone); 
387   
388     in >> nextKeyword;
389     if (fVerboseLevel>0) 
390       cout << nextKeyword << " ";      
391   }
392   while (nextKeyword == fgkMotifKeyword);
393     
394   if (nextKeyword != fgkRowSpecialKeyword) {
395      Fatal("ReadMotifSpecialData", "Wrong file format.");
396      return;
397   }      
398 }  
399
400 //_____________________________________________________________________________
401 void AliMpReader::ReadRowSpecialData(ifstream& in, AliMpXDirection direction)
402 {
403 // Reads row input data
404 // with a special (irregular) motifs.
405 // ---
406
407   Int_t id;
408   in >> id;
409   if (fVerboseLevel>0) 
410       cout << id << endl;      
411   
412   // Get the row and its border
413   AliMpRow* row = fSector->GetRow(id);
414
415   AliMpVRowSegmentSpecial* segment = 0;
416   if (direction == kLeft) {
417     AliMpVRowSegment* firstNormalSeg = row->GetRowSegment(0);
418     Double_t offsetX = firstNormalSeg->LeftBorderX();
419   
420     // Create a special row segment
421     segment = new AliMpRowSegmentLSpecial(row, offsetX);
422     row->AddRowSegmentInFront(segment);
423   }
424   else { 
425     AliMpVRowSegment* precedentNormalSeg 
426       = row->GetRowSegment(row->GetNofRowSegments()-1);
427     Double_t offsetX = precedentNormalSeg->RightBorderX();
428   
429     // Create a special row segment
430     segment = new AliMpRowSegmentRSpecial(row, offsetX);
431     row->AddRowSegment(segment);
432   }  
433       
434   TString nextKeyword;
435   in >> nextKeyword;
436   if (fVerboseLevel>0) 
437     cout << nextKeyword << " ";
438     
439   if (nextKeyword != fgkPadRowsKeyword) {
440      Fatal("ReadRowSpecialData", "Wrong file format.");
441      return;
442   }  
443     
444   ReadRowSegmentSpecialData(in, segment, direction); 
445   
446   // Update row segment and set it to all subzones associated with
447   // contained motifs
448   
449   segment->UpdateMotifVector();
450   segment->UpdatePadsOffset();
451   
452   for (Int_t i=0; i<segment->GetNofMotifs(); i++) {
453     AliMpSubZone* subZone = 0;
454     Int_t j = 0;
455     while (!subZone && j<fSector->GetNofZones())
456       subZone = fSector->GetZone(++j)->FindSubZone(segment->GetMotif(i));
457     
458     subZone->AddRowSegment(segment);
459   }  
460 }  
461
462 //_____________________________________________________________________________
463 void AliMpReader::ReadRowSegmentSpecialData(ifstream& in, 
464                                             AliMpVRowSegmentSpecial* segment,
465                                             AliMpXDirection direction)
466 {
467 // Reads row segment input data
468 // with a special (irregular) motifs.
469 // ---
470
471   Int_t nofPadRows;
472   in >> nofPadRows;
473   if (fVerboseLevel>0) 
474     cout << nofPadRows << endl;
475   
476   TString keyword;
477   in >> keyword;
478   if (fVerboseLevel>0) 
479     cout << keyword << " ";
480     
481   if (keyword != fgkPadRowSegmentKeyword) {
482      Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
483      return;
484   }  
485   
486   //
487   // Process data
488   //
489     
490   PadRowVector  newPadRows;
491   for (Int_t i=0; i<nofPadRows; i++) {
492     
493      // Create pad row
494      AliMpPadRow* padRow = new AliMpPadRow(direction);
495      segment->AddPadRow(padRow);
496      
497      // Keep the new rows in a temporary vector
498 #ifdef WITH_STL
499      newPadRows.push_back(padRow);
500 #endif
501 #ifdef WITH_ROOT
502      newPadRows.Add(padRow);
503 #endif
504   }   
505       
506   TString nextKeyword;
507   do {
508     // 
509     // Read data from file
510     //
511     Int_t    nofPadsInRow, motifPositionId;
512     TString   motifId, motifTypeId;
513     in >> nofPadsInRow;
514     in >> motifId;
515     in >> motifPositionId; 
516   
517     if (fVerboseLevel>0) 
518        cout << nofPadsInRow << " " << motifId << " " << motifPositionId << endl;
519
520     in >> nextKeyword;
521     if (fVerboseLevel>0) 
522       cout << nextKeyword << " ";
523
524     //
525     // Process data
526     //
527     
528     for (Int_t i=0; i<nofPadRows; i++) {
529     
530       // Get pad row from the temporary vector
531 #ifdef WITH_STL
532       AliMpPadRow* padRow = newPadRows[i];
533 #endif
534 #ifdef WITH_ROOT
535       AliMpPadRow* padRow = (AliMpPadRow*)newPadRows[i];
536 #endif
537       
538       // Find motif
539       AliMpVMotif* motif = fSector->GetMotifMap()->FindMotif(motifId);
540       
541       if (!motif) {
542         Fatal("ReadRowSegmentSpecialData", "Unknown motif.");
543         return;
544       }
545
546       // Create pad row segment
547       padRow->AddPadRowSegment(dynamic_cast<AliMpMotif *>(motif), 
548                                motifPositionId, nofPadsInRow);
549     }  
550   }
551   while (!in.eof() && (nextKeyword == fgkPadRowSegmentKeyword));
552   
553   if (in.eof()) return;
554
555   if (nextKeyword == fgkPadRowsKeyword) {
556     ReadRowSegmentSpecialData(in, segment, direction);
557   }
558   else if (nextKeyword == fgkRowSpecialKeyword) {
559     ReadRowSpecialData(in, direction);
560   }   
561   else {
562     Fatal("ReadRowSegmentSpecialData", "Wrong file format.");
563   } 
564 }  
565
566 //
567 // public methods
568 //
569
570 //_____________________________________________________________________________
571 AliMpSector* AliMpReader::BuildSector()
572 {
573 // Reads the mapping data from ascii file
574 // $MINSTALL/data/fileName and creates the basic objects:
575 // zones, subzones, rows, row segments, motifs.
576 // ---
577
578   // Open input file
579   ifstream in(AliMpFiles::Instance()
580               ->SectorFilePath(fStationType, fPlaneType).Data(), ios::in);
581   if (!in) {
582      cerr << AliMpFiles::Instance()
583               ->SectorFilePath(fStationType, fPlaneType) << endl;       
584      Error("BuildSector", "File not found.");
585      return 0;
586   }
587   
588   ReadSectorData(in);
589   fSector->SetRowSegmentOffsets();
590
591   // Open input file for special inner zone
592   TString sectorSpecialFileName 
593     = AliMpFiles::Instance()->SectorSpecialFilePath(fStationType, fPlaneType);
594   if (!gSystem->AccessPathName(sectorSpecialFileName.Data())) {
595     ifstream in2(sectorSpecialFileName.Data(), ios::in);
596     if (!in2) { 
597        cerr << AliMpFiles::Instance()
598               ->SectorSpecialFilePath(fStationType, fPlaneType) << endl;        
599        Error("BuildSector", "File not found.");
600        return 0;
601     }
602     
603     ReadSectorSpecialData(in2, kLeft);
604   }   
605
606   // Open input file for special outer zone
607   TString sectorSpecialFileName2 
608     = AliMpFiles::Instance()->SectorSpecialFilePath2(fStationType, fPlaneType);
609   if (!gSystem->AccessPathName(sectorSpecialFileName2.Data())) {
610     ifstream in3(sectorSpecialFileName2.Data(), ios::in);
611     if (!in3) { 
612        cerr << AliMpFiles::Instance()
613               ->SectorSpecialFilePath2(fStationType, fPlaneType) << endl;       
614        Error("Build", "File not found.");
615        return 0;
616     }
617     
618     ReadSectorSpecialData(in3, kRight);
619   }   
620
621   fSector->Initialize();
622   
623   return fSector;
624 }  
625
626 //_____________________________________________________________________________
627 AliMpMotifType* AliMpReader::BuildMotifType(const TString& motifTypeId)
628 {
629
630   // Read the files describing a motif in the "$MINSTALL/data" directory
631   // and fill the AliMpMotifType structure with.
632   // The files mentioned are are named padPos<maskName>.dat
633   // and connect<maskName>.dat
634
635   AliMpMotifType*  motifType = new AliMpMotifType(motifTypeId); 
636
637   TString strPadPos 
638     = AliMpFiles::Instance()
639       ->PadPosFilePath(fStationType, fPlaneType, motifTypeId);
640   ifstream padPos(strPadPos.Data());
641   if (fVerboseLevel>0) cout<<"Opening file "<<strPadPos<<endl;
642
643   PadMapType positions;
644
645   char line[256];
646   do {
647     padPos.getline(line,255);
648     if (!padPos) break;
649
650 #if defined (__HP_aCC) || (__alpha)
651     strstream strline;
652     strline << line;
653 #else
654     istringstream strline(line);
655 #endif    
656     string key;
657
658     strline>>key;
659     if ((key=="#") || (key=="") ) continue;
660
661     int i,j;
662     strline>>i>>j;
663 #ifdef WITH_STL
664     positions[key].first=i;
665     positions[key].second=j;
666 #endif
667 #ifdef WITH_ROOT
668     positions.Add(GetIndex(key), GetIndex(AliMpIntPair(i,j))); 
669 #endif
670   } while (!padPos.eof());
671
672   padPos.close();
673
674   if (fVerboseLevel>0) 
675     cout << "Opening file "
676          << AliMpFiles::Instance()->BergToGCFilePath(fStationType)
677          << endl;
678
679   ifstream bergToGCFile(AliMpFiles::Instance()->BergToGCFilePath(fStationType));
680   Int_t gassiChannel[80];
681   while(1) {
682     Int_t bergNum;
683     TString gcStr;
684     bergToGCFile>>bergNum>>gcStr;
685     if (!bergToGCFile.good()) break;
686     if (gcStr=="GND") continue;
687     if (bergNum>80) {
688         Fatal("BuildMotifType","Berg number > 80 ...");
689         continue;
690     }
691     gassiChannel[bergNum-1]= atoi(gcStr);
692   }
693   bergToGCFile.close();
694   
695   TString strMotif 
696     = AliMpFiles::Instance()
697       ->MotifFilePath(fStationType, fPlaneType, motifTypeId);
698   ifstream motif(strMotif);
699   if (fVerboseLevel>0) cout<<"Opening file "<<strMotif<<endl;
700
701
702   Int_t nofPadsX=0;
703   Int_t nofPadsY=0;
704
705   do {
706   
707     Int_t ix,iy,numBerg,numKapton,padNum,gassiNum;
708
709     TString lineStr,token;
710     lineStr.ReadLine(motif);
711     if (!motif.good()) break;
712 #if defined (__HP_aCC) || (__alpha)
713     strstream tokenList;
714     tokenList << lineStr.Data();
715 #else
716     istringstream tokenList(lineStr.Data());
717 #endif    
718     
719     token.ReadToken(tokenList);
720     if (!tokenList.good()) continue; // column is missing...
721     if ( (token.Length()>0) && (token[0]=='#') ) continue; // this is a comment line
722     
723     numBerg = atoi(token.Data());
724     if (numBerg==0) {
725       Warning("BuildMotifType","Berg number invalid");
726       continue;
727     }
728     
729     token.ReadToken(tokenList);
730     if (!tokenList.good()) continue; // column is missing...
731     numKapton = atoi(token.Data());
732     if (numKapton==0) continue;
733
734     
735     token.ReadToken(tokenList);
736     if (!tokenList.good()) continue; // column is missing...
737     if (token=="GND") continue;
738     string padName = token.Data();
739     padNum = motifType->PadNum(token);
740     
741      token.ReadToken(tokenList);
742      if (token.IsNull() ) continue; // column is missing...
743 //     if (token[0]!='E') {
744 //       cerr<<"Problem : gassinumber isn't begining with E:"<<token<<endl;
745 //       continue;
746 //     }  else {
747 //        gassiNum = atoi(token.Data() +1 )-1;
748 //     }
749     if ( (numBerg<1) || (numBerg>80) ) {
750         Warning("BuildMotifType","Berg number outside range");
751         continue;
752     }
753     
754     gassiNum  = gassiChannel[numBerg-1];
755
756 #ifdef WITH_STL
757     PadMapTypeIterator iter = positions.find(padName);
758     if (iter==positions.end()) {
759       cerr<<"Problem: Pad number "<<padNum<<" found in the file "<<strMotif
760           <<" but not in the file"<<strPadPos<<endl;
761       continue;
762     }
763
764     ix= iter->second.first;
765     iy= iter->second.second;
766 #endif
767
768 #ifdef WITH_ROOT
769     Long_t value = positions.GetValue(GetIndex(padName));
770     if (!value) {
771       cerr<<"Problem: Pad number "<<padNum<<" found in the file "<<strMotif
772           <<" but not in the file"<<strPadPos<<endl;
773       continue;
774     }
775
776     ix = GetPair(value).GetFirst();
777     iy = GetPair(value).GetSecond();
778 #endif
779
780     motifType->AddConnection(AliMpIntPair(ix,iy),
781                   new AliMpConnection(padNum,numBerg,numKapton,gassiNum));
782
783     if (ix>=nofPadsX) nofPadsX=ix+1;
784     if (iy>=nofPadsY) nofPadsY=iy+1;
785
786   } while (!motif.eof());    
787
788
789   motifType->SetNofPads(nofPadsX, nofPadsY);
790
791   motif.close();
792
793   return motifType;
794 }
795
796
797 //_____________________________________________________________________________
798 AliMpMotifSpecial*  
799 AliMpReader::BuildMotifSpecial(const TString& motifID,
800                                AliMpMotifType* motifType)
801 {
802 // Build a special motif by reading the file motifSpecial<motifId>.dat
803 // in the data directory
804 // ---
805
806   // Open the input file
807   ifstream in(AliMpFiles::Instance()
808               ->MotifSpecialFilePath(fStationType, fPlaneType, motifID).Data(), 
809               ios::in);
810   if (!in) {    
811      Error("BuildMotifSpecial", "File not found.");
812      return 0;
813   }
814
815   AliMpMotifSpecial* res = new AliMpMotifSpecial(motifID,motifType);
816   Int_t i,j;
817   Double_t x,y;
818   in >> i;
819   while (!in.eof()){
820     in >>j >>x >> y;
821     res->SetPadDimensions(AliMpIntPair(i,j),TVector2(x/2.,y/2.));
822     in >> i;
823   }
824   
825   in.close();
826   return res;
827 }
828
829
830 //_____________________________________________________________________________
831 void AliMpReader::SetVerboseLevel(Int_t verboseLevel)
832 {
833 // Sets verbose level.
834 // ---
835
836   fVerboseLevel = verboseLevel;
837 }
838