/[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.1 by kusanagi, Tue Jul 6 12:20:23 2004 UTC revision 6.10 by mocchiut, Mon Oct 16 16:02:20 2006 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Author: nagni $   * $Author: pam-rm2 $
3   * $Date: 2004/06/10 15:17:46 $   * $Date: 2006/08/23 14:39:44 $
4   * $Revision: 1.11 $   * $Revision: 6.8 $
5   *   *
6   * Implementation of the PamelaRun class.   * Implementation of the PamelaRun class.
7   */   */
8  #include <iostream>  #include <iostream>
9  #include <iomanip>  #include <iomanip>
 #include <sstream>  
10  #include <list>  #include <list>
11  #include <exception>  #include <exception>
12  #include <string>  #include <log4cxx/logger.h>
   
 #include <log4cpp/Category.hh>  
13    
14  #include <TFile.h>  //Substituted by Maurizio 05 Feb 2004  #include <TFile.h>  //Substituted by Maurizio 05 Feb 2004
15  #include <TTree.h>  //Substituted by Maurizio 05 Feb 2004  #include <TTree.h>  //Substituted by Maurizio 05 Feb 2004
# Line 26  Line 23 
23  #include "Algorithm.h"  #include "Algorithm.h"
24  #include "AlgorithmInfo.h"  #include "AlgorithmInfo.h"
25  #include "Exception.h"  #include "Exception.h"
26    #include <sys/stat.h>
27    
28  extern "C" {  extern "C" {
 #include "DirectoryStructure.h"  
29  #include <dirent.h>  #include <dirent.h>
30    #include "DirectoryStructure.h"
31  }  }
32    
33    #include "yodaversion.h"
34    //#define version 60313
35    //extern int GetYODAver();
36    
37  using namespace pamela;  using namespace pamela;
38    
39  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.PamelaRun");  static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.PamelaRun"));
40    
41  /**  /**
42   * Get the run name according to a certain run number.   * Get the run name according to a certain run number.
# Line 41  static log4cpp::Category& cat = log4cpp: Line 44  static log4cpp::Category& cat = log4cpp:
44   * @return a string with the run name.   * @return a string with the run name.
45   */   */
46  std::string PamelaRun::GetRunName(int run) {  std::string PamelaRun::GetRunName(int run) {
47    std::ostringstream t_Stream;    std::stringstream temp;
48    t_Stream << std::setw( 4 ) << std::setfill( '0' ) << run;    temp.str("");
49    return "Run" + t_Stream.str();    temp << std::setw( 4 ) << std::setfill( '0' ) << run;
50    //return std::string("aa");    return "Run" + temp.str();
51  }  }
52    
53  /**  /**
# Line 52  std::string PamelaRun::GetRunName(int ru Line 55  std::string PamelaRun::GetRunName(int ru
55   * @param int run - Number of the run to check   * @param int run - Number of the run to check
56   * @return int   * @return int
57   */   */
58  /*int PamelaRun::RunExists(int run) throw (std::exception){   void PamelaRun::RunExists(std::string input) 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  
  */  
  std::string PamelaRun::RunExists(std::string input) throw (std::exception){  
59   int res;   int res;
60   DIR *dirp;   DIR *dirp;
61   std::string fileName;   std::string fileName;
62   std::string pathDir((char*)getenv("YODA_DATA"));   //std::string pathDir((char*)getenv("YODA_DATA"));
63     std::string pathDir(GetPath());
64   std::string tempName;   std::string tempName;
65   std::string::size_type pos;   std::string::size_type pos;
66   std::ostringstream t_Stream;  
   
67   pos = input.find_last_of("/");   pos = input.find_last_of("/");
  //if ((pos == std::string::npos) && !input.empty()) ;//throw Exception("Directories not allowed....");  
68   fileName = input.substr(pos+1);   fileName = input.substr(pos+1);
69   pos = fileName.find_last_of(".");   pos = fileName.find_last_of(".");
70   fileName = fileName.substr(0,pos);   fileName = fileName.substr(0,pos);
71   pathDir = pathDir + "/";   pathDir = pathDir + "/";
72   tempName = pathDir + fileName;   tempName = pathDir + fileName;
73     oss.str("");
74   int i = 0;   oss << Path << "/" << fileName;
75   while (res){   UnpackPath = oss.str();
76      if ((dirp = opendir(tempName.c_str())) == NULL) {   oss.str("");
77          res = 0;   oss << fileName;
78      } else {   Run = oss.str();
         closedir(dirp);  
         t_Stream.str("");  
         t_Stream << std::setw( 2 ) << std::setfill( '0' ) << ++i;  
         tempName = pathDir + fileName + t_Stream.str() ;  
         res = 1;  
     }  
  }  
 return (fileName + t_Stream.str());  
79  }  }
80    
81  /**  /**
# Line 111  return (fileName + t_Stream.str()); Line 83  return (fileName + t_Stream.str());
83   * @param run Run number   * @param run Run number
84   * @param path Base path name to the data   * @param path Base path name to the data
85   */   */
86  PamelaRun::PamelaRun(std::string fileName, std::string path):  PamelaRun::PamelaRun(std::string fileName, std::string path, bool multiple, short compr):
87    Path(path),    Path(path),
88    RunNumber(1){ //veirificare se è possibilie eliminare questa variabile    Run(fileName),
89    Run = RunExists(fileName);    RunNumber(1),//veirificare se è possibilie eliminare questa variabile
90      Multiple(multiple),
91      SingleFile(0),
92      compression(compr){
93      logger->debug(_T("Constructor"));
94      //Run = RunExists(fileName);
95      RunExists(fileName);
96    info = RunInfo(this);    info = RunInfo(this);
   cat <<  log4cpp::Priority::DEBUG  
       <<  "Constructor"  
       <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
97  }  }
98    
99  /**  /**
# Line 128  PamelaRun::PamelaRun(std::string fileNam Line 103  PamelaRun::PamelaRun(std::string fileNam
103   * @return the complete path for this event type.   * @return the complete path for this event type.
104   */   */
105  std::string PamelaRun::GetDirName(PacketType const * type) const {  std::string PamelaRun::GetDirName(PacketType const * type) const {
106    std::string EventType = type->GetName();      //std::stringstream oss;
107    return Path + "/" + Run + "/" + EventType;      //std::string name = type->GetName();
108        //oss.str("");
109        //oss << Path << "/" << Run << "/" << "pippo";
110        //return oss.str();
111        //return "pippo";
112      //std::string EventType = type->GetName();
113        return Path + "/" + Run + "/" + type->GetName();
114  }  }
115    
116  /**  /**
# Line 138  std::string PamelaRun::GetDirName(Packet Line 119  std::string PamelaRun::GetDirName(Packet
119   * @param name subpacket name.   * @param name subpacket name.
120   * @return the complete path and file name.   * @return the complete path and file name.
121   */   */
122  std::string PamelaRun::GetFileName(const SubPacket* type, std::string name) const {  std::string PamelaRun::GetFileName(const SubPacket* type, std::string name) {
123    if (type->IsDetectorSpecific()) {    if (type->IsDetectorSpecific()) {
124      return GetDirName(type->GetPacketType()) + "/"      return UnpackPath + "/" + type->GetPacketType()->GetName() + "/"
125        + type->GetSubDetector()->GetName() + "/"        + Run + "." + type->GetPacketType()->GetName() + "."
       + Run + "." + type->GetPacketType()->GetName() + "."  
126        + type->GetSubDetector()->GetName() + "."        + type->GetSubDetector()->GetName() + "."
127        + name + ".root";        + name + ".root";
128    } else {    } else {
129      return GetDirName(type->GetPacketType()) + "/"      return UnpackPath + "/" + type->GetPacketType()->GetName() + "/"
130        + Run + "." + type->GetPacketType()->GetName() + "."        + Run + "." + type->GetPacketType()->GetName() + "."
131        + name + ".root";        + name + ".root";
132       /*
133        return Path + "/" + type->GetPacketType()->GetName() + "/"
134          + Run + "." + type->GetPacketType()->GetName() + "."
135          + name + ".root"; */
136    }    }
137  }  }
138    
# Line 157  std::string PamelaRun::GetFileName(const Line 141  std::string PamelaRun::GetFileName(const
141   * @param type subpacket type.   * @param type subpacket type.
142   * @return the complete path and file name.   * @return the complete path and file name.
143   */   */
144  std::string PamelaRun::GetFileName(const SubPacket* type) const {  std::string PamelaRun::GetFileName(const SubPacket* type)  {
145    return GetFileName(type, type->GetSubPacketName());    //return GetFileName(type, type->GetSubPacketName());
146        return GetFileName(type, "pippo");
147  }  }
148    
149  /**  /**
# Line 195  static std::list<std::string> GetRootFil Line 180  static std::list<std::string> GetRootFil
180    std::list<std::string> files;    std::list<std::string> files;
181    DIR *dir = opendir(path.c_str());    DIR *dir = opendir(path.c_str());
182    if (dir == 0) {    if (dir == 0) {
183      cat <<  log4cpp::Priority::DEBUG      logger->debug("Could not open " + path);
184          <<  "Could not open " << path      //throw Exception("Could not open " + path);
         <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
     throw Exception("Could not open " + path);  
185    }    }
186        
187    for (struct dirent *d = readdir(dir); d != NULL; d = readdir(dir)) {    for (struct dirent *d = readdir(dir); d != NULL; d = readdir(dir)) {
# Line 218  static std::list<std::string> GetRootFil Line 201  static std::list<std::string> GetRootFil
201        if (stat(nextfilename.c_str(), &buf) == 0) {        if (stat(nextfilename.c_str(), &buf) == 0) {
202          filename.insert(filename.size()-5, "*");          filename.insert(filename.size()-5, "*");
203        }        }
204        cat <<  log4cpp::Priority::DEBUG        logger->debug("Using " + filename);
           <<  "Using " << filename  
           <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
205        files.push_back(filename);        files.push_back(filename);
206      }      }
207    }    }
# Line 258  static void AddAllAsFriend(TChain* tree, Line 239  static void AddAllAsFriend(TChain* tree,
239    }    }
240    TFile* File = new TFile(BaseFileName.c_str(), "read");    TFile* File = new TFile(BaseFileName.c_str(), "read");
241    if (!File->IsOpen()) {    if (!File->IsOpen()) {
242      cat <<  log4cpp::Priority::WARN      logger->error("Could not open file " + BaseFileName + " for reading.");
         <<  "Could not open file " << BaseFileName << " for reading."  
         <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
243      return;      return;
244    }    }
245    TList* list = File->GetListOfKeys();    TList* list = File->GetListOfKeys();
# Line 271  static void AddAllAsFriend(TChain* tree, Line 250  static void AddAllAsFriend(TChain* tree,
250          TChain* FriendChain = new TChain(TreeName.c_str());          TChain* FriendChain = new TChain(TreeName.c_str());
251          FriendChain->Add(FileName.c_str());          FriendChain->Add(FileName.c_str());
252          tree->AddFriend(FriendChain, TreeName.c_str());          tree->AddFriend(FriendChain, TreeName.c_str());
253          std::ostringstream t_Stream;          //logger->warn("Adding chain " + TreeName + " with " + FriendChain->GetEntries() + " entries as Friend");
         t_Stream << "Adding chain " << TreeName << " with "  
                  << FriendChain->GetEntries() << " entries as Friend";  
         cat.debug(t_Stream.str());  
254        }        }
255      }      }
256      File->Close();      File->Close();
# Line 284  static void AddAllAsFriend(TChain* tree, Line 260  static void AddAllAsFriend(TChain* tree,
260          std::string TreeName = k->GetName();          std::string TreeName = k->GetName();
261          TTree* FriendTree = (TTree *)File->Get(TreeName.c_str());          TTree* FriendTree = (TTree *)File->Get(TreeName.c_str());
262          tree->AddFriend(FriendTree, TreeName.c_str());            tree->AddFriend(FriendTree, TreeName.c_str());  
263          std::ostringstream t_Stream;          //logger->debug("Adding tree " + TreeName + " with " + FriendTree->GetEntries() + " entries as Friend");
         t_Stream << "Adding tree " << TreeName << " with "  
                  << FriendTree->GetEntries() << " entries as Friend";  
         cat.debug(t_Stream.str());  
264        }        }
265      }      }
266    }    }
# Line 300  static void AddAllAsFriend(TChain* tree, Line 273  static void AddAllAsFriend(TChain* tree,
273   * @return The root trees with the friends.   * @return The root trees with the friends.
274   */   */
275  TTree* PamelaRun::ReadTTree(const PacketType* type) {  TTree* PamelaRun::ReadTTree(const PacketType* type) {
276    cat <<  log4cpp::Priority::DEBUG    oss.str("");
277        <<  "Getting root files of " << type->GetName()    oss <<  "Getting root files of " << type->GetName();
278        <<  "\n " << log4cpp::CategoryStream::ENDLINE;    logger->debug(oss.str().c_str());
279    RootTreeMap::iterator t = TTreeMap.find(type);    RootTreeMap::iterator t = TTreeMap.find(type);
280    if (t != TTreeMap.end()) {    if (t != TTreeMap.end()) {
281      return t->second;      return t->second;
282    } else {    } else {
283      cat <<  log4cpp::Priority::DEBUG      oss.str("");
284          <<  "Reading root files of " << type->GetName()      oss <<  "Reading root files of " << type->GetName();
285          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->debug(oss.str().c_str());
286      EventHeader header(type);      EventHeader header(type);
287      std::string HeaderFileName = GetFileName(&header);      std::string HeaderFileName = GetFileName(&header);
288      TChain* HeaderTree = ReadHeaderTree(type);      TChain* HeaderTree = ReadHeaderTree(type);
# Line 347  void PamelaRun::ReadSubPacket(void* subp Line 320  void PamelaRun::ReadSubPacket(void* subp
320        branch->SetAddress(subpacket);        branch->SetAddress(subpacket);
321        SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));        SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));
322      } else {      } else {
323          cat <<  log4cpp::Priority::ERROR          oss.str("");
324              <<  "Could not find data for " << packet->GetPacketType()->GetName() << "/" << name          oss <<  "Could not find data for " << packet->GetPacketType()->GetName() << "/" << name ;
325              <<  "\n " << log4cpp::CategoryStream::ENDLINE;          logger->error(oss.str().c_str());
326      }      }
327    }    }
328  }  }
# Line 400  void PamelaRun::ReadSubPacket(const Algo Line 373  void PamelaRun::ReadSubPacket(const Algo
373  TTree* PamelaRun::CreateTTree(Algorithm* algo, const SubPacket* packet,  TTree* PamelaRun::CreateTTree(Algorithm* algo, const SubPacket* packet,
374                                std::string name)                                std::string name)
375    throw (std::exception) {    throw (std::exception) {
376    std::string FileName = GetFileName(packet, name);    std::string FileName = "";
377    std::string EventType = packet->GetPacketType()->GetName();    std::string EventType = packet->GetPacketType()->GetName();
378      TFile* File = 0;
379      std::string TreeName = GetTreeName(packet);
380      TTree *tree = 0;
381      FileName = GetFileName(packet, name);
382    CreateDirectoryStructure(FileName.c_str());    CreateDirectoryStructure(FileName.c_str());
383    TFile* File = new TFile(FileName.c_str(), "create");    File = new TFile(FileName.c_str(), "create");
384      tree = new TTree(TreeName.c_str(), algo->GetAlgorithmName().c_str());
385      WritingRootTrees[packet->GetPacketType()].push_back(tree);
386      
387      File->SetCompressionLevel(compression);
388    if (!File->IsOpen()) {    if (!File->IsOpen()) {
389      cat <<  log4cpp::Priority::ERROR      logger->error("Could not open file " + FileName);
390          <<  "Could not open file " << FileName      //throw Exception("Could not open file " + FileName);
         <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
     throw Exception("Could not open file " + FileName);  
391    }    }
392    std::string TreeName = GetTreeName(packet);    logger->debug("Creating file " + FileName + " with Tree " + TreeName);
   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();  
   cat <<  log4cpp::Priority::INFO  
       <<  "Creating file " << FileName << " with Tree " << TreeName  
       <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
393    return tree;    return tree;
394  }  }
395    
# Line 437  TTree* PamelaRun::CreateTTree(Algorithm* Line 407  TTree* PamelaRun::CreateTTree(Algorithm*
407  void PamelaRun::WriteSubPacket(Algorithm *algo, void* subpacket,  void PamelaRun::WriteSubPacket(Algorithm *algo, void* subpacket,
408                                 const TClass *c, std::string name) {                                 const TClass *c, std::string name) {
409    SubPacket *packet = *(SubPacket **)subpacket;    SubPacket *packet = *(SubPacket **)subpacket;
410    cat <<  log4cpp::Priority::DEBUG    oss.str("");
411        <<  "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)"    oss <<  "Register: " << name << " for " << algo->GetAlgorithmName() << " (writing)";
412        <<  "\n " << log4cpp::CategoryStream::ENDLINE;    logger->debug(oss.str().c_str());
413    TTree* HeaderTree = ReadTTree(packet->GetPacketType());    TTree* HeaderTree = ReadTTree(packet->GetPacketType());
   TTree* tree = CreateTTree(algo, packet, name);  
   cat <<  log4cpp::Priority::DEBUG  
       <<  "Branch: " << name << " Class: " << c->GetName()  
       <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
   tree->Branch(name.c_str(), c->GetName(),  subpacket);  
   HeaderTree->AddFriend(tree, tree->GetName());  
   
414    std::string FullName = packet->GetPacketType()->GetName() + "." + name;    std::string FullName = packet->GetPacketType()->GetName() + "." + name;
415    SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));    if (Multiple) {
416            TTree* tree = CreateTTree(algo, packet, name);
417            oss.str("");
418            oss <<  "Branch: " << name << " Class: " << c->GetName();
419            logger->debug(oss.str().c_str());
420            tree->Branch(name.c_str(), c->GetName(),  subpacket);
421            HeaderTree->AddFriend(tree, tree->GetName());
422            SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));
423      } else {
424            std::string nameBranch(name);
425            HeaderTree->Branch(nameBranch.c_str(), c->GetName(),  subpacket);
426            SubPacketAddresses.insert(SubPacketMap::value_type(FullName, packet));
427      }
428  }  }
429    
430  /**  /**
# Line 468  void PamelaRun::WriteSubPacket(Algorithm Line 443  void PamelaRun::WriteSubPacket(Algorithm
443  }  }
444    
445  /**  /**
  * 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) {  
   cat <<  log4cpp::Priority::DEBUG  
       <<  "Creating header tree for " << type->GetName()  
       <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
   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()) {  
     cat <<  log4cpp::Priority::ERROR  
         <<  "Could not open file " << FileName  
         <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
     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();  
   cat <<  log4cpp::Priority::INFO  
       <<  "Creating file " << FileName << " with Tree Pscu"  
       <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
   tree->Branch(GetDefaultBranchName(&header).c_str(),  
                (*subpacket)->Class()->GetName(), subpacket);  
   TTreeMap.insert(RootTreeMap::value_type(type, tree));  
 }  
   
   
 /**  
446   * 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
447   * be used for raw data readers that create the initial event structure.   * be used for raw data readers that create the initial event structure.
448   * @param algo Algorithm that produces this SubPacket.   * @param algo Algorithm that produces this SubPacket.
449   * @param subpacket A pointer to the pointer of the header packet.   * @param subpacket A pointer to the pointer of the header packet.
450   */   */
451  void PamelaRun::WriteHeaders(Algorithm* algo, EventHeader** subpacket) {  void PamelaRun::WriteHeaders(Algorithm* algo, EventHeader** subpacket) {
452        WriteHeader(algo, subpacket, PacketType::PhysEndRun);
453        WriteHeader(algo, subpacket, PacketType::CalibCalPulse1);
454        WriteHeader(algo, subpacket, PacketType::CalibCalPulse2);
455      WriteHeader(algo, subpacket, PacketType::Physics);      WriteHeader(algo, subpacket, PacketType::Physics);
456      WriteHeader(algo, subpacket, PacketType::TabDump);      WriteHeader(algo, subpacket, PacketType::CalibTrkBoth);
457      WriteHeader(algo, subpacket, PacketType::VarDump);      WriteHeader(algo, subpacket, PacketType::CalibTrk1);
458      WriteHeader(algo, subpacket, PacketType::ArrDump);      WriteHeader(algo, subpacket, PacketType::CalibTrk2);
     WriteHeader(algo, subpacket, PacketType::Tmtc);  
     WriteHeader(algo, subpacket, PacketType::Mcmd);  
     WriteHeader(algo, subpacket, PacketType::Log);  
     WriteHeader(algo, subpacket, PacketType::CalibTrk);  
     WriteHeader(algo, subpacket, PacketType::CalibTrg);  
     WriteHeader(algo, subpacket, PacketType::CalibCal);  
     WriteHeader(algo, subpacket, PacketType::CalibTrd);  
459      WriteHeader(algo, subpacket, PacketType::CalibTof);      WriteHeader(algo, subpacket, PacketType::CalibTof);
460      WriteHeader(algo, subpacket, PacketType::CalibS4);      WriteHeader(algo, subpacket, PacketType::CalibS4);
461        WriteHeader(algo, subpacket, PacketType::CalibCalPed);
462        WriteHeader(algo, subpacket, PacketType::Calib1_Ac1);
463        WriteHeader(algo, subpacket, PacketType::Calib1_Ac2);
464        WriteHeader(algo, subpacket, PacketType::Calib2_Ac1);
465        WriteHeader(algo, subpacket, PacketType::Calib2_Ac2);
466      WriteHeader(algo, subpacket, PacketType::RunHeader);      WriteHeader(algo, subpacket, PacketType::RunHeader);
467      WriteHeader(algo, subpacket, PacketType::RunTrailer);      WriteHeader(algo, subpacket, PacketType::RunTrailer);
468      WriteHeader(algo, subpacket, PacketType::ForcedPkt);      WriteHeader(algo, subpacket, PacketType::CalibHeader);
469        WriteHeader(algo, subpacket, PacketType::CalibTrailer);
470        WriteHeader(algo, subpacket, PacketType::InitHeader);
471        WriteHeader(algo, subpacket, PacketType::InitTrailer);
472        WriteHeader(algo, subpacket, PacketType::EventTrk);
473        WriteHeader(algo, subpacket, PacketType::Log);
474        WriteHeader(algo, subpacket, PacketType::VarDump);
475        WriteHeader(algo, subpacket, PacketType::ArrDump);
476        WriteHeader(algo, subpacket, PacketType::TabDump);
477        WriteHeader(algo, subpacket, PacketType::Tmtc);
478        WriteHeader(algo, subpacket, PacketType::Mcmd);
479        WriteHeader(algo, subpacket, PacketType::ForcedFECmd);
480        WriteHeader(algo, subpacket, PacketType::Ac1Init);
481        WriteHeader(algo, subpacket, PacketType::CalInit);
482        WriteHeader(algo, subpacket, PacketType::TrkInit);
483        WriteHeader(algo, subpacket, PacketType::TofInit);
484        WriteHeader(algo, subpacket, PacketType::TrgInit);    
485        WriteHeader(algo, subpacket, PacketType::NdInit);    
486        WriteHeader(algo, subpacket, PacketType::S4Init);    
487        WriteHeader(algo, subpacket, PacketType::Ac2Init);
488        WriteHeader(algo, subpacket, PacketType::CalAlarm);    
489        WriteHeader(algo, subpacket, PacketType::Ac1Alarm);    
490        WriteHeader(algo, subpacket, PacketType::TrkAlarm);    
491        WriteHeader(algo, subpacket, PacketType::TrgAlarm);    
492        WriteHeader(algo, subpacket, PacketType::TofAlarm);
493        WriteHeader(algo, subpacket, PacketType::S4Alarm);
494        WriteHeader(algo, subpacket, PacketType::Ac2Alarm);    
495        WriteHeader(algo, subpacket, PacketType::TsbT);
496        WriteHeader(algo, subpacket, PacketType::TsbB);
497  }  }
498    
499  /**  /**
# Line 543  void PamelaRun::WriteFiles(void) { Line 508  void PamelaRun::WriteFiles(void) {
508      }      }
509    }    }
510    
511      TTree *softinfo = 0;
512      Int_t version=GetYODAver();
513      //Int_t version= 60312;
514      //printf("version = %f \n",version);
515      softinfo = new TTree("SoftInfo","YODA software info");
516      softinfo->Branch("SoftInfo",&version,"version/I");
517      softinfo->Fill();
518    
519    for (TTreeListMap::iterator i = WritingRootTrees.begin();    for (TTreeListMap::iterator i = WritingRootTrees.begin();
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      
527      softinfo->Delete();
528  }  }
529    
530  /**  /**
# Line 557  void PamelaRun::WriteFiles(void) { Line 532  void PamelaRun::WriteFiles(void) {
532   * @param type the package type of the trees to fill.   * @param type the package type of the trees to fill.
533   */   */
534  void PamelaRun::FillTrees(const PacketType* type) {  void PamelaRun::FillTrees(const PacketType* type) {
535    for (TTreeList::iterator j = WritingRootTrees[type].begin();    try{
536         j != WritingRootTrees[type].end(); j++) {      for (TTreeList::iterator j = WritingRootTrees[type].begin();
537      (*j)->Fill();          j != WritingRootTrees[type].end(); j++) {
538      ;              (*j)->Fill();
539        }
540      } catch(Exception exc){
541        logger->fatal("ORRORE!!!");
542    }    }
543  }  }
544    
545    
546    /**
547     * Write the header packet of a specified packet type. This is mainly used
548     * for the raw reader to create the base for the event structure.
549     * @param algo Algorithm that produces this SubPacket.
550     * @param subpacket A pointer to the pointer of the packet.
551     * @param type The packet type.
552     */
553    void PamelaRun::WriteHeader(Algorithm* algo, EventHeader** subpacket,
554                                const PacketType* type) {
555      EventHeader header(type);
556      std::string EventType = (&header)->GetPacketType()->GetName();
557    
558      std::string FileName = "";
559      TFile* File = 0;
560      Long64_t maxsize = 5000000000LL;
561      TTree::SetMaxTreeSize(maxsize);
562      TTree *tree = 0;
563      if ( Multiple ){
564            FileName = GetFileName(&header, GetDefaultBranchName(&header));
565            CreateDirectoryStructure(FileName.c_str());
566            File = new TFile(FileName.c_str(), "create");
567            File->SetCompressionLevel(compression);
568            tree = new TTree("Pscu", algo->GetAlgorithmName().c_str());
569            WritingRootTrees[(&header)->GetPacketType()].push_back(tree);
570            tree->GetCurrentFile()->cd();
571            tree->Branch(GetDefaultBranchName(&header).c_str(),
572                   (*subpacket)->Class()->GetName(), subpacket);
573            TTreeMap.insert(RootTreeMap::value_type(type, tree));
574      } else {
575            if (!Multiple && (SingleFile == NULL)){
576                    //std::string pathDir((char*)getenv("YODA_DATA"));
577                    SingleFile = new TFile((GetPath() + "/" + Run + ".root").c_str(), "update");
578                    SingleFile->SetCompressionLevel(compression);
579            }
580            tree = new TTree(EventType.c_str(), algo->GetAlgorithmName().c_str());
581            WritingRootTrees[type].push_back(tree);
582            tree->GetCurrentFile()->cd();
583            tree->Branch(GetDefaultBranchName(&header).c_str(),
584                   (*subpacket)->Class()->GetName(), subpacket);
585            TTreeMap.insert(RootTreeMap::value_type(type, tree));
586      }
587    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.6.10

  ViewVC Help
Powered by ViewVC 1.1.23