/[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 5.0 by kusanagi, Mon Aug 29 09:45:48 2005 UTC revision 5.1 by kusanagi, Sat Feb 4 12:37:43 2006 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Author: kusanagi $   * $Author: Maurizio Nagni $
3   * $Date: 2005/05/28 10:44:09 $   * $Date: 2005/08/29 09:45:48 $
4   * $Revision: 4.4 $   * $Revision: 5.0 $
5   *   *
6   * Implementation of the PamelaRun class.   * Implementation of the PamelaRun class.
7   */   */
# Line 9  Line 9 
9  #include <iomanip>  #include <iomanip>
10  #include <list>  #include <list>
11  #include <exception>  #include <exception>
 //#include <string>  
12  #include <log4cxx/logger.h>  #include <log4cxx/logger.h>
13    
14  #include <TFile.h>  //Substituted by Maurizio 05 Feb 2004  #include <TFile.h>  //Substituted by Maurizio 05 Feb 2004
# Line 52  std::string PamelaRun::GetRunName(int ru Line 51  std::string PamelaRun::GetRunName(int ru
51   * @param int run - Number of the run to check   * @param int run - Number of the run to check
52   * @return int   * @return int
53   */   */
 /*int PamelaRun::RunExists(int run) throw (std::exception){  
  int res;  
  DIR *dirp;  
  std::string pathDir((char*)getenv("YODA_DATA"));  
  pathDir = pathDir + "/";  
  pathDir = pathDir + GetRunName(run);  
 // Open the directory  
 if ((dirp = opendir(pathDir.c_str())) == NULL) {  
 res = 0;  
 } else {  
 closedir(dirp);  
 res = 1;  
 }  
 return res;  
 }*/  
   
   
 /**  
  * Check if the run number is already assigned  
  * @param int run - Number of the run to check  
  * @return int  
  */  
54   void PamelaRun::RunExists(std::string input) throw (std::exception){   void PamelaRun::RunExists(std::string input) throw (std::exception){
55   int res;   int res;
56   DIR *dirp;   DIR *dirp;
# Line 117  return res; Line 94  return res;
94   * @param run Run number   * @param run Run number
95   * @param path Base path name to the data   * @param path Base path name to the data
96   */   */
97  PamelaRun::PamelaRun(std::string fileName, std::string path):  PamelaRun::PamelaRun(std::string fileName, std::string path, bool multiple, short compr):
98    Path(path),    Path(path),
99    Run(fileName),    Run(fileName),
100    RunNumber(1){ //veirificare se è possibilie eliminare questa variabile    RunNumber(1),//veirificare se è possibilie eliminare questa variabile
101      Multiple(multiple),
102      SingleFile(0),
103      compression(compr){
104    logger->debug(_T("Constructor"));    logger->debug(_T("Constructor"));
105    //Run = RunExists(fileName);    //Run = RunExists(fileName);
106    RunExists(fileName);    RunExists(fileName);
# Line 404  void PamelaRun::ReadSubPacket(const Algo Line 384  void PamelaRun::ReadSubPacket(const Algo
384  TTree* PamelaRun::CreateTTree(Algorithm* algo, const SubPacket* packet,  TTree* PamelaRun::CreateTTree(Algorithm* algo, const SubPacket* packet,
385                                std::string name)                                std::string name)
386    throw (std::exception) {    throw (std::exception) {
387    std::string FileName = GetFileName(packet, name);    std::string FileName = "";
388    std::string EventType = packet->GetPacketType()->GetName();    std::string EventType = packet->GetPacketType()->GetName();
389      TFile* File = 0;
390      std::string TreeName = GetTreeName(packet);
391      TTree *tree = 0;
392      FileName = GetFileName(packet, name);
393    CreateDirectoryStructure(FileName.c_str());    CreateDirectoryStructure(FileName.c_str());
394    TFile* File = new TFile(FileName.c_str(), "create");    File = new TFile(FileName.c_str(), "create");
395    File->SetCompressionLevel(5);    tree = new TTree(TreeName.c_str(), algo->GetAlgorithmName().c_str());
396      WritingRootTrees[packet->GetPacketType()].push_back(tree);
397      
398      File->SetCompressionLevel(compression);
399    if (!File->IsOpen()) {    if (!File->IsOpen()) {
400      logger->error("Could not open file " + FileName);      logger->error("Could not open file " + FileName);
401      //throw Exception("Could not open file " + FileName);      //throw Exception("Could not open file " + FileName);
402    }    }
   std::string TreeName = GetTreeName(packet);  
   TTree *tree = new TTree(TreeName.c_str(), algo->GetAlgorithmName().c_str());  
   WritingRootTrees[packet->GetPacketType()].push_back(tree);  
   tree->GetCurrentFile()->cd();  
   AlgorithmInfo ai(algo);  
   ai.Write();  
   info.Write();  
403    logger->debug("Creating file " + FileName + " with Tree " + TreeName);    logger->debug("Creating file " + FileName + " with Tree " + TreeName);
404    return tree;    return tree;
405  }  }
# Line 442  void PamelaRun::WriteSubPacket(Algorithm Line 422  void PamelaRun::WriteSubPacket(Algorithm
422    oss <<  "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)";    oss <<  "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)";
423    logger->debug(oss.str().c_str());    logger->debug(oss.str().c_str());
424    TTree* HeaderTree = ReadTTree(packet->GetPacketType());    TTree* HeaderTree = ReadTTree(packet->GetPacketType());
   TTree* tree = CreateTTree(algo, packet, name);  
   oss.str("");  
   oss <<  "Branch: " << name << " Class: " << c->GetName();  
   logger->debug(oss.str().c_str());  
   tree->Branch(name.c_str(), c->GetName(),  subpacket);  
   HeaderTree->AddFriend(tree, tree->GetName());  
   
425    std::string FullName = packet->GetPacketType()->GetName() + "." + name;    std::string FullName = packet->GetPacketType()->GetName() + "." + name;
426    SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));    if (Multiple) {
427            TTree* tree = CreateTTree(algo, packet, name);
428            oss.str("");
429            oss <<  "Branch: " << name << " Class: " << c->GetName();
430            logger->debug(oss.str().c_str());
431            tree->Branch(name.c_str(), c->GetName(),  subpacket);
432            HeaderTree->AddFriend(tree, tree->GetName());
433            SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));
434      } else {
435            std::string nameBranch(name);
436            HeaderTree->Branch(nameBranch.c_str(), c->GetName(),  subpacket);
437            SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));
438      }
439  }  }
440    
441  /**  /**
# Line 469  void PamelaRun::WriteSubPacket(Algorithm Line 454  void PamelaRun::WriteSubPacket(Algorithm
454  }  }
455    
456  /**  /**
  * Write the header packet of a specified packet type. This is mainly used  
  * for the raw reader to create the base for the event structure.  
  * @param algo Algorithm that produces this SubPacket.  
  * @param subpacket A pointer to the pointer of the packet.  
  * @param type The packet type.  
  */  
 void PamelaRun::WriteHeader(Algorithm* algo, EventHeader** subpacket,  
                             const PacketType* type) {  
   EventHeader header(type);  
   std::string FileName = GetFileName(&header, GetDefaultBranchName(&header));  
   std::string EventType = (&header)->GetPacketType()->GetName();  
   CreateDirectoryStructure(FileName.c_str());  
   TFile* File = new TFile(FileName.c_str(), "create");  
   if (!File->IsOpen()) {  
     logger->error("Could not open file " + FileName);  
     //throw Exception("Could not open file " + FileName);  
   }  
   //std::string TreeName = GetTreeName(packet);  
   TTree *tree = new TTree("Pscu", algo->GetAlgorithmName().c_str());  
   WritingRootTrees[(&header)->GetPacketType()].push_back(tree);  
   tree->GetCurrentFile()->cd();  
   AlgorithmInfo ai(algo);  
   ai.Write();  
   info.Write();  
   std::stringstream temp;  
   //temp.str("");  
   //temp << "Created file" << FileName.c_str() << " with Tree Pscu" ;  
   //logger->debug(temp.str());  
   tree->Branch(GetDefaultBranchName(&header).c_str(),  
                (*subpacket)->Class()->GetName(), subpacket);  
   TTreeMap.insert(RootTreeMap::value_type(type, tree));  
 }  
   
   
 /**  
457   * Write the header packet to all ROOT files in the tree. Intended to   * Write the header packet to all ROOT files in the tree. Intended to
458   * be used for raw data readers that create the initial event structure.   * be used for raw data readers that create the initial event structure.
459   * @param algo Algorithm that produces this SubPacket.   * @param algo Algorithm that produces this SubPacket.
460   * @param subpacket A pointer to the pointer of the header packet.   * @param subpacket A pointer to the pointer of the header packet.
461   */   */
462  void PamelaRun::WriteHeaders(Algorithm* algo, EventHeader** subpacket) {  void PamelaRun::WriteHeaders(Algorithm* algo, EventHeader** subpacket) {
   
463      WriteHeader(algo, subpacket, PacketType::PhysEndRun);      WriteHeader(algo, subpacket, PacketType::PhysEndRun);
464      WriteHeader(algo, subpacket, PacketType::CalibCalPulse1);      WriteHeader(algo, subpacket, PacketType::CalibCalPulse1);
465      WriteHeader(algo, subpacket, PacketType::CalibCalPulse2);      WriteHeader(algo, subpacket, PacketType::CalibCalPulse2);
# Line 530  void PamelaRun::WriteHeaders(Algorithm* Line 479  void PamelaRun::WriteHeaders(Algorithm*
479      WriteHeader(algo, subpacket, PacketType::CalibTrailer);      WriteHeader(algo, subpacket, PacketType::CalibTrailer);
480      WriteHeader(algo, subpacket, PacketType::InitHeader);      WriteHeader(algo, subpacket, PacketType::InitHeader);
481      WriteHeader(algo, subpacket, PacketType::InitTrailer);      WriteHeader(algo, subpacket, PacketType::InitTrailer);
     WriteHeader(algo, subpacket, PacketType::EventTrk);  
     WriteHeader(algo, subpacket, PacketType::TestTrk);  
     WriteHeader(algo, subpacket, PacketType::TestTof);  
482      WriteHeader(algo, subpacket, PacketType::Log);      WriteHeader(algo, subpacket, PacketType::Log);
483      WriteHeader(algo, subpacket, PacketType::VarDump);      WriteHeader(algo, subpacket, PacketType::VarDump);
484      WriteHeader(algo, subpacket, PacketType::ArrDump);      WriteHeader(algo, subpacket, PacketType::ArrDump);
# Line 574  void PamelaRun::WriteFiles(void) { Line 520  void PamelaRun::WriteFiles(void) {
520         i != WritingRootTrees.end(); i++) {         i != WritingRootTrees.end(); i++) {
521      for (TTreeList::iterator j = i->second.begin();      for (TTreeList::iterator j = i->second.begin();
522           j != i->second.end(); j++) {           j != i->second.end(); j++) {
523        (*j)->GetCurrentFile()->Write();        (*j)->GetCurrentFile()->Write(0,TObject::kOverwrite);
524      }      }
525    }    }
526  }  }
# Line 595  void PamelaRun::FillTrees(const PacketTy Line 541  void PamelaRun::FillTrees(const PacketTy
541  }  }
542    
543    
544    /**
545     * Write the header packet of a specified packet type. This is mainly used
546     * for the raw reader to create the base for the event structure.
547     * @param algo Algorithm that produces this SubPacket.
548     * @param subpacket A pointer to the pointer of the packet.
549     * @param type The packet type.
550     */
551    void PamelaRun::WriteHeader(Algorithm* algo, EventHeader** subpacket,
552                                const PacketType* type) {
553      EventHeader header(type);
554      std::string EventType = (&header)->GetPacketType()->GetName();
555    
556      std::string FileName = "";
557      TFile* File = 0;
558      TTree *tree = 0;
559      if ( Multiple ){
560            FileName = GetFileName(&header, GetDefaultBranchName(&header));
561            CreateDirectoryStructure(FileName.c_str());
562            File = new TFile(FileName.c_str(), "create");
563            File->SetCompressionLevel(compression);
564            tree = new TTree("Pscu", algo->GetAlgorithmName().c_str());
565            WritingRootTrees[(&header)->GetPacketType()].push_back(tree);
566            tree->GetCurrentFile()->cd();
567            tree->Branch(GetDefaultBranchName(&header).c_str(),
568                   (*subpacket)->Class()->GetName(), subpacket);
569            TTreeMap.insert(RootTreeMap::value_type(type, tree));
570      } else {
571            if (!Multiple && (SingleFile == NULL)){
572                    std::string pathDir((char*)getenv("YODA_DATA"));
573                    SingleFile = new TFile((pathDir + "/" + Run + ".root").c_str(), "update");
574                    SingleFile->SetCompressionLevel(compression);
575            }
576            tree = new TTree(EventType.c_str(), algo->GetAlgorithmName().c_str());
577            WritingRootTrees[type].push_back(tree);
578            tree->GetCurrentFile()->cd();
579            tree->Branch(GetDefaultBranchName(&header).c_str(),
580                   (*subpacket)->Class()->GetName(), subpacket);
581            TTreeMap.insert(RootTreeMap::value_type(type, tree));
582      }
583    }

Legend:
Removed from v.5.0  
changed lines
  Added in v.5.1

  ViewVC Help
Powered by ViewVC 1.1.23