From a959ae8af2388e59bc4a374b1efc8438633b5c0f Mon Sep 17 00:00:00 2001 From: soul <soul@se51-99.jinr.ru> Date: Wed, 28 Dec 2016 10:52:39 +0300 Subject: [PATCH] move Event Display from bmnroot --- eventdisplay/CMakeLists.txt | 7 +- eventdisplay/FairEventManagerEditor.cxx | 27 +- eventdisplay/FairEventManagerEditor.h | 5 +- eventdisplay/bmn/BmnDigitDraw.cxx | 191 ------- eventdisplay/bmn/BmnDigitDraw.h | 63 --- eventdisplay/bmn/EventBDLinkDef.h | 5 - eventdisplay/bmn/EventBLinkDef.h | 5 - eventdisplay/raw/RawDataConverter.cxx | 272 --------- eventdisplay/raw/RawDataConverter.h | 44 -- eventdisplay/raw/RawDataParser.cxx | 701 ------------------------ eventdisplay/raw/RawDataParser.h | 69 --- eventdisplay/raw/RawMWPCDigitDraw.cxx | 156 ------ eventdisplay/raw/RawMWPCDigitDraw.h | 68 --- eventdisplay/raw/function_set.h | 479 ---------------- macro/mpd_scheduler | 2 +- 15 files changed, 27 insertions(+), 2067 deletions(-) delete mode 100644 eventdisplay/bmn/BmnDigitDraw.cxx delete mode 100644 eventdisplay/bmn/BmnDigitDraw.h delete mode 100644 eventdisplay/raw/RawDataConverter.cxx delete mode 100644 eventdisplay/raw/RawDataConverter.h delete mode 100644 eventdisplay/raw/RawDataParser.cxx delete mode 100644 eventdisplay/raw/RawDataParser.h delete mode 100644 eventdisplay/raw/RawMWPCDigitDraw.cxx delete mode 100644 eventdisplay/raw/RawMWPCDigitDraw.h delete mode 100644 eventdisplay/raw/function_set.h diff --git a/eventdisplay/CMakeLists.txt b/eventdisplay/CMakeLists.txt index 02689b4..5677ca4 100644 --- a/eventdisplay/CMakeLists.txt +++ b/eventdisplay/CMakeLists.txt @@ -43,18 +43,13 @@ FairWebScreenshots.cxx if (BMNROOT) Set(INCLUDE_DIRECTORIES - ${INCLUDE_DIRECTORIES} - ${CMAKE_SOURCE_DIR}/eventdisplay/raw + ${INCLUDE_DIRECTORIES} ${CMAKE_SOURCE_DIR}/bmndata ${CMAKE_SOURCE_DIR}/globaltracking ${CMAKE_SOURCE_DIR}/gem ) Set(SRCS ${SRCS} - raw/RawDataParser.cxx - raw/RawDataConverter.cxx - raw/RawMWPCDigitDraw.cxx - bmn/BmnDigitDraw.cxx bmn/BmnTrackDrawH.cxx bmn/BmnTrackDrawP.cxx bmn/BmnGlobalTrackDraw.cxx diff --git a/eventdisplay/FairEventManagerEditor.cxx b/eventdisplay/FairEventManagerEditor.cxx index 90aa69b..29b507f 100644 --- a/eventdisplay/FairEventManagerEditor.cxx +++ b/eventdisplay/FairEventManagerEditor.cxx @@ -22,6 +22,8 @@ #include "TGWindow.h" #include <TGLViewer.h> #include <TGLScenePad.h> +#include "TEveBrowser.h" +#include "TEveGedEditor.h" #include <iostream> using namespace std; @@ -59,7 +61,7 @@ void FairEventManagerEditor::Init() // create tab for event visualization MakeTitle("FairEventManager Editor"); TGVerticalFrame* fInfoFrame = CreateEditorTabSubFrame("Event Info"); - title1 = new TGCompositeFrame(fInfoFrame, 250, 10, kVerticalFrame | kLHintsExpandX | kFixedWidth | kOwnBackground); + TGCompositeFrame* title1 = new TGCompositeFrame(fInfoFrame, 250, 10, kVerticalFrame | kLHintsExpandX | kFixedWidth | kOwnBackground); // display file name TString Infile = "File: "; @@ -145,14 +147,14 @@ void FairEventManagerEditor::Init() title1->AddFrame(fMaxEnergy, new TGLayoutHints(kLHintsTop, 1, 1, 1, 0)); fManager->SetMaxEnergy(MAX_ENERGY); - TGHorizontalFrame* fGeometryFrame = new TGHorizontalFrame(title1); + fGeometryFrame = new TGHorizontalFrame(title1); // button: whether show detector geometry or not fGeometry = new TGCheckButton(fGeometryFrame, "show geometry"); fGeometryFrame->AddFrame(fGeometry, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,1,1)); fGeometry->Connect("Toggled(Bool_t)", "FairEventManagerEditor", this, "ShowGeometry(Bool_t)"); fGeometry->SetOn(); // button: whether show magnet or not - TGCheckButton* ShowMagnetButton = new TGCheckButton(fGeometryFrame, "show magnet"); + ShowMagnetButton = new TGCheckButton(fGeometryFrame, "show magnet"); fGeometryFrame->AddFrame(ShowMagnetButton, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,1,1)); ShowMagnetButton->Connect("Toggled(Bool_t)", "FairEventManagerEditor", this, "ShowMagnet(Bool_t)"); ShowMagnetButton->SetOn(); @@ -174,7 +176,7 @@ void FairEventManagerEditor::Init() } // group for displaying simulation and reconstruction data - groupData = new TGGroupFrame(title1, "Show MC and reco data"); + TGGroupFrame* groupData = new TGGroupFrame(title1, "Show MC and reco data"); groupData->SetTitlePos(TGGroupFrame::kCenter); TGHorizontalFrame* framePointsInfo = new TGHorizontalFrame(groupData); @@ -300,6 +302,11 @@ void FairEventManagerEditor::SelectPDG() // show or hide detector geometry void FairEventManagerEditor::ShowGeometry(Bool_t is_show) { + // set cursor HourClock + gVirtualX->SetCursor(gEve->GetMainWindow()->GetId(), gVirtualX->CreateCursor(kWatch)); + gVirtualX->SetCursor(gEve->GetLTEFrame()->GetListTree()->GetId(), gVirtualX->CreateCursor(kWatch)); + gVirtualX->SetCursor(gEve->GetLTEFrame()->GetEditor()->GetId(), gVirtualX->CreateCursor(kWatch)); + gEve->GetGlobalScene()->SetRnrState(is_show); if (!fManager->isOnline) { @@ -307,7 +314,19 @@ void FairEventManagerEditor::ShowGeometry(Bool_t is_show) fManager->fRhoZGeomScene->SetRnrState(is_show); } + // disable Magnet show choice while hiding of detector geometry + if (!is_show) + fGeometryFrame->HideFrame(ShowMagnetButton); + else + fGeometryFrame->ShowFrame(ShowMagnetButton); + gEve->Redraw3D(); + + // set cursor Pointer + gSystem->ProcessEvents(); + gVirtualX->SetCursor(gEve->GetMainWindow()->GetId(), gVirtualX->CreateCursor(kPointer)); + gVirtualX->SetCursor(gEve->GetLTEFrame()->GetListTree()->GetId(), gVirtualX->CreateCursor(kPointer)); + gVirtualX->SetCursor(gEve->GetLTEFrame()->GetEditor()->GetId(), gVirtualX->CreateCursor(kPointer)); } // show or hide magnet diff --git a/eventdisplay/FairEventManagerEditor.h b/eventdisplay/FairEventManagerEditor.h index 10b9f45..3025344 100644 --- a/eventdisplay/FairEventManagerEditor.h +++ b/eventdisplay/FairEventManagerEditor.h @@ -12,7 +12,6 @@ #include "TGButton.h" #include "TEveGValuators.h" #include "TGLabel.h" -#include "TMutex.h" #include "TSemaphore.h" #include "TGFileDialog.h" @@ -40,8 +39,8 @@ class FairEventManagerEditor : public TGedFrame TGCheckButton* fVizPri; TEveGValuator* fMinEnergy, *fMaxEnergy; TGLabel* fEventTime; - TGCompositeFrame* title1; - TGGroupFrame* groupData; + TGHorizontalFrame* fGeometryFrame; + TGCheckButton* ShowMagnetButton; TGCheckButton* fShowMCPoints, *fShowMCTracks, *fShowRecoPoints, *fShowRecoTracks; // current event number diff --git a/eventdisplay/bmn/BmnDigitDraw.cxx b/eventdisplay/bmn/BmnDigitDraw.cxx deleted file mode 100644 index 8262862..0000000 --- a/eventdisplay/bmn/BmnDigitDraw.cxx +++ /dev/null @@ -1,191 +0,0 @@ -п»ї// ------------------------------------------------------------------------- -// ----- BmnDigitDraw source file ----- -// ------------------------------------------------------------------------- -#include "BmnDigitDraw.h" -#include "BmnDchHit.h" -#include "BmnHitFinderRun1.h" -#include "RawDataConverter.h" - -#include "TEveManager.h" -#include "TGeoManager.h" - -#include <iostream> -using namespace std; - -// ----- Default constructor ------------------------------------------- -BmnDigitDraw::BmnDigitDraw() - : FairTask("BmnDigitDraw", 0), - fVerbose(0), - fDigitList(NULL), - fHitList(NULL), - fEventManager(NULL), - fq(NULL), - fColor(0), - fStyle(0), - fDetectorID(0) -{ -} - -// ----- Standard constructor ------------------------------------------ -BmnDigitDraw::BmnDigitDraw(const char* name, Int_t det_id, Color_t color ,Style_t mstyle,Int_t iVerbose) - : FairTask(name, iVerbose), - fVerbose(iVerbose), - fDigitList(NULL), - fHitList(NULL), - fEventManager(NULL), - fq(NULL), - fColor(color), - fStyle(mstyle), - fDetectorID(det_id) -{ -} - -// ------------------------------------------------------------------------- -InitStatus BmnDigitDraw::Init() -{ - if (fVerbose > 1) - cout<<"BmnDigitDraw::Init()"<<endl; - - if (fDetectorID == 0) - { - cout<<"BmnDigitDraw::Init() detector ID hasn't been set! Task will be deactivated"<<endl; - SetActive(kFALSE); - return kERROR; - } - - fEventManager = FairEventManager::Instance(); - if (fVerbose > 2) - cout<<"BmnDigitDraw::Init() get instance of EventManager: "<<fEventManager<<endl; - - FairRootManager* fManager = FairRootManager::Instance(); - if (fVerbose > 2) - cout<<"BmnDigitDraw::Init() get instance of FairRootManager: "<<fManager<<endl; - - fDigitList = (TClonesArray*)fManager->GetObject(GetName()); - if (fVerbose > 2) - cout<<"BmnDigitDraw::Init() get digit list: "<<fDigitList<<endl; - - //if (fEventManager->fEntryCount == 0) - // fEventManager->fEntryCount = bmn_digit_tree->GetEntries(); - //else - // fEventManager->fEntryCount = TMath::Min(fEventManager->fEntryCount, bmn_digit_tree->GetEntries()); - - fq = 0; - fHitList = new TClonesArray("BmnDchHit"); - - return kSUCCESS; -} - -void BmnDigitDraw::Exec(Option_t* option) -{ - if (IsActive()) - { - Reset(); - - switch (fDetectorID) - { - // MWPC digits - case 1: - { - RawDataConverter raw_converter; - for (int i = 1; i < 4; i++) - { - // get MWPC position - TGeoVolume* pVolume = gGeoManager->GetVolume("cave"); - if (pVolume != NULL) - { - TString node_name = TString::Format("mwpc%d_0", i); - TGeoNode* pFirstNode = pVolume->FindNode(node_name); - if (pFirstNode != NULL) - { - TGeoMatrix* pMatrix = pFirstNode->GetMatrix(); - //cout<<"mwpc_name: "<<node_name<<" X:"<<pMatrix->GetTranslation()[0]<<" Y:"<<pMatrix->GetTranslation()[1]<<" Z:"<<pMatrix->GetTranslation()[2]<<endl; - raw_converter.SetMwpcPosition(i, TVector3(pMatrix->GetTranslation()[0], pMatrix->GetTranslation()[1], pMatrix->GetTranslation()[2])); - } - else - cout<<"MWPC detector ("<<node_name<<") wasn't found. Default MWPC position is used for visual hits"<<endl; - } - else - cout<<"Cave volume wasn't found. Default MWPC position is used for visual hits"<<endl; - } - - raw_converter.MwpcDigits2MwpcHits(fDigitList, fHitList); - break; - } - // DCH digits - case 2: - ProcessDchDigits(fDigitList, fHitList); - break; - } - - cout<<GetName()<<" count: "<<fDigitList->GetEntries()<<". hit count: "<<fHitList->GetEntries()<<"."<<endl; - - Int_t npoints = fHitList->GetEntriesFast(); - TEvePointSet* q = new TEvePointSet(GetName(), npoints, TEvePointSelectorConsumer::kTVT_XYZ); - - q->SetOwnIds(kTRUE); - q->SetMarkerColor(fColor); - q->SetMarkerSize(1.5); - q->SetMarkerStyle(fStyle); - - for (Int_t i = 0; i < npoints; i++) - { - FairHit* p = (FairHit*) fHitList->At(i); - if (p != 0) - { - TVector3 vec(p->GetX(), p->GetY(), p->GetZ()); - q->SetNextPoint(vec.X(),vec.Y(), vec.Z()); - q->SetPointId(GetValue(p, i)); - //cout<<"VEC X: "<<vec.X()<<" Y:"<<vec.Y()<<" Z:"<<vec.Z()<<endl; - } - } - - if (fEventManager->EveRecoPoints == NULL) - { - fEventManager->EveRecoPoints = new TEveElementList("Reco points"); - gEve->AddElement(fEventManager->EveRecoPoints, fEventManager); - fEventManager->EveRecoPoints->SetRnrState(kFALSE); - } - - gEve->AddElement(q, fEventManager->EveRecoPoints); - - gEve->Redraw3D(kFALSE); - - fq = q; - }//if (IsActive()) -} - -TObject* BmnDigitDraw::GetValue(TObject* obj,Int_t i) -{ - return new TNamed(Form("Point %d", i),""); -} - -// ----- Destructor ---------------------------------------------------- -BmnDigitDraw::~BmnDigitDraw() -{ -} - -// ------------------------------------------------------------------------- -void BmnDigitDraw::SetParContainers() -{ -} - -/** Action after each event**/ -void BmnDigitDraw::Finish() -{ -} - -// ------------------------------------------------------------------------- -void BmnDigitDraw::Reset() -{ - fHitList->Delete(); - - if (fq != 0) - { - fq->Reset(); - - gEve->RemoveElement(fq, fEventManager->EveRecoPoints); - } -} - -ClassImp(BmnDigitDraw); diff --git a/eventdisplay/bmn/BmnDigitDraw.h b/eventdisplay/bmn/BmnDigitDraw.h deleted file mode 100644 index 70529e2..0000000 --- a/eventdisplay/bmn/BmnDigitDraw.h +++ /dev/null @@ -1,63 +0,0 @@ -// ------------------------------------------------------------------------- -// ----- BmnDigitDraw header file ----- -// ------------------------------------------------------------------------- - -#ifndef BMNDIGITDRAW_H -#define BMNDIGITDRAW_H - -#include "FairTask.h" -#include "FairEventManager.h" - -#include "TObject.h" -#include "TVector3.h" -#include "TClonesArray.h" -#include "TEvePointSet.h" - -class BmnDigitDraw : public FairTask -{ - public: - /** Default constructor **/ - BmnDigitDraw(); - - /** Standard constructor - *@param name Name of task - *@param iVerbose Verbosity level, - *@param det_id Detector ID: - * 1 - MWPC, 2 - DCH **/ - BmnDigitDraw(const char* name, Int_t det_id, Color_t color, Style_t mstyle, Int_t iVerbose = 1); - - /** Destructor **/ - virtual ~BmnDigitDraw(); - - /** Set verbosity level. For this task and all of the subtasks. **/ - void SetVerbose(Int_t iVerbose) {fVerbose = iVerbose;} - /** Executed task **/ - virtual void Exec(Option_t* option); - void Reset(); - - protected: - virtual TObject* GetValue(TObject* obj,Int_t i); - - // Verbosity level - Int_t fVerbose; - virtual void SetParContainers(); - virtual InitStatus Init(); - /** Action after each event**/ - virtual void Finish(); - TChain* bmn_digit_tree; //! - TClonesArray* fDigitList; //! - TClonesArray* fHitList; //! - FairEventManager* fEventManager; //! - TEvePointSet* fq; //! - Color_t fColor; //! - Style_t fStyle; //! - Int_t fDetectorID; //! - - private: - BmnDigitDraw(const BmnDigitDraw&); - BmnDigitDraw& operator=(const BmnDigitDraw&); - - ClassDef(BmnDigitDraw,1); -}; - -#endif diff --git a/eventdisplay/bmn/EventBDLinkDef.h b/eventdisplay/bmn/EventBDLinkDef.h index d7ea5a0..4ea72e0 100644 --- a/eventdisplay/bmn/EventBDLinkDef.h +++ b/eventdisplay/bmn/EventBDLinkDef.h @@ -21,11 +21,6 @@ // BmnRoot #pragma link C++ class FairMCModuleDraw; -#pragma link C++ class RawDataParser; -#pragma link C++ class RawDataConverter; -#pragma link C++ class RawMWPCDigitDraw; -#pragma link C++ class EventData; -#pragma link C++ class BmnDigitDraw; #pragma link C++ class BmnTrackDrawH; #pragma link C++ class BmnTrackDrawP; #pragma link C++ class BmnGlobalTrackDraw; diff --git a/eventdisplay/bmn/EventBLinkDef.h b/eventdisplay/bmn/EventBLinkDef.h index 98c3c0d..2232322 100644 --- a/eventdisplay/bmn/EventBLinkDef.h +++ b/eventdisplay/bmn/EventBLinkDef.h @@ -21,11 +21,6 @@ // BmnRoot #pragma link C++ class FairMCModuleDraw; -#pragma link C++ class RawDataParser; -#pragma link C++ class RawDataConverter; -#pragma link C++ class RawMWPCDigitDraw; -#pragma link C++ class EventData; -#pragma link C++ class BmnDigitDraw; #pragma link C++ class BmnTrackDrawH; #pragma link C++ class BmnTrackDrawP; #pragma link C++ class BmnGlobalTrackDraw; diff --git a/eventdisplay/raw/RawDataConverter.cxx b/eventdisplay/raw/RawDataConverter.cxx deleted file mode 100644 index da7f921..0000000 --- a/eventdisplay/raw/RawDataConverter.cxx +++ /dev/null @@ -1,272 +0,0 @@ -#include "RawDataConverter.h" -#include "BmnMwpcHit.h" - -#include "TGeoManager.h" -#include "TMath.h" -using namespace TMath; - -#include <iostream> -using namespace std; - -RawDataConverter::RawDataConverter() -{ - kTimeBin = 8; // ns - kNWires = 96; //in one plane - kAngleStep = 60.0; // degrees - kWireStep = 0.25; // cm - kPlaneWidth = kNWires * kWireStep; // cm - - kMwpcZpos = 50.0; // z-position of the center of MWPC - - MwpcPosition[0] = NULL; MwpcPosition[1] = NULL; MwpcPosition[2] = NULL; -} - -RawDataConverter::~RawDataConverter() -{ -} - -vector<TVector3*> RawDataConverter::MWPCEventToGeoVector(EventData* curEvent) -{ - bool isEmptyPlane = false; - for (int j = 0; j< 6; j++) - { - if (curEvent->MWPC1Planes[j].size() == 0) - isEmptyPlane = true; - } - - if (isEmptyPlane) - cout<<"WARNING!!! digits count 0"<<endl; - - cout<<"Search hits: "<<curEvent->MWPC1Planes[0].size()<<" : "<<curEvent->MWPC1Planes[1].size()<<" : "<<curEvent->MWPC1Planes[2].size()<<" : " - <<curEvent->MWPC1Planes[3].size()<<" : "<<curEvent->MWPC1Planes[4].size()<<" : "<<curEvent->MWPC1Planes[5].size()<<endl; - - vector<TVector3*> event_hits = SearchHits(curEvent->MWPC1Planes[0], curEvent->MWPC1Planes[1], curEvent->MWPC1Planes[2], - curEvent->MWPC1Planes[3], curEvent->MWPC1Planes[4], curEvent->MWPC1Planes[5]); - - return event_hits; -} - -TEvePointSet* RawDataConverter::Vector2EvePoints(vector<TVector3*>* pPointVector, TString strSetName, Color_t fColor, Style_t fStyle, Int_t iMarkerSize, bool isDebug) -{ - Int_t npoints = pPointVector->size(); - TEvePointSet* q = new TEvePointSet(strSetName, npoints, TEvePointSelectorConsumer::kTVT_XYZ); - - q->SetOwnIds(kTRUE); - q->SetMarkerColor(fColor); - q->SetMarkerSize(iMarkerSize); - q->SetMarkerStyle(fStyle); - - for (Int_t i = 0; i < npoints; i++) - { - TVector3* vec = (*pPointVector)[i]; - if (isDebug) - cout<<"Point "<<i<<": x="<<vec->X()<<" y="<<vec->Y()<<" z="<<vec->Z()<<endl; - - q->SetNextPoint(vec->X(), vec->Y(), vec->Z()); - q->SetPointId(new TNamed(Form("Point %d", i), strSetName.Data())); - - // bug in ROOT with one point drawing - if (npoints == 1) - { - q->SetNextPoint(vec->X()+0.0001, vec->Y(), vec->Z()); - q->SetPointId(new TNamed("Point 1", strSetName.Data())); - } - } - - return q; -} - -void RawDataConverter::SetMwpcPosition(int mwpc_number, TVector3 mwpc_position) -{ - if ((mwpc_number > 0) && (mwpc_number < 4)) - MwpcPosition[mwpc_number-1] = new TVector3(mwpc_position); - else - cout<<"RawDataConverter::SetMwpcPosition function error: incorrect MWPC number - "<<mwpc_number<<endl; -} - -void RawDataConverter::MwpcDigits2MwpcHits(TClonesArray* pMwpcDigits, TClonesArray* pMwpcHits) -{ - // divide digits by three MWPC - vector<BmnMwpcDigit*> x[3][6]; - for (int i = 0; i < pMwpcDigits->GetEntriesFast(); i++) - { - BmnMwpcDigit* pDigit = (BmnMwpcDigit*)pMwpcDigits->At(i); - int mwpc_number = pDigit->GetPlane() / 6; - int plane_number = pDigit->GetPlane() - mwpc_number*6; - pDigit->SetPlane(plane_number); - x[mwpc_number][plane_number].push_back(pDigit); - } - - // for three MWPC detectors convert to MWPC hits - for (int i = 0; i < 3; i++) - { - vector<TVector3*> hits = SearchHits(x[i][0], x[i][1], x[i][2], x[i][3], x[i][4], x[i][5]); - - // correct MWPC position - TVector3* pShift = MwpcPosition[i]; - if (pShift != NULL) - { - double dx = pShift->X(), dy = pShift->Y(), dz = pShift->Z(); - for (int j = 0; j < hits.size(); j++) - { - *hits[j] += TVector3(dx, dy, dz - kMwpcZpos); - } - } - - // write to MwpcHits array (TClonesArray) - for (int j = 0; j < hits.size(); j++) - { - new ((*pMwpcHits)[pMwpcHits->GetEntriesFast()]) BmnMwpcHit(0, *hits[j], TVector3(0, 0, 0), i); - //cout<<"Hit X: "<<hits[j]->X()<<" Y:"<<hits[j]->Y()<<" Z:"<<hits[j]->Z()<<endl; - } - } - - return; -} - -TVector3* RawDataConverter::CalcHitPosByTwoDigits(BmnMwpcDigit* dI, BmnMwpcDigit* dJ) -{ - Short_t dWireI = dI->GetWireNumber(); - Short_t dWireJ = dJ->GetWireNumber(); - Float_t xI = kPlaneWidth * (dWireI * 1.0 / kNWires - 0.5); //local X by wire number - Float_t xJ = kPlaneWidth * (dWireJ * 1.0 / kNWires - 0.5); //local X by wire number - Float_t aI = (dI->GetPlane() - 1) * kAngleStep * DegToRad(); //rotation angle by plane number - Float_t aJ = (dJ->GetPlane() - 1) * kAngleStep * DegToRad(); //rotation angle by plane number - Float_t xGlob = (xI * Sin(aJ) - xJ * Sin(aI)) / Sin(aJ - aI); - Float_t yGlob = (xI * Cos(aJ) - xJ * Cos(aI)) / Sin(aJ - aI); - Float_t zGlob = kMwpcZpos - Float_t(min(dI->GetPlane(), dJ->GetPlane()) - 3); //average position between two neighbor planes - TVector3* pos = new TVector3(xGlob, yGlob, zGlob); - return pos; -} - -vector<TVector3*> RawDataConverter::CreateHitsByTwoPlanes(vector<BmnMwpcDigit*> x, vector<BmnMwpcDigit*> y) { - vector<TVector3*> v; - for (Int_t i = 0; i < x.size(); ++i) { - BmnMwpcDigit* dI = (BmnMwpcDigit*) x.at(i); - for (Int_t j = 0; j < y.size(); ++j) { - BmnMwpcDigit* dJ = (BmnMwpcDigit*) y.at(j); - //if (dI->GetTime() != dJ->GetTime()) continue; - v.push_back(CalcHitPosByTwoDigits(dI, dJ)); - } - } - return v; -} - -vector<TVector3*> RawDataConverter::SearchHits(vector<BmnMwpcDigit*> x1, vector<BmnMwpcDigit*> u1, vector<BmnMwpcDigit*> v1, vector<BmnMwpcDigit*> x2, vector<BmnMwpcDigit*> u2, vector<BmnMwpcDigit*> v2) -{ - Float_t x = 0.0; - Float_t y = 0.0; - Float_t z = 0.0; - - //temporary parameter for excluding fakes - Float_t delta = 4.0; //cm - - vector<TVector3*> x1u1 = CreateHitsByTwoPlanes(x1, u1); - vector<TVector3*> u1v1 = CreateHitsByTwoPlanes(u1, v1); - vector<TVector3*> v1x2 = CreateHitsByTwoPlanes(v1, x2); - vector<TVector3*> x2u2 = CreateHitsByTwoPlanes(x2, u2); - vector<TVector3*> u2v2 = CreateHitsByTwoPlanes(u2, v2); - vector<TVector3*> v2x1 = CreateHitsByTwoPlanes(v2, x1); - - TVector3* pos3 = NULL; - vector<TVector3*> hits; - - for (Int_t i1 = 0; i1 < x1u1.size(); ++i1) { - TVector3* pos1 = x1u1.at(i1); - if (pos1->z() < 0) continue; - for (Int_t i2 = 0; i2 < v1x2.size(); ++i2) { - TVector3* pos2 = v1x2.at(i2); - if (pos2->z() < 0 || pos1->z() < 0) continue; - if (Sqrt((pos1->x() - pos2->x()) * (pos1->x() - pos2->x()) + (pos1->y() - pos2->y()) * (pos1->y() - pos2->y())) > delta) continue; - for (Int_t i3 = 0; i3 < u2v2.size(); ++i3) { - pos3 = u2v2.at(i3); - if (pos3->z() < 0 || pos2->z() < 0 || pos1->z() < 0) continue; - if (Sqrt((pos2->x() - pos3->x()) * (pos2->x() - pos3->x()) + (pos2->y() - pos3->y()) * (pos2->y() - pos3->y())) > delta) continue; - //Int_t ref = (dI->GetRefId() == dJ->GetRefId() && dI->GetRefId() == dK->GetRefId()) ? dI->GetRefId() : -1; - //cout << "ref = " << ref << " | x1:" << dI->GetRefId() << " | u1:" << dJ->GetRefId() << " | v1:" << dK->GetRefId() << endl; - x = (pos1->x() + pos2->x() + pos3->x()) / 3; - y = (pos1->y() + pos2->y() + pos3->y()) / 3; - z = (pos1->z() + pos2->z() + pos3->z()) / 3; - pos1->SetZ(-1.0); - pos2->SetZ(-1.0); - pos3->SetZ(-1.0); - TVector3* coord = new TVector3(x, y, z); - hits.push_back(coord); - } - } - } - - Double_t k = Tan(kAngleStep / 2 * DegToRad()); - Double_t b = kPlaneWidth * k; - delta = 0.5; //cm - - //Checking angle s between x1 and u1, x2 and u2 - for (Int_t i = 0; i < x1u1.size(); ++i) - { - TVector3* pos1 = x1u1.at(i); - if (pos1->z() < 0) continue; - if ((pos1->y() < (-k * pos1->x() + b)) && pos1->y() < (-k * pos1->x() - b)) continue; - for (Int_t j = 0; j < x2u2.size(); ++j) - { - TVector3* pos2 = x2u2.at(j); - if (pos2->z() < 0 || pos1->z() < 0) continue; - if ((pos2->y() < (-k * pos2->x() + b)) && pos2->y() < (-k * pos2->x() - b)) continue; - if (Sqrt((pos1->x() - pos2->x()) * (pos1->x() - pos2->x()) + (pos1->y() - pos2->y()) * (pos1->y() - pos2->y())) > delta) continue; - x = (pos1->x() + pos2->x()) * 0.5; - y = (pos1->y() + pos2->y()) * 0.5; - z = (pos1->z() + pos2->z()) * 0.5; - - pos1->SetZ(-1.0); - pos2->SetZ(-1.0); - - TVector3* coord = new TVector3(x, y, z); - hits.push_back(coord); - } - } - - //Checking angle s between u1 and v1, u2 and v2 - for (Int_t i = 0; i < u1v1.size(); ++i) { - TVector3* pos1 = u1v1.at(i); - if (pos1->z() < 0) continue; - if (pos1->x() > (-kPlaneWidth * 0.5) && pos1->x() < (kPlaneWidth * 0.5)) continue; - for (Int_t j = 0; j < u2v2.size(); ++j) { - TVector3* pos2 = u2v2.at(j); - if (pos2->z() < 0 || pos1->z() < 0) continue; - if (pos2->x() > (-kPlaneWidth * 0.5) && pos2->x() < (kPlaneWidth * 0.5)) continue; - if (Sqrt((pos1->x() - pos2->x()) * (pos1->x() - pos2->x()) + (pos1->y() - pos2->y()) * (pos1->y() - pos2->y())) > delta) continue; - x = (pos1->x() + pos2->x()) * 0.5; - y = (pos1->y() + pos2->y()) * 0.5; - z = (pos1->z() + pos2->z()) * 0.5; - - pos1->SetZ(-1.0); - pos2->SetZ(-1.0); - - TVector3* coord = new TVector3(x, y, z); - hits.push_back(coord); - } - } - - //Checking angle s between v1 and x2, v2 and x1 - for (Int_t i = 0; i < v1x2.size(); ++i) { - TVector3* pos1 = v1x2.at(i); - if (pos1->z() < 0) continue; - if ((pos1->y() < (k * pos1->x() + b)) && pos1->y() < (k * pos1->x() - b)) continue; - for (Int_t j = 0; j < v2x1.size(); ++j) { - TVector3* pos2 = v2x1.at(j); - if (pos2->z() < 0 || pos1->z() < 0) continue; - if ((pos2->y() < (k * pos2->x() + b)) && pos2->y() < (k * pos2->x() - b)) continue; - if (Sqrt((pos1->x() - pos2->x()) * (pos1->x() - pos2->x()) + (pos1->y() - pos2->y()) * (pos1->y() - pos2->y())) > delta) continue; - x = (pos1->x() + pos2->x()) * 0.5; - y = (pos1->y() + pos2->y()) * 0.5; - z = (pos1->z() + pos2->z()) * 0.5; - - pos1->SetZ(-1.0); - pos2->SetZ(-1.0); - - TVector3* coord = new TVector3(x, y, z); - hits.push_back(coord); - } - } - - return hits; -} diff --git a/eventdisplay/raw/RawDataConverter.h b/eventdisplay/raw/RawDataConverter.h deleted file mode 100644 index d0f557c..0000000 --- a/eventdisplay/raw/RawDataConverter.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef RAWDATACONVERTER_H -#define RAWDATACONVERTER_H - -#include "RawDataParser.h" - -#include "TVector3.h" -#include "TClonesArray.h" -#include "TEvePointSet.h" - -class RawDataConverter -{ - public: - Short_t kTimeBin; // ns - Short_t kNWires; //in one plane - Float_t kAngleStep; // degrees - Float_t kWireStep; // cm - Float_t kPlaneWidth; // cm - - Float_t kMwpcZpos; // z-position of the center of MWPC - - // nWire1 - number of the first wire //from 0 to 102 - // nWire2 - number of the second wire //from 0 to 102 - // nPlane1 - number of the first plane //from 1 to 6 - // nPlane2 - number of the second plane //from 1 to 6 - - /** Default constructor **/ - RawDataConverter(); - /** Destructor **/ - virtual ~RawDataConverter(); - - vector<TVector3*> SearchHits(vector<BmnMwpcDigit*> x1, vector<BmnMwpcDigit*> u1, vector<BmnMwpcDigit*> v1, vector<BmnMwpcDigit*> x2, vector<BmnMwpcDigit*> u2, vector<BmnMwpcDigit*> v2); - vector<TVector3*> MWPCEventToGeoVector(EventData* pEventData); - void MwpcDigits2MwpcHits(TClonesArray* pMwpcDigits, TClonesArray* pMwpcHits); - void SetMwpcPosition(int mwpc_number, TVector3 mwpc_position); - - static TEvePointSet* Vector2EvePoints(vector<TVector3*>* pPointVector, TString strSetName, Color_t fColor, Style_t fStyle, Int_t iMarkerSize = 1, bool isDebug = false); - - private: - TVector3* CalcHitPosByTwoDigits(BmnMwpcDigit* dI, BmnMwpcDigit* dJ); - vector<TVector3*> CreateHitsByTwoPlanes(vector<BmnMwpcDigit*> x, vector<BmnMwpcDigit*> y); - TVector3* MwpcPosition[3]; -}; - -#endif // RAWDATACONVERTER_H diff --git a/eventdisplay/raw/RawDataParser.cxx b/eventdisplay/raw/RawDataParser.cxx deleted file mode 100644 index 6ce6c4a..0000000 --- a/eventdisplay/raw/RawDataParser.cxx +++ /dev/null @@ -1,701 +0,0 @@ -#include "RawDataParser.h" -#include "function_set.h" - -#include <cerrno> -#include <iostream> -using namespace std; - -RawDataParser::RawDataParser() -{ - device_serial[0x1A8D] = 1; - device_serial[0x2950] = 2; - device_serial[0x3043] = 3; - device_serial[0x304E] = 4; - device_serial[0x4514] = 5; - device_serial[0x45DF] = 6; - - device_serial1[0x3F8B] = 1; - device_serial1[0x2950] = 2; - device_serial1[0x4514] = 3; - device_serial1[0x4504] = 4; - device_serial1[0x3043] = 5; - device_serial1[0x304E] = 6; - - device_serial2[0x47CB] = 1; - device_serial2[0x2A79] = 2; - device_serial2[0x3F1D] = 3; - device_serial2[0x4513] = 4; - device_serial2[0x3F97] = 5; - device_serial2[0x2FFF] = 6; -} - -RawDataParser::~RawDataParser() -{ -} - -//buffer - unsigned int array from file with HRB Raw Data Format 1.0 -//size - size of 'buffer' variable in words (unsigned int) -//fEventReadData - vector with EventData objects -int RawDataParser::ParseHRB1Buffer(unsigned int* buffer, long size, vector<EventData*>* fEventData) -{ - unsigned char byte_hh;//, byte_hl, byte_lh, byte_ll; - unsigned int int_h, int_l; - long cur_word = 0, i = 0; - //unsigned int max_diff = 0, = 0; - cout<<"enter of parsing file"<<endl; - //sleep(1); - int max_event_diff = 0, ind = 0; - while (cur_word < size) - { - ind++; - // M-Link HEADER - frame type - unsigned int x = buffer[cur_word++]; - - // check sync word: 0x2A50 - int_h = x >> 16; - if (int_h != 0x2A50) - { - fputs("sync word error, should be 0x2A50", stderr); - return -1; - } - - // check frame type: 0x5354 - stream data - int_l = x & 0xFFFF; - if (int_l != 0x5354) - { - fputs("frame type error, should be 0x5354", stderr); - return -2; - } - - // M-Link HEADER - frame info - x = buffer[cur_word++]; - - unsigned int frame_length = x >> 16; - unsigned int frame_number = x & 0xFFFF; - //cout<<"frame_length: "<<frame_length<<endl; - //cout<<"frame_number: "<<frame_number<<endl; - - // skip destination and source address - cur_word++; - - // M-Stream Header - data type and flags - x = buffer[cur_word++]; - byte_hh = *((unsigned char*)&x + 3); - if (byte_hh != 0xBC) - { - fputs("data type error, should be 0xBC", stderr); - return -3; - } - unsigned int fragment_length = x & 0xFFFF; - //cout<<"fragment_length: "<<fragment_length<<endl; - - // skip fragment ID and offset - cur_word++; - - // M-Stream Payload - device serial (define plane number starting with 1) - x = buffer[cur_word++]; - unsigned int plane_number = device_serial.find(x & 0xFFFF)->second; - //cout<<"plane_number: "<<plane_number<<endl; - - // M-Stream Payload - event (0:23 bits) and channel number - x = buffer[cur_word++]; - unsigned int event_number = x & 0xFFFFFF; - //cout<<"event_number: "<<event_number<<endl; - //if (event_number > max_event) - // max_event = event_number; - //if ((max_event - event_number) > max_diff) - // max_diff = max_event - event_number; - /* - vector<EventData*>::iterator it = fEventReadData->begin(); - EventData* pCurEvent = NULL; - for (i = 0; i < fEventReadData->size(); i++, it++) - { - pCurEvent = (*fEventReadData)[i]; - - if (pCurEvent->uiEventNumber == event_number) - break; - - if (pCurEvent->uiEventNumber > event_number) - { - pCurEvent = new EventData(); - pCurEvent->uiEventNumber = event_number; - - fEventReadData->insert(it, pCurEvent); - //cout<<"event was inner added: "<<i<<" event_number="<<event_number<<endl; - break; - } - } - if (i == fEventReadData->size()) - { - pCurEvent = new EventData(); - pCurEvent->uiEventNumber = event_number; - - fEventReadData->push_back(pCurEvent); - //cout<<"event was outer added: "<<i<<" event_number="<<event_number<<endl; - } - */ - - // M-Stream Payload - timestamp (high and low) - x = buffer[cur_word++]; - ULong64_t event_timestamp = x + (((ULong64_t)buffer[cur_word++]) << 32); - //ULong64_t event_timestamp = (((ULong64_t)x) << 32) + buffer[cur_word++]; - - vector<EventData*>::iterator it = fEventData->end(); - EventData* pCurEvent = NULL; - int cnt = 0; - for (i = fEventData->size() - 1; i >= 0; i--, it--, cnt++) - { - pCurEvent = (*fEventData)[i]; - - if (pCurEvent->event_timestamp < event_timestamp) - { - pCurEvent = new EventData(); - pCurEvent->event_timestamp = event_timestamp; - - //if (i == (fEventReadData->size()-1)) - // fEventReadData->push_back(pCurEvent); - //else - fEventData->insert(it, pCurEvent); - - break; - } - - if (pCurEvent->event_timestamp == event_timestamp) - break; - }// for - if (i < 0) - { - pCurEvent = new EventData(); - pCurEvent->event_timestamp = event_timestamp; - - if (fEventData->size() == 0) - fEventData->push_back(pCurEvent); - else - { - if (*it != *(fEventData->begin())) - { - cout<<"DATA ERROR: it != fEventReadData->begin()"<<endl; - sleep(3); - } - - fEventData->insert(it, pCurEvent); - } - } - if (cnt > max_event_diff) - max_event_diff = cnt; - - // define vector for digits by plane_number - vector<BmnMwpcDigit*>* pDigitsPlane = &pCurEvent->MWPC1Planes[plane_number-1]; - - // M-Stream data - searching for "1" bits - working only with 32-bit words ratio, can be generalized - if (((fragment_length / 16) * 16) != fragment_length) - { - fputs("fragment length isn't aligned with 4 32-bit word", stderr); - return -4; - } - int time_bin = 1; // starting from 1 - for (unsigned int ui = 16; ui < fragment_length; ui += 16, time_bin++) - { - // 96 bit for every wire and 32 bit is empty (zero) - for (int j = 0; j < 3; j++) - { - x = buffer[cur_word++]; - - int pos = sizeof(unsigned int)*8 - 1; - while ((pos--) >= 0) - { - if (CHECK_BIT(x, pos)) - { - // starting number from 0 - int active_wire = j*32 + pos; - - //cout<<"event timestamp: "<<event_timestamp<<"; plane: "<<plane_number<<"; time: "<<time_bin<<"; wire: "<<active_wire<<endl; - //sleep(1); - - BmnMwpcDigit* pDigit = new BmnMwpcDigit(plane_number, active_wire, time_bin, -1); - - pDigitsPlane->push_back(pDigit); - } - } - } - cur_word++; - }// for detector's wires - - // skip M-Link CRC - cur_word++; - - //cout<<endl<<endl; - }// while not end of file - - cout<<"exit of parsing file"<<" iterations count: "<<ind<<endl; - //cout<<"event count: "<<fEventReadData->size()<<endl; - //cout<<"max_event_diff: "<<max_event_diff<<endl; - //sleep(3); -} - -//buffer - unsigned int array from file with HRB Raw Data Format 2.0 -//size - size of 'buffer' variable in words (unsigned int) -//fEventData - vector with EventData objects -int RawDataParser::ParseHRB2Buffer(unsigned int* buffer, long size, vector<EventData*>* fEventData) -{ - unsigned char byte_hh; //, byte_hl, byte_lh, byte_ll; - unsigned int int_h, int_l; - long cur_word = 0, i = 0; - //unsigned int max_diff = 0, = 0; - cout<<"enter of parsing file"<<endl; - //sleep(1); - int max_event_diff = 0, ind = 0; - while (cur_word < size) - { - ind++; - // M-Link HEADER - frame type - unsigned int x = buffer[cur_word++]; - - // check sync word: 0x2A50 - int_h = x >> 16; - if (int_h != 0x2A50) - { - cout<<"sync word error, should be 0x2A50, but it's equal to "<<int_h<<endl; - return -1; - } - - // check frame type: 0x2A50 - stream data 2.0 - int_l = x & 0xFFFF; - if (int_l != 0x2A50) - { - fputs("frame type error, should be 0x2A50", stderr); - return -2; - } - - // M-Link HEADER - frame info - x = buffer[cur_word++]; - - unsigned int frame_length = x >> 16; - unsigned int frame_number = x & 0xFFFF; - //cout<<"frame_length: "<<frame_length<<endl; - //cout<<"frame_number: "<<frame_number<<endl; - - // skip destination and source address - cur_word++; - - int MWPC_number = -1; - unsigned int plane_number = 0; - // M-Stream Subtype 0 - device serial id (define plane number starting with 1) - x = buffer[cur_word++]; - int_l = x & 0xFFFF; - //cout<<"device_serial: 0x"<<int_to_hex_string(int_l)<<endl; - map<int,int>::iterator it_device = device_serial1.find(int_l); - if (it_device != device_serial1.end()) - { - MWPC_number = 1; - plane_number = it_device->second; - } - else - { - MWPC_number = 2; - it_device = device_serial2.find(int_l); - if (it_device == device_serial2.end()) - { - cout<<"error: device serial wasn't found in the map, exiting of parsing this file"<<endl; - return -3; - } - plane_number = it_device->second; - } - //cout<<"MWPC number: "<<MWPC_number<<". plane_number: "<<plane_number<<endl; - - // M-Stream Subtype 0 - device_id and fragment_length - x = buffer[cur_word++]; - unsigned int fragment_length = x & 0xFFFF; - //cout<<"fragment_length: "<<fragment_length<<endl; - unsigned int device_id = x >> 24; - //cout<<"device_id: 0x"<<int_to_hex_string(device_id)<<endl; - - // M-Stream Subtype 0 - event (0:23 bits) - x = buffer[cur_word++]; - unsigned int event_number = x & 0xFFFFFF; - //cout<<"event_number: "<<event_number<<endl; - - // M-Stream Subtype 0 - trigger timestamps: nanoseconds (32-bit word) and then seconds (32-bit word), e.i. low the high timestamp - x = buffer[cur_word++]; - //unsigned int timestamp_seconds = x; - //x = buffer[cur_word++]; - //unsigned int timestamp_nanoseconds = x; - ULong64_t event_timestamp = x + (((ULong64_t)buffer[cur_word++]) << 32); - //ULong64_t event_timestamp = (((ULong64_t)x) << 32) + buffer[cur_word++]; - - vector<EventData*>::iterator it = fEventData->end(); - EventData* pCurEvent = NULL; - int cnt = 0; - for (i = fEventData->size() - 1; i >= 0; i--, it--, cnt++) - { - pCurEvent = (*fEventData)[i]; - - if (pCurEvent->event_timestamp < event_timestamp) - { - pCurEvent = new EventData(); - pCurEvent->event_timestamp = event_timestamp; - - //if (i == (fEventData->size()-1)) - // fEventData->push_back(pCurEvent); - //else - fEventData->insert(it, pCurEvent); - - break; - } - - if (pCurEvent->event_timestamp == event_timestamp) - break; - }// for - if (i < 0) - { - pCurEvent = new EventData(); - pCurEvent->event_timestamp = event_timestamp; - - if (fEventData->size() == 0) - fEventData->push_back(pCurEvent); - else - { - if (*it != *(fEventData->begin())) - { - cout<<"DATA ERROR: it != fEventData->begin()"<<endl; - sleep(3); - } - - fEventData->insert(it, pCurEvent); - } - } - if (cnt > max_event_diff) - max_event_diff = cnt; - - // define vector for digits by MWPC and plane number - vector<BmnMwpcDigit*>* pDigitsPlane; - if (MWPC_number == 1) - pDigitsPlane = &pCurEvent->MWPC1Planes[plane_number-1]; - else - pDigitsPlane = &pCurEvent->MWPC2Planes[plane_number-1]; - - // M-Stream data - searching for "1" bits - working only with 32-bit words ratio, can be generalized - unsigned int start_data = 12; - if ((fragment_length - start_data) % 16 != 0) - { - cout<<"data length isn't aligned with 4 32-bit word"<<endl; - return -4; - } - int time_bin = 1; // starting from 1 - int pos_bits = sizeof(unsigned int)*8 - 1, pos; - for (unsigned int ui = start_data; ui < fragment_length; ui += 16, time_bin++) - { - // 96 bit for every wire and 32 bit is empty (zero) - for (int j = 0; j < 3; j++) - { - x = buffer[cur_word++]; - if (x == 0) - continue; - - pos = pos_bits; - while ((pos--) >= 0) - { - if (CHECK_BIT(x, pos)) - { - // starting number from 0 - int active_wire = j*32 + pos; - - //cout<<"time stamp: "<<event_timestamp<<", bin: "<<time_bin<<"; MWPC: "<<MWPC_number<<"; plane: "<<plane_number<<"; wire: "<<active_wire<<endl; - //sleep(1); - - BmnMwpcDigit* pDigit = new BmnMwpcDigit(plane_number, active_wire, time_bin, -1); - - pDigitsPlane->push_back(pDigit); - } - } - } - cur_word++; - }// for detector's wires - - // skip M-Link CRC - //cur_word++; - - //cout<<endl<<endl; - }// while not end of file - - cout<<"exit of parsing file"<<" iterations count: "<<ind<<endl; - cout<<"event count: "<<fEventData->size()<<endl; - //cout<<"max_event_diff: "<<max_event_diff<<endl; - //sleep(1); - - return 0; -} - -//buffer - unsigned int array from file with HRB Raw Data Format 2.0 -//size - size of 'buffer' variable in words (unsigned int) -//fEventData - vector with EventData objects -int RawDataParser::ParseWaveBuffer(unsigned int* buffer, long size, vector<EventData*>* fEventData) -{ - unsigned char byte_hh; //, byte_hl, byte_lh, byte_ll; - unsigned int int_h, int_l; - long cur_word = 0, i = 0; - //unsigned int max_diff = 0, = 0; - cout<<"enter of parsing file"<<endl; - //sleep(1); - int max_event_diff = 0, ind = 0; - while (cur_word < size) - { - ind++; - // M-Link HEADER - frame type - unsigned int x = buffer[cur_word++]; - - // check sync word: 0x2A50 - int_h = x >> 16; - if (int_h != 0x2A50) - { - cout<<"sync word error, should be 0x2A50, but it's equal to "<<int_h<<endl; - return -1; - } - - // check frame type: 0x2A50 - stream data 2.0 - int_l = x & 0xFFFF; - if (int_l != 0x2A50) - { - fputs("frame type error, should be 0x2A50", stderr); - return -2; - } - - // M-Link HEADER - frame info - x = buffer[cur_word++]; - - unsigned int frame_length = x >> 16; - unsigned int frame_number = x & 0xFFFF; - cout<<"frame_length: "<<frame_length<<endl; - cout<<"frame_number: "<<frame_number<<endl; - - // M-Stream SUBTYPE 0 Event Header (4 * DWORD) - // skip destination and source address - cur_word++; - - // M-Stream Subtype 0 - device serial id (define plane number starting with 1) - x = buffer[cur_word++]; - int_h = x >> 16; - int_l = x & 0xFFFF; - cout<<"device_serial: 0x"<<int_to_hex_string(int_h)<<int_to_hex_string(int_l)<<endl; - - // M-Stream Subtype 0 - device_id and fragment_length - x = buffer[cur_word++]; - unsigned int fragment_length = x & 0xFFFF; - cout<<"fragment_length: "<<fragment_length<<endl; - unsigned int device_id = x >> 24; - cout<<"device_id: 0x"<<int_to_hex_string(device_id)<<endl; - - // M-Stream Subtype 0 - event (0:23 bits) - x = buffer[cur_word++]; - unsigned int event_number = x & 0xFFFFFF; - cout<<"event_number: "<<event_number<<endl; - - // M-Stream Subtype 0 - readout channels 31:0 bit mask - cur_word++; - - // M-Stream Subtype 0 - readout channels 63:32 bit mask - cur_word++; - - - - - // M-Stream SUBTYPE 1 Event Header (4 * DWORD) - - -/* - // M-Stream Subtype 0 - trigger timestamps: nanoseconds (32-bit word) and then seconds (32-bit word), e.i. low the high timestamp - x = buffer[cur_word++]; - //unsigned int timestamp_seconds = x; - //x = buffer[cur_word++]; - //unsigned int timestamp_nanoseconds = x; - ULong64_t event_timestamp = x + (((ULong64_t)buffer[cur_word++]) << 32); - //ULong64_t event_timestamp = (((ULong64_t)x) << 32) + buffer[cur_word++]; - - vector<EventData*>::iterator it = fEventData->end(); - EventData* pCurEvent = NULL; - int cnt = 0; - for (i = fEventData->size() - 1; i >= 0; i--, it--, cnt++) - { - pCurEvent = (*fEventData)[i]; - - if (pCurEvent->event_timestamp < event_timestamp) - { - pCurEvent = new EventData(); - pCurEvent->event_timestamp = event_timestamp; - - //if (i == (fEventData->size()-1)) - // fEventData->push_back(pCurEvent); - //else - fEventData->insert(it, pCurEvent); - - break; - } - - if (pCurEvent->event_timestamp == event_timestamp) - break; - }// for - if (i < 0) - { - pCurEvent = new EventData(); - pCurEvent->event_timestamp = event_timestamp; - - if (fEventData->size() == 0) - fEventData->push_back(pCurEvent); - else - { - if (*it != *(fEventData->begin())) - { - cout<<"DATA ERROR: it != fEventData->begin()"<<endl; - sleep(3); - } - - fEventData->insert(it, pCurEvent); - } - } - if (cnt > max_event_diff) - max_event_diff = cnt; - - // define vector for digits by MWPC and plane number - vector<BmnMwpcDigit*>* pDigitsPlane; - if (MWPC_number == 1) - pDigitsPlane = &pCurEvent->MWPC1Planes[plane_number-1]; - else - pDigitsPlane = &pCurEvent->MWPC2Planes[plane_number-1]; - - // M-Stream data - searching for "1" bits - working only with 32-bit words ratio, can be generalized - unsigned int start_data = 12; - if ((fragment_length - start_data) % 16 != 0) - { - cout<<"data length isn't aligned with 4 32-bit word"<<endl; - return -4; - } - int time_bin = 1; // starting from 1 - int pos_bits = sizeof(unsigned int)*8 - 1, pos; - for (unsigned int i = start_data; i < fragment_length; i += 16, time_bin++) - { - // 96 bit for every wire and 32 bit is empty (zero) - for (int j = 0; j < 3; j++) - { - x = buffer[cur_word++]; - if (x == 0) - continue; - - pos = pos_bits; - while ((pos--) >= 0) - { - if (CHECK_BIT(x, pos)) - { - // starting number from 0 - int active_wire = j*32 + pos; - - //cout<<"time stamp: "<<event_timestamp<<", bin: "<<time_bin<<"; MWPC: "<<MWPC_number<<"; plane: "<<plane_number<<"; wire: "<<active_wire<<endl; - //sleep(1); - - BmnMwpcDigit* pDigit = new BmnMwpcDigit(plane_number, active_wire, time_bin, -1); - - pDigitsPlane->push_back(pDigit); - } - } - } - cur_word++; - }// for detector's wires -*/ - // skip M-Link CRC - //cur_word++; - - //cout<<endl<<endl; - }// while not end of file - - cout<<"exit of parsing file"<<" iterations count: "<<ind<<endl; - cout<<"event count: "<<fEventData->size()<<endl; - //cout<<"max_event_diff: "<<max_event_diff<<endl; - //sleep(1); - - return 0; -} - -void RawDataParser::GenerateMWPCFileNames(char* raw_file_name_begin, map<int, int>* p_device_serial, TString* mwpc_file_names) -{ - map<int,int>::iterator it_planes = p_device_serial->begin(); - - // cycle for six plane (six device identificator) - for (int i = 1; i <= p_device_serial->size(); i++, it_planes++) - { - mwpc_file_names[i-1] = raw_file_name_begin; - mwpc_file_names[i-1] += int_to_hex_string(it_planes->first); - mwpc_file_names[i-1] += ".dat"; - //cout<<"MWPC: "<<mwpc_file_names[i-1]<<endl; - } -} - -void RawDataParser::ParseHRBFiles(vector<EventData*>* pEventData, TString* raw_file_names, long* lStart) -{ - // buffer with 4-bytes words - unsigned int* buffer; - long lSize, curStart; - size_t size; - FILE* pRawFile; - - for (int mwpc_iter = 1; mwpc_iter < 3; mwpc_iter++) - { - // cycle for six plane (six device identificator) - for (int i = 1; i <= 6; i++) - { - pRawFile = fopen(replace_vmc_path_linux(raw_file_names[(mwpc_iter-1)*6 + (i-1)].Data()).data(), "rb"); - if (pRawFile == NULL) - { - fprintf(stderr,"Error opening file (%s): %s\n", strerror(errno), raw_file_names[(mwpc_iter-1)*6 + (i-1)].Data()); - return; - } - - // obtain file size: - fseek(pRawFile, 0, SEEK_END); - lSize = ftell(pRawFile); - - if (lStart == NULL) - curStart = 0; - else - curStart = lStart[(mwpc_iter-1)*6 + (i-1)]; - - if (lSize <= curStart) - { - fclose(pRawFile); - return; - } - - fseek(pRawFile, curStart, SEEK_SET); - - // allocate memory containing new tail of file: - buffer = new unsigned int[(lSize-curStart) / 4]; - if (buffer == NULL) - { - fputs("Memory error", stderr); - fclose(pRawFile); - return; - } - - // copy the file into the buffer: - size = fread(buffer, 4, (lSize-curStart)/4, pRawFile); - if (size != (lSize-curStart)/4) - { - fputs("Reading error", stderr); - free(buffer); - fclose(pRawFile); - return; - } - - // the whole file is now loaded in the memory 'buffer' - fclose(pRawFile); - - //parse the data - int result_error = ParseHRB2Buffer(buffer, (lSize-curStart)/4, pEventData); - - free(buffer); - - if (lStart != NULL) - lStart[(mwpc_iter-1)*6 + (i-1)] = lSize; - }// for cycle for six plane (six device identificator) - }// for cycle for MWPC detectors - - return; -} diff --git a/eventdisplay/raw/RawDataParser.h b/eventdisplay/raw/RawDataParser.h deleted file mode 100644 index 958f2b6..0000000 --- a/eventdisplay/raw/RawDataParser.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef RAWDATAPARSER_H -#define RAWDATAPARSER_H - -#include "BmnMwpcDigit.h" - -#include <map> - -class EventData : public TObject -{ - public: - ULong64_t event_timestamp; - - vector<BmnMwpcDigit*> MWPC1Planes[6]; - vector<BmnMwpcDigit*> MWPC2Planes[6]; - - EventData() - { - } - - EventData(const EventData& event_data) - { - //uiEventNumber = event_data.uiEventNumber; - event_timestamp = event_data.event_timestamp; - - for (int i = 0; i < 6; i++) - MWPC1Planes[i] = event_data.MWPC1Planes[i]; - - for (int i = 0; i < 6; i++) - MWPC2Planes[i] = event_data.MWPC2Planes[i]; - } - - virtual ~EventData() {} - - ClassDef(EventData, 0) //EventData -}; - -class RawDataParser -{ - public: - //map with device identificator corresponding plane number (starting with 1) - map<int, int> device_serial; // { {0x1A8D, 1}, {0x2950, 2}, {0x3043, 3}, {0x304E, 4}, {0x4514, 5}, {0x45DF, 6} }; - map<int, int> device_serial1; // { {0x3F8B, 1}, {0x2950, 2}, {0x4514, 3}, {0x4504, 4}, {0x3043, 5}, {0x304E, 6} }; - map<int, int> device_serial2; // { {0x47CB, 1}, {0x2A79, 2}, {0x3F1D, 3}, {0x4513, 4}, {0x3F97, 5}, {0x2FFF, 6} }; - - /** Default constructor **/ - RawDataParser(); - /** Destructor **/ - virtual ~RawDataParser(); - - //buffer - unsigned int array from file with HRB Raw Data Format 1.0 (MWPC) - //size - size of 'buffer' variable in words (unsigned int) - //fEventData - vector with EventData objects - int ParseHRB1Buffer(unsigned int* buffer, long size, vector<EventData*>* fEventData); - - //buffer - unsigned int array from file with HRB Raw Data Format 2.0 (MWPC) - //size - size of 'buffer' variable in words (unsigned int) - //fEventData - vector with EventData objects - int ParseHRB2Buffer(unsigned int* buffer, long size, vector<EventData*>* fEventData); - - //buffer - unsigned int array from file with MStreamWaveformDigitizer Format (ZDC + ECAL) - //size - size of 'buffer' variable in words (unsigned int) - //fEventData - vector with EventData objects - int ParseWaveBuffer(unsigned int* buffer, long size, vector<EventData*>* fEventData); - - void GenerateMWPCFileNames(char* raw_file_name_begin, map<int, int>* device_serial, TString* mwpc_file_names); - void ParseHRBFiles(vector<EventData*>* pEventData, TString* raw_file_names, long* lStart = NULL); -}; - -#endif // RAWDATAPARSER_H diff --git a/eventdisplay/raw/RawMWPCDigitDraw.cxx b/eventdisplay/raw/RawMWPCDigitDraw.cxx deleted file mode 100644 index 10e3301..0000000 --- a/eventdisplay/raw/RawMWPCDigitDraw.cxx +++ /dev/null @@ -1,156 +0,0 @@ -п»ї// ------------------------------------------------------------------------- -// ----- RawMWPCDigitDraw source file ----- -// ----- ----- -// ------------------------------------------------------------------------- -#include "RawMWPCDigitDraw.h" - -#include "TEveManager.h" -#include "TEveTreeTools.h" -#include "TString.h" - -#include <iostream> -using namespace std; - -// ----- Default constructor ------------------------------------------- -RawMWPCDigitDraw::RawMWPCDigitDraw() - : FairTask("RawMWPCDigitDraw", 0), - fVerbose(0), - fEventManager(NULL), - fq(NULL), - fColor(0), - fStyle(0) -{ - pEventData = new vector<EventData*>(); -} - -// ----- Standard constructor ------------------------------------------ -RawMWPCDigitDraw::RawMWPCDigitDraw(const char* name, Color_t color ,Style_t mstyle,Int_t iVerbose) - : FairTask(name, iVerbose), - fVerbose(iVerbose), - fEventManager(NULL), - fq(NULL), - fColor(color), - fStyle(mstyle) -{ - pEventData = new vector<EventData*>(); -} - -// ------------------------------------------------------------------------- -InitStatus RawMWPCDigitDraw::Init() -{ - if (fVerbose > 1) - cout<<"RawMWPCDigitDraw::Init()"<<endl; - - // read source files and generate vector of EventData objects - RawDataParser raw_parser; - - TString* mwpc_names = new TString[12]; - raw_parser.GenerateMWPCFileNames(source_file_name, &raw_parser.device_serial1, mwpc_names); - raw_parser.GenerateMWPCFileNames(source_file_name, &raw_parser.device_serial2, &mwpc_names[6]); - - raw_parser.ParseHRBFiles(pEventData, mwpc_names); - - delete[] mwpc_names; - - fEventManager = FairEventManager::Instance(); - if (fVerbose > 2) - cout<<"RawMWPCDigitDraw::Init() get instance of FairEventManager "<<endl; - - //cout<<endl<<"fEntryCount "<<fEventManager->fEntryCount<<" Event Count "<<pEventData->size()<<endl; - if (fEventManager->fEntryCount == 0) - fEventManager->fEntryCount = pEventData->size(); - else - fEventManager->fEntryCount = TMath::Min(fEventManager->fEntryCount, (Long64_t)pEventData->size()); - - return kSUCCESS; -} - -void RawMWPCDigitDraw::Exec(Option_t* option) -{ - if (IsActive()) - { - Reset(); - - Int_t event_number = fEventManager->GetCurrentEvent(); - - // convert EventData object to vector of coordinates - if (event_number >= pEventData->size()) - { - cout<<"Programming Error: event_number >= EventData vector size : "<<event_number<<" >= "<<pEventData->size()<<endl; - return; - } - - EventData* curEvent = (*pEventData)[event_number]; - cout<<"Event processing: "<<event_number<<endl; - - RawDataConverter raw_converter; - vector<TVector3*> event_hits = raw_converter.MWPCEventToGeoVector(curEvent); - - Int_t npoints = event_hits.size(); - cout<<"Point vector size: "<<npoints<<endl; - - TEvePointSet* q = new TEvePointSet(GetName(), npoints, TEvePointSelectorConsumer::kTVT_XYZ); - q->SetOwnIds(kTRUE); - q->SetMarkerColor(fColor); - q->SetMarkerSize(1.5); - q->SetMarkerStyle(fStyle); - - for (Int_t i = 0; i < npoints; i++) - { - TVector3* vec = event_hits.at(i); - if (vec != 0) - { - q->SetNextPoint(vec->X(),vec->Y(), vec->Z()); - q->SetPointId(new TNamed(Form("Point %d", i),"")); - } - } - - if (fEventManager->EveRecoPoints == NULL) - { - fEventManager->EveRecoPoints = new TEveElementList("Reco points"); - gEve->AddElement(fEventManager->EveRecoPoints, fEventManager); - fEventManager->EveRecoPoints->SetRnrState(kFALSE); - } - - gEve->AddElement(q, fEventManager->EveRecoPoints); - - gEve->Redraw3D(kFALSE); - - fq = q; - }//if IsActive() -} - -TObject* RawMWPCDigitDraw::GetValue(TObject* obj,Int_t i) -{ - return new TNamed(Form("Point %d", i),""); -} - -// ----- Destructor ---------------------------------------------------- -RawMWPCDigitDraw::~RawMWPCDigitDraw() -{ - delete pEventData; -} - -// ------------------------------------------------------------------------- -void RawMWPCDigitDraw::SetParContainers() -{ -} - -// ------------------------------------------------------------------------- -/** Action after each event**/ -void RawMWPCDigitDraw::Finish() -{ -} - -// ------------------------------------------------------------------------- -void RawMWPCDigitDraw::Reset() -{ - if (fq != 0) - { - fq->Reset(); - - gEve->RemoveElement(fq, fEventManager->EveRecoPoints); - } -} - -ClassImp(RawMWPCDigitDraw); diff --git a/eventdisplay/raw/RawMWPCDigitDraw.h b/eventdisplay/raw/RawMWPCDigitDraw.h deleted file mode 100644 index 3faa18a..0000000 --- a/eventdisplay/raw/RawMWPCDigitDraw.h +++ /dev/null @@ -1,68 +0,0 @@ -// ------------------------------------------------------------------------- -// ----- RawMWPCDigitDraw header file ----- -// ----- ----- -// ------------------------------------------------------------------------- - - -#ifndef RAWMWPCDIGITDRAW_H -#define RAWMWPCDIGITDRAW_H - -#include "RawDataConverter.h" - -#include "FairTask.h" -#include "FairEventManager.h" - -#include "TEvePointSet.h" -#include "TObject.h" -#include "TVector3.h" - -#include <vector> - -class RawMWPCDigitDraw : public FairTask -{ - public: - /** Default constructor **/ - RawMWPCDigitDraw(); - - - /** Standard constructor - *@param name Name of task - *@param iVerbose Verbosity level - **/ - RawMWPCDigitDraw(const char* name, Color_t color ,Style_t mstyle, Int_t iVerbose = 1); - - /** Destructor **/ - virtual ~RawMWPCDigitDraw(); - - /** Set verbosity level. For this task and all of the subtasks. **/ - void SetVerbose(Int_t iVerbose) { fVerbose = iVerbose; } - /** Executed task **/ - virtual void Exec(Option_t* option); - void Reset(); - - char* source_file_name; //! - - protected: - //TVector3 GetVector(TObject* obj); - TObject* GetValue(TObject* obj,Int_t i); - - Int_t fVerbose; // Verbosity level - virtual void SetParContainers() ; - virtual InitStatus Init(); - /** Action after each event**/ - virtual void Finish(); - - FairEventManager* fEventManager; //! - TEvePointSet* fq; //! - Color_t fColor; //! - Style_t fStyle; //! - vector<EventData*>* pEventData; //! - - private: - RawMWPCDigitDraw(const RawMWPCDigitDraw&); - RawMWPCDigitDraw& operator=(const RawMWPCDigitDraw&); - - ClassDef(RawMWPCDigitDraw,1); -}; - -#endif diff --git a/eventdisplay/raw/function_set.h b/eventdisplay/raw/function_set.h deleted file mode 100644 index 2036a53..0000000 --- a/eventdisplay/raw/function_set.h +++ /dev/null @@ -1,479 +0,0 @@ -//============================================================================ -// Name : function_set.h -// Author : Konstantin Gertsenberger (gertsen@jinr.ru) -// Description : set of common C++ functions -// Version : 1.00 -//============================================================================ - -#ifndef FUNCTION_SET_H -#define FUNCTION_SET_H - -// C++ includes -#include <unistd.h> -#include <iostream> -#include <cstring> -#include <string> -#include <stdlib.h> -#include <stdio.h> -#include <sstream> -#include <ctime> -//#include <sys/types.h> -#include <sys/stat.h> - -using namespace std; - -/* declarations */ - -/* OS FUNCTIONS */ -// execute system command in shell (bash) -int system_command_linux(string aCommand, string& result); -// change tilda symbol on HOME in linux path -string replace_home_symbol_linux(string path); -// change $VMCWORKDIR symbol in linux path -string replace_vmc_path_linux(string path); -// get processor core count on this machine -int get_linux_processor_count(); -// get maximum available processor count on Sun Grid Engine system -int get_sge_processor_count(); -// get maximum available processor count on Torque batch system -int get_torque_processor_count(); - -/* GLOBAL APPLICATION FUNCTIONS */ -// get application name in linux -string get_app_name_linux(); -// get aplication directory (path without file name) in linux -string get_app_dir_linux(); - -/* NUMBER FUNCTIONS */ -// check bit in 'variable' at 'position' -#define CHECK_BIT(variable,position) ((variable) & (1ULL<<(position))) - -/* STRING FUNCTIONS */ -// convert integer number to string -string convert_int_to_string(int number); -// convert integer (hexadecimal value) to string with hexadecimal presentation without "0x" -string int_to_hex_string(int int_number); -// convert string with hexadecimal presentation without "0x" to integer -int hex_string_to_int(string hex_string); -// is string an integer number? -bool is_string_number(const string& s); -// convert array of chars to the new lowercase array -char* convert_pchar_to_lowercase_new(char* input_char_array); -// replace string 's' by string 'd' in text -void replace_string_in_text(string &text, string s, string d); -// return string without leading and trailing spaces and tabs -string trim(const string& str, const string& whitespace = " \t\r"); -// return string changing whitespaces and tabs by single whitespace -string reduce(const string& str, const string& fill = " ", const string& whitespace = " \t\r"); - -/* DIR & FILE FUNCTIONS */ -// check directory exists: 0 - not exists, 1 - exists, -2 - cannot access -int check_directory_exist(const char* path); -// check and create directory if not exists: 0 - not existed before, 1 - existed, -1 - errno error, -2 - cannot access -int create_directory(const char* path); -// get file name without extension from a path -string get_file_name(string path); -// get file name with extension from path -string get_file_name_with_ext(string path); - -/* TIME FUNCTIONS */ -// get current date as string -string get_current_date(); - - -#ifndef ONLY_DECLARATIONS - - -/* */ -/* */ -/* OS FUNCTIONS */ -/* */ -/* */ - -// execute system command in shell (bash) -int system_command_linux(string aCommand, string& result) -{ - FILE* f; - if (!(f = popen(aCommand.c_str(), "r"))) - { - cout<<"system_command_linux error: popen failed"<<endl; - return 1; - } - - const int BUFSIZE = 4096; - char buf[BUFSIZE]; - if (fgets(buf,BUFSIZE,f) != NULL) - result = buf; - - pclose(f); - return 0; -} - -// change tilda symbol on HOME in linux path -string replace_home_symbol_linux(string path) -{ - size_t np = path.find_first_of('~'); - if (np != string::npos) - { - bool isNewPath = false; - char* pPath = getenv("HOME"); - if (pPath == NULL) - { - pPath = new char[2]; - pPath[0] = '/'; - pPath[1] = '\0'; - isNewPath = true; - } - - do - { - path.erase(np, 1); - path.insert(np, pPath); - np = path.find_first_of('~'); - } while (np != string::npos); - - if (isNewPath) - delete[] pPath; - } - - return path; -} - -// change $VMCWORKDIR symbol in linux path -string replace_vmc_path_linux(string path) -{ - char* pPath = getenv("VMCWORKDIR"); - bool isNewPath = false; - if (pPath == NULL) - { - pPath = new char[2]; - pPath[0] = '/'; - pPath[1] = '\0'; - isNewPath = true; - } - - size_t found; - while ((found = path.find("$VMCWORKDIR")) != string::npos) - { - path.replace(found, 11, pPath); - } - - if (isNewPath) - delete[] pPath; - - return path; -} - -// get processor core count on this machine -int get_linux_processor_count() -{ - return sysconf(_SC_NPROCESSORS_ONLN); -} - -// get maximum available processor count on Sun Grid Engine system -int get_sge_processor_count() -{ - int proc_count = 0; - - const int MAX_BUFFER = 255; - char buffer[MAX_BUFFER]; - - // define count of processors for all.q queue - string data, strDiff; - FILE* stream = popen("export SGE_SINGLE_LINE=1; qconf -sq all.q | grep slots", "r"); - while (fgets(buffer, MAX_BUFFER, stream) != NULL) - data.append(buffer); - pclose(stream); - - size_t found = data.find("="), found2 = string::npos; - while (found != string::npos) - { - found2 = data.find("]", found); - strDiff = data.substr(found+1, found2 - found - 1); - proc_count += atoi(strDiff.c_str()); - strDiff.clear(); - - found = data.find("=", found2); - } - - data.clear(); - - cout<<"SGE processor count: "<<proc_count<<endl; - - return proc_count; -} - -// get maximum available processor count on Torque batch system -int get_torque_processor_count() -{ - int proc_count = 0; - - const int MAX_BUFFER = 255; - char buffer[MAX_BUFFER]; - - // define count of processors for all.q queue - string data, strDiff; - FILE* stream = popen("qconf -sq all.q | grep slots", "r"); - while (fgets(buffer, MAX_BUFFER, stream) != NULL) - data.append(buffer); - pclose(stream); - - size_t found = data.find("="), found2 = string::npos; - while (found != string::npos) - { - found2 = data.find("]", found); - strDiff = data.substr(found+1, found2 - found - 1); - proc_count += atoi(strDiff.c_str()); - strDiff.clear(); - - found = data.find("=", found2); - } - - data.clear(); - - return proc_count; -} - - -/* */ -/* */ -/* GLOBAL APPLICATION FUNCTIONS */ -/* */ -/* */ - -// get application name in linux -string get_app_name_linux() -{ - pid_t procpid = getpid(); - stringstream toCom; - toCom << "cat /proc/" << procpid << "/comm"; - string fRes=""; - system_command_linux(toCom.str(), fRes); - size_t last_pos = fRes.find_last_not_of(" \n\r\t") + 1; - if (last_pos != string::npos) - fRes.erase(last_pos); - - return fRes; -} - -// get aplication directory (path without file name) in linux -string get_app_dir_linux() -{ - pid_t procpid = getpid(); - string appName = get_app_name_linux(); - stringstream command; - command << "readlink /proc/" << procpid << "/exe | sed \"s/\\(\\/" << appName << "\\)$//\""; - string fRes; - system_command_linux(command.str(),fRes); - - // remove '\n' from end of the string and add final '/' - fRes = fRes.erase(fRes.length()-1, 1); - fRes.push_back('/'); - - return fRes; -} - - -/* */ -/* */ -/* NUMBER FUNCTIONS */ -/* */ -/* */ - - - -/* */ -/* */ -/* STRING FUNCTIONS */ -/* */ -/* */ - -// convert integer number to string -string convert_int_to_string(int number) -{ - stringstream ss; - ss<<number; - return ss.str(); -} - -// convert integer (hexadecimal value) to string with hexadecimal presentation without "0x" -string int_to_hex_string(int int_number) -{ - stringstream stream; - stream<<std::hex<<int_number; - return stream.str(); -} - -// convert string with hexadecimal presentation without "0x" to integer -int hex_string_to_int(string hex_string) -{ - int x; - stringstream stream; - stream<<std::hex<<hex_string; - stream>>x; - return x; -} - -// is string an integer number? -bool is_string_number(const string& s) -{ - string::const_iterator it = s.begin(); - while (it != s.end() && std::isdigit(*it)) ++it; - return !s.empty() && it == s.end(); -} - -// convert array of chars to the new lowercase array -char* convert_pchar_to_lowercase_new(char* input_char_array) -{ - if (input_char_array == NULL) - return NULL; - - const int length = strlen(input_char_array); // get the length of the text - char* lower = new char[length + 1]; // allocate 'length' bytes + 1 (for null terminator) and cast to char* - lower[length] = 0; // set the last byte to a null terminator - - // copy all character bytes to the new buffer using tolower - for( int i = 0; i < length; i++ ) - lower[i] = tolower(input_char_array[i]); - - - return lower; -} - -// replace string 's' by string 'd' in text -void replace_string_in_text(string &text, string old_substring, string new_substring) -{ - int start = -1; - - do - { - start = text.find(old_substring, start + 1); - if (start > -1) - text.replace(start, old_substring.length(), new_substring.c_str()); - } - while (start > -1); -} - -// return string without leading and trailing spaces and tabs -string trim(const string& str, const string& whitespace) -{ - size_t strBegin = str.find_first_not_of(whitespace); - if (strBegin == string::npos) - return ""; // no content - - size_t strEnd = str.find_last_not_of(whitespace); - size_t strRange = strEnd - strBegin + 1; - - return str.substr(strBegin, strRange); -} - -// return string changing whitespaces and tabs by single whitespace -string reduce(const string& str, const string& fill, const string& whitespace) -{ - // trim first - string result = trim(str, whitespace); - - // replace sub ranges - size_t beginSpace = result.find_first_of(whitespace); - while (beginSpace != string::npos) - { - size_t endSpace = result.find_first_not_of(whitespace, beginSpace); - size_t range = endSpace - beginSpace; - - result.replace(beginSpace, range, fill); - - size_t newStart = beginSpace + fill.length(); - beginSpace = result.find_first_of(whitespace, newStart); - } - - return result; -} - - -/* */ -/* */ -/* DIR & FILE FUNCTIONS */ -/* */ -/* */ - -// check directory exists: 0 - not exists, 1 - exists, -2 - cannot access -int check_directory_exist(const char* path) -{ - struct stat info; - - if (stat(path, &info) != 0) - return -2; - else if (info.st_mode & S_IFDIR) - return 1; - else - return 0; -} - -// check and create directory if not exists: 0 - not existed before, 1 - existed, -1 - errno error, -2 - cannot access -int create_directory(const char* path) -{ - struct stat info; - - if (stat(path, &info) != 0) - return -2; - else if (info.st_mode & S_IFDIR) - return 1; - else - { - int status = mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - return status; - } -} - -// get file name without extension from a path -string get_file_name(string path) -{ - // Remove directory if present. - size_t last_slash_idx = path.find_last_of("/"); - if (string::npos != last_slash_idx) - path.erase(0, last_slash_idx + 1); - - // Remove extension if present. - size_t period_idx = path.rfind('.'); - if (string::npos != period_idx) - path.erase(period_idx); - - return path; -} - -// get file name with extension from path -string get_file_name_with_ext(string path) -{ - // Remove directory if present. - size_t last_slash_idx = path.find_last_of("/"); - if (string::npos != last_slash_idx) - path.erase(0, last_slash_idx + 1); - - return path; -} - - -/* */ -/* */ -/* TIME FUNCTIONS */ -/* */ -/* */ - -// get current date as string -string get_current_date() -{ - time_t rawtime; - time(&rawtime); - - struct tm* timeinfo; - timeinfo = localtime(&rawtime); - - char buffer[80]; - strftime(buffer, 80, "%d-%m-%Y", timeinfo); - string str(buffer); - - return str; -} - -#endif /* ONLY_DECLARATIONS */ -#endif /* FUNCTION_SET_H */ diff --git a/macro/mpd_scheduler b/macro/mpd_scheduler index 6fa6c4e..359776e 160000 --- a/macro/mpd_scheduler +++ b/macro/mpd_scheduler @@ -1 +1 @@ -Subproject commit 6fa6c4e754ee426a963539351e0c9190d538b2ea +Subproject commit 359776e24be261ff7b620c0b6b04214308a5ef7e -- GitLab