/[PAMELA software]/yoda/event/PamelaRun.cpp
ViewVC logotype

Diff of /yoda/event/PamelaRun.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by kusanagi, Thu Aug 19 15:24:10 2004 UTC revision 1.6 by kusanagi, Tue Sep 21 20:23:37 2004 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Author: kusanagi $   * $Author: kusanagi $
3   * $Date: 2004/07/29 16:18:54 $   * $Date: 2004/08/19 15:24:10 $
4   * $Revision: 1.4 $   * $Revision: 1.5 $
5   *   *
6   * Implementation of the PamelaRun class.   * Implementation of the PamelaRun class.
7   */   */
# Line 11  Line 11 
11  #include <list>  #include <list>
12  #include <exception>  #include <exception>
13  #include <string>  #include <string>
14    #include <log4cxx/logger.h>
 #include <log4cpp/Category.hh>  
15    
16  #include <TFile.h>  //Substituted by Maurizio 05 Feb 2004  #include <TFile.h>  //Substituted by Maurizio 05 Feb 2004
17  #include <TTree.h>  //Substituted by Maurizio 05 Feb 2004  #include <TTree.h>  //Substituted by Maurizio 05 Feb 2004
# Line 26  Line 25 
25  #include "Algorithm.h"  #include "Algorithm.h"
26  #include "AlgorithmInfo.h"  #include "AlgorithmInfo.h"
27  #include "Exception.h"  #include "Exception.h"
28    #include <sys/stat.h>
29    
30  extern "C" {  extern "C" {
 #include "DirectoryStructure.h"  
31  #include <dirent.h>  #include <dirent.h>
32    #include "DirectoryStructure.h"
33  }  }
34    
35  using namespace pamela;  using namespace pamela;
36    
37  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.PamelaRun");  static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.PamelaRun"));
38    static std::stringstream oss;
39    
40  /**  /**
41   * Get the run name according to a certain run number.   * Get the run name according to a certain run number.
# Line 44  std::string PamelaRun::GetRunName(int ru Line 46  std::string PamelaRun::GetRunName(int ru
46    std::ostringstream t_Stream;    std::ostringstream t_Stream;
47    t_Stream << std::setw( 4 ) << std::setfill( '0' ) << run;    t_Stream << std::setw( 4 ) << std::setfill( '0' ) << run;
48    return "Run" + t_Stream.str();    return "Run" + t_Stream.str();
   //return std::string("aa");  
49  }  }
50    
51  /**  /**
# Line 114  return (fileName + t_Stream.str()); Line 115  return (fileName + t_Stream.str());
115  PamelaRun::PamelaRun(std::string fileName, std::string path):  PamelaRun::PamelaRun(std::string fileName, std::string path):
116    Path(path),    Path(path),
117    RunNumber(1){ //veirificare se è possibilie eliminare questa variabile    RunNumber(1){ //veirificare se è possibilie eliminare questa variabile
118      logger->debug(_T("Constructor"));
119    Run = RunExists(fileName);    Run = RunExists(fileName);
120    info = RunInfo(this);    info = RunInfo(this);
   cat <<  log4cpp::Priority::DEBUG  
       <<  "Constructor"  
       <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
121  }  }
122    
123  /**  /**
# Line 195  static std::list<std::string> GetRootFil Line 194  static std::list<std::string> GetRootFil
194    std::list<std::string> files;    std::list<std::string> files;
195    DIR *dir = opendir(path.c_str());    DIR *dir = opendir(path.c_str());
196    if (dir == 0) {    if (dir == 0) {
197      cat <<  log4cpp::Priority::DEBUG      oss.flush();
198          <<  "Could not open " << path      oss <<  "Could not open " << path;
199          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->debug(oss.str().c_str());
200      throw Exception("Could not open " + path);      throw Exception("Could not open " + path);
201    }    }
202        
# Line 218  static std::list<std::string> GetRootFil Line 217  static std::list<std::string> GetRootFil
217        if (stat(nextfilename.c_str(), &buf) == 0) {        if (stat(nextfilename.c_str(), &buf) == 0) {
218          filename.insert(filename.size()-5, "*");          filename.insert(filename.size()-5, "*");
219        }        }
220        cat <<  log4cpp::Priority::DEBUG        oss.flush();
221            <<  "Using " << filename        oss <<  "Using " << filename;
222            <<  "\n " << log4cpp::CategoryStream::ENDLINE;        logger->debug(oss.str().c_str());
223        files.push_back(filename);        files.push_back(filename);
224      }      }
225    }    }
# Line 258  static void AddAllAsFriend(TChain* tree, Line 257  static void AddAllAsFriend(TChain* tree,
257    }    }
258    TFile* File = new TFile(BaseFileName.c_str(), "read");    TFile* File = new TFile(BaseFileName.c_str(), "read");
259    if (!File->IsOpen()) {    if (!File->IsOpen()) {
260      cat <<  log4cpp::Priority::WARN      oss.flush();
261          <<  "Could not open file " << BaseFileName << " for reading."      oss <<  "Could not open file " << BaseFileName << " for reading.";
262          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->warn(oss.str().c_str());
263      return;      return;
264    }    }
265    TList* list = File->GetListOfKeys();    TList* list = File->GetListOfKeys();
# Line 271  static void AddAllAsFriend(TChain* tree, Line 270  static void AddAllAsFriend(TChain* tree,
270          TChain* FriendChain = new TChain(TreeName.c_str());          TChain* FriendChain = new TChain(TreeName.c_str());
271          FriendChain->Add(FileName.c_str());          FriendChain->Add(FileName.c_str());
272          tree->AddFriend(FriendChain, TreeName.c_str());          tree->AddFriend(FriendChain, TreeName.c_str());
273          std::ostringstream t_Stream;          oss.flush();
274          t_Stream << "Adding chain " << TreeName << " with "          oss << "Adding chain " << TreeName << " with "
275                   << FriendChain->GetEntries() << " entries as Friend";              << FriendChain->GetEntries() << " entries as Friend";
276          cat.debug(t_Stream.str());          logger->warn(oss.str().c_str());
277        }        }
278      }      }
279      File->Close();      File->Close();
# Line 284  static void AddAllAsFriend(TChain* tree, Line 283  static void AddAllAsFriend(TChain* tree,
283          std::string TreeName = k->GetName();          std::string TreeName = k->GetName();
284          TTree* FriendTree = (TTree *)File->Get(TreeName.c_str());          TTree* FriendTree = (TTree *)File->Get(TreeName.c_str());
285          tree->AddFriend(FriendTree, TreeName.c_str());            tree->AddFriend(FriendTree, TreeName.c_str());  
286          std::ostringstream t_Stream;          oss.flush();
287          t_Stream << "Adding tree " << TreeName << " with "          oss << "Adding tree " << TreeName << " with "
288                   << FriendTree->GetEntries() << " entries as Friend";              << FriendTree->GetEntries() << " entries as Friend";
289          cat.debug(t_Stream.str());          logger->debug(oss.str().c_str());
290        }        }
291      }      }
292    }    }
# Line 300  static void AddAllAsFriend(TChain* tree, Line 299  static void AddAllAsFriend(TChain* tree,
299   * @return The root trees with the friends.   * @return The root trees with the friends.
300   */   */
301  TTree* PamelaRun::ReadTTree(const PacketType* type) {  TTree* PamelaRun::ReadTTree(const PacketType* type) {
302    cat <<  log4cpp::Priority::DEBUG    oss.flush();
303        <<  "Getting root files of " << type->GetName()    oss <<  "Getting root files of " << type->GetName();
304        <<  "\n " << log4cpp::CategoryStream::ENDLINE;    logger->debug(oss.str().c_str());
305    RootTreeMap::iterator t = TTreeMap.find(type);    RootTreeMap::iterator t = TTreeMap.find(type);
306    if (t != TTreeMap.end()) {    if (t != TTreeMap.end()) {
307      return t->second;      return t->second;
308    } else {    } else {
309      cat <<  log4cpp::Priority::DEBUG      oss.flush();
310          <<  "Reading root files of " << type->GetName()      oss <<  "Reading root files of " << type->GetName();
311          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->debug(oss.str().c_str());
312      EventHeader header(type);      EventHeader header(type);
313      std::string HeaderFileName = GetFileName(&header);      std::string HeaderFileName = GetFileName(&header);
314      TChain* HeaderTree = ReadHeaderTree(type);      TChain* HeaderTree = ReadHeaderTree(type);
# Line 347  void PamelaRun::ReadSubPacket(void* subp Line 346  void PamelaRun::ReadSubPacket(void* subp
346        branch->SetAddress(subpacket);        branch->SetAddress(subpacket);
347        SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));        SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));
348      } else {      } else {
349          cat <<  log4cpp::Priority::ERROR          oss.flush();
350              <<  "Could not find data for " << packet->GetPacketType()->GetName() << "/" << name          oss <<  "Could not find data for " << packet->GetPacketType()->GetName() << "/" << name ;
351              <<  "\n " << log4cpp::CategoryStream::ENDLINE;          logger->error(oss.str().c_str());
352      }      }
353    }    }
354  }  }
# Line 405  TTree* PamelaRun::CreateTTree(Algorithm* Line 404  TTree* PamelaRun::CreateTTree(Algorithm*
404    CreateDirectoryStructure(FileName.c_str());    CreateDirectoryStructure(FileName.c_str());
405    TFile* File = new TFile(FileName.c_str(), "create");    TFile* File = new TFile(FileName.c_str(), "create");
406    if (!File->IsOpen()) {    if (!File->IsOpen()) {
407      cat <<  log4cpp::Priority::ERROR      oss.flush();
408          <<  "Could not open file " << FileName      oss <<  "Could not open file " << FileName ;
409          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->error(oss.str().c_str());
410      throw Exception("Could not open file " + FileName);      throw Exception("Could not open file " + FileName);
411    }    }
412    std::string TreeName = GetTreeName(packet);    std::string TreeName = GetTreeName(packet);
# Line 417  TTree* PamelaRun::CreateTTree(Algorithm* Line 416  TTree* PamelaRun::CreateTTree(Algorithm*
416    AlgorithmInfo ai(algo);    AlgorithmInfo ai(algo);
417    ai.Write();    ai.Write();
418    info.Write();    info.Write();
419    cat <<  log4cpp::Priority::INFO    oss.flush();
420        <<  "Creating file " << FileName << " with Tree " << TreeName    oss <<  "Creating file " << FileName << " with Tree " << TreeName;
421        <<  "\n " << log4cpp::CategoryStream::ENDLINE;    logger->info(oss.str().c_str());
422    return tree;    return tree;
423  }  }
424    
# Line 437  TTree* PamelaRun::CreateTTree(Algorithm* Line 436  TTree* PamelaRun::CreateTTree(Algorithm*
436  void PamelaRun::WriteSubPacket(Algorithm *algo, void* subpacket,  void PamelaRun::WriteSubPacket(Algorithm *algo, void* subpacket,
437                                 const TClass *c, std::string name) {                                 const TClass *c, std::string name) {
438    SubPacket *packet = *(SubPacket **)subpacket;    SubPacket *packet = *(SubPacket **)subpacket;
439    cat <<  log4cpp::Priority::DEBUG    oss.flush();
440        <<  "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)"    oss <<  "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)";
441        <<  "\n " << log4cpp::CategoryStream::ENDLINE;    logger->debug(oss.str().c_str());
442    TTree* HeaderTree = ReadTTree(packet->GetPacketType());    TTree* HeaderTree = ReadTTree(packet->GetPacketType());
443    TTree* tree = CreateTTree(algo, packet, name);    TTree* tree = CreateTTree(algo, packet, name);
444    cat <<  log4cpp::Priority::DEBUG    oss.flush();
445        <<  "Branch: " << name << " Class: " << c->GetName()    oss <<  "Branch: " << name << " Class: " << c->GetName();
446        <<  "\n " << log4cpp::CategoryStream::ENDLINE;    logger->debug(oss.str().c_str());
447    tree->Branch(name.c_str(), c->GetName(),  subpacket);    tree->Branch(name.c_str(), c->GetName(),  subpacket);
448    HeaderTree->AddFriend(tree, tree->GetName());    HeaderTree->AddFriend(tree, tree->GetName());
449    
# Line 476  void PamelaRun::WriteSubPacket(Algorithm Line 475  void PamelaRun::WriteSubPacket(Algorithm
475   */   */
476  void PamelaRun::WriteHeader(Algorithm* algo, EventHeader** subpacket,  void PamelaRun::WriteHeader(Algorithm* algo, EventHeader** subpacket,
477                              const PacketType* type) {                              const PacketType* type) {
478    cat <<  log4cpp::Priority::DEBUG    oss.flush();
479        <<  "Creating header tree for " << type->GetName()    oss <<  "Creating header tree for " << type->GetName();
480        <<  "\n " << log4cpp::CategoryStream::ENDLINE;    logger->debug(oss.str().c_str());
481    EventHeader header(type);    EventHeader header(type);
482    std::string FileName = GetFileName(&header, GetDefaultBranchName(&header));    std::string FileName = GetFileName(&header, GetDefaultBranchName(&header));
483    std::string EventType = (&header)->GetPacketType()->GetName();    std::string EventType = (&header)->GetPacketType()->GetName();
484    CreateDirectoryStructure(FileName.c_str());    CreateDirectoryStructure(FileName.c_str());
485    TFile* File = new TFile(FileName.c_str(), "create");    TFile* File = new TFile(FileName.c_str(), "create");
486    if (!File->IsOpen()) {    if (!File->IsOpen()) {
487      cat <<  log4cpp::Priority::ERROR      oss.flush();
488          <<  "Could not open file " << FileName      oss     <<  "Could not open file " << FileName ;
489          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->error(oss.str().c_str());
490      throw Exception("Could not open file " + FileName);      throw Exception("Could not open file " + FileName);
491    }    }
492    //std::string TreeName = GetTreeName(packet);    //std::string TreeName = GetTreeName(packet);
# Line 497  void PamelaRun::WriteHeader(Algorithm* a Line 496  void PamelaRun::WriteHeader(Algorithm* a
496    AlgorithmInfo ai(algo);    AlgorithmInfo ai(algo);
497    ai.Write();    ai.Write();
498    info.Write();    info.Write();
499    cat <<  log4cpp::Priority::INFO    oss.flush();
500        <<  "Creating file " << FileName << " with Tree Pscu"    oss <<  "Creating file " << FileName << " with Tree Pscu";
501        <<  "\n " << log4cpp::CategoryStream::ENDLINE;    logger->info(oss.str().c_str());
502    tree->Branch(GetDefaultBranchName(&header).c_str(),    tree->Branch(GetDefaultBranchName(&header).c_str(),
503                 (*subpacket)->Class()->GetName(), subpacket);                 (*subpacket)->Class()->GetName(), subpacket);
504    TTreeMap.insert(RootTreeMap::value_type(type, tree));    TTreeMap.insert(RootTreeMap::value_type(type, tree));
# Line 534  void PamelaRun::WriteHeaders(Algorithm* Line 533  void PamelaRun::WriteHeaders(Algorithm*
533      WriteHeader(algo, subpacket, PacketType::InitTrailer);      WriteHeader(algo, subpacket, PacketType::InitTrailer);
534      WriteHeader(algo, subpacket, PacketType::EventTrk);      WriteHeader(algo, subpacket, PacketType::EventTrk);
535      WriteHeader(algo, subpacket, PacketType::TestTrk);      WriteHeader(algo, subpacket, PacketType::TestTrk);
536        WriteHeader(algo, subpacket, PacketType::TestTof);
537      WriteHeader(algo, subpacket, PacketType::Log);      WriteHeader(algo, subpacket, PacketType::Log);
538      WriteHeader(algo, subpacket, PacketType::VarDump);      WriteHeader(algo, subpacket, PacketType::VarDump);
539      WriteHeader(algo, subpacket, PacketType::ArrDump);      WriteHeader(algo, subpacket, PacketType::ArrDump);
# Line 546  void PamelaRun::WriteHeaders(Algorithm* Line 546  void PamelaRun::WriteHeaders(Algorithm*
546      WriteHeader(algo, subpacket, PacketType::TrkInit);      WriteHeader(algo, subpacket, PacketType::TrkInit);
547      WriteHeader(algo, subpacket, PacketType::TofInit);      WriteHeader(algo, subpacket, PacketType::TofInit);
548      WriteHeader(algo, subpacket, PacketType::TrgInit);          WriteHeader(algo, subpacket, PacketType::TrgInit);    
549        WriteHeader(algo, subpacket, PacketType::CalAlarm);    
550        WriteHeader(algo, subpacket, PacketType::AcAlarm);    
551        WriteHeader(algo, subpacket, PacketType::TrkAlarm);    
552        WriteHeader(algo, subpacket, PacketType::TrgAlarm);    
553        WriteHeader(algo, subpacket, PacketType::TofAlarm);    
554  }  }
555    
556  /**  /**
# Line 581  void PamelaRun::FillTrees(const PacketTy Line 586  void PamelaRun::FillTrees(const PacketTy
586    }    }
587  }  }
588    
589    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.23