ATLAS Offline Software
LArBadChanBlobUtils.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 namespace LArBadChanBlobUtils {
6 
7  /// Creates a BLOB of the right size and copies the content of the
8  /// vector of pair<HWIdentifier, LArBadChannel> into the blob.
9  /// creating inside the blob the vector of pair<HWIdentifier32, LArBadChannel>
10  /// Returns a pointer to the new blob, which has to be managed
11  /// (and eventually released) by the caller
12  template <class T>
13  void fillBlob( const std::vector< std::pair<HWIdentifier,T> >& vec, coral::Blob& blob)
14  {
15  typedef typename T::BitWord BitWord;
16  typedef std::pair<HWIdentifier,T> Entry;
17 
18  std::size_t nbytes = vec.size() * ( sizeof( Channel) + sizeof( BitWord));
19  blob.resize(nbytes);
20  void* adr = blob.startingAddress();
21  for (const Entry& ent : vec) {
22  Channel* ch = static_cast<Channel*>( adr);
23  *ch = ent.first.get_identifier32().get_compact(); // assign channel, here is the conversion to 32bit
24  BitWord* st = static_cast<BitWord*>(ch+1); // st points just after channel
25  *st = ent.second.packedData(); // assign status
26  adr = static_cast<void*>(st+1);
27  }
28  }
29 
30  template <class T>
31  std::vector<std::pair<HWIdentifier,T> > decodeBlob( const coral::Blob* blobp,
32  std::size_t chanSize,
33  std::size_t stateSize,
34  int endian,
35  int version,
36  MsgStream& log)
37  {
38  typedef std::pair<HWIdentifier,T> Entry;
39  typedef typename T::BitWord BitWord;
40 
41  std::vector<Entry> result;
42  std::size_t step = sizeof( Channel) + sizeof( BitWord);
43  if (!checkBlob( blobp, chanSize, stateSize, endian, version, step, sizeof(BitWord), log)) {
44  return result;
45  }
46 
47  std::size_t vecSize = blobp->size() / step;
48  result.reserve( vecSize);
49  const void* adr = blobp->startingAddress();
50  for (std::size_t i=0; i< vecSize; i++) {
51  const Channel* ch = static_cast<const Channel*>( adr);
52  const BitWord* st = static_cast<const BitWord*>(ch+1);
53  adr = static_cast<const void*>(st+1);
54  result.push_back( Entry( HWIdentifier(Identifier32(*ch)), T(*st)));
55  }
56 
57  return result;
58  }
59 
60 }