HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hmdcoepaddrcorrpar.cc
Go to the documentation of this file.
1 //*****************************************************************************
2 // File: $RCSfile: $
3 //
4 // Author: Joern Wuestenfeld
5 //
6 // Version: $Revision $
7 // Modified by $Author $
8 //
9 //
10 //*****************************************************************************
11 //_HADES_CLASS_DESCRIPTION
12 ///////////////////////////////////////////////////////////////////////////////
13 // HMdcOepAddrCorrPar
14 //
15 // Parameter container for the MDC unapcker.
16 // This container keeps all parameters that are needed for the unpacker of
17 // the MDC data to correct wrong OEP addresses.
18 //
19 //*****************************************************************************
20 
21 #include "hmdcoepaddrcorrpar.h"
22 #include "hpario.h"
23 #include "hdetpario.h"
24 #include "hparamlist.h"
25 
26 #include <stdlib.h>
27 #include <iostream>
28 #include <iomanip>
29 
30 HMdcOepAddrCorrPar::HMdcOepAddrCorrPar(const char* name, const char* title, const char* context)
31  : HParCond(name,title,context)
32 {
33  // default constructor
34 }
35 /*
36 HMdcOepAddrCorrPar::HMdcOepAddrCorrPar(HMdcOepAddrCorrPar &par)
37 {
38  // copy constructor
39 }
40 */
42 {
43  //destructor
44  address.clear();
45 }
46 
48 {
49  // check if the passeda ddress is in the map, and return the corrected address then.
50  // If address has been mapped, return true, else false.
51  map<Int_t,Int_t>::iterator it = address.find(*addr);
52  if (it != address.end())
53  {
54  *addr = (*it).second;
55  return kTRUE;
56  }
57  else
58  return kFALSE;
59 }
60 
61 Bool_t HMdcOepAddrCorrPar::init(HParIo* inp,Int_t* set)
62 {
63  // intitializes the container from an input
64  HDetParIo* input=inp->getDetParIo("HCondParIo");
65  if (input) {
66  Bool_t rc = input->init(this,set);
67  if (rc){
68  if(changed){
69  address.clear();
70  for(Int_t i = 0; i < AddressLookupMap.GetSize()/2; i++)
71  {
72  address[AddressLookupMap[i*2+0]] = AddressLookupMap[i*2+1]; // set addFrom,addTo
73  }
74  }
75  return rc;
76  }
77  }
78  return kFALSE;
79 }
80 
81 
83 {
84  // put parameters to param list
85  putToArray();
86  l->add("AddressLookupMap",AddressLookupMap);
87 
88 }
89 
91 {
92  // Retrieve parameters from HParamList,
93  if (!l) return kFALSE;
94 
95  if(! (l->fill("AddressLookupMap", &AddressLookupMap) ))
96  {
97  return kFALSE;
98  }
99  address.clear();
100  for(Int_t i = 0; i<AddressLookupMap.GetSize()/2; i++)
101  {
102  address.insert(make_pair(AddressLookupMap[i*2+0],AddressLookupMap[i*2+1])); // set addFrom,addTo
103  }
104  return kTRUE;
105 }
106 
107 void HMdcOepAddrCorrPar::setMapping(Int_t mapFrom, Int_t mapTo)
108 {
109  // add a pair of addresses, that should be mapped.
110  map<Int_t,Int_t>::iterator it;
111 
112  it = address.find(mapFrom);
113  if(it == address.end())
114  {
115  // new address
116  address.insert(make_pair(mapFrom,mapTo));
117  }
118  else
119  {
120  // already existing address modified
121  (*it).second = mapTo;
122  }
123 }
125 { // put all mapping pairs from map address
126  // and put them into the TArrayI. This methode
127  // should be used only if values should
128  // be set from macro to create the container
129  // content after the values have been added
130  // to the map using setMapping()
131 
132  map<Int_t,Int_t>::iterator it;
133  Int_t s,i = 0;
134  s = address.size();
135 
136  AddressLookupMap.Reset();
137  AddressLookupMap.Set(s*2);
138  for(it= address.begin(); it!= address.end(); it++)
139  {
140  AddressLookupMap[i*2+0] = (*it).first;
141  AddressLookupMap[i*2+1] = (*it).second;
142  i++;
143  }
144 }
146 {
147  print();
148  cout<<"size="<<AddressLookupMap.GetSize()<<endl;
149 
150  for(Int_t i = 0; i < AddressLookupMap.GetSize()/2; i++)
151  {
152  cout<<setw(4)<<i<<" correction pair: 0x"<<hex<<AddressLookupMap[i*2+0]<<" ==> 0x"<<hex<<AddressLookupMap[i*2+1]<<dec<<endl;
153  }
154 }
155 
156 void HMdcOepAddrCorrPar::Streamer(TBuffer &R__b)
157 {
158  // Stream an object of class HMdcOepAddrCorrPar.
159 
160  UInt_t R__s, R__c;
161  if (R__b.IsReading()) {
162  Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
163  HParCond::Streamer(R__b);
164  AddressLookupMap.Streamer(R__b);
165 
166  address.clear();
167  for(Int_t i = 0; i<AddressLookupMap.GetSize()/2; i++)
168  {
169  address.insert(make_pair(AddressLookupMap[i*2+0],AddressLookupMap[i*2+1])); // set addFrom,addTo
170  }
171 
172  R__b.CheckByteCount(R__s, R__c, HMdcOepAddrCorrPar::IsA());
173  } else {
174  R__c = R__b.WriteVersion(HMdcOepAddrCorrPar::IsA(), kTRUE);
175  HParCond::Streamer(R__b);
176  AddressLookupMap.Streamer(R__b);
177  R__b.SetByteCount(R__c, kTRUE);
178  }
179 }
180 
181 
182 
HMdcOepAddrCorrPar(const char *name="MdcOepAddrCorrPar", const char *title="Mdc unpacker lookuptable for data recovery", const char *context="MdcOepAddrCorrParProduction")
void setMapping(Int_t adress, Int_t mapTo)
virtual Bool_t init(HParSet *, Int_t *)
Definition: hdetpario.h:27
virtual HDetParIo * getDetParIo(const Text_t *)
Definition: hpario.cc:50
Definition: hpario.h:11
void add(HParamObj &)
Definition: hparamlist.cc:415
TString input
Definition: GarReader.C:5
Bool_t changed
static flag
Definition: hparset.h:14
virtual void print()
Definition: hparset.cc:130
map< Int_t, Int_t > address
Bool_t rc
Bool_t checkAddress(Int_t *addr)
Bool_t fill(const Text_t *, Text_t *, const Int_t)
Definition: hparamlist.cc:561
TArrayI AddressLookupMap
Map wrong addresses of OEP's to correct ones e.g. 2001 -> 2003.
Bool_t getParams(HParamList *l)
void putParams(HParamList *l)
virtual Bool_t init(void)
Definition: hparset.h:21