+ if (!fManager) {
+ AliError("No digitisation manager defined");
+ return;
+ }
+
+ // Clear array of deposited energies
+ fEdep.Reset();
+
+ AliRunLoader* runLoader = 0;
+ if (!gAlice) {
+ TString folderName(fManager->GetInputFolderName(0));
+ runLoader = AliRunLoader::GetRunLoader(folderName.Data());
+ if (!runLoader) {
+ AliError(Form("Failed at getting run loader from %s",
+ folderName.Data()));
+ return;
+ }
+ if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
+ runLoader->GetAliRun();
+ }
+ if (!gAlice) {
+ AliError("Can not get Run from Run Loader");
+ return;
+ }
+
+ // Get the AliFMD object
+ fFMD = static_cast<AliFMD*>(gAlice->GetDetector("FMD"));
+ if (!fFMD) {
+ AliError("Can not get FMD from gAlice");
+ return;
+ }
+
+
+ // Loop over input files
+ Int_t nFiles= fManager->GetNinputs();
+ AliFMDDebug(1, (" Digitizing event number %d, got %d inputs",
+ fManager->GetOutputEventNr(), nFiles));
+ for (Int_t inputFile = 0; inputFile < nFiles; inputFile++) {
+ AliFMDDebug(5, ("Now reading input # %d", inputFile));
+ // Get the current loader
+ AliRunLoader* currentLoader =
+ AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
+ if (!currentLoader) {
+ Error("Exec", Form("no run loader for input file # %d", inputFile));
+ continue;
+ }
+
+ // Cache contriutions
+ AliFMDDebug(5, ("Now summing the contributions from input # %d",inputFile));
+
+ // Get the FMD loader
+ AliLoader* inFMD = currentLoader->GetLoader("FMDLoader");
+ // And load the summable digits
+ inFMD->LoadSDigits("READ");
+
+ // Get the tree of summable digits
+ TTree* sdigitsTree = inFMD->TreeS();
+ if (!sdigitsTree) {
+ AliError("No sdigit tree from manager");
+ continue;
+ }
+ if (AliLog::GetDebugLevel("FMD","") >= 10) {
+ TFile* file = sdigitsTree->GetCurrentFile();
+ if (!file) {
+ AliWarning("Input tree has no file!");
+ }
+ else {
+ AliFMDDebug(10, ("Input tree file %s content:", file->GetName()));
+ file->ls();
+ }
+ // AliFMDDebug(5, ("Input tree %s file structure:",
+ // sdigitsTree->GetName()));
+ // sdigitsTree->Print();
+ }
+
+ // Get the FMD branch
+ TBranch* sdigitsBranch = sdigitsTree->GetBranch("FMD");
+ if (!sdigitsBranch) {
+ AliError("Failed to get sdigit branch");
+ return;
+ }
+
+ // Set the branch addresses
+ fFMD->SetTreeAddress();
+
+ // Sum contributions from the sdigits
+ AliFMDDebug(3, ("Will now sum contributions from SDigits"));
+ SumContributions(sdigitsBranch);
+
+ // Unload the sdigits
+ inFMD->UnloadSDigits();
+ }
+
+ TString outFolder(fManager->GetOutputFolderName());
+ AliRunLoader* out = AliRunLoader::GetRunLoader(outFolder.Data());
+ AliLoader* outFMD = out->GetLoader("FMDLoader");
+ if (!outFMD) {
+ AliError("Cannot get the FMDLoader output folder");
+ return;
+ }
+ TTree* outTree = MakeOutputTree(outFMD);
+ if (!outTree) {
+ AliError("Failed to get output tree");
+ return;
+ }
+ // Set the branch address
+ fFMD->SetTreeAddress();
+
+ // And digitize the cached data
+ DigitizeHits();
+
+ // Fill the tree
+ Int_t write = outTree->Fill();
+ AliFMDDebug(5, ("Wrote %d bytes to digit tree", write));
+
+ // Store the digits
+ StoreDigits(outFMD);