FairRoot/PandaRoot
PndMQFileSinkBursts.cxx
Go to the documentation of this file.
1 /*
2  * File: PndMQFileSinkBursts.tpl
3  * Author: winckler, A. Rybalchenko
4  *
5  * Created on March 11, 2014, 12:12 PM
6  */
7 
8 // Implementation of PndMQFileSinkBursts::Run() with Boost transport data format
9 #include "PndMQFileSinkBursts.h"
10 #include "PndMQGapEventBuilder.h"
13 #include "PndMapSorter.h"
14 #include "PndGeoHandling.h"
15 
16 class TMessage2 : public TMessage
17 {
18  public:
19  TMessage2(void* buf, Int_t len)
20  : TMessage(buf, len)
21  {
22  ResetBit(kIsOwner);
23  }
24 };
25 
26 void PndMQFileSinkBursts::CustomCleanup(void *data, void *hint)
27 {
28  delete (std::string*)hint;
29 }
30 
32 {
33  PndMQGapEventBuilder eventBuilder;
34  PndMapSorter mapSorter;
35  PndMvdPixelClusterFinder clusterFinder;
36  PndMQMvdChargeWeightedPixelMapping* pixelMapping = 0;
37  PndGeoHandling* geoHandler = 0;
39  {
40  while (CheckCurrentState(RUNNING))
41  {
42  FairMQParts parts;
43  std::unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage());
44  if (Receive(msg, "data-in") >= 0)
45  {
46  // LOG(INFO) << "Received data!" << std::endl;
47  string msgStr(static_cast<char*>(msg->GetData()), msg->GetSize());
48  istringstream ibuffer(msgStr);
49  if(!ibuffer.good())
50  LOG(INFO) << "IBUFFER IS BAD!";
51  boost::archive::text_iarchive InputArchive(ibuffer);
52 
53  InputArchive >> fBurstData;
54 
55  fNewRunId = fBurstData.fHeader.fRunID;
56  if (fNewRunId != fCurrentRunId) {
59  fGeoPar->GetGeometry();
60  fDigiPar = (PndSdsPixelDigiPar*)fParCList->FindObject("MVDPixelDigiPar");
61  fTotPar = (PndSdsTotDigiPar*)fParCList->FindObject("MVDPixelTotDigiPar");
62  fSensorPar = (PndSensorNamePar*)fParCList->FindObject("PndSensorNamePar");
64  if (geoHandler == 0){
65  geoHandler = new PndGeoHandling(fSensorPar);
66  }
67  LOG(INFO) << "Conversion Method: " << *fDigiPar;
68  LOG(INFO) << "Tot Info: " << *fTotPar;
69  if (pixelMapping == 0){
70  pixelMapping = new PndMQMvdChargeWeightedPixelMapping(geoHandler, fDigiPar, fTotPar);
71  }
72  }
73 
74 
75  if (fBurstData.fData.size() < 1) continue;
76  LOG(INFO) << "BurstData size: " << fBurstData.fData[0].size();
77  for (auto dataItr : fBurstData.fData[0])
78  LOG(INFO) << dataItr->GetTimeStamp();
79  mapSorter.AddElements(fBurstData.fData[0]);
80  mapSorter.WriteOutAll();
81  std::vector<FairTimeStamp*> sortedData = mapSorter.GetOutputData();
82 // for (auto i : sortedData){
83 // LOG(INFO) << "sorted: " << i->GetTimeStamp();
84 // }
85  eventBuilder.FillData(std::move(sortedData));
86  std::vector<std::vector<FairTimeStamp*> > gapData = eventBuilder.GetSeparatedData();
87  if (fBurstData.fHeader.fBranchName == "MVDPixelDigis"){
88  for (auto gapIter : gapData){
89  std::vector<PndSdsDigiPixel*> digiPixel;
90  if (gapIter.size() > 1){
91  LOG(INFO) << "GapSize > 1 " << gapIter.size();
92  for (auto dataIter : gapIter){
93  digiPixel.push_back((PndSdsDigiPixel*) dataIter);
94 // LOG(INFO) << "DataInGap: " << *(PndSdsDigiPixel*) dataIter;
95  }
96  std::vector<std::vector< Int_t> > clusterInts = clusterFinder.GetClusters(digiPixel);
97  for (auto clusterIter : clusterInts)
98  {
99  LOG(INFO) << "ClusterSize: " << clusterIter.size();
100  std::vector<PndSdsDigiPixel*> digiInCluster;
101  for (auto digiInClusterItr : clusterIter){
102  int pos = digiInClusterItr;
103  digiInCluster.push_back(digiPixel[pos]);
104  }
105  if (digiInCluster.size() > 0){
106  PndSdsHit hit = pixelMapping->GetCluster(digiInCluster);
107  digiInCluster.clear();
108  LOG(INFO) << "Hit: " << hit;
109  }
110  }
111  }
112  }
113  }
114 // for (auto sdItr : sortedData)
115 // delete(sdItr);
116 // sortedData.clear();
117 // mapSorter.DeleteOutputData();
118  }
119  }
120  if (pixelMapping != 0)
121  delete pixelMapping;
122  if (geoHandler != 0)
123  delete geoHandler;
124 
125  }
126  else
127  {
128  LOG(ERROR) << " Boost Serialization not ok";
129  }
130 }
131 
133  for ( int iparC = 0 ; iparC < fParCList->GetEntries() ; iparC++ ) {
134  FairParGenericSet* tempObj = (FairParGenericSet*)(fParCList->At(iparC));
135  fParCList->Remove(tempObj);
136  fParCList->AddAt(UpdateParameter(tempObj),iparC);
137  }
138 }
139 
140 FairParGenericSet* PndMQFileSinkBursts::UpdateParameter(FairParGenericSet* thisPar) {
141  std::string paramName = thisPar->GetName();
142  // boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
143  std::string* reqStr = new std::string(paramName + "," + std::to_string(fCurrentRunId));
144  LOG(WARN) << "Requesting parameter \"" << paramName << "\" for Run ID " << fCurrentRunId << " (" << thisPar << ")";
145  std::unique_ptr<FairMQMessage> req(NewMessage(const_cast<char*>(reqStr->c_str()), reqStr->length(), CustomCleanup, reqStr));
146  std::unique_ptr<FairMQMessage> rep(NewMessage());
147 
148  if (Send(req,"param") > 0)
149  {
150  if (Receive(rep,"param") > 0)
151  {
152  TMessage2 tm(rep->GetData(), rep->GetSize());
153  thisPar = (FairParGenericSet*)tm.ReadObject(tm.GetClass());
154  LOG(WARN) << "Received parameter"<< paramName <<" from the server (" << thisPar << ")" << tm.GetClass()->GetName() << " DataSize: " << rep->GetSize();
155  thisPar->print();
156  return thisPar;
157  }
158  }
159  return NULL;
160 }
TVector3 pos
PndSdsTotDigiPar * fTotPar
Charge Digitization Parameter Class for SDS.
std::string move
PndSdsHit GetCluster(std::vector< PndSdsDigiPixel * > &pixelArray)
Main function of class to calculate the PndSdsHit out of the given PndSdsDigis.
TMessage2(void *buf, Int_t len)
PndSensorNamePar * fSensorPar
Class to access the naming information of the MVD.
PndSdsPixelDigiPar * fDigiPar
std::vector< std::vector< Int_t > > GetClusters(std::vector< PndSdsDigiPixel * > &hits)
PndSdsChargedWeightedPixelMapping: Gets a vector of DigiHits and calculates the cluster center weight...
std::vector< std::vector< PndSdsDigiTopix4 > > GetSeparatedData()
virtual void AddElements(std::vector< FairTimeStamp * > dataArray)
static void CustomCleanup(void *data, void *hint)
virtual std::vector< FairTimeStamp * > GetOutputData()
Data class to store the digi output of a pixel module.
PndSdsMCPoint * hit
Definition: anasim.C:70
FairParGenericSet * UpdateParameter(FairParGenericSet *thisPar)
Unique match between SensorID and path in TGeoManager.
Digitization Parameter Class for SDS-Pixel part.