1818#include " TFile.h"
1919
2020#include " TPCCalibration/CMVContainer.h"
21- #include " DataFormatsTPC/CMV.h"
2221
2322namespace o2 ::tpc
2423{
2524
26- void CMVContainer ::reserve (uint32_t expectedTFs , uint32_t expectedCRUs )
25+ void CMVPerInterval ::reserve (uint32_t nTFs , uint32_t nCRUs )
2726{
28- const std::size_t n = static_cast <std::size_t >(expectedTFs) * expectedCRUs * o2::tpc::cmv::NTimeBinsPerTF;
29- cmvValues.reserve (n);
30- cru.reserve (n);
31- timebin.reserve (n);
32- tf.reserve (n);
33- }
34-
35- void CMVContainer::addEntry (float cmvVal, uint32_t cruID, uint32_t tb, uint32_t tfCounter)
36- {
37- cmvValues.push_back (cmvVal);
38- cru.push_back (cruID);
39- timebin.push_back (tb);
40- tf.push_back (tfCounter);
41- }
42-
43- void CMVContainer::addPacket (const float * packet, uint32_t cruID, uint32_t tbOffset, uint32_t tfCounter)
44- {
45- for (uint32_t tb = 0 ; tb < o2::tpc::cmv::NTimeBinsPerPacket; ++tb) {
46- addEntry (packet[tb], cruID, tbOffset + tb, tfCounter);
27+ mCMVPerTF .resize (nTFs);
28+ for (auto & tfData : mCMVPerTF ) {
29+ tfData.mDataPerTF .resize (nCRUs);
4730 }
4831}
4932
50- std::size_t CMVContainer::size () const { return cmvValues.size (); }
51-
52- bool CMVContainer::empty () const { return cmvValues.empty (); }
53-
54- void CMVContainer::clear ()
33+ void CMVPerInterval::clear ()
5534{
56- cmvValues.clear ();
57- cru.clear ();
58- timebin.clear ();
59- tf.clear ();
60- nTFs = 0 ;
61- nCRUs = 0 ;
35+ mCMVPerTF .clear ();
6236 firstTF = 0 ;
37+ lastTF = 0 ;
6338}
6439
65- std::string CMVContainer ::summary () const
40+ std::string CMVPerInterval ::summary () const
6641{
67- return fmt::format (" CMVContainer: {} entries, {} TFs, {} CRUs, firstTF={}" ,
68- size (), nTFs, nCRUs, firstTF);
42+ const std::size_t nCRUs = empty () ? 0 : mCMVPerTF .front ().mDataPerTF .size ();
43+ return fmt::format (" CMVPerInterval: {} TFs, {} CRU slots, firstTF={}, lastTF={}" ,
44+ size (), nCRUs, firstTF, lastTF);
6945}
7046
71- std::unique_ptr<TTree> CMVContainer ::toTTree () const
47+ std::unique_ptr<TTree> CMVPerInterval ::toTTree () const
7248{
73- const std::size_t n = size ();
74- if (n == 0 ) {
75- throw std::runtime_error (" CMVContainer::toTTree() called on empty container" );
49+ if (empty ()) {
50+ throw std::runtime_error (" CMVPerInterval::toTTree() called on empty container" );
7651 }
7752
7853 auto tree = std::make_unique<TTree>(" ccdb_object" , " ccdb_object" );
7954 tree->SetAutoSave (0 );
8055 tree->SetDirectory (nullptr );
8156
82- // Point branches directly at the vector data
83- float * pCmv = const_cast <float *>(cmvValues.data ());
84- uint32_t * pCru = const_cast <uint32_t *>(cru.data ());
85- uint32_t * pTimebin = const_cast <uint32_t *>(timebin.data ());
86- uint32_t * pTf = const_cast <uint32_t *>(tf.data ());
57+ const CMVPerInterval* ptr = this ;
58+ tree->Branch (" CMVPerInterval" , &ptr);
59+ tree->Fill ();
8760
88- tree->Branch (" cmv" , pCmv, fmt::format (" cmv[{}]/F" , n).c_str ());
89- tree->Branch (" cru" , pCru, fmt::format (" cru[{}]/i" , n).c_str ());
90- tree->Branch (" timebin" , pTimebin, fmt::format (" timebin[{}]/i" , n).c_str ());
91- tree->Branch (" tf" , pTf, fmt::format (" tf[{}]/i" , n).c_str ());
61+ tree->ResetBranchAddresses ();
9262
93- tree->Fill ();
9463 return tree;
9564}
9665
97- void CMVContainer ::writeToFile (const std::string& filename, const std::unique_ptr<TTree>& tree) const
66+ void CMVPerInterval ::writeToFile (const std::string& filename, const std::unique_ptr<TTree>& tree) const
9867{
9968 TFile f (filename.c_str (), " RECREATE" );
10069 if (f.IsZombie ()) {
101- throw std::runtime_error (fmt::format (" CMVContainer ::writeToFile: cannot open '{}'" , filename));
70+ throw std::runtime_error (fmt::format (" CMVPerInterval ::writeToFile: cannot open '{}'" , filename));
10271 }
10372 tree->Write ();
10473 f.Close ();
10574}
10675
107- CMVContainer CMVContainer ::fromTTree (TTree* tree, int entry)
76+ CMVPerInterval CMVPerInterval ::fromTTree (TTree* tree, int entry)
10877{
10978 if (!tree) {
110- throw std::runtime_error (" CMVContainer::fromTTree: null TTree pointer" );
111- }
112-
113- CMVContainer c;
114- const Long64_t nEntries = tree->GetEntries ();
115- if (nEntries <= 0 ) {
116- return c;
79+ throw std::runtime_error (" CMVPerInterval::fromTTree: null TTree pointer" );
11780 }
11881
119- // Read the array branches back into vectors in one GetEntry() call
120- std::vector<float > bCmv (nEntries);
121- std::vector<uint32_t > bCru (nEntries), bTimebin (nEntries), bTf (nEntries);
122-
123- tree->SetBranchAddress (" cmv" , bCmv.data ());
124- tree->SetBranchAddress (" cru" , bCru.data ());
125- tree->SetBranchAddress (" timebin" , bTimebin.data ());
126- tree->SetBranchAddress (" tf" , bTf.data ());
127-
82+ CMVPerInterval* ptr = nullptr ;
83+ tree->SetBranchAddress (" CMVPerInterval" , &ptr);
12884 tree->GetEntry (entry);
12985
130- c.cmvValues = std::move (bCmv);
131- c.cru = std::move (bCru);
132- c.timebin = std::move (bTimebin);
133- c.tf = std::move (bTf);
86+ if (!ptr) {
87+ throw std::runtime_error (" CMVPerInterval::fromTTree: failed to read object from TTree" );
88+ }
13489
135- return c;
90+ CMVPerInterval result = std::move (*ptr);
91+ delete ptr;
92+ return result;
13693}
13794
138- } // namespace o2::tpc
95+ } // namespace o2::tpc
0 commit comments