EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmDigiManager.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmDigiManager.cxx
1 
2 // -------------------------------------------------------------------------
3 // ----- CbmDigiManager source file -----
4 // ----- Created 08/05/07 by V. Friese -----
5 // -------------------------------------------------------------------------
6 // Includes from cbmroot
7 #include "CbmDigiManager.h"
8 
9 #include "CbmDigi.h"
10 
11 #include "FairRootManager.h"
12 
13 // Includes from ROOT
14 #include "TClonesArray.h"
15 
16 // Includes from c++
17 #include <iostream>
18 #include <iomanip>
19 
21 using std::cout;
22 using std::endl;
23 using std::left;
24 using std::right;
25 using std::setw;
26 using std::fixed;
27 using std::setprecision;
28 using std::pair;
29 
30 // ----- Default constructor -------------------------------------------
32  : FairTask("DigiManager"),
33  fDigiMap(),
34  fTimer()
35 {
36  for (Int_t iSys=0; iSys<16; iSys++) fDigis[iSys] = NULL;
37  fSystem[0] = "";
38  fSystem[1] = "MVD";
39  fSystem[2] = "STS";
40  fSystem[3] = "RICH";
41  fSystem[4] = "MUCH";
42  fSystem[5] = "TRD";
43  fSystem[6] = "TOF";
44  fSystem[7] = "ECAL";
45  fSystem[8] = "PSD";
46  for (Int_t iSys=9; iSys<16; iSys++) fSystem[iSys] = "";
47 }
48 // -------------------------------------------------------------------------
49 
50 
51 
52 // ----- Destructor ----------------------------------------------------
54 // -------------------------------------------------------------------------
55 
56 
57 
58 // ----- Virtual public method Exec ------------------------------------
59 void CbmDigiManager::Exec(Option_t* opt) {
60 
61  // Clear map and timer
62  fTimer.Start();
63  fDigiMap.clear();
64 
65  // Loop over all digi collections
66  Int_t nDigis[16];
67  for (Int_t iSys=0; iSys<16; iSys++) {
68  nDigis[iSys] = 0;
69  if ( ! fDigis[iSys] ) continue;
70 
71  // Loop over digis in this collection
72  nDigis[iSys] = fDigis[iSys]->GetEntriesFast();
73  for (Int_t iDigi=0; iDigi<nDigis[iSys]; iDigi++) {
74  CbmDigi* digi = (CbmDigi*) fDigis[iSys]->At(iDigi);
75  if ( digi->GetSystemId() != iSys ) {
76  cout << "-E- " << GetName() << "::Exec: digi with system ID "
77  << digi->GetSystemId() << " in digi collection " << iSys
78  << "(" << fSystem[iSys] << ")" << endl;
79  Fatal("Exec", "Wrong system ID for digi");
80  }
81  Int_t iDet = digi->GetDetectorId();
82  Int_t iChan = digi->GetChannelNr();
83  pair<Int_t, Int_t> a(iDet, iChan);
84 
85  // Check for existing entries in the map (should not happen)
86  if (fDigiMap.find(a) != fDigiMap.end() ) {
87  cout << "-W- " << GetName() << "::Exec: Multiple entry in "
88  << fSystem[iSys] << " digi collection; detector " << iDet
89  << ", channel " << iChan << endl;
90  continue;
91  }
92 
93  // Enter digi into the map
94  fDigiMap[a] = digi;
95 
96  } // Loop over digis in the collection
97  } // Loop over collections
98 
99 
100 
101  // Control output
102  fTimer.Stop();
103  cout << "+ ";
104  cout << setw(15) << left << fName << ": " << setprecision(4) << setw(8)
105  << fixed << right << fTimer.RealTime()
106  << " s";
107  for (Int_t iSys=0; iSys<15; iSys++)
108  if ( fDigis[iSys] ) cout << ", " << fSystem[iSys]
109  << " " << nDigis[iSys];
110  cout << endl;
111 
112 }
113 // -------------------------------------------------------------------------
114 
115 
116 
117 
118 // ----- Public method GetDigi -----------------------------------------
119 CbmDigi* CbmDigiManager::GetDigi(Int_t iDetector, Int_t iChannel) {
120 
121  pair<Int_t, Int_t> a(iDetector, iChannel);
122 
123  if ( fDigiMap.find(a) == fDigiMap.end() ) return NULL;
124  else return fDigiMap[a];
125 
126 }
127 // -------------------------------------------------------------------------
128 
129 
130 
131 
132 // ----- Virtual private method Init -----------------------------------
134 
136  if ( ! ioman ) Fatal("Init", "No FairRootManager");
137 
138  Int_t nColl = 0;
139  for (Int_t iSys=0; iSys<16; iSys++) {
140 
141  TString digiName = fSystem[iSys];
142  digiName += "Digi";
143  fDigis[iSys] = (TClonesArray*) ioman->GetObject(digiName.Data());
144  if ( fDigis[iSys] ) nColl++;
145  }
146 
147  cout << "-I- " << GetName() << "::Init: " << nColl
148  << " digi collection";
149  if ( nColl != 1 ) cout << "s";
150  cout << " found." << endl;
151 
152  return kSUCCESS;
153 
154 }
155 // -------------------------------------------------------------------------
156 
157 
158