1 | /** |
---|
2 | * John Idarraga <idarraga@cern.ch> |
---|
3 | */ |
---|
4 | |
---|
5 | |
---|
6 | #include "eudaq/write_mdm.h" |
---|
7 | |
---|
8 | #include "TString.h" |
---|
9 | |
---|
10 | #include <vector> |
---|
11 | #include <map> |
---|
12 | |
---|
13 | using namespace std; |
---|
14 | |
---|
15 | namespace eudaq { |
---|
16 | |
---|
17 | /* in any code this would be the part called once per frame to do the filling*/ |
---|
18 | void mdm::dofill(int detId, int col, int row, int cnt, int lvl1){ |
---|
19 | |
---|
20 | m_frames[m_detIdToIndex[detId]]->LoadFramePixel( |
---|
21 | col, |
---|
22 | row, |
---|
23 | cnt, |
---|
24 | lvl1 |
---|
25 | ); |
---|
26 | //std::cout << lvl1 << std::endl; |
---|
27 | } |
---|
28 | |
---|
29 | void mdm::writetontuple(int detId, int frameId){ |
---|
30 | |
---|
31 | std::cout << " AllPixRun::FillFramesNtuple --> detId = " << detId << " insideId = " << m_frames[m_detIdToIndex[detId]]->GetDetectorId() << std::endl; |
---|
32 | |
---|
33 | // fill one frame, set ID first |
---|
34 | m_frames[m_detIdToIndex[detId]]->SetCurrentFrameId(frameId); |
---|
35 | |
---|
36 | WriteToNtuple::GetInstance(m_dataset, |
---|
37 | m_tempdir, |
---|
38 | m_nOfDetectors, |
---|
39 | m_frames[m_detIdToIndex[detId]]->GetDetectorId(), m_detIdToIndexArray)->fillVars(m_frames[m_detIdToIndex[detId]]); |
---|
40 | |
---|
41 | } |
---|
42 | |
---|
43 | mdm::mdm() { |
---|
44 | |
---|
45 | m_nOfDetectors = -1; |
---|
46 | m_initialized = false; |
---|
47 | |
---|
48 | } |
---|
49 | void mdm::init(vector<int> detIDs, TString dataset, int width, int height){ |
---|
50 | |
---|
51 | std::cout << "Initializing mdm data model. Conversion to MAFalda format (idarraga@cern.ch)" << std::endl; |
---|
52 | |
---|
53 | m_dataset = dataset; |
---|
54 | m_nOfDetectors = (int)detIDs.size(); |
---|
55 | |
---|
56 | // Create as many frame handlers as pixel detectors |
---|
57 | m_frames = new FramesHandler * [m_nOfDetectors]; |
---|
58 | m_detIdToIndexArray = new int [m_nOfDetectors]; |
---|
59 | |
---|
60 | TString tempDataset = ""; |
---|
61 | |
---|
62 | int cntr = 0; |
---|
63 | vector<int>::iterator detItr = detIDs.begin(); |
---|
64 | for ( ; detItr != detIDs.end() ; detItr++ ) { |
---|
65 | |
---|
66 | tempDataset = dataset; |
---|
67 | tempDataset += "_"; |
---|
68 | tempDataset += (*detItr); // append detector id |
---|
69 | |
---|
70 | std::cout << " Detector [" << *detItr << "] with dataset " << tempDataset << std::endl; |
---|
71 | |
---|
72 | // FramesHandler constructor will communicate to FrameStruct the dataset. |
---|
73 | m_frames[cntr] = new FramesHandler(tempDataset); |
---|
74 | // parameters |
---|
75 | m_frames[cntr]->SetDetectorId(*detItr); |
---|
76 | m_frames[cntr]->SetnX( width ); |
---|
77 | m_frames[cntr]->SetnY( height ); |
---|
78 | |
---|
79 | // map detId to Index |
---|
80 | m_detIdToIndex[*detItr] = cntr; // key is the detId --> value is the index |
---|
81 | // copy in C-style array needed for limitations with serialization |
---|
82 | m_detIdToIndexArray[cntr] = *detItr; |
---|
83 | |
---|
84 | cntr++; |
---|
85 | } |
---|
86 | |
---|
87 | m_initialized = true; |
---|
88 | } |
---|
89 | |
---|
90 | } |
---|