Commit 2d907c52 authored by Stezowski Olivier's avatar Stezowski Olivier
Browse files

New LogMessage operational (with indentation)

Add trigger WriteOnly and anti-coincidences (to be fully tested)
output frame added to the agent if not know
Run (subrun) number now written in conf frame



git-svn-id: svn+ssh://anonsvn.in2p3.fr/agata/gammaware/trunk@1431 c3abf467-7ff2-0310-b516-c5fb849bdde0
parent 5f00f3c7
......@@ -71,12 +71,12 @@ template <typename Prod_actor, typename Filt_actor, typename Cons_actor>
Bool_t EmulatorPFC<Prod_actor,Filt_actor,Cons_actor>::Init()
{
UInt_t err = 0u;
fLog.GetProcessMethod() = "Init";
fLog.SetProcessMethod("Init");
// just in case a actor forget to call it and it is required.
NarvalInterface::process_config(fPathProd.data(),&err);
if ( err > 0u ) {
fLog << warning << " in NarvalInterface::process_config " << dolog;
fLog << warning << " in NarvalInterface::process_config " << nline;
}
err = 0u;
......@@ -119,7 +119,8 @@ Bool_t EmulatorPFC<Prod_actor,Filt_actor,Cons_actor>::Init()
fLog << error << " in process_initialise for Consumer " << dolog;
return false;
}
return true;
fLog << dolog; return true;
}
......@@ -215,12 +216,12 @@ template <typename Prod_actor, typename Cons_actor>
Bool_t EmulatorPC<Prod_actor,Cons_actor>::Init()
{
UInt_t err = 0u;
fLog.GetProcessMethod() = "Init";
fLog.SetProcessMethod("Init");
// just in case a actor forget to call it and it is required.
NarvalInterface::process_config(fPathProd.data(),&err);
if ( err > 0u ) {
fLog << warning << " in NarvalInterface::process_config " << dolog;
fLog << warning << " in NarvalInterface::process_config " << nline;
}
err = 0u;
......@@ -250,7 +251,8 @@ Bool_t EmulatorPC<Prod_actor,Cons_actor>::Init()
fLog << error << " in process_initialise for Consumer " << dolog;
return false;
}
return true;
fLog << dolog; return true;
}
......
......@@ -132,6 +132,7 @@ void TestLOG()
lev3.ToLog_3();
printf("\n*************** Log cout, and depth *************** \n");
LogMessage::SetIndentParameters(1,2);
LogMessage::gkMaxDepth = 5;
/* LogMessage::gkAutoClear = 2; */
......
......@@ -13,16 +13,21 @@
<node CREATED="1242632992109" ID="Freemind_Link_1399566782" MODIFIED="1242633020494" TEXT="ADF">
<node CREATED="1239723004578" ID="Freemind_Link_123529709" MODIFIED="1239723007763" TEXT="Trigger">
<node CREATED="1239723009897" ID="Freemind_Link_628233298" MODIFIED="1239723030811" TEXT="Multiple output should be possible"/>
<node CREATED="1239723035793" ID="Freemind_Link_1038749396" MODIFIED="1239723074642" TEXT="Output should be added to ConfAgent &#xa;if not yet defined"/>
<node CREATED="1239723035793" ID="Freemind_Link_1038749396" MODIFIED="1270816477756" TEXT="Output should be added to ConfAgent &#xa;if not yet defined">
<icon BUILTIN="button_ok"/>
</node>
<node CREATED="1239801552955" ID="Freemind_Link_80049017" MODIFIED="1239801629983" TEXT="methods to Add already allocated frames">
<icon BUILTIN="help"/>
</node>
<node CREATED="1258039207093" ID="Freemind_Link_873562074" MODIFIED="1258039885789" TEXT="New class working with pointers on Frame. ">
<node CREATED="1258039207093" ID="Freemind_Link_873562074" MODIFIED="1270816498428" TEXT="New class working with pointers on Frame. ">
<icon BUILTIN="button_ok"/>
<hook NAME="accessories/plugins/NodeNote.properties">
<text>The pointer takes care of the suitable modifications for the Frame. Should be general enough&#xa;to trigg on event number, time stamp ... version ??? ... etc &#xa;&#xa;Possible name DFTrigger (Data Flow )</text>
</hook>
</node>
<node CREATED="1258382437422" ID="Freemind_Link_1508399804" MODIFIED="1258382453992" TEXT="Only input or output should be possible"/>
<node CREATED="1258382437422" ID="Freemind_Link_1508399804" MODIFIED="1270816511091" TEXT="Only input or output should be possible">
<icon BUILTIN="button_ok"/>
</node>
<node CREATED="1267028544882" ID="Freemind_Link_1606262057" MODIFIED="1267028594329" TEXT="add static Build method in AgataFrameTrigger ">
<icon BUILTIN="button_ok"/>
</node>
......
......@@ -115,7 +115,7 @@ public:
virtual UInt_t GetDataLength() const
{
UInt_t i = 0u; fBuffer->SetOffset(); (*fBuffer) >> i;
if ( i > kKeyLength )
if ( i >= kKeyLength )
i = i - kKeyLength ;
return i;
......
......@@ -24,6 +24,9 @@
#include "BasicAFC.h"
#endif
#include "RunAgent.h"
#include "MetaFrame.h"
#include <iostream>
#include <iomanip>
#include <fstream>
......@@ -36,12 +39,15 @@ BasicAFC::BasicAFC() :
fPath("./"),
fBaseForName("AFC_"),
fCurrentFile(0x0),
fCurrentFileNumber(0u),
fMaxSize(kMaxInt_t)
fMaxSize(kMaxInt_t),
fVertex(0x0)
{
Log.GetProcessName() = "BasicAFC"; Log.SetPID(GetPID());
// log system
Log.GetProcessName() = "BasicAFC";
Log.SetPID(GetPID());
// frameio related
GetFrameIO().SetName("BasicAFC");
// to be sure unknown frames are written in the ouput
GetFrameIO().SetModel(ConfAgent::kSafe);
// to protect readings in the source of frames
......@@ -65,13 +71,40 @@ void BasicAFC::process_config (const Char_t *directory_path, UInt_t *error_code)
}
}
void BasicAFC::SyncAgent()
{
Int_t run, subrun; // std::string expname;
// agent to be synchronized
ConfAgent *agent = GetFrameIO().GetConfAgent();
// ask Narval for different parameters
if ( NarvalInterface::GetGlobalParameter("run_number",run) != 0 )
run = agent->GetRunAgent()->GetRun(); // something goes wrong, does not change the current run number
// GetGlobalParameter("",expname); ??
// a new run is open, go back to zero for subrun otherwise keep the current value
if ( run != agent->GetRunAgent()->GetRun() )
subrun = 0;
else
subrun = agent->GetRunAgent()->GetSubRun();
// now change the status of the conf agent
agent->GetRunAgent()->SetRun(run, subrun);
}
Bool_t BasicAFC::NewFile()
{
Log.SetProcessMethod("NewFile");
Bool_t ok = false;
// close if already open
if ( fCurrentFile )
::fclose(fCurrentFile);
// ask NarvalInterface for exp name, run number etc ...
SyncAgent();
// open the file
std::string tmp = fPath;
......@@ -79,50 +112,80 @@ Bool_t BasicAFC::NewFile()
tmp += '/';
std::ostringstream filename;
filename << tmp << fBaseForName
<< std::setfill('0') << std::setw(4) << fCurrentFileNumber++ << std::setfill(' ')
<< ".adf";
filename << tmp << fBaseForName
<< std::setfill('0') << std::setw(4) << GetFrameIO().GetConfAgent()->GetRunAgent()->GetSubRun() << std::setfill(' ')
<< ".adf";
fCurrentFile = ::fopen(filename.str().data(),"wb");
if ( fCurrentFile != 0x0 ) {
Log << info << "A new output file has just been open "
<< filename.str();
Log << info << "A new output file has just been open " << filename.str() << nline;
fEndOfFrames.SetFile
(fCurrentFile,fMaxSize);
GetFrameIO().SetStatus
(BaseFrameIO::kIdle);
// add conf frame at the beginning of the file and a vertex frame.
GetFrameIO().RecordGlobalConfiguration();
if ( fVertex ) {
// interface to the vertex frame
VertexInterface *v = GetDataPointer<VertexInterface>(fVertex->GetOutputFrame());
if ( v ) {
// global doppler correction is in RunAgent
RunAgent *ragent = GetFrameIO().GetConfAgent()->GetRunAgent();
// copy from agent to frame then dump the frame on output
v->SetPosition(ragent->GetX(),ragent->GetY(),ragent->GetZ());
v->SetDirection(ragent->GetDX(),ragent->GetDY(),ragent->GetDZ());
v->SetBeta(ragent->GetBeta());
fVertex->GetOutputFrame()->Write();
// set to true
fVertex->Fired(true);
// and record
GetFrameIO().Record();
}
}
GetFrameIO().GetConfAgent()->GetRunAgent()->SetSubRun(GetFrameIO().GetConfAgent()->GetRunAgent()->GetSubRun()+1);
ok = true;
}
else {
Log << warning << "Cannot open file "
<< filename.str();
<< filename.str() << nline;
GetFrameIO().SetStatus(BaseFrameIO::kFinished);
}
return ok;
Log << dolog; return ok;
}
UInt_t BasicAFC::ProcessBlock (ADF::FrameBlock &in)
{
Log.ClearMessage(); Log.SetProcessMethod("ProcessBlock");
// attach the FrameBlocks
GetFrameIO().Attach(&in,0x0);
// fill the output block with the frames from the input block
while ( GetFrameIO().Notify() ) {
}
// interruption: means end of file or out is full
if ( GetFrameIO().GetCurrentBlockIN()->IsEoB() ) { // the file has been read
while ( 1 ) {
// fill the output block with the frames from the input block
while ( GetFrameIO().Notify() ) {
}
if ( GetFrameIO().GetCurrentBlockOUT()->IsEoB() ) { // the output file is full
NewFile();
continue;
}
// interruption: means end of file or out is full
if ( GetFrameIO().GetCurrentBlockIN()->IsEoB() ) // the input block is treated
break;
}
if ( GetFrameIO().GetCurrentBlockOUT()->IsEoB() ) { // the output block is full
NewFile();
}
//
GetFrameIO().Detach(&in,0x0);
return 0u;
// send messages to the log if any
Log << dolog; return 0u;
}
......@@ -131,8 +194,15 @@ void BasicAFC::process_initialise (UInt_t *error_code)
*error_code = 0;
Log.ClearMessage(); Log.SetProcessMethod("process_initialise");
// creates a trigger to register at the beginning of the file a global vertex frame
// that is initiated from ADF.conf
fVertex = AgataFrameTrigger::Build("GVertex","","meta:vertex");
if ( fVertex )
GetFrameIO().Register(fVertex);
// read an input file to get the base filename and the path
std::string conffile = GetConfPath();
std::string conffile =
GetConfPath();
conffile += "BasicAFC.conf";
std::ifstream filein(conffile.data());
......@@ -140,16 +210,16 @@ void BasicAFC::process_initialise (UInt_t *error_code)
std::string pathforfiles, basename;
UInt_t starting_number;
filein >> pathforfiles >> basename >> starting_number;
if ( filein.good() ) {
fPath = pathforfiles;
fBaseForName = basename;
fCurrentFileNumber = starting_number;
GetFrameIO().GetConfAgent()->GetRunAgent()->SetSubRun(starting_number);
}
filein.close();
}
filein.close();
// open the first file
if ( !NewFile() )
*error_code = 1;
......
......@@ -30,6 +30,7 @@
#include "Counter.h"
#endif
#include "Trigger.h"
//! basic consumer, it counts and dumps Frame in files
/*!
......@@ -37,22 +38,27 @@
class BasicAFC : public ADF::NarvalConsumer
{
private:
//! source of the frames
//! destination of the frames
ADF::FileBlock fEndOfFrames;
private:
//! directory where to write files
std::string fPath;
//! base for all the files produced
std::string fBaseForName;
//! current file
FILE *fCurrentFile;
//! current file number
UInt_t fCurrentFileNumber;
//! max size for a file (in bytes)
UInt_t fMaxSize;
private:
ADF::AgataFrameTrigger *fVertex;
protected:
//! open a new file
Bool_t NewFile();
//! synchronize the current agent asking Narval (through NarvalInterface)
void SyncAgent();
public:
BasicAFC();
......@@ -67,12 +73,6 @@ public:
//! Destructor implementation
virtual void process_reset (UInt_t *error_code);
//! Ask the algorithm to process the input data block
/*!
*/
// virtual void process_block (void *input_buffer, UInt_t size_of_input_buffer, UInt_t *error_code)
// { ADF::NarvalConsumer::process_block(input_buffer,size_of_input_buffer,error_code); }
virtual UInt_t ProcessBlock (ADF::FrameBlock &) ;
};
......
/***************************************************************************
* Copyright (C) 2004 by Olivier Stezowski *
* stezow(AT)ipnl.in2p3.fr *
* stezow(AT)ipnl.in2p3.fr *
* *
* 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 *
......@@ -13,7 +13,7 @@
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* aLong_t with this program; if not, write to the *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
......
/***************************************************************************
* Copyright (C) 2004 by Olivier Stezowski *
* stezow(AT)ipnl.in2p3.fr *
* stezow(AT)ipnl.in2p3.fr *
* *
* 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 *
......@@ -13,7 +13,7 @@
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* aLong_t with this program; if not, write to the *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
......
......@@ -120,6 +120,7 @@ private:
public:
AgataConfAgent();
AgataConfAgent(const char *);
virtual ~AgataConfAgent();
//! to get the Data Flow Agent in charge of knowing the structure of the DF
......@@ -158,19 +159,25 @@ AgataConfAgent::AgataConfAgent() :
fDFAgent(new DFAgent("ADF::ConfAgent","Agata")),
fRunAgent(new RunAgent("ADF::ConfAgent","Run"))
{
fLog.GetProcessName() = "ADF::AgataConfAgent"; fLog.SetProcessMethod("AgataConfAgent()");
// configuration from the input file of the distribution
// if not found in the install path (make install not done properly)
// try in the current directory
std::string tmp; Bool_t is_one = false;
std::string tmp;
// first the one in the distribution
tmp = GetPathToConfFile();
if ( tmp.size() > 0 && !(tmp.at(tmp.size()-1) == '/') )
tmp += '/';
tmp += "ADF.conf";
if ( Configure(tmp.data(),"in") )
is_one = true;
// second the one in the ADF_CONF_PATH path
if ( Configure(tmp.data(),"in") )
fLog << info << "Init Global Conf Agent from distribution " << tmp << nline;
else
fLog << warning << "Failed to init Global Conf Agent from distribution " << tmp << nline;
// second the one in the ADF_CONF_PATH path or if not defined in the current directory
if ( ::getenv("ADF_CONF_PATH") ) {
tmp = ::getenv("ADF_CONF_PATH");
......@@ -178,16 +185,33 @@ AgataConfAgent::AgataConfAgent() :
if ( tmp.size() > 0 && !(tmp.at(tmp.size()-1) == '/') )
tmp += '/';
tmp += "ADF.conf";
if ( Configure(tmp.data(),"in") ) {
is_one = true;
}
if ( !is_one ) {
Configure("./ADF.conf","in");
}
if ( Configure(tmp.data(),"in") )
fLog << info << "Init Global Conf Agent from ADF_CONF_PATH " << tmp << nline;
else
fLog << warning << "Failed to init Global Conf Agent from ADF_CONF_PATH " << tmp << nline;
}
else {
fLog << warning << "ADF_CONF_PATH NOT DEFINED !, try init Global Conf Agent from current dir ..." << nline;
if ( Configure("./ADF.conf","in") )
fLog << warning << "... DONE" << nline;
else
fLog << warning << "... FAILED" << nline;
}
fLog << dolog;
SetLastModif();
}
AgataConfAgent::AgataConfAgent(const char *comment) :
ConfAgent(),
fDFAgent(new DFAgent("ADF::ConfAgent","Agata")),
fRunAgent(new RunAgent("ADF::ConfAgent","Run"))
{
fLog.GetProcessName() = "ADF::AgataConfAgent";
SetComment(comment);
}
AgataConfAgent::~AgataConfAgent()
{
if ( fDFAgent ) {
......@@ -199,17 +223,15 @@ AgataConfAgent::~AgataConfAgent()
}
ConfAgent *AgataConfAgent::Clone(const char *comment)
{
{
// check the global agent exists
ConfAgent::theGlobalAgent();
// first creats a new agent
AgataConfAgent *aconf = new AgataConfAgent();
AgataConfAgent *aconf = new AgataConfAgent(comment);
if ( aconf == 0x0 )
return 0x0;
aconf->SetComment(comment);
// now copy the content of the global agent to it using Configure
std::ostringstream o;
ConfAgent::theGlobalAgent()->DoConfigure(o);
......
......@@ -46,6 +46,8 @@ DFAgent::DFAgent(const Char_t *rid, const Char_t *srid, Bool_t is_record) :
fListOfFrames(),
fListOfFactories()
{
fLog.GetProcessName() = "ADF::DFAgent";
// the three main factories are added to the main factory in case it has not yet been done
// key factory
if ( !KeyFactory::IsKnown("Agata") )
......@@ -64,27 +66,6 @@ DFAgent::DFAgent(const Char_t *rid, const Char_t *srid, Bool_t is_record) :
fAutoConf.second = FactoryItem("NONE","NONE",Version(0,0));
}
/*
DFAgent::DFAgent(const char *comment) :
fModel(ConfAgent::kStrict),
fEndian(BaseBuffer::kLittle),
fPrimaryKey("Default","FS",Version(0,1)) ,
fAutoConf(),
fListOfFrames(),
fListOfFactories()
{
// prepare factories for the current endian
KeyFactory::SetEndian(fEndian,std::string("all"));
// to remove end of line character
if (fComment.size() > 0)
if ( fComment.at(fComment.length()-1) == '\n' )
fComment.erase(fComment.size()-1);
SetLastModif();
}
*/
DFAgent::~DFAgent()
{
fListOfFrames.clear(); fListOfFactories.clear();
......@@ -340,7 +321,7 @@ Bool_t DFAgent::ProcessLine(const string &aline)
}
else {
fLog << error
<< "AutoConf " << itemkey << itemframe << " is not known \n";
<< "AutoConf " << itemkey << itemframe << " is not known " << nline;
}
}
else ok_decode = false;
......@@ -412,7 +393,6 @@ Bool_t DFAgent::DoConfigure (istream &in)
Bool_t ok = true;
// set reference to this method for log system
fLog.SetProcessMethod("Configure(istream)");
in.clear();
// init itself
......@@ -424,17 +404,13 @@ Bool_t DFAgent::DoConfigure (istream &in)
// Frame
in.seekg (0, ios::beg);
ok = ok && FrameFactory::theMainFactory().DoConfigure(in);
fLog << dolog;
return ok;
}
Bool_t DFAgent::DoConfigure (ostream &out)
{
// set reference to this method for log system
fLog.SetProcessMethod("Configure(ostream)");
out.clear();
// add a start record
......@@ -473,9 +449,7 @@ Bool_t DFAgent::DoConfigure (ostream &out)
FrameFactory::theMainFactory().DoConfigure(out);
out << "# \n";
fLog << dolog;
return out.good();
}
......@@ -53,7 +53,7 @@ DotConf::DotConf() :
}
DotConf::DotConf(const Char_t *rid, const Char_t *srid, Bool_t is_record) :
fLog(rid),
fLog("ADF::DotConf"),
fSkipLine('#'),
fWithRecord(is_record),
fRID(rid),
......@@ -163,8 +163,7 @@ Bool_t DotConf::IsEndOfRecord(const std::string &st)
Bool_t DotConf::DoConfigure (istream &in)
{
// to locate the log message
fLog.SetProcessMethod("Configure(istream)");
fLog.ClearMessage();
fLog.SetProcessMethod("DoConfigure(istream)");
// local required
string tmp; Bool_t is_a_record = false, do_process = false, ok_decode = true;
......@@ -210,7 +209,7 @@ Bool_t DotConf::DoConfigure (istream &in)
}
*/
return ok_decode;
fLog << dolog; return ok_decode;
}
Bool_t DotConf::AddRecord(std::ostream &out, char t)
......@@ -254,7 +253,6 @@ Bool_t DotConf::Configure(const char *name, const char *option)
{
// set reference to this method for log system
fLog.SetProcessMethod("Configure(const char *name)");
fLog.ClearMessage();
Bool_t ok; std::string opt = option;
if ( opt == "in" ) {
......@@ -275,15 +273,15 @@ Bool_t DotConf::Configure(const char *name, const char *option)
ok = false;
fileout.close();
}
fLog << dolog;
return ok;
fLog << dolog; return ok;
}
Bool_t DotConf::Configure(ConfigurationFrame *frame, const char *option)
{
// set reference to this method for log system
fLog.SetProcessMethod("Configure(ConfigurationFrame *name)");
// fLog.ClearMessage();
Bool_t ok; std::string opt = option;
......@@ -303,7 +301,6 @@ Bool_t DotConf::Configure(ConfigurationFrame *frame, const char *option)
frame->String() = out.str();
frame->Write();
}
fLog << dolog;
return ok;
fLog << dolog; return ok;
}