]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliFMDMap.cxx
bug fix when grid connection is down
[u/mrichter/AliRoot.git] / STEER / AliFMDMap.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 caches of per-strip information.
21 // This is used to index a strip. 
22 // Data stored depends on derived class. 
23 // This class provides some common infra-structure.
24 // Derived classes sould define Reset, and operator(). 
25 //
26 #include "AliFMDMap.h"          // ALIFMDMAP_H
27 #include "AliLog.h"
28 //#include <TClass.h>
29 //#include <TBuffer.h>
30 #include <TFile.h>
31 #include <TList.h>
32 #include <TStreamerInfo.h>
33
34 //____________________________________________________________________
35 ClassImp(AliFMDMap)
36 #if 0
37   ; // This is here to keep Emacs for indenting the next line
38 #endif
39
40 //____________________________________________________________________
41 AliFMDMap::AliFMDMap(UShort_t maxDet, 
42                      UShort_t maxRing, 
43                      UShort_t maxSec, 
44                      UShort_t maxStr)
45   : fMaxDetectors(maxDet), 
46     fMaxRings(maxRing), 
47     fMaxSectors(maxSec), 
48     fMaxStrips(maxStr)
49 {
50   // Construct a map
51   //
52   // Parameters:
53   //     maxDet       Maximum # of detectors
54   //     maxRinf      Maximum # of rings
55   //     maxSec       Maximum # of sectors
56   //     maxStr       Maximum # of strips
57   SetBit(kNeedUShort, kFALSE);
58 }
59
60 //____________________________________________________________________
61 void
62 AliFMDMap::CheckNeedUShort(TFile* file) 
63 {
64   if (!file) return;
65   TObject* o = file->GetStreamerInfoList()->FindObject("AliFMDMap");
66   if (!o) return;
67   TStreamerInfo* info = static_cast<TStreamerInfo*>(o);
68   if (info->GetClassVersion() == 2) SetBit(kNeedUShort);
69 }
70 //____________________________________________________________________
71 Int_t 
72 AliFMDMap::CheckIndex(UShort_t det, Char_t ring, UShort_t sec, UShort_t str) const
73 {
74   // Check that the index supplied is OK.   Returns true index, or -1
75   // on error. 
76   if (det < 1) return -1;
77   UShort_t ringi = (ring == 'I' ||  ring == 'i' ? 0 : 1);
78   Int_t idx = 
79     (str + fMaxStrips * (sec + fMaxSectors * (ringi + fMaxRings * (det-1))));
80   if (TestBit(kNeedUShort)) idx = UShort_t(idx);
81   if (idx < 0 || idx >= fMaxDetectors * fMaxRings * fMaxSectors * fMaxStrips) 
82     return -1;
83   return idx;
84 }
85
86     
87 //____________________________________________________________________
88 Int_t 
89 AliFMDMap::CalcIndex(UShort_t det, Char_t ring, UShort_t sec, UShort_t str) const
90 {
91   // Calculate index into storage from arguments. 
92   // 
93   // Parameters: 
94   //     det       Detector #
95   //     ring      Ring ID
96   //     sec       Sector # 
97   //     str       Strip # 
98   //
99   // Returns appropriate index into storage 
100   //
101   Int_t idx = CheckIndex(det, ring, sec, str);
102   if (idx < 0) {
103     UShort_t ringi = (ring == 'I' ||  ring == 'i' ? 0 : 1);
104     AliFatal(Form("Index (%d,'%c',%d,%d) out of bounds, "
105                   "in particular the %s index ", 
106                   det, ring, sec, str, 
107                   (det > fMaxDetectors ? "Detector" : 
108                    (ringi >= fMaxRings ? "Ring" : 
109                     (sec >= fMaxSectors ? "Sector" : "Strip")))));
110     return 0;
111   }
112   return idx;
113 }
114
115 #if 0
116 //___________________________________________________________________
117 void AliFMDMap::Streamer(TBuffer &R__b)
118 {
119   // Stream an object of class AliFMDMap.
120   // This is overridden so that we can know the version of the object
121   // that we are reading in.  In this way, we can fix problems that
122   // might occur in the class. 
123   if (R__b.IsReading()) {
124     // read the class version from the buffer
125     UInt_t R__s, R__c;
126     Version_t version = R__b.ReadVersion(&R__s, &R__c, this->Class());
127     TFile *file = (TFile*)R__b.GetParent();
128     if (file && file->GetVersion() < 30000) version = -1; 
129     AliFMDMap::Class()->ReadBuffer(R__b, this, version, R__s, R__c);
130     if (version == 2) SetBit(kNeedUShort);
131   } else {
132     AliFMDMap::Class()->WriteBuffer(R__b, this);
133   }
134 }
135 #endif
136
137 //___________________________________________________________________
138 //
139 // EOF
140 //