Commit 8c46864b authored by J.Dudouet [IPNL/CSNSM]'s avatar J.Dudouet [IPNL/CSNSM]
Browse files

Add of the BashColor class


git-svn-id: svn+ssh://anonsvn.in2p3.fr/agata/gammaware/trunk@2023 c3abf467-7ff2-0310-b516-c5fb849bdde0
parent 56f9a13c
......@@ -19,8 +19,9 @@
#include "TStyle.h"
#include "TPaveStats.h"
#include "TPaveText.h"
#include "TSystem.h"
ClassImp(KeyWatcher);
//ClassImp(KeyWatcher);
KeyWatcher::KeyWatcher( const char * name, const char * title, TDirectory *sp_dir, TDirectory *tag_dir):
Watcher(name,title,sp_dir,tag_dir),
......@@ -30,7 +31,8 @@ KeyWatcher::KeyWatcher( const char * name, const char * title, TDirectory *sp_di
LastTimeStamp(0),
fLastFillSec(0),
fLastFillMin(0),
fLastFillH(0)
fLastFillH(0),
fBashColor(new BashColor())
{
fHistInSec = MakeTH1<TH1F>((TString)name+"_1hour",(TString)title+" on 1 hour (1bin=100#mus)",36000,0,3600);
fHistInMin = MakeTH1<TH1F>((TString)name+"_12hour",(TString)title+" on 12 hour (1bin=6s)",7200,0,720);
......@@ -61,6 +63,8 @@ KeyWatcher::KeyWatcher( const char * name, const char * title, TDirectory *sp_di
NextCycleMin = 720.;
NextCycleH = 48.;
IsDumpKeysActive = false;
fDumpKeyFile = 0x0;
}
Bool_t KeyWatcher::SetTrigger( ADF::DFTrigger *trigger )
......@@ -240,7 +244,10 @@ void KeyWatcher::Exec(Option_t * /*option*/)
TString MessageType = AgataKeyFactory::theFactory()->GetMessage(MainKey->GetMessage());
if(!fHistMessageType->GetXaxis()->FindBin(MessageType)) cout<<"WARNING ! Unknown message type : "<<MessageType<<endl;
if(IsDumpKeysActive) MainKey->GetRealBuffer()->Export(fDumpKeyFile,MainKey->GetKeyLength());
if(!fHistMessageType->GetXaxis()->FindBin(MessageType))
cout<<"WARNING ! Unknown message type : "<<MessageType<<endl;
else fHistMessageType->Fill(MessageType,1);
UInt_t length, current, eventnumber, message; ULong64_t timestamp; TString SubMess;
......@@ -602,3 +609,47 @@ void KeyWatcher::ShowMessageType()
st->SetY2NDC(1-topmarg);
}
void KeyWatcher::DumpKeys(bool ActiveDump)
{
if( !IsDumpKeysActive && ActiveDump)
{
std::ostringstream filename;
int fCurrentFileNumber = 0;
filename << (TString)GetName() + "_" << std::setfill('0') << std::setw(4) << fCurrentFileNumber << ".keys";
while(gSystem->IsFileInIncludePath(filename.str().data()))
{
filename.str("");
filename << (TString)GetName() + "_" << std::setfill('0') << std::setw(4) << fCurrentFileNumber++ << ".keys";
}
fDumpKeyFile = ::fopen(filename.str().data(),"wb");
fFileName = filename.str();
fBashColor->SetInfoOut();
cout<<"Keys will be dumped in the file : "<<fFileName<<endl;
}
else if( IsDumpKeysActive && !ActiveDump )
{
if ( fDumpKeyFile ) ::fclose(fDumpKeyFile);
fDumpKeyFile = 0x0;
fBashColor->SetInfoOut();
cout<<"Dumped-keys file : "<<fFileName<<" is close !"<<endl;
}
else if( IsDumpKeysActive && ActiveDump )
{
fBashColor->SetWarningOut();
cout<<"Keys dumping already active"<<endl;
}
else if( !IsDumpKeysActive && !ActiveDump )
{
fBashColor->SetWarningOut();
cout<<"Keys dumping is not active"<<endl;
}
IsDumpKeysActive = ActiveDump;
fBashColor->ResetColor();
}
......@@ -5,6 +5,7 @@
#include "TH2.h"
#include "CanvasVisu.h"
#include "BashColor.h"
#include "Watchers.h"
#include "AgataKeyFactory.h"
......@@ -15,6 +16,9 @@ using namespace Gw;
class KeyWatcher : public Watcher, public CanvasVisu
{
private:
BashColor *fBashColor;
protected:
SharedFP *fFrame;
......@@ -48,6 +52,11 @@ protected:
double fLastFillMin;
double fLastFillH;
protected:
FILE *fDumpKeyFile;
bool IsDumpKeysActive;
TString fFileName;
public:
KeyWatcher(const char * name, const char * title, TDirectory *sp_dir = 0x0, TDirectory *tag_dir = 0x0);
virtual ~KeyWatcher() {;}
......@@ -66,6 +75,8 @@ public:
ULong64_t GetFirstTS(){return FirstTimeStamp;}
void DumpKeys(bool ActiveDump = false); //*MENU*;
ClassDef(KeyWatcher,0) // To get a 3D map of hits in a particular crystal
};
......
......@@ -38,8 +38,8 @@ set( without_dictionnaries
BaseBuffer
BasicAFC
BasicAFP
ReadMezzAFP
BufferIO
BufferIO
ReadMezzAFP
ADFCentralLog
CompositeFrame
ConfAgent
......
......@@ -32,8 +32,6 @@
#include "AgataFrameFactory.h"
#include "AgataKeyFactory.h"
using namespace ADF;
ReadMezzAFP::ReadMezzAFP():
NarvalProducer(),
fSourceOfFrames(aMByte,ConfAgent::kRead),
......@@ -47,7 +45,9 @@ ReadMezzAFP::ReadMezzAFP():
fEndOfFrame("EndOfFrame"),
fFrameCrystal_Out(NULL),
fTrigger("data:crystal"),
fdebug(false)
fdebug(false),
fBashColor(new BashColor()),
fUseKeyFilter(false)
{
if(fdebug) std::cout<<"\E[31;1m"<<"Construct in"<<"\E[m"<<std::endl;
......@@ -299,13 +299,35 @@ void ReadMezzAFP::process_initialise (unsigned int *error_code)
}
fConfMode = 2;
}
if( tmp[0] == 'f' ) { // the .conf contains a key filter
std::string pathforfilter;
decode >> option >> pathforfilter;
if(decode.good()){
fKeyFilterFile = 0x0;
fKeyFilterFile = ::fopen(pathforfilter.data(),"rb");
if(fKeyFilterFile = 0x0)
{
fBashColor->SetErrorOut();
std::cout<<"Key filter file not found, key filter ignored !"<<std::endl;
fBashColor->ResetColor();
}
else
{
fBashColor->SetInfoOut();
std::cout<<"Key filter file : "<<pathforfilter<<" will be used !"<<std::endl;
fBashColor->ResetColor();
fUseKeyFilter = true;
}
}
}
getline(filein,tmp);
tmp += " ";
}
}
else
{
std::cout<<conffile.data()<<" not found !"<<std::endl;
std::cout<<"\E[31;1m"<<conffile.data()<<" not found !"<<"\E[m"<<std::endl;
}
filein.close();
......@@ -328,7 +350,10 @@ void ReadMezzAFP::process_initialise (unsigned int *error_code)
// Read the crystal producer conf file
std::string ConfFilePath = fPath;
replace(ConfFilePath,"/Data/","/Conf/");
std::vector<std::string> token = split(ConfFilePath,'/');
replace(ConfFilePath,token[token.size()-3],"/Conf/");
ConfFilePath += "CrystalProducer.conf";
std::ifstream ProdConfFile(ConfFilePath.data());
......@@ -351,7 +376,7 @@ void ReadMezzAFP::process_initialise (unsigned int *error_code)
}
else
{
std::cout<<ConfFilePath.data()<<" not found !"<<std::endl;
std::cout<<"\E[31;1m"<<ConfFilePath.data()<<" not found !"<<"\E[m"<<std::endl;
return;
}
......
......@@ -28,6 +28,10 @@
#include "FrameBlock.h"
#include "Trigger.h"
#include "BashColor.h"
#include "BufferIO.h"
#include <list>
#include <utility>
#include <vector>
......@@ -36,6 +40,9 @@
/*!
*/
using namespace ADF;
class ReadMezzAFP : public ADF::NarvalProducer
{
public:
......@@ -72,6 +79,13 @@ private:
private:
bool fdebug;
BashColor *fBashColor;
protected:
FILE * fKeyFilterFile;
bool fUseKeyFilter;
BufferIO *fKeyFilterBuffer;
protected:
unsigned short crystal_id;
......
/***************************************************************************
* Copyright (c) IPNL, IN2P3, CNRS *
* Contibutor(s) : *
* Jeremie Dudouet dudouet(AT)ipnl.in2p3.fr [2014] *
* Olivier Stezowski stezow(AT)ipnl.in2p3.fr [2014] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "BashColor.h"
BashColor::BashColor()
{
fColor = "";
fType = "0;3";
}
BashColor::~BashColor()
{
}
void BashColor::SetType(bType type)
{
switch (type) {
case kRegular:
fType = "0;3";
break;
case kBold:
fType = "1;3";
break;
case kUnderline:
fType = "4;3";
break;
case kBoldUnderline:
fType = "1;4;3";
break;
case kBackGround:
fType = "0;4";
break;
case kHighIntensity:
fType = "0;9";
break;
case kBoldHighIntensity:
fType = "1;9";
break;
case kHighIntensityBackground:
fType = "0;10";
break;
}
ProcessColor();
}
void BashColor::SetColor(BColor col)
{
std::ostringstream oss;
oss<<col;
fColor = oss.str();
ProcessColor();
}
void BashColor::ProcessColor()
{
std::string s = "\e[" + fType + fColor + "m";
std::cout<<s;
}
void BashColor::ResetColor()
{
fColor = "";
fType = "0";
ProcessColor();
fColor = "";
fType = "0;3";
}
void BashColor::SetErrorOut()
{
SetColor(kRed);
SetType(kBoldHighIntensity);
}
void BashColor::SetWarningOut()
{
SetColor(kYellow);
SetType(kBoldUnderline);
}
void BashColor::SetInfoOut()
{
SetColor(kBlue);
SetType(kBoldHighIntensity);
}
/***************************************************************************
* Copyright (c) IPNL, IN2P3, CNRS *
* Contibutor(s) : *
* Jeremie Dudouet dudouet(AT)ipnl.in2p3.fr [2014] *
* Olivier Stezowski stezow(AT)ipnl.in2p3.fr [2014] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef BashColor_H
#define BashColor_H
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
class BashColor
{
public:
//! current state of the FrameIO
enum BColor
{
kBlack = 0,
kRed = 1,
kGreen = 2,
kYellow = 3,
kBlue = 4,
kPurple = 5,
kCyan = 6,
kWhite = 7
};
enum bType
{
kRegular = 0,
kBold = 1,
kUnderline = 2,
kBoldUnderline = 3,
kBackGround = 4,
kHighIntensity = 5,
kBoldHighIntensity = 6,
kHighIntensityBackground = 7
};
public:
BashColor();
virtual ~BashColor();
std::string fColor;
std::string fType;
void SetType(bType type);
void SetColor(BColor col);
void SetErrorOut();
void SetWarningOut();
void SetInfoOut();
void ProcessColor();
void ResetColor();
};
#endif
......@@ -42,6 +42,7 @@ set( without_dictionnaries
# ../../adf/LogCollector
# ../../adf/LogMessage
XtermProgressBar
BashColor
)
# add includes : root + current (before to have the latest) + all gw includes copied in CMAKE_BINARY_DIR/include
#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment