FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MyWriteoutBuffer.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 /*
9  * MyWriteoutBuffer.cxx
10  *
11  * Created on: Mar 7, 2012
12  * Author: uhlig
13  */
14 
15 #include "MyWriteoutBuffer.h"
16 
17 #include "MyDataClass.h"
18 
21  , fData_map()
22 {}
23 
24 MyWriteoutBuffer::MyWriteoutBuffer(TString branchName, TString folderName, Bool_t persistance)
25  : FairWriteoutBuffer(branchName, "MyDataClass", folderName, persistance)
26  , fData_map()
27 {}
28 
30 
31 std::vector<std::pair<double, MyDataClass*>> MyWriteoutBuffer::Modify(std::pair<double, MyDataClass*> oldData,
32  std::pair<double, MyDataClass*> newData)
33 {
34  std::vector<std::pair<double, MyDataClass*>> result;
35  std::pair<double, MyDataClass*> singleResult;
36  if (newData.first > 0) {
37  singleResult.first = oldData.first + newData.first;
38  }
39  singleResult.second = oldData.second;
40  singleResult.second->AddCharge(newData.second->GetCharge());
41  if (fVerbose > 0) {
42  std::cout << "Modify hit" << std::endl;
43  std::cout << "OldData: " << oldData.first << " : " << oldData.second << " NewData: " << newData.first << " : "
44  << newData.second << std::endl;
45  std::cout << "Resulting Data: " << singleResult.first << " : " << singleResult.second << std::endl;
46  }
47 
48  result.push_back(singleResult);
49  return result;
50 }
51 
53 {
55  TClonesArray* myArray = ioman->GetTClonesArray(fBranchName);
56  if (fVerbose > 1) {
57  std::cout << "Data Inserted: " << *(MyDataClass*)(data) << std::endl;
58  }
59  new ((*myArray)[myArray->GetEntries()]) MyDataClass(*(MyDataClass*)(data));
60 }
61 
63 {
64  std::map<MyDataClass, double>::iterator it;
65  MyDataClass myData = *(MyDataClass*)data;
66  it = fData_map.find(myData);
67  if (it == fData_map.end()) {
68  return -1;
69  } else {
70  return it->second;
71  }
72 }
73 
74 void MyWriteoutBuffer::FillDataMap(FairTimeStamp* data, double activeTime)
75 {
76  MyDataClass myData = *(MyDataClass*)data;
77  fData_map[myData] = activeTime;
78 }
79 
81 {
82  MyDataClass myData = *(MyDataClass*)data;
83  if (fData_map.find(myData) != fData_map.end()) {
84  fData_map.erase(fData_map.find(myData));
85  }
86 }
87 
virtual void FillDataMap(FairTimeStamp *data, double activeTime)
add a new element in the search buffer
virtual std::vector< std::pair< double, MyDataClass * > > Modify(std::pair< double, MyDataClass * > oldData, std::pair< double, MyDataClass * > newData)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
void AddNewDataToTClonesArray(FairTimeStamp *)
TClonesArray * GetTClonesArray(TString branchName)
virtual void EraseDataFromDataMap(FairTimeStamp *data)
delete the element from the search buffer (see PndSdsDigiPixelWriteoutBuffer)
virtual double FindTimeForData(FairTimeStamp *data)
std::map< MyDataClass, double > fData_map
A container class to store digi data during events.
virtual ~MyWriteoutBuffer()