HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hmdccalparraw.cc
Go to the documentation of this file.
1 //*-- AUTHOR : J. Kempter
2 //*-- Modified : 17/01/2002 by I. Koenig
3 
4 //_HADES_CLASS_DESCRIPTION
5 ////////////////////////////////////////////////////////////////////////////
6 // HMdcCalParRaw
7 //
8 // Container class for the TDC calibration parameters of the MDC
9 //
10 ////////////////////////////////////////////////////////////////////////////
11 using namespace std;
12 #include <stdlib.h>
13 
14 #include "hmdccalparraw.h"
15 #include "hades.h"
16 #include "hruntimedb.h"
17 #include "hspectrometer.h"
18 #include "hmdcdetector.h"
19 #include "hpario.h"
20 #include "hdetpario.h"
21 #include "hmdcrawstruct.h"
22 #include "hmessagemgr.h"
23 #include <iostream>
24 #include <iomanip>
25 
31 
32 void HMdcCalParTdc::fill(HMdcCalParTdc& r) {
33  slope=r.getSlope();
34  offset=r.getOffset();
35  slopeErr=r.getSlopeErr();
36  offsetErr=r.getOffsetErr();
37  slopeMethod=r.getSlopeMethod();
38  offsetMethod=r.getOffsetMethod();
39 }
40 
41 HMdcCalParMbo::HMdcCalParMbo(Int_t tdc, const Text_t* name) {
42  // constructor takes to number of TDC channels and the name of the MBO
43  SetName(name);
44  array = new TObjArray(tdc);
45  for (Int_t i=0; i<tdc; ++i) array->AddAt(new HMdcCalParTdc(),i);
46 }
47 
49  // destructor
50  array->Delete();
51  delete array;
52 }
53 
55  // constructor takes the number of MBOs
56  array = new TObjArray(mbo);
57 }
58 
60  // destructor
61  array->Delete();
62  delete array;
63 }
64 
65 void HMdcCalParRawMod::createMbo(Int_t mbo, Int_t nTdcs, const Char_t* mboName) {
66  // creates the array object of type HMdcCalParMbo
67  if (mbo<array->GetSize() && array->At(mbo)==NULL) {
68  array->AddAt(new HMdcCalParMbo(nTdcs,mboName),mbo);
69  }
70 }
71 
73  // constructor takes the number of modules
74  array = new TObjArray(mod);
75  for (Int_t i=0; i<mod; i++)
76  array->AddAt(new HMdcCalParRawMod(),i);
77 }
78 
80  // destructor
81  array->Delete();
82  delete array;
83 }
84 
85 HMdcCalParRaw::HMdcCalParRaw(const Char_t* name,const Char_t* title,
86  const Char_t* context,Int_t n)
87  : HParSet(name,title,context) {
88  // constructor
89  strcpy(detName,"Mdc");
90  array = new TObjArray(n);
91  for (Int_t i=0; i<n; i++) array->AddAt(new HMdcCalParRawSec(),i);
92  gHades->getRuntimeDb()->getContainer("MdcRawStruct");
93 }
94 
96  // destructor
97  array->Delete();
98  delete array;
99 }
100 
101 Bool_t HMdcCalParRaw::init(HParIo* inp,Int_t* set) {
102  // creates the array objects of type HMdcCalParRawMbo using the data in the parameter container
103  // MdcRawStruct and initializes the container from an input
104  HMdcRawStruct* pRawStruct=
105  (HMdcRawStruct*)gHades->getRuntimeDb()->findContainer("MdcRawStruct");
106  if (pRawStruct==NULL) {
107  Error("HMdcCalParRaw::init()","MdcCalParRaw not initialized, container MdcRawStruct not found");
108  return kFALSE;
109  }
110  for(Int_t s=0;s<getSize();s++) {
111  HMdcCalParRawSec& secPar=(*this)[s];
112  HMdcRawSecStru& secStru=(*pRawStruct)[s];
113  for(Int_t m=0;m<secPar.getSize();m++) {
114  HMdcCalParRawMod& modPar=secPar[m];
115  HMdcRawModStru& modStru=secStru[m];
116  for(Int_t i=0;i<modStru.getSize();i++) {
117  modPar.createMbo(i,modStru[i].getNTdcs(),modStru[i].GetName());
118  }
119  }
120  }
121  HDetParIo* input=inp->getDetParIo("HMdcParIo");
122  if (input) return (input->init(this,set));
123  return kFALSE;
124 }
125 
127  // writes the container to an output
128  HDetParIo* out=output->getDetParIo("HMdcParIo");
129  if (out) return out->write(this);
130  return -1;
131 }
132 
133 void HMdcCalParRaw::readline(const Char_t* buf, Int_t* set) {
134  // decodes one line read from ascii file I/O and calls HMdcCalParTdc::fill(...)
135  Int_t sec, mod, mbo, tdc, slopeMethod,offsetMethod;
136  Float_t slope, offset, slopeErr,offsetErr;
137  Char_t mboName[10];
138  sscanf(buf,"%i%i%i%s%i%f%f%f%f%i%i",
139  &sec, &mod, &mbo, mboName, &tdc, &slope, &offset, &slopeErr,
140  &offsetErr, &slopeMethod, &offsetMethod);
141  Int_t n=sec*4+mod;
142  if (!set[n]) return;
143  HMdcCalParMbo& rMbo=(*this)[sec][mod][mbo];
144  rMbo.SetName(mboName);
145  HMdcCalParTdc& t=rMbo[tdc];
146  t.fill(slope,offset,slopeErr,offsetErr,slopeMethod,offsetMethod);
147  set[n]=999;
148 }
149 
150 void HMdcCalParRaw::putAsciiHeader(TString& header) {
151  // puts the ascii header to the string used in HMdcParAsciiFileIo
152  header=
153  "# Calibration parameters of the MDC\n"
154  "# Format:\n"
155  "# sector module mbo mboName tdc slope offset slopeErr offsetErr slopeMethod offsetMethod\n";
156 }
157 
158 Bool_t HMdcCalParRaw::writeline(Char_t *buf, Int_t sec, Int_t mod, Int_t mbo, Int_t tdc) {
159  // writes one line to the buffer used by ascii file I/O
160  HMdcCalParMbo& rMbo=(*this)[sec][mod][mbo];
161  HMdcCalParTdc& chan=rMbo[tdc];
162  sprintf(buf,"%1i %1i %2i %s %3i % 10.5f % 10.2f % 12.5f % 12.2f %1i %1i \n",
163  sec, mod, mbo, rMbo.GetName(), tdc,
164  chan.getSlope(), chan.getOffset(), chan.getSlopeErr(),
165  chan.getOffsetErr(),chan.getSlopeMethod(), chan.getOffsetMethod());
166  return kTRUE;
167 }
168 
170  // clears the container
171  for(Int_t s=0;s<getSize();s++) {
172  HMdcCalParRawSec& sec=(*this)[s];
173  for(Int_t m=0;m<sec.getSize();m++) {
174  HMdcCalParRawMod& mod=sec[m];
175  for(Int_t l=0;l<mod.getSize();l++) {
176  HMdcCalParMbo& mbo=mod[l];
177  for(Int_t c=0;c<mbo.getSize();c++) mbo[c].clear();
178  }
179  }
180  }
181  status=kFALSE;
183 }
185  // prints the container
186  SEPERATOR_msg("-",60);
187  INFO_msg(10,HMessageMgr::DET_MDC,"HMdcCalParRaw");
188  for(Int_t s=0;s<getSize();s++) {
189  HMdcCalParRawSec& sec=(*this)[s];
190  for(Int_t m=0;m<sec.getSize();m++) {
191  HMdcCalParRawMod& mod=sec[m];
192  for(Int_t l=0;l<mod.getSize();l++) {
193  HMdcCalParMbo& mbo=mod[l];
194  for(Int_t c=0;c<mbo.getSize();c++){
195  gHades->getMsg()->info(10,HMessageMgr::DET_MDC,GetName(),
196  "%1i %1i %2i %s %3i % 10.5f % 10.2f % 12.5f % 12.2f %1i %1i\n",
197  s, m, l, mbo.GetName(),c,
198  mbo[c].getSlope(),mbo[c].getOffset(),
199  mbo[c].getSlopeErr(),mbo[c].getOffsetErr(),
200  mbo[c].getSlopeMethod(),mbo[c].getOffsetMethod()
201  );
202  }
203  }
204  }
205  }
206  SEPERATOR_msg("-",60);
207 }
208 void HMdcCalParRaw::Streamer(TBuffer &R__b)
209 {
210  // Stream an object of class HMdcCalParRaw.
211  TString fAuthor;
212  TString fDescription;
213  TString fRunsUsed;
214  TString fValidity;
215 
216  UInt_t R__s, R__c;
217  if (R__b.IsReading())
218  {
219  Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
220  if(R__v==1)
221  {
222  HParSet::Streamer(R__b);
223  R__b >> array;
224  fAuthor.Streamer(R__b);
225  fDescription.Streamer(R__b);
226  fRunsUsed.Streamer(R__b);
227  fValidity.Streamer(R__b);
228  R__b.CheckByteCount(R__s, R__c, HMdcCalParRaw::IsA());
229  }
230  else if(R__v==2)
231  {
232  HParSet::Streamer(R__b);
233  R__b >> array;
234  R__b.CheckByteCount(R__s, R__c, HMdcCalParRaw::IsA());
235  }
236  else{Error("HMdcCalParRaw:Streamer()","Read version not known!");}
237  }
238  else
239  {
240  HMdcCalParRaw::Class()->WriteBuffer(R__b,this);
241  }
242 }
243 
HMdcCalParRawMod(Int_t mbo=16)
Float_t getOffsetErr()
Definition: hmdccalparraw.h:24
Text_t detName[20]
Definition: hparset.h:11
Int_t getSize()
Definition: hmdccalparraw.h:64
Float_t getOffset()
Definition: hmdccalparraw.h:22
void fill(Float_t s, Float_t o, Float_t sE, Float_t oE, Int_t sM, Int_t oM)
Definition: hmdccalparraw.h:27
HRuntimeDb * getRuntimeDb(void)
Definition: hades.h:111
virtual Bool_t init(HParSet *, Int_t *)
Definition: hdetpario.h:27
Int_t n
Bool_t writeline(Char_t *, Int_t, Int_t, Int_t, Int_t)
Float_t getSlopeErr()
Definition: hmdccalparraw.h:23
virtual HDetParIo * getDetParIo(const Text_t *)
Definition: hpario.cc:50
void info(Char_t level, Int_t det, const Char_t *className, const Char_t *text)
Definition: hmessagemgr.cc:473
Definition: hpario.h:11
Int_t getSlopeMethod()
Definition: hmdccalparraw.h:25
void resetInputVersions()
Definition: hparset.cc:144
virtual Int_t write()
Definition: hparset.cc:119
void createMbo(Int_t, Int_t, const Char_t *)
TString input
Definition: GarReader.C:5
HMdcCalParMbo(Int_t tdc=96, const Text_t *name="")
void readline(const Char_t *, Int_t *)
Definition: hparset.h:9
HMdcCalParRawSec(Int_t mod=4)
Hades * gHades
Definition: hades.cc:1213
#define INFO_msg(level, det, text)
Definition: hmessagemgr.h:54
HParSet * findContainer(const Char_t *)
Definition: hruntimedb.cc:143
return output
HParSet * getContainer(const Text_t *)
Definition: hruntimedb.cc:124
TObjArray * array
Bool_t status
versions of container in the 2 possible inputs
Definition: hparset.h:13
Float_t getSlope()
Definition: hmdccalparraw.h:21
Int_t getOffsetMethod()
Definition: hmdccalparraw.h:26
ClassImp(HMdcCalParTdc) ClassImp(HMdcCalParMbo) ClassImp(HMdcCalParRawMod) ClassImp(HMdcCalParRawSec) ClassImp(HMdcCalParRaw) void HMdcCalParTdc
#define SEPERATOR_msg(sep, num)
Definition: hmessagemgr.h:63
virtual Int_t write(HParSet *)
Definition: hdetpario.h:30
void putAsciiHeader(TString &)
HMdcCalParRaw(const Char_t *name="MdcCalParRaw", const Char_t *title="raw calibration parameters for Mdc", const Char_t *context="MdcCalParRawProduction", Int_t n=6)
HMessageMgr * getMsg(void)
Definition: hades.h:113
virtual Bool_t init(void)
Definition: hparset.h:21