2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 namespace LArBadChanBlobUtils {
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
13 void fillBlob( const std::vector< std::pair<HWIdentifier,T> >& vec, coral::Blob& blob)
15 typedef typename T::BitWord BitWord;
16 typedef std::pair<HWIdentifier,T> Entry;
18 std::size_t nbytes = vec.size() * ( sizeof( Channel) + sizeof( BitWord));
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);
31 std::vector<std::pair<HWIdentifier,T> > decodeBlob( const coral::Blob* blobp,
33 std::size_t stateSize,
38 typedef std::pair<HWIdentifier,T> Entry;
39 typedef typename T::BitWord BitWord;
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)) {
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)));