DA rpms
[u/mrichter/AliRoot.git] / TOF / MakeCDBEntryProblematic.C
CommitLineData
a1f56f35 1MakeCDBEntryProblematic(Int_t startRun = 0, Int_t endRun = AliCDBRunRange::Infinity(), const Char_t *filename = NULL, const Char_t *dbString = "local://$ALICE_ROOT/OCDB")
8da43270 2{
3
4 /* create object */
5 TH1C *obj = new TH1C("hProblematic", "", 157248, 0., 157248.);
6
7 /* update object */
8 if (filename) {
9 printf("PROBLEMATIC HISTO WILL BE UPDATED ACCORDING TO INPUT LIST\n");
10 printf("inputList: %s\n", filename);
11 UpdateProblematicHisto(obj, filename);
12 }
13 else {
14 printf("EMPTY PROBLEMATIC HISTO WILL BE GENERATED\n");
15 }
16
17 /* create cdb info */
18 AliCDBId id("TOF/Calib/Problematic", startRun, endRun);
19 AliCDBMetaData *md = new AliCDBMetaData();
20 md->SetResponsible("Roberto Preghenella");
21 md->SetComment("Problematic");
22 md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
23 md->SetBeamPeriod(0);
24
25 /* put object in cdb */
26 AliCDBManager *cdb = AliCDBManager::Instance();
a1f56f35 27 cdb->SetDefaultStorage(dbString);
8da43270 28 cdb->GetDefaultStorage()->Put(obj, id, md);
29
30}
31
32Bool_t
33UpdateProblematicHisto(TH1C *histo, const Char_t *filename)
34{
35 /*
36 * this routine updates the problematic histo taking
37 * problematic channels from a list specified in the
38 * file written in ASCII format according to the
39 * following formats based on electronics-oriented indices:
40 *
41 * # disable single crate
42 * # crate[0-71]
43 *
44 * # disable single TRM
45 * # crate[0-71] trm[3-12]
46 *
47 * # disable single chain
48 * # crate[0-71] trm[3-12] chain[0-1]
49 *
50 * # disable single TDC
51 * # crate[0-71] trm[3-12] chain[0-1] tdc[0-14]
52 *
53 * # disable single channel
54 * # crate[0-71] trm[3-12] chain[0-1] tdc[0-14] channel[0-7]
55 *
56 *
57 * EXAMPLE:
58 * # this list will set as problematics:
59 * # - all channels of crate-39
60 * # - all channels of TRM-03 crate-40
61 * # - all channels of chain-A TRM-07 crate-04
62 * # - all channels of TDC-04 chain-B TRM-09 crate-07
63 * # - channel-03 TDC-02 chain-A TRM-04 crate-00
64 * 39
65 * 40 3
66 * 4 7 0
67 * 7 9 1 4
68 * 0 4 0 2 3
69 *
70 */
71
72 /* check histo */
73 if (!histo) {
74 printf("WARNING: NULL histo, will just run in DUMMY mode\n");
75 }
76
77 /* open ASCII file */
78 ifstream filein;
79 filein.open(filename, ifstream::in);
80
81 /* loop over lines in file */
82 char buf[1024];
83 TString str;
84 TObjString *ostr;
85 TObjArray *oa;
86 Int_t crate, trm, chain, tdc, channel;
87 Int_t irequest = 0, nflagged;
88 printf("processing requests to flag problematic channels:\n");
89 while (filein.good()) {
90 filein.getline(buf, 1024);
91 /* check whether we got to EOF */
92 if (filein.eof()) break;
93 /* put buffer in a TString */
94 str = buf;
95 /* check whether commented line */
96 if (str.BeginsWith("#")) continue;
97 irequest++;
98 /* tokenize */
99 oa = str.Tokenize(" ");
100 switch (oa->GetEntries()) {
101 case 1:
102 ostr = (TObjString *)oa->At(0);
103 crate = atoi(ostr->GetName());
104 if (crate < 0 || crate > 71) {
105 printf("%d.) invalid crate number: %d\n", irequest, crate);
106 break;
107 }
108 nflagged = FlagAsProblematic(histo, crate);
109 printf("%d.) crate flagged as problematic (%d channels): crate-%02d\n", irequest, nflagged, crate);
110 break;
111 case 2:
112 ostr = (TObjString *)oa->At(0);
113 crate = atoi(ostr->GetName());
114 if (crate < 0 || crate > 71) {
115 printf("%d.) invalid crate number: %d\n", irequest, crate);
116 break;
117 }
118 ostr = (TObjString *)oa->At(1);
119 trm = atoi(ostr->GetName());
120 if (trm < 3 || trm > 12) {
121 printf("%d.) invalid TRM number: %d\n", irequest, trm);
122 break;
123 }
124 nflagged = FlagAsProblematic(histo, crate, trm);
125 printf("%d.) TRM flagged as problematic (%d channels): crate-%02d TRM-%02d\n", irequest, nflagged, crate, trm);
126 break;
127 case 3:
128 ostr = (TObjString *)oa->At(0);
129 crate = atoi(ostr->GetName());
130 if (crate < 0 || crate > 71) {
131 printf("%d.) invalid crate number: %d\n", irequest, crate);
132 break;
133 }
134 ostr = (TObjString *)oa->At(1);
135 trm = atoi(ostr->GetName());
136 if (trm < 3 || trm > 12) {
137 printf("%d.) invalid TRM number: %d\n", irequest, trm);
138 break;
139 }
140 ostr = (TObjString *)oa->At(2);
141 chain = atoi(ostr->GetName());
142 if (chain < 0 || chain > 1) {
143 printf("%d.) invalid chain number: %d\n", irequest, chain);
144 break;
145 }
146 nflagged = FlagAsProblematic(histo, crate, trm, chain);
147 printf("%d.) chain flagged as problematic (%d channels): crate-%02d TRM-%02d chain-%s\n", irequest, nflagged, crate, trm, chain == 0 ? "A" : "B");
148 break;
149 case 4:
150 ostr = (TObjString *)oa->At(0);
151 crate = atoi(ostr->GetName());
152 if (crate < 0 || crate > 71) {
153 printf("%d.) invalid crate number: %d\n", irequest, crate);
154 break;
155 }
156 ostr = (TObjString *)oa->At(1);
157 trm = atoi(ostr->GetName());
158 if (trm < 3 || trm > 12) {
159 printf("%d.) invalid TRM number: %d\n", irequest, trm);
160 break;
161 }
162 ostr = (TObjString *)oa->At(2);
163 chain = atoi(ostr->GetName());
164 if (chain < 0 || chain > 1) {
165 printf("%d.) invalid chain number: %d\n", irequest, chain);
166 break;
167 }
168 ostr = (TObjString *)oa->At(3);
169 tdc = atoi(ostr->GetName());
170 if (tdc < 0 || tdc > 14) {
171 printf("%d.) invalid chain number: %d\n", irequest, chain);
172 break;
173 }
174 nflagged = FlagAsProblematic(histo, crate, trm, chain, tdc);
175 printf("%d.) TDC flagged as problematic (%d channels): crate-%02d TRM-%02d chain-%s TDC-%02d\n", irequest, nflagged, crate, trm, chain == 0 ? "A" : "B", tdc);
176 break;
177 case 5:
178 ostr = (TObjString *)oa->At(0);
179 crate = atoi(ostr->GetName());
180 if (crate < 0 || crate > 71) {
181 printf("%d.) invalid crate number: %d\n", irequest, crate);
182 break;
183 }
184 ostr = (TObjString *)oa->At(1);
185 trm = atoi(ostr->GetName());
186 if (trm < 3 || trm > 12) {
187 printf("invalid TRM number: %d\n", irequest, trm);
188 break;
189 }
190 ostr = (TObjString *)oa->At(2);
191 chain = atoi(ostr->GetName());
192 if (chain < 0 || chain > 1) {
193 printf("%d.) invalid chain number: %d\n", irequest, chain);
194 break;
195 }
196 ostr = (TObjString *)oa->At(3);
197 tdc = atoi(ostr->GetName());
198 if (tdc < 0 || tdc > 14) {
199 printf("%d.) invalid chain number: %d\n", irequest, chain);
200 break;
201 }
202 ostr = (TObjString *)oa->At(4);
203 channel = atoi(ostr->GetName());
204 if (channel < 0 || channel > 7) {
205 printf("%d.) invalid channel number: %d\n", irequest, channel);
206 break;
207 }
208 nflagged = FlagAsProblematic(histo, crate, trm, chain, tdc, channel);
209 printf("%d.) channel flagged as problematic (%d channels): crate-%02d TRM-%02d chain-%s TDC-%02d, channel-%d\n", irequest, nflagged, crate, trm, chain == 0 ? "A" : "B", tdc, channel);
210 break;
211 default:
212 printf("%d.) invalid format: %s\n", irequest, str.Data());
213 break;
214 }
215 }
216
217 /* close file */
218 filein.close();
219
220 return kTRUE;
221}
222
223Int_t
224FlagAsProblematic(TH1C *histo, Int_t crate = -1, Int_t trm = -1, Int_t chain = -1, Int_t tdc = -1, Int_t channel = -1)
225{
226
227 /*
228 * flag as problematic according to parameters
229 */
230
231 /* loop over everything checking request */
232 Int_t det[5], dummy, index, nflagged = 0;
233 for (Int_t icrate = 0; icrate < 72; icrate++) {
234 if (crate != -1 && icrate != crate) continue;
235 for (Int_t itrm = 3; itrm <= 12; itrm++) {
236 if (trm != -1 && itrm != trm) continue;
237 for (Int_t ichain = 0; ichain < 2; ichain++) {
238 if (chain != -1 && ichain != chain) continue;
239 for (Int_t itdc = 0; itdc < 15; itdc++) {
240 if (tdc != -1 && itdc != tdc) continue;
241 for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
242 if (channel != -1 && ichannel != channel) continue;
243 AliTOFRawStream::EquipmentId2VolumeId(icrate, itrm, ichain, itdc, ichannel, det);
244 dummy = det[4];
245 det[4] = det[3];
246 det[3] = dummy;
247 if (det[0] < 0 || det[0] > 17 ||
248 det[1] < 0 || det[1] > 4 ||
249 det[2] < 0 || det[2] > 18 ||
250 det[3] < 0 || det[3] > 1 ||
251 det[4] < 0 || det[4] > 47) {
252 // printf("invalid volume indices: EO = (%d %d %d %d %d), VOL = (%d %d %d %d %d)\n", icrate, itrm, ichain, itdc, ichannel, det[0], det[1], det[2], det[3], det[4]);
253 continue;
254 }
255 index = AliTOFGeometry::GetIndex(det);
256 if (index < 0 || index > 157248) {
257 // printf("invalid calib index: EO = (%d %d %d %d %d), VOL = (%d %d %d %d %d), CAL = %d\n", icrate, itrm, ichain, itdc, ichannel, det[0], det[1], det[2], det[3], det[4], index);
258 continue;
259 }
260 nflagged++;
261 if (!histo) continue;
262 histo->SetBinContent(index + 1, 0x1);
263 }
264 }
265 }
266 }
267 }
268
269 return nflagged;
270}