ATLAS Offline Software
RoiSerialise.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 //
5 // @file RoiSerialise.cxx
6 //
7 // utilities to serialise and deserialise to and from
8 // std::vector<IRoiDescriptor*>, TrigRoiDescriptorCollection etc
9 //
10 // @author M.Sutton
11 //
12 //
13 // $Id: serialise.cxx, v0.0 Sat 31 Oct 2015 08:20:38 CET sutt $
14 
15 
16 #include <iostream>
17 
19 
20 
21 
22 inline const uint32_t& uconv( const float& x) { return reinterpret_cast<const uint32_t&>(x); }
23 inline const float& fconv( const uint32_t& x) { return reinterpret_cast<const float&>(x); }
24 
25 
26 namespace RoiUtil {
27 
28  enum ROIENUM {
33  };
34 
35  enum MASK {
36  FULLSCAN = 0x1,
37  COMPOSITE = 0x2,
38  ROITYPE = 0x4
39  };
40 
41 }
42 
43 
45 void RoiUtil::serialise( const std::vector<const IRoiDescriptor*>& rois, RoiUtil::roiserial_type& s ) {
46  s.clear();
47  s.resize(rois.size());
48  for ( size_t i=0 ; i<rois.size() ; i++ ) RoiUtil::serialise( rois[i], s[i] );
49 }
50 
51 
54  s.clear();
55  s.resize(rois.size());
56  for ( size_t i=0 ; i<rois.size() ; i++ ) RoiUtil::serialise( rois[i], s[i] );
57 }
58 
59 
60 
62 void RoiUtil::deserialise( const RoiUtil::roiserial_type& s, std::vector<const IRoiDescriptor*>& rois ) {
63  if ( s.empty() ) return;
64  rois.resize(s.size());
65  for ( size_t i=0 ; i<s.size() ; i++ ) {
66  if ( s[i].empty() ) continue;
67  const roitype_t* s_end = &s[i][0];
68  const roitype_t* s_last = &s[i].back();
69  rois[i] = RoiUtil::deserialise( s_end, s_last );
70  }
71  // const roitype_t* s_end = &s[0];
72  // const roitype_t* s_last = &s.back();
73  // while ( s_end<s_last ) rois.push_back( RoiUtil::deserialise( s_end, s_last ) );
74 }
75 
76 
79  if ( s.empty() ) return;
80  for ( size_t i=0 ; i<s.size() ; i++ ) {
81  if ( s[i].empty() ) continue;
82  const roitype_t* s_end = &s[i][0];
83  const roitype_t* s_last = &s[i].back();
86  rois.push_back( dynamic_cast<TrigRoiDescriptor*>(RoiUtil::deserialise( s_end, s_last )) );
87 
88  }
90  // const roitype_t* s_end = &s[0];
91  // const roitype_t* s_last = &s.back();
92  // while ( s_end<s_last ) rois.push_back( dynamic_cast<TrigRoiDescriptor*>(RoiUtil::deserialise( s_end, s_last )) );
93 }
94 
95 
97 void RoiUtil::serialise( const IRoiDescriptor* roi, std::vector<RoiUtil::roitype_t>& s ) {
98 
100  uint32_t param = ( (roi->version()&0xff) << 8);
101 
103  // if ( roi->isFullscan() ) param |= 1;
104  if ( roi->isFullscan() ) param |= RoiUtil::FULLSCAN;
105 
107  // if ( roi->composite() ) param |= 0x2;
108  if ( roi->composite() ) param |= RoiUtil::COMPOSITE;
109 
111  uint32_t extra[3] = { roi->roiWord(), roi->l1Id(), roi->roiId() };
112 
113  // bool plusextra = false;
114  // for ( int i=0 ; i<3 ; i++ ) plusextra |= ( extra[i]!=0 );
115  bool plusextra = ( extra[0]!=0 ) || ( extra[1]!=0 ) || ( extra[2]!=0 );
116 
117  // if ( plusextra ) param |= 0x4;
118  if ( plusextra ) param |= RoiUtil::ROITYPE;
119 
120  // s.push_back( roi->isFullscan() ? 1 : 0 );
121  s.push_back( *((roitype_t*)&param) );
122 
123  int Nextra = 0;
124  if ( plusextra ) Nextra = 3;
125 
126  if ( !roi->isFullscan() ) {
128  s.push_back( uconv(roi->eta()) );
129  s.push_back( uconv(roi->etaMinus()) );
130  s.push_back( uconv(roi->etaPlus()) );
131 
132  s.push_back( uconv(roi->phi()) );
133  s.push_back( uconv(roi->phiMinus()) );
134  s.push_back( uconv(roi->phiPlus()) );
135 
136  s.push_back( uconv(roi->zed()) );
137  s.push_back( uconv(roi->zedMinus()) );
138  s.push_back( uconv(roi->zedPlus()) );
139  }
140 
141  for ( int i=0 ; i<Nextra ; i++ ) s.push_back( extra[i] ); // push back the size of extra information if required
142 
144  if ( roi->composite() ) {
145  s.push_back( roi->size() );
146 
148  // if ( roi->composite() && roi->size()>0 ) {
149  if ( roi->size()>0 ) {
150  IRoiDescriptor::roi_iterator itr = roi->begin();
151  IRoiDescriptor::roi_iterator iend = roi->end();
152  while ( itr!=iend ) RoiUtil::serialise( *itr++, s );
153  }
154  }
155 
156 }
157 
158 
159 
160 
163 
164  TrigRoiDescriptor* roi = 0;
165 
166  const roitype_t* s = s_end;
167 
169  uint32_t param = *((uint32_t*)(&s[RoiUtil::PARAM]));
170 
172  int version = (param>>8);
173 
176 
178  bool fullscan = false;
179  if (param&1) fullscan = true;
180 
182  bool composite = false;
183  if (param&2) composite = true;
184 
185  bool roiwords = false;
186  if (param&4) roiwords = true;
187 
189  if ( fullscan ) s_end += RoiUtil::PARAM;
190  else s_end += RoiUtil::ZEDPLUS;
191 
193  unsigned Nextra = ( roiwords ? 3 : 0 );
194  s_end += Nextra;
195 
199  if ( s_end>s_last ) return 0;
200 
202  s_end++;
203 
205  unsigned extra[3] = { 0, 0, 0 };
206  unsigned extra_start = ( fullscan ? RoiUtil::PARAM+1 : RoiUtil::ZEDPLUS+1 );
207 
208  for ( unsigned i=0 ; i<Nextra ; i++ ) extra[i] = unsigned( s[extra_start+i] );
209 
210  unsigned roiWord = extra[0];
211  unsigned l1Id = extra[1];
212  unsigned roiId = extra[2];
213 
215  if ( fullscan ) roi = new TrigRoiDescriptor( true );
216  else {
218 
221  roi = new TrigRoiDescriptor( roiWord, l1Id, roiId,
225 
226  }
227 
228  if ( roi && version>roi->version() ) roi->version( version );
229 
230 
234  if ( roi && composite ) {
235 
236  roi->setComposite(true);
237 
239 
240  unsigned size = *s_end;
241 
242  s_end++;
243 
244  std::cout << "size " << size << std::endl;
245 
246  if ( size>0 ) {
247  for ( unsigned i=0 ; i<size ; i++ ) {
248  roi->push_back( RoiUtil::deserialise( s_end, s_last ) );
249  }
250  }
251  }
252 
253  return roi;
254 
255 }
256 
257 
IRoiDescriptor::phi
virtual double phi() const =0
Methods to retrieve data members.
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
IRoiDescriptor::begin
virtual roi_iterator begin() const =0
const limit iterators
RoiUtil::serialise
void serialise(const std::vector< const IRoiDescriptor * > &rois, roiserial_type &s)
serialise an entire vector of IRoiDescriptors
Definition: RoiSerialise.cxx:45
RoiUtil::ROIENUM
ROIENUM
Definition: RoiSerialise.cxx:28
IRoiDescriptor::roi_iterator
std::vector< const IRoiDescriptor * >::const_iterator roi_iterator
Definition: IRoiDescriptor.h:28
RoiUtil::FULLSCAN
@ FULLSCAN
Definition: RoiSerialise.cxx:36
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
IRoiDescriptor::etaMinus
virtual double etaMinus() const =0
IRoiDescriptor::size
virtual unsigned size() const =0
number of constituents
RoiUtil::ROITYPE
@ ROITYPE
Definition: RoiSerialise.cxx:38
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
IRoiDescriptor::end
virtual roi_iterator end() const =0
IRoiDescriptor::etaPlus
virtual double etaPlus() const =0
RoiUtil::PHI
@ PHI
Definition: RoiSerialise.cxx:31
x
#define x
uconv
const uint32_t & uconv(const float &x)
Definition: RoiSerialise.cxx:22
RoiUtil::PHIPLUS
@ PHIPLUS
Definition: RoiSerialise.cxx:31
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
RoiUtil::PARAM
@ PARAM
Definition: RoiSerialise.cxx:29
xAOD::roiWord
roiWord
Definition: TrigMissingET_v1.cxx:36
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
IRoiDescriptor::eta
virtual double eta() const =0
RoiDescriptor::push_back
void push_back(const IRoiDescriptor *roi)
add a RoiDescriptor
Definition: RoiDescriptor.h:157
lumiFormat.i
int i
Definition: lumiFormat.py:85
IRoiDescriptor
Describes the API of the Region of Ineterest geometry.
Definition: IRoiDescriptor.h:23
xAOD::roiId
setTeId setLumiBlock roiId
Definition: L2StandAloneMuon_v1.cxx:331
fconv
const float & fconv(const uint32_t &x)
Definition: RoiSerialise.cxx:23
RoiUtil::roiserial_type
std::vector< std::vector< roitype_t > > roiserial_type
Definition: RoiSerialise.h:22
RoiUtil::deserialise
void deserialise(const roiserial_type &s, std::vector< const IRoiDescriptor * > &rois)
deserialise uint32_t vector into a full vector of IRoiDescriptors
Definition: RoiSerialise.cxx:62
IRoiDescriptor::phiMinus
virtual double phiMinus() const =0
IRoiDescriptor::roiId
virtual unsigned int roiId() const =0
identifiers
RoiUtil::roitype_t
uint32_t roitype_t
Definition: RoiSerialise.h:21
RoiUtil::ETAPLUS
@ ETAPLUS
Definition: RoiSerialise.cxx:30
RoiUtil::COMPOSITE
@ COMPOSITE
Definition: RoiSerialise.cxx:37
RoiUtil::ETAMINUS
@ ETAMINUS
Definition: RoiSerialise.cxx:30
IRoiDescriptor::phiPlus
virtual double phiPlus() const =0
extreme phi values
python.handimod.extra
int extra
Definition: handimod.py:522
RoiUtil::ZEDMINUS
@ ZEDMINUS
Definition: RoiSerialise.cxx:32
RoiUtil
Definition: RoiUtil.h:20
IRoiDescriptor::l1Id
virtual unsigned int l1Id() const =0
RoiUtil::ETA
@ ETA
Definition: RoiSerialise.cxx:30
get_generator_info.version
version
Definition: get_generator_info.py:33
IRoiDescriptor::zedPlus
virtual double zedPlus() const =0
the zed and eta values at the most forward and most rear ends of the RoI
TrigRoiDescriptorCollection
Definition: TrigRoiDescriptorCollection.h:21
RoiUtil::ZEDPLUS
@ ZEDPLUS
Definition: RoiSerialise.cxx:32
TriggerTest.rois
rois
Definition: TriggerTest.py:23
IRoiDescriptor::isFullscan
virtual bool isFullscan() const =0
is this a full detector RoI?
RoiSerialise.h
IRoiDescriptor::zed
virtual double zed() const =0
IRoiDescriptor::zedMinus
virtual double zedMinus() const =0
RoiDescriptor::setComposite
void setComposite(bool b=true)
Definition: RoiDescriptor.h:138
RoiUtil::ZED
@ ZED
Definition: RoiSerialise.cxx:32
TrigRoiDescriptor
Athena::TPCnvVers::Current TrigRoiDescriptor
Definition: TrigSteeringEventTPCnv.cxx:68
RoiDescriptor::version
virtual int version() const override final
versioning
Definition: RoiDescriptor.h:123
RoiUtil::PHIMINUS
@ PHIMINUS
Definition: RoiSerialise.cxx:31
RoiUtil::MASK
MASK
Definition: RoiSerialise.cxx:35
IRoiDescriptor::version
virtual int version() const =0
which roi version?
IRoiDescriptor::roiWord
virtual unsigned int roiWord() const =0
IRoiDescriptor::composite
virtual bool composite() const =0
Super RoI access methods.